use of htsjdk.variant.variantcontext.VariantContext in project gatk-protected by broadinstitute.
the class AnnotateVcfWithExpectedAlleleFraction method apply.
@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext refContext, final FeatureContext fc) {
final double[] weights = vc.getGenotypes().stream().mapToDouble(g -> weight(g)).toArray();
final double expectedAlleleFraction = MathUtils.sum(MathArrays.ebeMultiply(weights, mixingFractionsInSampleOrder));
vcfWriter.add(new VariantContextBuilder(vc).attribute(EXPECTED_ALLELE_FRACTION_NAME, expectedAlleleFraction).make());
}
use of htsjdk.variant.variantcontext.VariantContext in project gatk-protected by broadinstitute.
the class CalculateMixingFractions method apply.
@Override
public void apply(final VariantContext vc, final ReadsContext readsContext, final ReferenceContext refContext, final FeatureContext fc) {
if (!isBiallelicSingletonHetSnp(vc)) {
return;
}
final Optional<String> variantSample = StreamSupport.stream(vc.getGenotypes().spliterator(), false).filter(genotype -> genotype.isHet()).map(genotype -> genotype.getSampleName()).findFirst();
if (!variantSample.isPresent()) {
return;
}
final List<GATKRead> reads = new ArrayList<>();
final List<Integer> offsets = new ArrayList<>();
for (final GATKRead read : readsContext) {
if (read.failsVendorQualityCheck()) {
continue;
}
final AlignmentStateMachine asm = new AlignmentStateMachine(read);
while (asm.stepForwardOnGenome() != null && asm.getGenomePosition() < vc.getStart()) {
}
if (asm.getGenomePosition() == vc.getStart()) {
reads.add(read);
offsets.add(asm.getReadOffset());
}
}
final ReadPileup pileup = new ReadPileup(vc, reads, offsets);
final byte altBase = vc.getAlternateAllele(0).getBases()[0];
final long altCount = StreamSupport.stream(pileup.spliterator(), false).filter(pe -> pe.getBase() == altBase).count();
final long totalCount = pileup.size();
sampleCounts.get(variantSample.get()).addCounts(altCount, totalCount);
}
use of htsjdk.variant.variantcontext.VariantContext in project gatk-protected by broadinstitute.
the class CalculateGenotypePosteriors method apply.
@Override
public void apply(final VariantContext variant, final ReadsContext readsContext, final ReferenceContext referenceContext, final FeatureContext featureContext) {
final Collection<VariantContext> vcs = featureContext.getValues(getDrivingVariantsFeatureInput());
final Collection<VariantContext> otherVCs = featureContext.getValues(supportVariants);
final int missing = supportVariants.size() - otherVCs.size();
for (final VariantContext vc : vcs) {
final VariantContext vc_familyPriors;
final VariantContext vc_bothPriors;
//do family priors first (if applicable)
final VariantContextBuilder builder = new VariantContextBuilder(vc);
//only compute family priors for biallelelic sites
if (!skipFamilyPriors && vc.isBiallelic()) {
final GenotypesContext gc = famUtils.calculatePosteriorGLs(vc);
builder.genotypes(gc);
}
VariantContextUtils.calculateChromosomeCounts(builder, false);
vc_familyPriors = builder.make();
if (!skipPopulationPriors) {
vc_bothPriors = PosteriorProbabilitiesUtils.calculatePosteriorProbs(vc_familyPriors, otherVCs, missing * numRefIfMissing, globalPrior, !ignoreInputSamples, defaultToAC, useACoff);
} else {
final VariantContextBuilder builder2 = new VariantContextBuilder(vc_familyPriors);
VariantContextUtils.calculateChromosomeCounts(builder, false);
vc_bothPriors = builder2.make();
}
vcfWriter.add(vc_bothPriors);
}
}
use of htsjdk.variant.variantcontext.VariantContext in project gatk-protected by broadinstitute.
the class FilterMutectCalls method onTraversalSuccess.
@Override
public Object onTraversalSuccess() {
final String tumorSample = getHeaderForVariants().getMetaDataLine(Mutect2Engine.TUMOR_SAMPLE_KEY_IN_VCF_HEADER).getValue();
final Mutect2FilteringEngine filteringEngine = new Mutect2FilteringEngine(MTFAC, tumorSample);
// TODO: implement sophisticated filtering
for (final VariantContext vc : unfilteredCalls) {
final VariantContextBuilder vcb = new VariantContextBuilder(vc);
vcb.filters(filteringEngine.calculateFilters(MTFAC, vc));
vcfWriter.add(vcb.make());
}
return "SUCCESS";
}
use of htsjdk.variant.variantcontext.VariantContext in project gatk-protected by broadinstitute.
the class ReferenceBasesUnitTest method test.
@Test
public void test() {
final File refFasta = new File(b37_reference_20_21);
final ReferenceDataSource refDataSource = new ReferenceFileSource(refFasta);
final ReferenceContext ref = new ReferenceContext(refDataSource, new SimpleInterval("20", 10_000_000, 10_000_200));
final VariantContext vc = new VariantContextBuilder("source", "20", 10_000_100, 10_000_100, Collections.singleton(Allele.create((byte) 'A', true))).make();
final String refBases = (String) new ReferenceBases().annotate(ref, vc, null).get(ReferenceBases.REFERENCE_BASES_KEY);
Assert.assertEquals(refBases, "ACTGCATCCCTTGCATTTCC");
}
Aggregations