Search in sources :

Example 51 with VariantContextBuilder

use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.

the class MakeSitesOnlyVcf method subsetToSamplesWithOriginalAnnotations.

/** 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();
}
Also used : GenotypesContext(htsjdk.variant.variantcontext.GenotypesContext) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder)

Example 52 with VariantContextBuilder

use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.

the class HaplotypeUnitTest method basicInsertTest.

private void basicInsertTest(String ref, String alt, int loc, Cigar cigar, String hap, String newHap) {
    final Haplotype h = new Haplotype(hap.getBytes());
    final Allele h1refAllele = Allele.create(ref, true);
    final Allele h1altAllele = Allele.create(alt, false);
    final ArrayList<Allele> alleles = new ArrayList<>();
    alleles.add(h1refAllele);
    alleles.add(h1altAllele);
    final VariantContext vc = new VariantContextBuilder().alleles(alleles).loc("1", loc, loc + h1refAllele.getBases().length - 1).make();
    h.setAlignmentStartHapwrtRef(0);
    h.setCigar(cigar);
    final Haplotype h1 = h.insertAllele(vc.getReference(), vc.getAlternateAllele(0), loc, vc.getStart());
    final Haplotype h1expected = new Haplotype(newHap.getBytes());
    Assert.assertEquals(h1, h1expected);
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) ArrayList(java.util.ArrayList) VariantContext(htsjdk.variant.variantcontext.VariantContext)

Example 53 with VariantContextBuilder

use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.

the class GenotypeConcordanceTest method testGenotypeConcordanceDetermineStateNull.

@Test
public void testGenotypeConcordanceDetermineStateNull() throws Exception {
    final List<Allele> alleles = makeUniqueListOfAlleles(Aref, C);
    final Genotype gt1 = GenotypeBuilder.create(TRUTH_SAMPLE_NAME, Arrays.asList(Aref, C));
    final VariantContext vc1 = new VariantContextBuilder("test", snpLoc, snpLocStart, snpLocStop, alleles).genotypes(gt1).make();
    testGenotypeConcordanceDetermineState(null, TruthState.MISSING, null, CallState.MISSING, 0, 0);
    testGenotypeConcordanceDetermineState(vc1, TruthState.HET_REF_VAR1, null, CallState.MISSING, 0, 0);
    testGenotypeConcordanceDetermineState(null, TruthState.MISSING, vc1, CallState.HET_REF_VAR1, 0, 0);
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) Genotype(htsjdk.variant.variantcontext.Genotype) VariantContext(htsjdk.variant.variantcontext.VariantContext) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 54 with VariantContextBuilder

use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.

the class GenotypeConcordanceTest method testGenotypeConcordanceDetermineStateDp.

@Test
public void testGenotypeConcordanceDetermineStateDp() throws Exception {
    final List<Allele> allelesNormal = makeUniqueListOfAlleles(Aref, C);
    final Genotype gtNormal = GenotypeBuilder.create(TRUTH_SAMPLE_NAME, Arrays.asList(Aref, C));
    final VariantContext vcNormal = new VariantContextBuilder("test", snpLoc, snpLocStart, snpLocStop, allelesNormal).genotypes(gtNormal).make();
    final List<Allele> allelesLowDp = makeUniqueListOfAlleles(Aref, C);
    final Genotype gtLowDp = new GenotypeBuilder(TRUTH_SAMPLE_NAME, Arrays.asList(Aref, C)).DP(4).make();
    final VariantContext vcLowDp = new VariantContextBuilder("test", snpLoc, snpLocStart, snpLocStop, allelesLowDp).genotypes(gtLowDp).make();
    testGenotypeConcordanceDetermineState(vcLowDp, TruthState.LOW_DP, vcNormal, CallState.HET_REF_VAR1, 0, 20);
    testGenotypeConcordanceDetermineState(vcLowDp, TruthState.HET_REF_VAR1, vcLowDp, CallState.HET_REF_VAR1, 0, 2);
    testGenotypeConcordanceDetermineState(vcNormal, TruthState.HET_REF_VAR1, vcLowDp, CallState.LOW_DP, 0, 20);
    testGenotypeConcordanceDetermineState(vcNormal, TruthState.HET_REF_VAR1, vcLowDp, CallState.HET_REF_VAR1, 0, 2);
    testGenotypeConcordanceDetermineState(vcLowDp, TruthState.LOW_DP, vcLowDp, CallState.LOW_DP, 0, 20);
    testGenotypeConcordanceDetermineState(vcLowDp, TruthState.HET_REF_VAR1, vcLowDp, CallState.HET_REF_VAR1, 0, 2);
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) Genotype(htsjdk.variant.variantcontext.Genotype) VariantContext(htsjdk.variant.variantcontext.VariantContext) GenotypeBuilder(htsjdk.variant.variantcontext.GenotypeBuilder) Test(org.testng.annotations.Test) CommandLineProgramTest(org.broadinstitute.hellbender.CommandLineProgramTest)

Example 55 with VariantContextBuilder

use of htsjdk.variant.variantcontext.VariantContextBuilder in project gatk by broadinstitute.

the class GermlineProbabilityCalculatorUnitTest method testGetGermlineAltAlleleFrequencies.

@Test
public void testGetGermlineAltAlleleFrequencies() {
    final double defaultAF = 0.001;
    final double nonDefaultAF1 = 0.1;
    final double nonDefaultAF2 = 0.01;
    final Allele Aref = Allele.create("A", true);
    final Allele C = Allele.create("C");
    final Allele G = Allele.create("G");
    final Allele T = Allele.create("T");
    final String source = "SOURCE";
    final int start = 1;
    final int stop = 1;
    //biallelic, vc has the same alt allele
    final List<Allele> altAlleles1 = Arrays.asList(C);
    final VariantContext vc1 = new VariantContextBuilder(source, "1", start, stop, Arrays.asList(Aref, C)).attribute(VCFConstants.ALLELE_FREQUENCY_KEY, new double[] { nonDefaultAF1 }).make();
    final double[] af1 = GermlineProbabilityCalculator.getGermlineAltAlleleFrequencies(altAlleles1, Optional.of(vc1), defaultAF);
    Assert.assertEquals(af1.length, altAlleles1.size());
    Assert.assertEquals(af1[0], nonDefaultAF1, 0.00001);
    //biallelic, vc has different alt allele
    final List<Allele> altAlleles2 = Arrays.asList(C);
    final VariantContext vc2 = new VariantContextBuilder(source, "1", start, stop, Arrays.asList(Aref, G)).attribute(VCFConstants.ALLELE_FREQUENCY_KEY, new double[] { nonDefaultAF1 }).make();
    final double[] af2 = GermlineProbabilityCalculator.getGermlineAltAlleleFrequencies(altAlleles2, Optional.of(vc2), defaultAF);
    Assert.assertEquals(af2.length, altAlleles2.size());
    Assert.assertEquals(af2[0], defaultAF, 0.00001);
    //triallelic, same alt alleles
    final List<Allele> altAlleles3 = Arrays.asList(C, G);
    final VariantContext vc3 = new VariantContextBuilder(source, "1", start, stop, Arrays.asList(Aref, C, G)).attribute(VCFConstants.ALLELE_FREQUENCY_KEY, new double[] { nonDefaultAF1, nonDefaultAF2 }).make();
    final double[] af3 = GermlineProbabilityCalculator.getGermlineAltAlleleFrequencies(altAlleles3, Optional.of(vc3), defaultAF);
    Assert.assertEquals(af3.length, altAlleles3.size());
    Assert.assertEquals(af3[0], nonDefaultAF1, 0.00001);
    Assert.assertEquals(af3[1], nonDefaultAF2, 0.00001);
    //triallelic, same alt alleles in different order
    final List<Allele> altAlleles4 = Arrays.asList(C, G);
    final VariantContext vc4 = new VariantContextBuilder(source, "1", start, stop, Arrays.asList(Aref, G, C)).attribute(VCFConstants.ALLELE_FREQUENCY_KEY, new double[] { nonDefaultAF1, nonDefaultAF2 }).make();
    final double[] af4 = GermlineProbabilityCalculator.getGermlineAltAlleleFrequencies(altAlleles4, Optional.of(vc4), defaultAF);
    Assert.assertEquals(af4.length, altAlleles4.size());
    Assert.assertEquals(af4[0], nonDefaultAF2, 0.00001);
    Assert.assertEquals(af4[1], nonDefaultAF1, 0.00001);
    //triallelic, only one allele in common
    final List<Allele> altAlleles5 = Arrays.asList(C, G);
    final VariantContext vc5 = new VariantContextBuilder(source, "1", start, stop, Arrays.asList(Aref, C, T)).attribute(VCFConstants.ALLELE_FREQUENCY_KEY, new double[] { nonDefaultAF1, nonDefaultAF2 }).make();
    final double[] af5 = GermlineProbabilityCalculator.getGermlineAltAlleleFrequencies(altAlleles5, Optional.of(vc5), defaultAF);
    Assert.assertEquals(af5.length, altAlleles5.size());
    Assert.assertEquals(af5[0], nonDefaultAF1, 0.00001);
    Assert.assertEquals(af5[1], defaultAF, 0.00001);
}
Also used : Allele(htsjdk.variant.variantcontext.Allele) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) VariantContext(htsjdk.variant.variantcontext.VariantContext) BaseTest(org.broadinstitute.hellbender.utils.test.BaseTest) Test(org.testng.annotations.Test)

Aggregations

VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)57 VariantContext (htsjdk.variant.variantcontext.VariantContext)40 Test (org.testng.annotations.Test)26 Allele (htsjdk.variant.variantcontext.Allele)25 BaseTest (org.broadinstitute.hellbender.utils.test.BaseTest)21 Genotype (htsjdk.variant.variantcontext.Genotype)12 ReferenceContext (org.broadinstitute.hellbender.engine.ReferenceContext)8 SimpleInterval (org.broadinstitute.hellbender.utils.SimpleInterval)7 GenotypeBuilder (htsjdk.variant.variantcontext.GenotypeBuilder)6 GenotypesContext (htsjdk.variant.variantcontext.GenotypesContext)6 File (java.io.File)6 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)5 VCFHeader (htsjdk.variant.vcf.VCFHeader)5 CommandLineProgramTest (org.broadinstitute.hellbender.CommandLineProgramTest)5 BeforeTest (org.testng.annotations.BeforeTest)5 SAMSequenceRecord (htsjdk.samtools.SAMSequenceRecord)4 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)4 VCFHeaderLine (htsjdk.variant.vcf.VCFHeaderLine)3 ArrayList (java.util.ArrayList)3 Collectors (java.util.stream.Collectors)3