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();
}
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);
}
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);
}
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);
}
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);
}
Aggregations