1 package org.broadinstitute.hellbender.tools.walkers.annotator;
2 
3 import htsjdk.variant.variantcontext.Allele;
4 import htsjdk.variant.variantcontext.VariantContext;
5 import htsjdk.variant.vcf.VCFConstants;
6 import htsjdk.variant.vcf.VCFInfoHeaderLine;
7 import htsjdk.variant.vcf.VCFStandardHeaderLines;
8 import org.broadinstitute.barclay.help.DocumentedFeature;
9 import org.broadinstitute.hellbender.engine.ReferenceContext;
10 import org.broadinstitute.hellbender.utils.Utils;
11 import org.broadinstitute.hellbender.utils.genotyper.AlleleLikelihoods;
12 import org.broadinstitute.hellbender.utils.help.HelpConstants;
13 import org.broadinstitute.hellbender.utils.read.GATKRead;
14 
15 import java.util.Collections;
16 import java.util.List;
17 import java.util.Map;
18 
19 /**
20  * Total depth of coverage per sample and over all samples.
21  *
22  * <p>This annotation is used to provide counts of read depth at two different levels, with some important differences. At the sample level (FORMAT), the DP value is the count of reads that passed the caller's internal quality control metrics (such as MAPQ > 17, for example). At the site level (INFO), the DP value is the unfiltered depth over all samples.</p>
23  *
24  * <p>See the method documentation on <a href="http://www.broadinstitute.org/gatk/guide/article?id=4721">using coverage information</a> for important interpretation details.</p>
25  *
26  * <h3>Caveats</h3>
27  * <ul>
28  *     <li>If downsampling is enabled (as is done by default for some analyses to remove excessive coverage), the depth of coverage effectively seen by the caller may be inferior to the actual depth of coverage in the original file. If using "-dcov D", the maximum depth that can be seen for N samples will be N * D.</li>
29  * </ul>
30  *
31  * <h3>Related annotations</h3>
32  * <ul>
33  *     <li><b><a href="https://www.broadinstitute.org/gatk/guide/tooldocs/org_broadinstitute_gatk_tools_walkers_annotator_DepthPerAlleleBySample.php">DepthPerAlleleBySample</a></b> calculates depth of coverage for each allele per sample (AD).</li>
34  *     <li><b><a href="https://www.broadinstitute.org/gatk/guide/tooldocs/org_broadinstitute_gatk_tools_walkers_annotator_DepthPerSampleHC.php">DepthPerSampleHC</a></b> calculates depth of coverage after filtering by HaplotypeCaller.</li>
35  * </ul>
36  */
37 @DocumentedFeature(groupName=HelpConstants.DOC_CAT_ANNOTATORS, groupSummary=HelpConstants.DOC_CAT_ANNOTATORS_SUMMARY, summary="Total depth of coverage per sample and over all samples (DP)")
38 public final class Coverage extends InfoFieldAnnotation implements StandardAnnotation, StandardMutectAnnotation {
39 
40     @Override
annotate(final ReferenceContext ref, final VariantContext vc, final AlleleLikelihoods<GATKRead, Allele> likelihoods)41     public Map<String, Object> annotate(final ReferenceContext ref,
42                                         final VariantContext vc,
43                                         final AlleleLikelihoods<GATKRead, Allele> likelihoods) {
44         Utils.nonNull(vc);
45         if (likelihoods == null || likelihoods.evidenceCount() == 0) {
46             return Collections.emptyMap();
47         }
48 
49         final int depth = likelihoods.evidenceCount();
50         return Collections.singletonMap(getKeyNames().get(0), String.format("%d", depth));
51     }
52 
53     @Override
getKeyNames()54     public List<String> getKeyNames() { return Collections.singletonList(VCFConstants.DEPTH_KEY); }
55 
56     @Override
getDescriptions()57     public List<VCFInfoHeaderLine> getDescriptions() {
58         return Collections.singletonList(VCFStandardHeaderLines.getInfoLine(getKeyNames().get(0)));
59     }
60 }
61