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.variantcontext.VariantContextUtils;
6 import htsjdk.variant.vcf.VCFConstants;
7 import htsjdk.variant.vcf.VCFInfoHeaderLine;
8 import htsjdk.variant.vcf.VCFStandardHeaderLines;
9 import org.broadinstitute.barclay.help.DocumentedFeature;
10 import org.broadinstitute.hellbender.engine.ReferenceContext;
11 import org.broadinstitute.hellbender.utils.Utils;
12 import org.broadinstitute.hellbender.utils.genotyper.AlleleLikelihoods;
13 import org.broadinstitute.hellbender.utils.help.HelpConstants;
14 import org.broadinstitute.hellbender.utils.read.GATKRead;
15 
16 import java.util.*;
17 
18 
19 /**
20  * Counts and frequency of alleles in called genotypes
21  *
22  * <p>This annotation outputs the following:</p>
23  *
24  *     <ul>
25  *     <li>Number of times each ALT allele is represented, in the same order as listed (AC)</li>
26  *     <li>Frequency of each ALT allele, in the same order as listed (AF)</li>
27  *     <li>Total number of alleles in called genotypes (AN)</li>
28  * </ul>
29  * <h3>Example</h3>
30  * <pre>AC=1;AF=0.500;AN=2</pre>
31  * <p>This set of annotations, relating to a heterozygous call(0/1) means there is 1 alternate allele in the genotype. The corresponding allele frequency is 0.5 because there is 1 alternate allele and 1 reference allele in the genotype.
32  * The total number of alleles in the genotype should be equivalent to the ploidy of the sample.</p>
33  *
34  */
35 @DocumentedFeature(groupName=HelpConstants.DOC_CAT_ANNOTATORS, groupSummary=HelpConstants.DOC_CAT_ANNOTATORS_SUMMARY, summary="Counts and frequency of alleles in called genotypes (AC, AF, AN)")
36 public final class ChromosomeCounts extends InfoFieldAnnotation implements StandardAnnotation {
37 
38     public static final String[] keyNames = {
39             VCFConstants.ALLELE_NUMBER_KEY,
40             VCFConstants.ALLELE_COUNT_KEY,
41             VCFConstants.ALLELE_FREQUENCY_KEY };
42 
43     public static final VCFInfoHeaderLine[] descriptions = {
44             VCFStandardHeaderLines.getInfoLine(VCFConstants.ALLELE_FREQUENCY_KEY),
45             VCFStandardHeaderLines.getInfoLine(VCFConstants.ALLELE_COUNT_KEY),
46             VCFStandardHeaderLines.getInfoLine(VCFConstants.ALLELE_NUMBER_KEY) };
47 
48 
49     @Override
annotate(final ReferenceContext ref, final VariantContext vc, AlleleLikelihoods<GATKRead, Allele> likelihoods)50     public Map<String, Object> annotate(final ReferenceContext ref,
51                                         final VariantContext vc,
52                                         AlleleLikelihoods<GATKRead, Allele> likelihoods) {
53         Utils.nonNull(vc);
54         if ( ! vc.hasGenotypes() ) {
55             return Collections.emptyMap();
56         }
57 
58         return VariantContextUtils.calculateChromosomeCounts(vc, new LinkedHashMap<>(), true, Collections.emptySet());
59     }
60 
61     @Override
getKeyNames()62     public List<String> getKeyNames() {
63         return Arrays.asList(keyNames);
64     }
65 
66     @Override
getDescriptions()67     public List<VCFInfoHeaderLine> getDescriptions() { return Arrays.asList(descriptions); }
68 }
69