use of htsjdk.variant.variantcontext.GenotypesContext in project gatk by broadinstitute.
the class ExcessHet method annotate.
@Override
public Map<String, Object> annotate(final ReferenceContext ref, final VariantContext vc, final ReadLikelihoods<Allele> likelihoods) {
final GenotypesContext genotypes = vc.getGenotypes();
if (genotypes == null || !vc.isVariant()) {
return Collections.emptyMap();
}
final Pair<Integer, Double> sampleCountEH = calculateEH(vc, genotypes);
final int sampleCount = sampleCountEH.getLeft();
final double eh = sampleCountEH.getRight();
if (sampleCount < 1) {
return Collections.emptyMap();
}
return Collections.singletonMap(getKeyNames().get(0), (Object) String.format("%.4f", eh));
}
use of htsjdk.variant.variantcontext.GenotypesContext in project gatk 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 CoverageUnitTest 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();
}
use of htsjdk.variant.variantcontext.GenotypesContext in project gatk by broadinstitute.
the class SelectVariants method subsetRecord.
/**
* Helper method to subset a VC record, modifying some metadata stored in the INFO field (i.e. AN, AC, AF).
*
* @param vc the VariantContext record to subset
* @param preserveAlleles should we trim constant sequence from the beginning and/or end of all alleles, or preserve it?
* @param removeUnusedAlternates removes alternate alleles with AC=0
* @return the subsetted VariantContext
*/
private VariantContext subsetRecord(final VariantContext vc, final boolean preserveAlleles, final boolean removeUnusedAlternates) {
//subContextFromSamples() always decodes the vc, which is a fairly expensive operation. Avoid if possible
if (noSamplesSpecified && !removeUnusedAlternates) {
return vc;
}
// strip out the alternate alleles that aren't being used
final VariantContext sub = vc.subContextFromSamples(samples, removeUnusedAlternates);
// If no subsetting happened, exit now
if (sub.getNSamples() == vc.getNSamples() && sub.getNAlleles() == vc.getNAlleles()) {
return vc;
}
// fix the PL and AD values if sub has fewer alleles than original vc and remove a fraction of the genotypes if needed
final GenotypesContext oldGs = sub.getGenotypes();
GenotypesContext newGC = sub.getNAlleles() == vc.getNAlleles() ? oldGs : AlleleSubsettingUtils.subsetAlleles(oldGs, 0, vc.getAlleles(), sub.getAlleles(), GenotypeAssignmentMethod.DO_NOT_ASSIGN_GENOTYPES, vc.getAttributeAsInt(VCFConstants.DEPTH_KEY, 0));
if (fractionGenotypes > 0) {
final List<Genotype> genotypes = newGC.stream().map(genotype -> randomGenotypes.nextDouble() > fractionGenotypes ? genotype : new GenotypeBuilder(genotype).alleles(getNoCallAlleles(genotype.getPloidy())).noGQ().make()).collect(Collectors.toList());
newGC = GenotypesContext.create(new ArrayList<>(genotypes));
}
// since the VC has been subset (either by sample or allele), we need to strip out the MLE tags
final VariantContextBuilder builder = new VariantContextBuilder(sub);
builder.rmAttributes(Arrays.asList(GATKVCFConstants.MLE_ALLELE_COUNT_KEY, GATKVCFConstants.MLE_ALLELE_FREQUENCY_KEY));
builder.genotypes(newGC);
addAnnotations(builder, vc, sub.getSampleNames());
final VariantContext subset = builder.make();
return preserveAlleles ? subset : GATKVariantContextUtils.trimAlleles(subset, true, true);
}
use of htsjdk.variant.variantcontext.GenotypesContext 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();
}
Aggregations