use of htsjdk.variant.variantcontext.GenotypesContext 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.GenotypesContext in project gatk by broadinstitute.
the class QualByDepth method annotate.
@Override
public Map<String, Object> annotate(final ReferenceContext ref, final VariantContext vc, final ReadLikelihoods<Allele> likelihoods) {
Utils.nonNull(vc);
if (!vc.hasLog10PError()) {
return Collections.emptyMap();
}
final GenotypesContext genotypes = vc.getGenotypes();
if (genotypes == null || genotypes.isEmpty()) {
return Collections.emptyMap();
}
int depth = 0;
int ADrestrictedDepth = 0;
for (final Genotype genotype : genotypes) {
// we care only about variant calls with likelihoods
if (!genotype.isHet() && !genotype.isHomVar()) {
continue;
}
// if we have the AD values for this sample, let's make sure that the variant depth is greater than 1!
if (genotype.hasAD()) {
final int[] AD = genotype.getAD();
final int totalADdepth = (int) MathUtils.sum(AD);
if (totalADdepth != 0) {
if (totalADdepth - AD[0] > 1) {
ADrestrictedDepth += totalADdepth;
}
depth += totalADdepth;
}
} else if (likelihoods != null) {
depth += likelihoods.sampleReadCount(likelihoods.indexOfSample(genotype.getSampleName()));
} else if (genotype.hasDP()) {
depth += genotype.getDP();
}
}
// if the AD-restricted depth is a usable value (i.e. not zero), then we should use that one going forward
if (ADrestrictedDepth > 0) {
depth = ADrestrictedDepth;
}
if (depth == 0) {
return Collections.emptyMap();
}
final double qual = -10.0 * vc.getLog10PError();
double QD = qual / depth;
// Hack: see note in the fixTooHighQD method below
QD = fixTooHighQD(QD);
return Collections.singletonMap(getKeyNames().get(0), String.format("%.2f", QD));
}
use of htsjdk.variant.variantcontext.GenotypesContext in project gatk by broadinstitute.
the class AFCalculatorProvider method getInstance.
/**
* Returns a AF calculator capable to handle a particular variant-context.
* @param variantContext the target context build.
* @param defaultPloidy the assumed ploidy in case that there is no a GT call present to determine it.
* @return never {@code null}
*/
public AFCalculator getInstance(final VariantContext variantContext, final int defaultPloidy, final int maximumAltAlleles) {
Utils.nonNull(variantContext, "variant context cannot be null");
final int sampleCount = variantContext.getNSamples();
if (sampleCount == 0) {
return getInstance(defaultPloidy, maximumAltAlleles);
}
final GenotypesContext genotypes = variantContext.getGenotypes();
final Genotype firstGenotype = genotypes.get(0);
int ploidy = firstGenotype.getPloidy();
if (ploidy <= 0) {
ploidy = defaultPloidy;
}
for (int i = 1; i < sampleCount; i++) {
final Genotype genotype = genotypes.get(i);
final int declaredPloidy = genotype.getPloidy();
final int actualPloidy = declaredPloidy <= 0 ? defaultPloidy : declaredPloidy;
if (actualPloidy != ploidy) {
ploidy = AFCalculatorImplementation.UNBOUND_PLOIDY;
break;
}
}
return getInstance(ploidy, Math.min(variantContext.getNAlleles() - 1, maximumAltAlleles));
}
use of htsjdk.variant.variantcontext.GenotypesContext in project gatk by broadinstitute.
the class InbreedingCoeff method annotate.
@Override
public Map<String, Object> annotate(final ReferenceContext ref, final VariantContext vc, final ReadLikelihoods<Allele> likelihoods) {
Utils.nonNull(vc);
final GenotypesContext genotypes = (founderIds == null || founderIds.isEmpty()) ? vc.getGenotypes() : vc.getGenotypes(founderIds);
if (genotypes == null || genotypes.size() < MIN_SAMPLES || !vc.isVariant()) {
return Collections.emptyMap();
}
final Pair<Integer, Double> sampleCountCoeff = calculateIC(vc, genotypes);
final int sampleCount = sampleCountCoeff.getLeft();
final double F = sampleCountCoeff.getRight();
if (sampleCount < MIN_SAMPLES) {
logger.warn("Annotation will not be calculated, must provide at least " + MIN_SAMPLES + " samples");
return Collections.emptyMap();
}
return Collections.singletonMap(getKeyNames().get(0), String.format("%.4f", F));
}
use of htsjdk.variant.variantcontext.GenotypesContext in project gatk by broadinstitute.
the class MappingQualityZeroUnitTest method makeVC.
private VariantContext makeVC() {
final GenotypesContext testGC = GenotypesContext.create(2);
final Allele refAllele = Allele.create("A", true);
final Allele altAllele = Allele.create("T");
return (new VariantContextBuilder()).alleles(Arrays.asList(refAllele, altAllele)).chr("1").start(15L).stop(15L).genotypes(testGC).make();
}
Aggregations