public VariantContextBuilder alleles(final List<String> alleleStrings) { final List<Allele> alleles = new ArrayList<>(alleleStrings.size()); for ( int i = 0; i < alleleStrings.size(); i++ ) { alleles.add(Allele.create(alleleStrings.get(i), i == 0)); } return alleles(alleles); }
private VariantContext addNonRefSymbolicAllele(final VariantContext mergedVC) { final VariantContextBuilder vcb = new VariantContextBuilder(mergedVC); final List<Allele> originalList = mergedVC.getAlleles(); final List<Allele> alleleList = new ArrayList<>(originalList.size() + 1); alleleList.addAll(mergedVC.getAlleles()); alleleList.add(GATKVCFConstants.NON_REF_SYMBOLIC_ALLELE); vcb.alleles(alleleList); return vcb.make(); }
public VariantContext createEmptyContext(VariantContext other, List<String> samples) { VariantContextBuilder builder = new VariantContextBuilder(); // set the alleles to be the same builder.alleles(other.getAlleles()); builder.loc(other.getChr(),other.getStart(),other.getEnd()); // set all genotypes to empty List<Genotype> genotypes = new ArrayList<Genotype>(samples.size()); for ( String sample : samples ) genotypes.add(GenotypeBuilder.create(sample, new ArrayList<Allele>(0))); builder.genotypes(genotypes); return builder.make(); }
@DataProvider() public Iterator<Object[]> variantProvider() { final VariantContextBuilder vc_builder = new VariantContextBuilder("test", "chr1", 1, 1, Arrays.asList(refA, G)); final List<Object[]> variants = new ArrayList<Object[]>(10); // unfiltered variants.add(new Object[]{vc_builder.alleles(Arrays.asList(refA, G)).make(), true}); // passing variants.add(new Object[]{vc_builder.alleles(Arrays.asList(refA, G)).passFilters().make(), true}); // failing variants.add(new Object[]{vc_builder.alleles(Arrays.asList(refA, G)).filters(Collections.singleton("FILTER")).make(), false}); return variants.iterator(); }
@Test public void testMultipleSNPAlleleOrdering() { final List<Allele> allelesNaturalOrder = Arrays.asList(Aref, C, T); final List<Allele> allelesUnnaturalOrder = Arrays.asList(Aref, T, C); VariantContext naturalVC = snpBuilder.alleles(allelesNaturalOrder).make(); VariantContext unnaturalVC = snpBuilder.alleles(allelesUnnaturalOrder).make(); Assert.assertEquals(new ArrayList<>(naturalVC.getAlleles()), allelesNaturalOrder); Assert.assertEquals(new ArrayList<>(unnaturalVC.getAlleles()), allelesUnnaturalOrder); }
private static void addGenotypesToTestData() { final ArrayList<VariantContext> sites = new ArrayList<VariantContext>(); sites.add(builder().alleles("A").make()); sites.add(builder().alleles("A", "C", "T").make()); sites.add(builder().alleles("A", "AC").make()); sites.add(builder().alleles("A", "ACAGT").make()); for ( VariantContext site : sites ) { addGenotypes(site); } }
public static VariantContext subsetAlleles(final VariantContext originalVc, final List<Allele> allelesToKeep) { VariantContextBuilder vcBuilder = new VariantContextBuilder(originalVc).alleles(allelesToKeep); GenotypesContext newGenotypes = subsetAlleles(originalVc.getGenotypes(), originalVc.getAlleles(), allelesToKeep); vcBuilder.genotypes(newGenotypes); return vcBuilder.make(); }
@Test public void testCreateAlleleMapping(){ final List<Allele> alleles = Arrays.asList(Aref,Symbolic,T); final VariantContext vc = new VariantContextBuilder().chr("chr1").alleles(alleles).make(); Map<Allele, Allele> map = GATKVariantContextUtils.createAlleleMapping(ATref, vc, alleles); final List<Allele> expectedAlleles = Arrays.asList(Allele.create("<Symbolic>", false), Allele.create("TT", false)); for ( int i = 0; i < vc.getAlternateAlleles().size(); i++ ){ Assert.assertEquals(map.get(vc.getAlternateAlleles().get(i)), expectedAlleles.get(i)); } }
/** Makes a new VariantContext with only the desired samples. */ private static VariantContext subsetToSamplesWithOriginalAnnotations(final VariantContext ctx, final Set<String> samples) { final VariantContextBuilder builder = new VariantContextBuilder(ctx); final GenotypesContext newGenotypes = ctx.getGenotypes().subsetToSamples(samples); builder.alleles(ctx.getAlleles()); return builder.genotypes(newGenotypes).make(); } }
@Test(expectedExceptions = IllegalStateException.class) public void testCreateAlleleMappingException(){ final List<Allele> alleles = Arrays.asList(Aref, Symbolic, T); final VariantContext vc = new VariantContextBuilder().chr("chr1").alleles(alleles).make(); // Throws an exception if the ref allele length <= ref allele length to extend Map<Allele, Allele> map = GATKVariantContextUtils.createAlleleMapping(Aref, vc, alleles); }
public static VariantContext subsetAlleles(final VariantContext originalVc, final List<Allele> allelesToKeep) { VariantContextBuilder vcBuilder = new VariantContextBuilder(originalVc).alleles(allelesToKeep); GenotypesContext newGenotypes = subsetAlleles(originalVc.getGenotypes(), originalVc.getAlleles(), allelesToKeep); vcBuilder.genotypes(newGenotypes); return vcBuilder.make(); }
/** Makes a new VariantContext with only the desired samples. */ private static VariantContext subsetToSamplesWithOriginalAnnotations(final VariantContext ctx, final Set<String> samples) { final VariantContextBuilder builder = new VariantContextBuilder(ctx); final GenotypesContext newGenotypes = ctx.getGenotypes().subsetToSamples(samples); builder.alleles(ctx.getAlleles()); return builder.genotypes(newGenotypes).make(); } }
@Test public void testInsertionDeletionBecomingNullAllele() { final byte[] ref = "CAAA".getBytes(); final GenomeLoc refLoc = genomeLocParser.createGenomeLoc("2", 1700, 1700 + ref.length); // insertion + deletion results in a null allele, should return false final VariantContext thisVC = new VariantContextBuilder().loc("2", 1700, 1701).alleles("CA","C").make(); final VariantContext nextVC = new VariantContextBuilder().loc("2", 1703, 1703).alleles("A","AA").make(); final VariantContext mergedVC = merger.createMergedVariantContext(thisVC, nextVC, ref, refLoc); Assert.assertNull(mergedVC, "Insertion deletion becoming a null allele should return a null variant context"); }
@Test(dataProvider = "totalPloidyData") public void testTotalPloidy(final int[] ploidies, final int defaultPloidy, final int expected) { final Genotype[] genotypes = new Genotype[ploidies.length]; final List<Allele> vcAlleles = Arrays.asList(Aref,C); for (int i = 0; i < genotypes.length; i++) genotypes[i] = new GenotypeBuilder().alleles(GATKVariantContextUtils.noCallAlleles(ploidies[i])).make(); final VariantContext vc = new VariantContextBuilder().chr("seq1").genotypes(genotypes).alleles(vcAlleles).make(); Assert.assertEquals(GATKVariantContextUtils.totalPloidy(vc,defaultPloidy),expected," " + defaultPloidy + " " + Arrays.toString(ploidies)); }
@Test public void testReverseComplementFailureDoesNotErrorOut() { final VariantContextBuilder builder = new VariantContextBuilder().source("test").loc("chr1", 1, 4); final Allele originalRef = Allele.create("CCCC", true); final Allele originalAlt = Allele.create("C", false); builder.alleles(Arrays.asList(originalRef, originalAlt)); final Interval interval = new Interval("chr1", 1, 4, true, "test "); final String reference = "ATGATGATGA"; final ReferenceSequence refSeq = new ReferenceSequence("chr1", 10, reference.getBytes()); // we don't actually care what the results are here -- we just want to make sure that it doesn't fail final VariantContextBuilder result = LiftoverUtils.reverseComplementVariantContext(builder.make(), interval, refSeq); }
@Test public void TestAllGenotypesAreUnfilteredAndCalled(){ final VariantContext vc = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype1).make(); Assert.assertTrue(PhasingUtils.allGenotypesAreUnfilteredAndCalled(vc)); }
@Test public void TestSomeSampleHasDoubleNonReferenceAlleleTrue(){ Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList2).make(); VariantContext vc = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype).make(); Assert.assertTrue(PhasingUtils.someSampleHasDoubleNonReferenceAllele(vc1, vc)); }
@Test public void TestMergeIntoMNPvalidationDiffSampleNames() { final Genotype genotype = new GenotypeBuilder().name("sample1").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList1).make(); final VariantContext vc = new VariantContextBuilder().chr(contig).id("id1").source("TC").start(start).stop(start).alleles(alleleList1).genotypes(genotype).make(); Assert.assertFalse(PhasingUtils.mergeIntoMNPvalidationCheck(genomeLocParser, vc, vc2)); }
@Test public void TestDoubleAllelesSegregatePerfectlyAmongSamples(){ final Genotype genotype = new GenotypeBuilder().name("sample").attribute("HP", new String[]{"10-1", "10-2"}).alleles(alleleList2).make(); final VariantContext vc = new VariantContextBuilder().chr(contig).id("id2").source("GA").start(start+1).stop(start+1).alleles(alleleList2).genotypes(genotype).make(); Assert.assertTrue(PhasingUtils.doubleAllelesSegregatePerfectlyAmongSamples(vc1, vc)); }