Java Code Examples for htsjdk.variant.variantcontext.VariantContext#hasGenotypes()
The following examples show how to use
htsjdk.variant.variantcontext.VariantContext#hasGenotypes() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: StrandBiasTest.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override //template method for calculating strand bias annotations using the three different methods public Map<String, Object> annotate(final ReferenceContext ref, final VariantContext vc, final AlleleLikelihoods<GATKRead, Allele> likelihoods) { Utils.nonNull(vc); if ( !vc.isVariant() ) { return Collections.emptyMap(); } // if the genotype and strand bias are provided, calculate the annotation from the Genotype (GT) field if ( vc.hasGenotypes() ) { for (final Genotype g : vc.getGenotypes()) { if (g.hasAnyAttribute(GATKVCFConstants.STRAND_BIAS_BY_SAMPLE_KEY)) { return calculateAnnotationFromGTfield(vc.getGenotypes()); } } } if (likelihoods != null) { return calculateAnnotationFromLikelihoods(likelihoods, vc); } return Collections.emptyMap(); }
Example 2
Source File: SampleList.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public Map<String, Object> annotate(final ReferenceContext ref, final VariantContext vc, final AlleleLikelihoods<GATKRead, Allele> likelihoods) { Utils.nonNull(vc); if ( vc.isMonomorphicInSamples() || !vc.hasGenotypes() ) { return Collections.emptyMap(); } final StringBuilder samples = new StringBuilder(); for ( final Genotype genotype : vc.getGenotypesOrderedByName() ) { if ( genotype.isCalled() && !genotype.isHomRef() ){ if ( samples.length() > 0 ) { samples.append(","); } samples.append(genotype.getSampleName()); } } if ( samples.length() == 0 ) { return Collections.emptyMap(); } return Collections.singletonMap(getKeyNames().get(0), samples.toString()); }
Example 3
Source File: ValidationReport.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
@Override public void update2(VariantContext eval, VariantContext comp, final ReferenceContext referenceContext, final ReadsContext readsContext, final FeatureContext featureContext) { if ( comp != null ) { // we only need to consider sites in comp if ( REQUIRE_IDENTICAL_ALLELES && (eval != null && haveDifferentAltAlleles(eval, comp))) nDifferentAlleleSites++; else { SiteStatus evalStatus = calcSiteStatus(eval); final Set<String> evalSamples = getWalker().getSampleNamesForEvaluation(); if ( comp.hasGenotypes() && ! evalSamples.isEmpty() && comp.hasGenotypes(evalSamples) ) // if we have genotypes in both eval and comp, subset comp down just the samples in eval comp = comp.subContextFromSamples(evalSamples, false); SiteStatus compStatus = calcSiteStatus(comp); counts[compStatus.ordinal()][evalStatus.ordinal()]++; } } }
Example 4
Source File: ValidationReport.java From gatk with BSD 3-Clause "New" or "Revised" License | 6 votes |
private SiteStatus calcSiteStatus(VariantContext vc) { if ( vc == null ) return SiteStatus.NO_CALL; if ( vc.isFiltered() ) return SiteStatus.FILTERED; if ( vc.isMonomorphicInSamples() ) return SiteStatus.MONO; if ( vc.hasGenotypes() ) return SiteStatus.POLY; // must be polymorphic if isMonomorphicInSamples was false and there are genotypes if ( vc.hasAttribute(VCFConstants.ALLELE_COUNT_KEY) ) { int ac = 0; if ( vc.getNAlleles() > 2 ) { return SiteStatus.POLY; } else ac = vc.getAttributeAsInt(VCFConstants.ALLELE_COUNT_KEY, 0); return ac > 0 ? SiteStatus.POLY : SiteStatus.MONO; } else { return TREAT_ALL_SITES_IN_EVAL_VCF_AS_CALLED ? SiteStatus.POLY : SiteStatus.NO_CALL; // we can't figure out what to do } }
Example 5
Source File: RMSMappingQuality.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
/** * * @return the number of reads at the given site, calculated as InfoField {@link VCFConstants#DEPTH_KEY} minus the * format field {@link GATKVCFConstants#MIN_DP_FORMAT_KEY} or DP of each of the HomRef genotypes at that site * @throws UserException.BadInput if the {@link VCFConstants#DEPTH_KEY} is missing or if the calculated depth is <= 0 */ @VisibleForTesting private static int getNumOfReads(final VariantContext vc) { if(vc.hasAttribute(GATKVCFConstants.MAPPING_QUALITY_DEPTH_DEPRECATED)) { int mqDP = vc.getAttributeAsInt(GATKVCFConstants.MAPPING_QUALITY_DEPTH_DEPRECATED, 0); if (mqDP > 0) { return mqDP; } } //don't use the full depth because we don't calculate MQ for reference blocks //don't count spanning deletion calls towards number of reads int numOfReads = vc.getAttributeAsInt(VCFConstants.DEPTH_KEY, -1); if(vc.hasGenotypes()) { for(final Genotype gt : vc.getGenotypes()) { if(hasReferenceDepth(gt)) { //site-level DP contribution will come from MIN_DP for gVCF-called reference variants or DP for BP resolution if (gt.hasExtendedAttribute(GATKVCFConstants.MIN_DP_FORMAT_KEY)) { numOfReads -= Integer.parseInt(gt.getExtendedAttribute(GATKVCFConstants.MIN_DP_FORMAT_KEY).toString()); } else if (gt.hasDP()) { numOfReads -= gt.getDP(); } } else if(hasSpanningDeletionAllele(gt)) { //site-level DP contribution will come from MIN_DP for gVCF-called reference variants or DP for BP resolution if (gt.hasExtendedAttribute(GATKVCFConstants.MIN_DP_FORMAT_KEY)) { numOfReads -= Integer.parseInt(gt.getExtendedAttribute(GATKVCFConstants.MIN_DP_FORMAT_KEY).toString()); } else if (gt.hasDP()) { numOfReads -= gt.getDP(); } } } } if (numOfReads <= 0){ numOfReads = -1; //return -1 to result in a NaN } return numOfReads; }
Example 6
Source File: ChromosomeCounts.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Map<String, Object> annotate(final ReferenceContext ref, final VariantContext vc, AlleleLikelihoods<GATKRead, Allele> likelihoods) { Utils.nonNull(vc); if ( ! vc.hasGenotypes() ) { return Collections.emptyMap(); } return VariantContextUtils.calculateChromosomeCounts(vc, new LinkedHashMap<>(), true, Collections.emptySet()); }
Example 7
Source File: GenotypeSummaries.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
@Override public Map<String, Object> annotate(final ReferenceContext ref, final VariantContext vc, final AlleleLikelihoods<GATKRead, Allele> likelihoods) { Utils.nonNull(vc); if ( ! vc.hasGenotypes() ) { return Collections.emptyMap(); } final Map<String,Object> returnMap = new LinkedHashMap<>(); returnMap.put(GATKVCFConstants.NOCALL_CHROM_KEY, vc.getNoCallCount()); final DescriptiveStatistics stats = new DescriptiveStatistics(); for( final Genotype g : vc.getGenotypes() ) { if( g.hasGQ() ) { stats.addValue(g.getGQ()); } } if( stats.getN() > 0L ) { returnMap.put(GATKVCFConstants.GQ_MEAN_KEY, String.format("%.2f", stats.getMean())); if( stats.getN() > 1L ) { returnMap.put(GATKVCFConstants.GQ_STDEV_KEY, String.format("%.2f", stats.getStandardDeviation())); } } return returnMap; }
Example 8
Source File: VariantAFEvaluator.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
public void update1(VariantContext vc, final ReferenceContext referenceContext, final ReadsContext readsContext, final FeatureContext featureContext) { vc.getStart(); if (vc == null || !vc.isSNP() || (getWalker().ignoreAC0Sites() && vc.isMonomorphicInSamples())) { return; } for (final Genotype genotype : vc.getGenotypes()) { // eval array if (!genotype.isNoCall()) { if (genotype.getPloidy() != PLOIDY) { throw new UserException.BadInput("This tool only works with ploidy 2"); } // add AF at this site this.totalCalledSites += 1; int numReferenceAlleles= genotype.countAllele(vc.getReference()); double varAFHere = (PLOIDY - numReferenceAlleles)/PLOIDY; this.sumVariantAFs += varAFHere; totalHetSites += numReferenceAlleles == 1 ? 1 : 0; totalHomVarSites += numReferenceAlleles == 0 ? 1 : 0; totalHomRefSites += numReferenceAlleles == 2 ? 1 : 0; } } if (!vc.hasGenotypes()) { // comp ( sites only thousand genomes ) this.totalCalledSites += 1; this.sumVariantAFs += vc.getAttributeAsDouble("AF", 0.0); } }
Example 9
Source File: VariantContextTestUtils.java From gatk with BSD 3-Clause "New" or "Revised" License | 5 votes |
public static void assertVariantContextsHaveSameGenotypes(final VariantContext actual, final VariantContext expected, final List<String> attributesToIgnore) { Assert.assertEquals(actual.hasGenotypes(), expected.hasGenotypes(), "hasGenotypes"); if ( expected.hasGenotypes() ) { BaseTest.assertEqualsSet(actual.getSampleNames(), expected.getSampleNames(), "sample names set"); Assert.assertEquals(actual.getSampleNamesOrderedByName(), expected.getSampleNamesOrderedByName(), "sample names"); final Set<String> samples = expected.getSampleNames(); for ( final String sample : samples ) { assertGenotypesAreEqual(actual.getGenotype(sample), expected.getGenotype(sample), attributesToIgnore); } } }
Example 10
Source File: VariantDataManager.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
private boolean isValidVariant( final VariantContext evalVC, final VariantContext trainVC, final boolean TRUST_ALL_POLYMORPHIC) { return trainVC != null && trainVC.isNotFiltered() && trainVC.isVariant() && checkVariationClass( evalVC, trainVC ) && (TRUST_ALL_POLYMORPHIC || !trainVC.hasGenotypes() || trainVC.isPolymorphicInSamples()); }
Example 11
Source File: RMSMappingQuality.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
/** * * @return the number of reads at the given site, trying first {@Link GATKVCFConstants.RAW_MAPPING_QUALITY_WITH_DEPTH_KEY}, * falling back to calculating the value as InfoField {@link VCFConstants#DEPTH_KEY} minus the * format field {@link GATKVCFConstants#MIN_DP_FORMAT_KEY} or DP of each of the HomRef genotypes at that site. * If neither of those is possible, will fall back to calculating the reads from the likelihoods data if provided. * @throws UserException.BadInput if the {@link VCFConstants#DEPTH_KEY} is missing or if the calculated depth is <= 0 */ @VisibleForTesting static long getNumOfReads(final VariantContext vc, final AlleleLikelihoods<GATKRead, Allele> likelihoods) { if(vc.hasAttribute(GATKVCFConstants.RAW_MAPPING_QUALITY_WITH_DEPTH_KEY)) { List<Long> mqTuple = VariantContextGetters.getAttributeAsLongList(vc, GATKVCFConstants.RAW_MAPPING_QUALITY_WITH_DEPTH_KEY,0L); if (mqTuple.get(TOTAL_DEPTH_INDEX) > 0) { return mqTuple.get(TOTAL_DEPTH_INDEX); } } long numOfReads = 0; if (vc.hasAttribute(VCFConstants.DEPTH_KEY)) { numOfReads = VariantContextGetters.getAttributeAsLong(vc, VCFConstants.DEPTH_KEY, -1L); if(vc.hasGenotypes()) { for(final Genotype gt : vc.getGenotypes()) { if(gt.isHomRef()) { //site-level DP contribution will come from MIN_DP for gVCF-called reference variants or DP for BP resolution if (gt.hasExtendedAttribute(GATKVCFConstants.MIN_DP_FORMAT_KEY)) { numOfReads -= Long.parseLong(gt.getExtendedAttribute(GATKVCFConstants.MIN_DP_FORMAT_KEY).toString()); } else if (gt.hasDP()) { numOfReads -= gt.getDP(); } } } } // If there is no depth key, try to compute from the likelihoods } else if (likelihoods != null && likelihoods.numberOfAlleles() != 0) { for (int i = 0; i < likelihoods.numberOfSamples(); i++) { for (GATKRead read : likelihoods.sampleEvidence(i)) { if (read.getMappingQuality() != QualityUtils.MAPPING_QUALITY_UNAVAILABLE) { numOfReads++; } } } } if (numOfReads <= 0) { numOfReads = -1; //return -1 to result in a NaN } return numOfReads; }
Example 12
Source File: MendelianViolationEvaluator.java From gatk with BSD 3-Clause "New" or "Revised" License | 4 votes |
public void update1(VariantContext vc, final ReferenceContext referenceContext, final ReadsContext readsContext, final FeatureContext featureContext) { if (vc.isBiallelic() && vc.hasGenotypes()) { // todo -- currently limited to biallelic loci if (mv.countFamilyViolations(sampleDB, null, vc) > 0){ nLociViolations++; nViolations += mv.getViolationsCount(); mvRefRef_Var += mv.getParentsRefRefChildVar(); mvRefRef_Het += mv.getParentsRefRefChildHet(); mvRefHet_Var += mv.getParentsRefHetChildVar(); mvRefVar_Var += mv.getParentsRefVarChildVar(); mvRefVar_Ref += mv.getParentsRefVarChildRef(); mvVarHet_Ref += mv.getParentsVarHetChildRef(); mvVarVar_Ref += mv.getParentsVarVarChildRef(); mvVarVar_Het += mv.getParentsVarVarChildHet(); } HomRefHomRef_HomRef += mv.getRefRefRef(); HetHet_Het += mv.getHetHetHet(); HetHet_HomRef += mv.getHetHetHomRef(); HetHet_HomVar += mv.getHetHetHomVar(); HomVarHomVar_HomVar += mv.getVarVarVar(); HomRefHomVAR_Het += mv.getRefVarHet(); HetHet_inheritedRef += mv.getParentsHetHetInheritedRef(); HetHet_inheritedVar += mv.getParentsHetHetInheritedVar(); HomRefHet_inheritedRef += mv.getParentsRefHetInheritedRef(); HomRefHet_inheritedVar += mv.getParentsRefHetInheritedVar(); HomVarHet_inheritedRef += mv.getParentsVarHetInheritedRef(); HomVarHet_inheritedVar += mv.getParentsVarHetInheritedVar(); if(mv.getFamilyCalledCount()>0 || mv.getFamilyLowQualsCount()>0 || mv.getFamilyCalledCount()>0){ nVariants++; nFamCalled += mv.getFamilyCalledCount(); nLowQual += mv.getFamilyLowQualsCount(); nNoCall += mv.getFamilyNoCallCount(); nVarFamCalled += mv.getVarFamilyCalledCount(); } else{ nSkipped++; } } }