Search in sources :

Example 6 with GenotypesContext

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

Example 7 with GenotypesContext

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

Example 8 with GenotypesContext

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

Example 9 with GenotypesContext

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);
}
Also used : Genotype(htsjdk.variant.variantcontext.Genotype) VCFHeaderLine(htsjdk.variant.vcf.VCFHeaderLine) DocumentedFeature(org.broadinstitute.barclay.help.DocumentedFeature) Allele(htsjdk.variant.variantcontext.Allele) CommandLineProgramProperties(org.broadinstitute.barclay.argparser.CommandLineProgramProperties) java.util(java.util) GenotypeLikelihoods(htsjdk.variant.variantcontext.GenotypeLikelihoods) VCFStandardHeaderLines(htsjdk.variant.vcf.VCFStandardHeaderLines) VCFHeader(htsjdk.variant.vcf.VCFHeader) Argument(org.broadinstitute.barclay.argparser.Argument) GenotypeAssignmentMethod(org.broadinstitute.hellbender.tools.walkers.genotyper.GenotypeAssignmentMethod) StandardArgumentDefinitions(org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions) SampleDB(org.broadinstitute.hellbender.utils.samples.SampleDB) VariantProgramGroup(org.broadinstitute.hellbender.cmdline.programgroups.VariantProgramGroup) VariantIDsVariantFilter(org.broadinstitute.hellbender.engine.filters.VariantIDsVariantFilter) VariantContextUtils(htsjdk.variant.variantcontext.VariantContextUtils) SampleDBBuilder(org.broadinstitute.hellbender.utils.samples.SampleDBBuilder) ReferenceContext(org.broadinstitute.hellbender.engine.ReferenceContext) FeatureContext(org.broadinstitute.hellbender.engine.FeatureContext) VCFConstants(htsjdk.variant.vcf.VCFConstants) VariantWalker(org.broadinstitute.hellbender.engine.VariantWalker) GenotypeBuilder(htsjdk.variant.variantcontext.GenotypeBuilder) Predicate(java.util.function.Predicate) SAMSequenceDictionary(htsjdk.samtools.SAMSequenceDictionary) VariantFilterLibrary(org.broadinstitute.hellbender.engine.filters.VariantFilterLibrary) Collectors(java.util.stream.Collectors) VariantFilter(org.broadinstitute.hellbender.engine.filters.VariantFilter) File(java.io.File) GenotypesContext(htsjdk.variant.variantcontext.GenotypesContext) UserException(org.broadinstitute.hellbender.exceptions.UserException) AlleleSubsettingUtils(org.broadinstitute.hellbender.tools.walkers.genotyper.AlleleSubsettingUtils) org.broadinstitute.hellbender.utils.variant(org.broadinstitute.hellbender.utils.variant) MendelianViolation(org.broadinstitute.hellbender.utils.samples.MendelianViolation) VariantContextWriter(htsjdk.variant.variantcontext.writer.VariantContextWriter) VariantTypesVariantFilter(org.broadinstitute.hellbender.engine.filters.VariantTypesVariantFilter) ChromosomeCounts(org.broadinstitute.hellbender.tools.walkers.annotator.ChromosomeCounts) PedigreeValidationType(org.broadinstitute.hellbender.utils.samples.PedigreeValidationType) VariantContext(htsjdk.variant.variantcontext.VariantContext) VCFUtils(htsjdk.variant.vcf.VCFUtils) Utils(org.broadinstitute.hellbender.utils.Utils) Hidden(org.broadinstitute.barclay.argparser.Hidden) FeatureInput(org.broadinstitute.hellbender.engine.FeatureInput) ReadsContext(org.broadinstitute.hellbender.engine.ReadsContext) Pattern(java.util.regex.Pattern) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) GenotypesContext(htsjdk.variant.variantcontext.GenotypesContext) VariantContextBuilder(htsjdk.variant.variantcontext.VariantContextBuilder) VariantContext(htsjdk.variant.variantcontext.VariantContext) Genotype(htsjdk.variant.variantcontext.Genotype) GenotypeBuilder(htsjdk.variant.variantcontext.GenotypeBuilder)

Example 10 with GenotypesContext

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

Aggregations

GenotypesContext (htsjdk.variant.variantcontext.GenotypesContext)11 VariantContextBuilder (htsjdk.variant.variantcontext.VariantContextBuilder)6 Allele (htsjdk.variant.variantcontext.Allele)4 Genotype (htsjdk.variant.variantcontext.Genotype)3 VariantContext (htsjdk.variant.variantcontext.VariantContext)3 SAMSequenceDictionary (htsjdk.samtools.SAMSequenceDictionary)1 GenotypeBuilder (htsjdk.variant.variantcontext.GenotypeBuilder)1 GenotypeLikelihoods (htsjdk.variant.variantcontext.GenotypeLikelihoods)1 VariantContextUtils (htsjdk.variant.variantcontext.VariantContextUtils)1 VariantContextWriter (htsjdk.variant.variantcontext.writer.VariantContextWriter)1 VCFConstants (htsjdk.variant.vcf.VCFConstants)1 VCFHeader (htsjdk.variant.vcf.VCFHeader)1 VCFHeaderLine (htsjdk.variant.vcf.VCFHeaderLine)1 VCFStandardHeaderLines (htsjdk.variant.vcf.VCFStandardHeaderLines)1 VCFUtils (htsjdk.variant.vcf.VCFUtils)1 File (java.io.File)1 java.util (java.util)1 Predicate (java.util.function.Predicate)1 Pattern (java.util.regex.Pattern)1 Collectors (java.util.stream.Collectors)1