-
Notifications
You must be signed in to change notification settings - Fork 586
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Adding argument to GenotypeGVCFs to keep only RAW_GT_COUNT #7996
Changes from 3 commits
9ec8ca4
4a8b3cf
522cd29
470c858
bf9fffc
263d2d8
7462183
aaad296
65e4309
27b3994
fdccc7b
8d314f6
f7b8aa9
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -98,6 +98,8 @@ public final class GenotypeGVCFs extends VariantLocusWalker { | |
public static final String ALL_SITES_SHORT_NAME = "all-sites"; | ||
public static final String KEEP_COMBINED_LONG_NAME = "keep-combined-raw-annotations"; | ||
public static final String KEEP_COMBINED_SHORT_NAME = "keep-combined"; | ||
public static final String KEEP_SPECIFIED_RAW_ANNOTATION_LONG_NAME = "keep-specific-raw-annotation"; | ||
public static final String KEEP_SPECIFIED_RAW_ANNOTATION_SHORT_NAME = "keep-raw"; | ||
public static final String FORCE_OUTPUT_INTERVALS_NAME = "force-output-intervals"; | ||
|
||
@Argument(fullName = StandardArgumentDefinitions.OUTPUT_LONG_NAME, shortName = StandardArgumentDefinitions.OUTPUT_SHORT_NAME, | ||
|
@@ -132,19 +134,25 @@ public final class GenotypeGVCFs extends VariantLocusWalker { | |
doc = "LOD threshold to emit variant to VCF.") | ||
protected double tlodThreshold = 3.5; //allow for some lower quality variants | ||
|
||
|
||
/** | ||
* Margin of error in allele fraction to consider a somatic variant homoplasmic, i.e. if there is less than a 0.1% reference allele fraction, those reads are likely errors | ||
*/ | ||
@Argument(fullName=CombineGVCFs.ALLELE_FRACTION_DELTA_LONG_NAME, doc = "Margin of error in allele fraction to consider a somatic variant homoplasmic") | ||
protected double afTolerance = 1e-3; //based on Q30 as a "good" base quality score | ||
|
||
/** | ||
* If specified, keep the combined raw annotations (e.g. AS_SB_TABLE) after genotyping. This is applicable to Allele-Specific annotations | ||
* If specified, keep all the combined raw annotations (e.g. AS_SB_TABLE) after genotyping. This is applicable to Allele-Specific annotations | ||
*/ | ||
@Argument(fullName=KEEP_COMBINED_LONG_NAME, shortName = KEEP_COMBINED_SHORT_NAME, doc = "If specified, keep the combined raw annotations") | ||
protected boolean keepCombined = false; | ||
|
||
/** | ||
* Keep only the specific combined raw annotations specified (removing the other raw annotations if keep-combined-raw-annotations is not set). | ||
*/ | ||
@Argument(fullName= KEEP_SPECIFIED_RAW_ANNOTATION_LONG_NAME, shortName = KEEP_SPECIFIED_RAW_ANNOTATION_SHORT_NAME, optional = true, | ||
doc="Keep only the specific combined raw annotations specified (removing the other raw annotations).") | ||
protected List<String> keepSpecifiedRawAnnotations = new ArrayList<>(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Depending on what you do with |
||
|
||
@ArgumentCollection | ||
private GenotypeCalculationArgumentCollection genotypeArgs = new GenotypeCalculationArgumentCollection(); | ||
|
||
|
@@ -262,7 +270,7 @@ public void onTraversalStart() { | |
Collections.emptyList(); | ||
|
||
Collection<Annotation> variantAnnotations = makeVariantAnnotations(); | ||
annotationEngine = new VariantAnnotatorEngine(variantAnnotations, dbsnp.dbsnp, Collections.emptyList(), false, keepCombined); | ||
annotationEngine = new VariantAnnotatorEngine(variantAnnotations, dbsnp.dbsnp, Collections.emptyList(), false, keepCombined, keepSpecifiedRawAnnotations); | ||
|
||
merger = new ReferenceConfidenceVariantContextMerger(annotationEngine, getHeaderForVariants(), somaticInput, false, true); | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,12 +4,14 @@ | |
import htsjdk.variant.vcf.*; | ||
import org.apache.logging.log4j.LogManager; | ||
import org.apache.logging.log4j.Logger; | ||
import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions; | ||
import org.broadinstitute.hellbender.engine.FeatureContext; | ||
import org.broadinstitute.hellbender.engine.FeatureDataSource; | ||
import org.broadinstitute.hellbender.engine.FeatureInput; | ||
import org.broadinstitute.hellbender.engine.ReferenceContext; | ||
import org.broadinstitute.hellbender.exceptions.GATKException; | ||
import org.broadinstitute.hellbender.exceptions.UserException; | ||
import org.broadinstitute.hellbender.tools.walkers.GenotypeGVCFs; | ||
import org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.ReducibleAnnotation; | ||
import org.broadinstitute.hellbender.tools.walkers.annotator.allelespecific.ReducibleAnnotationData; | ||
import org.broadinstitute.hellbender.utils.Utils; | ||
|
@@ -43,6 +45,7 @@ public final class VariantAnnotatorEngine { | |
private boolean expressionAlleleConcordance; | ||
private final boolean useRawAnnotations; | ||
private final boolean keepRawCombinedAnnotations; | ||
private final List<String> rawAnnotationsToKeep; | ||
|
||
private final static Logger logger = LogManager.getLogger(VariantAnnotatorEngine.class); | ||
private final static OneShotLogger jumboAnnotationsLogger = new OneShotLogger(VariantAnnotatorEngine.class); | ||
|
@@ -59,17 +62,20 @@ public final class VariantAnnotatorEngine { | |
* @param useRaw When this is set to true, the annotation engine will call {@link ReducibleAnnotation#annotateRawData(ReferenceContext, VariantContext, AlleleLikelihoods)} | ||
* on annotations that extend {@link ReducibleAnnotation}, instead of {@link InfoFieldAnnotation#annotate(ReferenceContext, VariantContext, AlleleLikelihoods)}, | ||
* @param keepCombined If true, retain the combined raw annotation values instead of removing them after finalizing | ||
* @param rawAnnotationsToKeep List of raw annotations to keep even when others are removed | ||
*/ | ||
public VariantAnnotatorEngine(final Collection<Annotation> annotationList, | ||
final FeatureInput<VariantContext> dbSNPInput, | ||
final List<FeatureInput<VariantContext>> featureInputs, | ||
final boolean useRaw, | ||
boolean keepCombined){ | ||
boolean keepCombined, | ||
meganshand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
final List<String> rawAnnotationsToKeep){ | ||
Utils.nonNull(featureInputs, "comparisonFeatureInputs is null"); | ||
infoAnnotations = new ArrayList<>(); | ||
genotypeAnnotations = new ArrayList<>(); | ||
jumboInfoAnnotations = new ArrayList<>(); | ||
jumboGenotypeAnnotations = new ArrayList<>(); | ||
final List<String> variantAnnotationKeys = new ArrayList<>(); | ||
for (Annotation annot : annotationList) { | ||
if (annot instanceof InfoFieldAnnotation) { | ||
infoAnnotations.add((InfoFieldAnnotation) annot); | ||
|
@@ -82,11 +88,18 @@ public VariantAnnotatorEngine(final Collection<Annotation> annotationList, | |
} else { | ||
throw new GATKException.ShouldNeverReachHereException("Unexpected annotation type: " + annot.getClass().getName()); | ||
} | ||
variantAnnotationKeys.addAll(((VariantAnnotation) annot).getKeyNames()); | ||
} | ||
variantOverlapAnnotator = initializeOverlapAnnotator(dbSNPInput, featureInputs); | ||
reducibleKeys = new LinkedHashSet<>(); | ||
useRawAnnotations = useRaw; | ||
keepRawCombinedAnnotations = keepCombined; | ||
for (String rawAnnot : rawAnnotationsToKeep) { | ||
meganshand marked this conversation as resolved.
Show resolved
Hide resolved
|
||
if (!variantAnnotationKeys.contains(rawAnnot)) { | ||
throw new UserException("Requested --" + GenotypeGVCFs.KEEP_SPECIFIED_RAW_ANNOTATION_LONG_NAME + ": " + rawAnnot + " is not available. Add requested annotation with --" + StandardArgumentDefinitions.ANNOTATION_LONG_NAME + "."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's confusing that the command line looks something like: And this exception message, while helpful, doesn't actually tell you what value you need to supply to the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. |
||
} | ||
} | ||
this.rawAnnotationsToKeep = rawAnnotationsToKeep; | ||
for (InfoFieldAnnotation annot : infoAnnotations) { | ||
if (annot instanceof ReducibleAnnotation) { | ||
for (final String rawKey : ((ReducibleAnnotation) annot).getRawKeyNames()) { | ||
|
@@ -96,6 +109,14 @@ public VariantAnnotatorEngine(final Collection<Annotation> annotationList, | |
} | ||
} | ||
|
||
public VariantAnnotatorEngine(final Collection<Annotation> annotationList, | ||
final FeatureInput<VariantContext> dbSNPInput, | ||
final List<FeatureInput<VariantContext>> featureInputs, | ||
final boolean useRaw, | ||
boolean keepCombined){ | ||
this(annotationList, dbSNPInput, featureInputs, useRaw, keepCombined, Collections.emptyList()); | ||
} | ||
|
||
private VariantOverlapAnnotator initializeOverlapAnnotator(final FeatureInput<VariantContext> dbSNPInput, final List<FeatureInput<VariantContext>> featureInputs) { | ||
final Map<FeatureInput<VariantContext>, String> overlaps = new LinkedHashMap<>(); | ||
for ( final FeatureInput<VariantContext> fi : featureInputs) { | ||
|
@@ -253,6 +274,14 @@ public Map<String, Object> combineAnnotations(final List<Allele> allelesList, Ma | |
public VariantContext finalizeAnnotations(VariantContext vc, VariantContext originalVC) { | ||
final Map<String, Object> variantAnnotations = new LinkedHashMap<>(vc.getAttributes()); | ||
|
||
//save annotations that have been requested to be kept | ||
final Map<String, Object> savedRawAnnotations = new LinkedHashMap<>(); | ||
for(String rawAnnot : rawAnnotationsToKeep) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment about final here. Note that it's actually used in other loops in this method...up to you if you want to make it consistent everywhere. |
||
if (variantAnnotations.containsKey(rawAnnot)) { | ||
savedRawAnnotations.put(rawAnnot, variantAnnotations.get(rawAnnot)); | ||
} | ||
} | ||
|
||
// go through all the requested info annotationTypes | ||
for (final InfoFieldAnnotation annotationType : infoAnnotations) { | ||
if (annotationType instanceof ReducibleAnnotation) { | ||
|
@@ -280,6 +309,8 @@ public VariantContext finalizeAnnotations(VariantContext vc, VariantContext orig | |
variantAnnotations.remove(GATKVCFConstants.VARIANT_DEPTH_KEY); | ||
variantAnnotations.remove(GATKVCFConstants.RAW_GENOTYPE_COUNT_KEY); | ||
} | ||
//add back raw annotations that have specifically been requested to keep | ||
variantAnnotations.putAll(savedRawAnnotations); | ||
|
||
// generate a new annotated VC | ||
final VariantContextBuilder builder = new VariantContextBuilder(vc).attributes(variantAnnotations); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -43,8 +43,6 @@ | |
import java.security.NoSuchAlgorithmException; | ||
import java.util.*; | ||
import java.util.function.BiConsumer; | ||
import java.util.function.Consumer; | ||
import java.util.function.IntUnaryOperator; | ||
import java.util.stream.Collectors; | ||
import java.util.stream.Stream; | ||
|
||
|
@@ -930,7 +928,8 @@ public void testRawGtCountAnnotation() { | |
args.addReference(b37_reference_20_21) | ||
.addVCF(reblockedGVCF) | ||
.addOutput(output) | ||
.add("keep-combined-raw-annotations", true) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Note that this replaces the previous test in favor of this new one. Perhaps we should consider just adding a new test, so that we cover both 1) keeping all combined annotations, and 2) keeping only the specified raw annotations? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. We've now made these two arguments (keep all combined and keeping only specified) mutually exclusive (not at the time of your review, but since then based on other comments). So I'm going to leave this test as is. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, just to be clear, you mean you'll revert this test to its original behavior, right? In that case, will you add another test for the keep-specified behavior? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The original behavior of There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Sorry, by "original behavior" I mean the current behavior of the test as it is in master. This test sets In contrast, you modify the test in your branch so that only Probably not anything to sweat about, but that's all that I wanted to point out in my original comment. I'll leave it up to you to decide if There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Oh! Sorry, I see what you're saying now. I think I originally added this test as a way of testing |
||
.add(GenotypeGVCFs.KEEP_COMBINED_LONG_NAME, false) | ||
.add(GenotypeGVCFs.KEEP_SPECIFIED_RAW_ANNOTATION_LONG_NAME, GATKVCFConstants.RAW_GENOTYPE_COUNT_KEY) | ||
.add("A", "RawGtCount"); | ||
runCommandLine(args); | ||
|
||
|
@@ -942,6 +941,7 @@ public void testRawGtCountAnnotation() { | |
Assert.assertEquals(rawGtCount.get(0), "."); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. What's going on with the hom-ref count? I see the TODO in the RawGtCount class but I don't understand the fundamental limitation. Incidentally, perhaps we can go ahead and expand the header-line documentation of this annotation to explicitly give the hom-ref/het/hom-var order. Maybe this is obvious to everyone else, but why not document it for dummies like me? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The issue is that Also I added the documentation to the header line. |
||
Assert.assertEquals(rawGtCount.get(1), "2"); | ||
Assert.assertEquals(rawGtCount.get(2), "0"); | ||
Assert.assertFalse(vc.getAttributes().containsKey(GATKVCFConstants.RAW_MAPPING_QUALITY_WITH_DEPTH_KEY)); | ||
} | ||
|
||
} | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should we perhaps use
mutex
to ensure we don't use both-keep-raw
and-keep-combined
simultaneously?Do you have an idea of the usefulness of
-keep-combined
(i.e., the convenience of being able to keep all combined raw annotations, even if we don't know what those annotations might be) and where it might be currently used (e.g., WARP WDLs, etc.)? How much of a pain would it be to require the use of-keep-raw
in all cases---presumably one would always be able to know which annotations one wants to keep?In any case,
-keep-raw
and-keep-combined
(and the corresponding long names) don't really give the sense of-keep
and-keep-all
that is implemented here. Assuming we have the freedom to muck with the name of-keep-combined
, do you think it might be worth changing? And should we also change the short/long names of-keep-raw
to somehow includecombined
(as you note in the Javadoc here)?A general comment: as a relative neophyte to this annotation framework, I will say that I find the lack of clear documentation/definitions for terms like "combined" and "raw" makes it hard to be sure what these arguments (or even the tool) are doing, especially from the doc strings and tool docs alone. Given that you have more experience with this framework, do you feel the same, or do you think things are clear as is?
Happy to hash all of this out further offline/elsewhere, seems a bit thorny!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't know if
-keep-combined
is used anywhere currently. I'm assuming it's mostly useful for debugging/development, but I don't know. I would rather not break backwards compatibility though, so I think we should still leave it in and I have a preference to not rename it.I can add some more documentation for these arguments though to help make it clearer. I agree that the names don't well represent what they are doing.