Java Code Examples for htsjdk.variant.variantcontext.Allele#create()
The following examples show how to use
htsjdk.variant.variantcontext.Allele#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HaplotypeProbabilitiesTest.java From picard with MIT License | 6 votes |
@Test(dataProvider = "dataTestpEvidenceGivenPriorFromGLs") public void testpEvidenceGivenPriorFromGLs(final HaplotypeProbabilitiesFromGenotypeLikelihoods hp, final List<Snp> snps, final List<Boolean> swaps, final List<double[]> logLikelihoods) { for (int i = 0; i < snps.size(); ++i) { final Allele a = Allele.create(swaps.get(i) ? snps.get(i).getAllele2() : snps.get(i).getAllele1()); final Allele b = Allele.create(swaps.get(i) ? snps.get(i).getAllele1() : snps.get(i).getAllele2()); hp.addToLogLikelihoods(snps.get(i), CollectionUtil.makeList(a, b), logLikelihoods.get(i)); } final double[] postLogLikelihood = new double[nGenotypes]; for (final int genotype:genotypes) { postLogLikelihood[genotype] = log10(hp.getHaplotype().getHaplotypeFrequency(genotype)); for (int i = 0; i < logLikelihoods.size(); i++) { final double[] genotypeLogLikelihoods = logLikelihoods.get(i); Assert.assertEquals(genotypeLogLikelihoods.length, nGenotypes); final int swappedGenotype = swaps.get(i) ? nGenotypes - genotype - 1 : genotype; postLogLikelihood[genotype] += genotypeLogLikelihoods[swappedGenotype]; } } assertEqualDoubleArrays(hp.getPosteriorProbabilities(), MathUtil.pNormalizeLogProbability(postLogLikelihood), 1e-10); }
Example 2
Source File: EventMap.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Create a block substitution out of two variant contexts that start at the same position * * vc1 can be SNP, and vc2 can then be either a insertion or deletion. * If vc1 is an indel, then vc2 must be the opposite type (vc1 deletion => vc2 must be an insertion) * * @param vc1 the first variant context we want to merge * @param vc2 the second * @return a block substitution that represents the composite substitution implied by vc1 and vc2 */ protected VariantContext makeBlock(final VariantContext vc1, final VariantContext vc2) { Utils.validateArg( vc1.getStart() == vc2.getStart(), () -> "vc1 and 2 must have the same start but got " + vc1 + " and " + vc2); Utils.validateArg( vc1.isBiallelic(), "vc1 must be biallelic"); if ( ! vc1.isSNP() ) { Utils.validateArg ( (vc1.isSimpleDeletion() && vc2.isSimpleInsertion()) || (vc1.isSimpleInsertion() && vc2.isSimpleDeletion()), () -> "Can only merge single insertion with deletion (or vice versa) but got " + vc1 + " merging with " + vc2); } else { Utils.validateArg(!vc2.isSNP(), () -> "vc1 is " + vc1 + " but vc2 is a SNP, which implies there's been some terrible bug in the cigar " + vc2); } final Allele ref, alt; final VariantContextBuilder b = new VariantContextBuilder(vc1); if ( vc1.isSNP() ) { // we have to repair the first base, so SNP case is special cased if ( vc1.getReference().equals(vc2.getReference()) ) { // we've got an insertion, so we just update the alt to have the prev alt ref = vc1.getReference(); alt = Allele.create(vc1.getAlternateAllele(0).getDisplayString() + vc2.getAlternateAllele(0).getDisplayString().substring(1), false); } else { // we're dealing with a deletion, so we patch the ref ref = vc2.getReference(); alt = vc1.getAlternateAllele(0); b.stop(vc2.getEnd()); } } else { final VariantContext insertion = vc1.isSimpleInsertion() ? vc1 : vc2; final VariantContext deletion = vc1.isSimpleInsertion() ? vc2 : vc1; ref = deletion.getReference(); alt = insertion.getAlternateAllele(0); b.stop(deletion.getEnd()); } return b.alleles(Arrays.asList(ref, alt)).make(); }
Example 3
Source File: TandemRepeatUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test public void testUsingVCNoRepeat() { // - [ref] / ATC from 20-20 final String insLoc = "chr1"; final int insLocStart = 6; final int insLocStop = 6; final byte[] refBytes = "GTATCATCATCGGA".getBytes(); final Allele nullR = Allele.create("A", true); final Allele atc = Allele.create("AATC", false); // A*,ATC, context = ATC ATC ATC : (ATC)3 -> (ATC)4 final VariantContext vc = new VariantContextBuilder("foo", insLoc, insLocStart, insLocStop, Arrays.asList(nullR,atc)).make(); final SimpleInterval interval= new SimpleInterval(insLoc, insLocStart, insLocStop); final SimpleInterval interval1 = new SimpleInterval(insLoc, 1, refBytes.length); final ReferenceBases ref1 = new ReferenceBases(refBytes, interval1); final SAMSequenceDictionary dict = new SAMSequenceDictionary(Arrays.asList(new SAMSequenceRecord(insLoc, refBytes.length))); final ReferenceContext ref = new ReferenceContext(ReferenceDataSource.of(ref1, dict), interval, 0, 20); final InfoFieldAnnotation ann = new TandemRepeat(); final Map<String, Object> a = ann.annotate(ref, vc, null); Assert.assertTrue(a.isEmpty()); }
Example 4
Source File: ReadThreadingAssemblerUnitTest.java From gatk-protected with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(dataProvider = "AssembleIntervalsWithVariantData") public void testAssembleRefAndInsertion(final ReadThreadingAssembler assembler, final SimpleInterval loc, final int nReadsToUse, final int variantSite) { final byte[] refBases = seq.getSubsequenceAt(loc.getContig(), loc.getStart(), loc.getEnd()).getBases(); for ( int insertionLength = 1; insertionLength < 10; insertionLength++ ) { final Allele refBase = Allele.create(refBases[variantSite], false); final Allele altBase = Allele.create(new String(refBases).substring(variantSite, variantSite + insertionLength + 1), true); final VariantContextBuilder vcb = new VariantContextBuilder("x", loc.getContig(), variantSite, variantSite + insertionLength, Arrays.asList(refBase, altBase)); testAssemblyWithVariant(assembler, refBases, loc, nReadsToUse, vcb.make()); } }
Example 5
Source File: FuncotationMapUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static VariantContext createVariantContext(final String contig, final int start, final int end, final String ref, final String alt, final String referenceFileName) { final Allele refAllele = Allele.create(ref, true); final Allele altAllele = Allele.create(alt); final VariantContextBuilder variantContextBuilder = new VariantContextBuilder( referenceFileName, contig, start, end, Arrays.asList(refAllele, altAllele) ); return variantContextBuilder.make(); }
Example 6
Source File: ReadThreadingAssemblerUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Test(dataProvider = "AssembleIntervalsWithVariantData") public void testAssembleRefAndDeletion(final ReadThreadingAssembler assembler, final SimpleInterval loc, final int nReadsToUse, final int variantSite) { final byte[] refBases = seq.getSubsequenceAt(loc.getContig(), loc.getStart(), loc.getEnd()).getBases(); for ( int deletionLength = 1; deletionLength < 10; deletionLength++ ) { final Allele refBase = Allele.create(new String(refBases).substring(variantSite, variantSite + deletionLength + 1), true); final Allele altBase = Allele.create(refBase.getBases()[0], false); final VariantContextBuilder vcb = new VariantContextBuilder("x", loc.getContig(), variantSite, variantSite + deletionLength, Arrays.asList(refBase, altBase)); testAssemblyWithVariant(assembler, refBases, loc, nReadsToUse, vcb.make()); } }
Example 7
Source File: FuncotatorUtils.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * Get the strand-corrected (reverse complemented) {@link Allele} for the given {@link Allele} and {@link Strand}. * @param allele The {@link Allele} to correct for strandedness. * @param strand The {@link Strand} on which the given {@code allele} lies. Must be valid as per {@link #assertValidStrand(Strand)} * @return The {@link Allele} with sequence corrected for strand. */ public static Allele getStrandCorrectedAllele(final Allele allele, final Strand strand) { assertValidStrand(strand); if ( strand == Strand.POSITIVE ) { return Allele.create(allele, false); } else { return Allele.create(ReadUtils.getBasesReverseComplement(allele.getBases()), false); } }
Example 8
Source File: SimpleSVType.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
public Insertion(final NovelAdjacencyAndAltHaplotype novelAdjacencyAndAltHaplotype, final ReferenceMultiSparkSource reference) { super(novelAdjacencyAndAltHaplotype.getLeftJustifiedLeftRefLoc().getContig(), novelAdjacencyAndAltHaplotype.getLeftJustifiedLeftRefLoc().getStart(), getEnd(novelAdjacencyAndAltHaplotype), getIDString(novelAdjacencyAndAltHaplotype), Allele.create(getRefBases(novelAdjacencyAndAltHaplotype, reference), true), Allele.create(createBracketedSymbAlleleString(GATKSVVCFConstants.SYMB_ALT_ALLELE_INS)), getLength(novelAdjacencyAndAltHaplotype), noExtraAttributes); }
Example 9
Source File: MergePedIntoVcf.java From picard with MIT License | 5 votes |
private Allele formatAllele(final String alleleA) { if (alleleA.equals(SPAN_DEL_STRING)) { return Allele.SPAN_DEL; } else if (alleleA.contains(SPAN_DEL_STRING)) { return Allele.create(alleleA.replace(SPAN_DEL_STRING.charAt(0), ' ').trim(), true); } else { return Allele.create(alleleA, false); } }
Example 10
Source File: AnnotatedIntervalToSegmentVariantContextConverter.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
private static Allele convertActualSegCallToAllele(final CalledCopyRatioSegment.Call call) { if (call == null) { return Allele.UNSPECIFIED_ALTERNATE_ALLELE; } switch (call) { case DELETION: return Allele.create(SimpleSVType.createBracketedSymbAlleleString("DEL"), false); case AMPLIFICATION: return Allele.create(SimpleSVType.createBracketedSymbAlleleString("INS"), false); case NEUTRAL: return COPY_NEUTRAL_ALLELE; default: throw new GATKException.ShouldNeverReachHereException(call.getOutputString() + " is not represented in conversion to variant context."); } }
Example 11
Source File: SimpleSVType.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
@VisibleForTesting // TODO: 6/12/18 note the following implementation sets POS and REF at the anchor base, which is not requested by the VCF spec // TODO: 6/12/18 also, this interface lets one call inversion with SVLEN !=0, which is not the same as VCF spec examples public Inversion(final NovelAdjacencyAndAltHaplotype novelAdjacencyAndAltHaplotype, final int svLength, final ReferenceMultiSparkSource reference) { super(novelAdjacencyAndAltHaplotype.getLeftJustifiedLeftRefLoc().getContig(), novelAdjacencyAndAltHaplotype.getLeftJustifiedLeftRefLoc().getStart(), novelAdjacencyAndAltHaplotype.getLeftJustifiedRightRefLoc().getEnd(), getIDString(novelAdjacencyAndAltHaplotype), Allele.create(extractRefBases(novelAdjacencyAndAltHaplotype.getLeftJustifiedLeftRefLoc(), reference), true), Allele.create(createBracketedSymbAlleleString(GATKSVVCFConstants.SYMB_ALT_ALLELE_INV)), svLength, Collections.singletonMap((novelAdjacencyAndAltHaplotype.getStrandSwitch() == StrandSwitch.FORWARD_TO_REVERSE) ? GATKSVVCFConstants.INV55 : GATKSVVCFConstants.INV33, true)); }
Example 12
Source File: PairHMMLikelihoodCalculationEngineUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
@BeforeClass public void setup() { // alleles Aref = Allele.create("A", true); Cref = Allele.create("C", true); T = Allele.create("T"); C = Allele.create("C"); G = Allele.create("G"); ATC = Allele.create("ATC"); ATCATC = Allele.create("ATCATC"); }
Example 13
Source File: GencodeFuncotationFactoryUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Test(dataProvider = "provideForCreateNonBasicFuncotations") void createNonBasicFuncotations(final int start, final int end) { final String contig = "chr19"; final SimpleInterval variantInterval = new SimpleInterval( contig, start, end ); final Allele refAllele = Allele.create("C", true); final Allele altAllele = Allele.create("G", false); final VariantContextBuilder variantContextBuilder = new VariantContextBuilder( FuncotatorReferenceTestUtils.retrieveHg19Chr19Ref(), contig, start, end, Arrays.asList(refAllele, altAllele) ); final VariantContext variantContext = variantContextBuilder.make(); // Get our gene feature iterator: final CloseableTribbleIterator<GencodeGtfFeature> gtfFeatureIterator; try { gtfFeatureIterator = muc16NonBasicFeatureReader.query(contig, start, end); } catch (final IOException ex) { throw new GATKException("Could not finish the test!", ex); } // Get the gene. // We know the first gene is the right one - the gene in question is the MUC16 gene: final GencodeGtfGeneFeature gene = (GencodeGtfGeneFeature) gtfFeatureIterator.next(); final ReferenceContext referenceContext = new ReferenceContext(refDataSourceHg19Ch19, variantInterval ); // Create a factory for our funcotations: try (final GencodeFuncotationFactory funcotationFactory = new GencodeFuncotationFactory( IOUtils.getPath(FuncotatorTestConstants.GENCODE_DATA_SOURCE_FASTA_PATH_HG19), "VERSION", GencodeFuncotationFactory.DEFAULT_NAME, FuncotatorArgumentDefinitions.TRANSCRIPT_SELECTION_MODE_DEFAULT_VALUE, new HashSet<>(), new LinkedHashMap<>(), createFeatureInputForMuc16Ds(GencodeFuncotationFactory.DEFAULT_NAME), "HG19")) { // Generate our funcotations: final List<Feature> featureList = new ArrayList<>(); featureList.add( gene ); final List<Funcotation> funcotations = funcotationFactory.createFuncotationsOnVariant(variantContext, referenceContext, featureList); // Make sure we get what we expected (a single IGR funcotation): Assert.assertEquals(funcotations.size(), 1); Assert.assertTrue(funcotations.get(0) instanceof GencodeFuncotation); final GencodeFuncotation gencodeFuncotation = (GencodeFuncotation)funcotations.get(0); Assert.assertEquals(gencodeFuncotation.getVariantClassification(), GencodeFuncotation.VariantClassification.IGR); Assert.assertNull(gencodeFuncotation.getHugoSymbol()); } }
Example 14
Source File: AmberVCF.java From hmftools with GNU General Public License v3.0 | 4 votes |
private static List<Allele> alleles(@NotNull final TumorBAF baf) { final Allele ref = Allele.create(baf.ref(), true); final Allele alt = Allele.create(baf.alt(), false); return Lists.newArrayList(ref, alt); }
Example 15
Source File: GencodeFuncotationFactoryUnitTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
@DataProvider Object[][] provideDataForTestCalculateGcContent() { // Base Position: // //1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890 //0000000001111111111222222222233333333334444444444555555555566666666667777777777888888888899999999990 //0000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000001 final String seq = "AAAAATTTTTGGGGGCCCCCAAAAATTTTTGGGGGCCCCCAAAAATTTTTGGGGGCCCCCAAAAATTTTTGGGGGCCCCCAAAAATTTTTGGGGGCCCCC"; final String contig = "test"; return new Object[][] { // MNPs: { Allele.create("A", true), Allele.create("G"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 1, 1), 1, 0.0 }, { Allele.create("A", true), Allele.create("G"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 1, 1), 9, 0.0 }, { Allele.create("A", true), Allele.create("G"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 1, 1), 10, 1.0/11.0 }, { Allele.create("C", true), Allele.create("G"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,100,100), 1, 1 }, { Allele.create("C", true), Allele.create("G"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,100,100), 9, 1 }, { Allele.create("C", true), Allele.create("G"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,100,100), 10, 10.0/11.0 }, { Allele.create("T", true), Allele.create("G"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 50, 50), 1, 1.0/3.0 }, { Allele.create("T", true), Allele.create("G"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 50, 50), 9, 9.0/19.0 }, { Allele.create("T", true), Allele.create("G"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 50, 50), 10, 11.0/21.0 }, { Allele.create("T", true), Allele.create("G"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 50, 50), 50, 50.0/100.0 }, { Allele.create("AAAAA", true), Allele.create("GGGGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 1, 5), 1, 0.0 }, { Allele.create("AAAAA", true), Allele.create("GGGGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 1, 5), 9, 4.0 / 14.0 }, { Allele.create("AAAAA", true), Allele.create("GGGGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 1, 5), 10, 5.0/15.0 }, { Allele.create("GCCCCC", true), Allele.create("AGGGGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,95,100), 1, 1 }, { Allele.create("GCCCCC", true), Allele.create("AGGGGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,95,100), 9, 10.0/15.0 }, { Allele.create("GCCCCC", true), Allele.create("AGGGGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,95,100), 10, 10.0/16.0 }, { Allele.create("TGGGGG", true), Allele.create("AAAAAA"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,50, 55), 1, 6.0/8.0 }, { Allele.create("TGGGGG", true), Allele.create("AAAAAA"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,50, 55), 9, 10.0/24.0 }, { Allele.create("TGGGGG", true), Allele.create("AAAAAA"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,50, 55), 10, 11.0/26.0 }, { Allele.create("TGGGGG", true), Allele.create("AAAAAA"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,50, 55), 50, 50.0/100.0 }, // Insertions: { Allele.create("A", true), Allele.create("AG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 1, 1), 1, 0.0 }, { Allele.create("A", true), Allele.create("AGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 1, 1), 9, 0.0 }, { Allele.create("A", true), Allele.create("AGGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 1, 1), 10, 1.0/11.0 }, { Allele.create("C", true), Allele.create("CG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,100,100), 1, 1 }, { Allele.create("C", true), Allele.create("CGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,100,100), 9, 1 }, { Allele.create("C", true), Allele.create("CGGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,100,100), 10, 1 }, { Allele.create("T", true), Allele.create("TG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 50, 50), 1, 1.0/2.0 }, { Allele.create("T", true), Allele.create("TGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 50, 50), 9, 9.0/18.0 }, { Allele.create("T", true), Allele.create("TGGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 50, 50), 10, 10.0/20.0 }, { Allele.create("T", true), Allele.create("TGGGG"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 50, 50), 49, 49.0/98.0 }, // Deletions: { Allele.create("AAAAA", true), Allele.create("A"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig, 1, 5), 10, 5.0/15.0 }, { Allele.create("GCCCCC", true), Allele.create("G"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,95,100), 10, 10.0/15.0 }, { Allele.create("TGGGGG", true), Allele.create("T"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,50, 55), 10, 10.0/25.0 }, { Allele.create("TG", true), Allele.create("T"), FuncotatorTestUtils.createReferenceContextFromBasesAndLocation(seq, contig,50, 51), 10, 10.0/21.0 }, }; }
Example 16
Source File: LiftoverVcfTest.java From picard with MIT License | 4 votes |
@DataProvider(name = "noCallAndSymbolicData") public Iterator<Object[]> noCallAndSymbolicData() { final VariantContextBuilder builder = new VariantContextBuilder().source("test1").chr("chr1").attribute("TEST_ATTRIBUTE", 1).attribute("TEST_ATTRIBUTE2", "Hi").attribute("TEST_ATTRIBUTE3", new double[]{1.2, 2.1}); final VariantContextBuilder result_builder = new VariantContextBuilder().source("test1").chr("chr1").attribute("TEST_ATTRIBUTE", 1).attribute("TEST_ATTRIBUTE2", "Hi").attribute("TEST_ATTRIBUTE3", new double[]{1.2, 2.1}); result_builder.attribute(LiftoverVcf.ORIGINAL_CONTIG, "chr1"); final GenotypeBuilder genotypeBuilder = new GenotypeBuilder("test1"); final GenotypeBuilder resultGenotypeBuilder = new GenotypeBuilder("test1"); final List<Object[]> tests = new ArrayList<>(); final Allele CRef = Allele.create("C", true); final Allele GRef = Allele.create("G", true); final Allele T = Allele.create("T", false); final Allele A = Allele.create("A", false); final Allele DEL = Allele.create("*", false); final Allele nonRef = Allele.create("<*>", false); final LiftOver liftOver = new LiftOver(TWO_INTERVAL_CHAIN_FILE); final LiftOver liftOverRC = new LiftOver(CHAIN_FILE); builder.source("test1"); int start = 10; builder.start(start).stop(start).alleles(CollectionUtil.makeList(CRef, T, nonRef)); result_builder.start(start).stop(start).alleles(CollectionUtil.makeList(CRef, T, nonRef)); genotypeBuilder.alleles(CollectionUtil.makeList(Allele.create("."), Allele.create("."))); resultGenotypeBuilder.alleles(CollectionUtil.makeList(Allele.create("."), Allele.create("."))); builder.genotypes(genotypeBuilder.make()); result_builder.genotypes(resultGenotypeBuilder.make()); result_builder.attribute(LiftoverVcf.ORIGINAL_START, start); tests.add(new Object[]{liftOver, builder.make(), result_builder.make(), false}); builder.source("test2"); builder.start(start).stop(start).alleles(CollectionUtil.makeList(CRef, T, DEL)); result_builder.start(start).stop(start).alleles(CollectionUtil.makeList(CRef, T, DEL)); result_builder.attribute(LiftoverVcf.ORIGINAL_START, start); genotypeBuilder.alleles(CollectionUtil.makeList(T, DEL)); resultGenotypeBuilder.alleles(CollectionUtil.makeList(T, DEL)); builder.genotypes(genotypeBuilder.make()); result_builder.genotypes(resultGenotypeBuilder.make()); tests.add(new Object[]{liftOver, builder.make(), result_builder.make(), false}); //reverse complement builder.source("test3"); int offset = 3; start = CHAIN_SIZE - offset; int liftedStart = 1 + offset; builder.start(start).stop(start).alleles(CollectionUtil.makeList(CRef, T, DEL, nonRef)); result_builder.start(liftedStart).stop(liftedStart).alleles(CollectionUtil.makeList(GRef, A, DEL, nonRef)); result_builder.attribute(LiftoverVcf.ORIGINAL_START, start); result_builder.attribute(LiftoverVcf.ORIGINAL_ALLELES, LiftoverUtils.allelesToStringList(builder.getAlleles())); result_builder.attribute(LiftoverUtils.REV_COMPED_ALLELES, true); genotypeBuilder.alleles(CollectionUtil.makeList(T, DEL)); resultGenotypeBuilder.alleles(CollectionUtil.makeList(A, DEL)); builder.genotypes(genotypeBuilder.make()); result_builder.genotypes(resultGenotypeBuilder.make()); tests.add(new Object[]{liftOverRC, builder.make(), result_builder.make(), true}); builder.source("test4"); offset = 4; start = CHAIN_SIZE - offset; liftedStart = 1 + offset; builder.start(start).stop(start).alleles(CollectionUtil.makeList(CRef, T, nonRef)); result_builder.start(liftedStart).stop(liftedStart).alleles(CollectionUtil.makeList(GRef, A, nonRef)); result_builder.attribute(LiftoverVcf.ORIGINAL_START, start); result_builder.attribute(LiftoverVcf.ORIGINAL_ALLELES, LiftoverUtils.allelesToStringList(builder.getAlleles())); genotypeBuilder.alleles(CollectionUtil.makeList(T, Allele.NO_CALL)); resultGenotypeBuilder.alleles(CollectionUtil.makeList(A, Allele.NO_CALL)); builder.genotypes(genotypeBuilder.make()); result_builder.genotypes(resultGenotypeBuilder.make()); tests.add(new Object[]{liftOverRC, builder.make(), result_builder.make(), true}); return tests.iterator(); }
Example 17
Source File: ValidateVariants.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
@Override public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext ref, final FeatureContext featureContext) { if (DO_NOT_VALIDATE_FILTERED && vc.isFiltered()) { return; } // get the true reference allele final Allele reportedRefAllele = vc.getReference(); final int refLength = reportedRefAllele.length(); final Allele observedRefAllele = hasReference() ? Allele.create(Arrays.copyOf(ref.getBases(), refLength)) : null; final Set<String> rsIDs = getRSIDs(featureContext); if (VALIDATE_GVCF) { final SimpleInterval refInterval = ref.getInterval(); validateVariantsOrder(vc); // GenomeLocSortedSet will automatically merge intervals that are overlapping when setting `mergeIfIntervalOverlaps` // to true. In a GVCF most blocks are adjacent to each other so they wouldn't normally get merged. We check // if the current record is adjacent to the previous record and "overlap" them if they are so our set is as // small as possible while still containing the same bases. final int start = (previousInterval != null && previousInterval.overlapsWithMargin(refInterval, 1)) ? previousInterval.getStart() : refInterval.getStart(); final int end = (previousInterval != null && previousInterval.overlapsWithMargin(refInterval, 1)) ? Math.max(previousInterval.getEnd(), vc.getEnd()) : vc.getEnd(); final GenomeLoc possiblyMergedGenomeLoc = genomeLocSortedSet.getGenomeLocParser().createGenomeLoc(refInterval.getContig(), start, end); genomeLocSortedSet.add(possiblyMergedGenomeLoc, true); previousInterval = new SimpleInterval(possiblyMergedGenomeLoc); previousStart = vc.getStart(); validateGVCFVariant(vc); } for (final ValidationType t : validationTypes) { try{ applyValidationType(vc, reportedRefAllele, observedRefAllele, rsIDs, t); } catch (TribbleException e) { throwOrWarn(new UserException.FailsStrictValidation(drivingVariantFile, t, e.getMessage())); } } }
Example 18
Source File: AlleleListUnitTester.java From gatk with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Generate testing alleles. Guarantees that alleles are unique. * * <p> * Basically all are random alleles given the maximum allele length. * </p> * * <p> * So with a low max-allele-length and high allele-count you can force repeats. * </p> * * @param alleleCount number of alleles to generate. * @param maxAlleleLength the maximum length of the allele in bases. * * @throws RuntimeException if {@code alleleCount} is negative or {@code maxAlleleLength} is less than 1. * @return never {@code null}. */ public static Allele[] generateRandomUniqueAlleles(final int alleleCount, final int maxAlleleLength) { Utils.validateArg(maxAlleleLength > 0, "the max allele length cannot be less than 1"); final Set<Allele> set = new LinkedHashSet<>(alleleCount); while(set.size() < alleleCount){ final int alleleLength = rnd.nextInt(maxAlleleLength) + 1; final Allele result = Allele.create(rndDNA.nextBases(alleleLength)); set.add(result); } return set.toArray(new Allele[set.size()]); }
Example 19
Source File: AlleleListUnitTester.java From gatk with BSD 3-Clause "New" or "Revised" License | 3 votes |
/** * Generate testing alleles. * * <p> * Basically all are random alleles given the maximum allele length. * </p> * * <p> * So with a low max-allele-length and high allele-count you can force repeats. * </p> * * @param alleleCount number of alleles to generate. * @param maxAlleleLength the maximum length of the allele in bases. * * @throws RuntimeException if {@code alleleCount} is negative or {@code maxAlleleLength} is less than 1. * @return never {@code null}. */ public static Allele[] generateRandomAlleles(final int alleleCount, final int maxAlleleLength) { if (maxAlleleLength < 1) throw new IllegalArgumentException("the max allele length cannot be less than 1"); final Allele[] result = new Allele[alleleCount]; for (int i = 0; i < alleleCount; i++) { final int alleleLength = rnd.nextInt(maxAlleleLength) + 1; result[i] = Allele.create(rndDNA.nextBases(alleleLength)); } return result; }