-
Notifications
You must be signed in to change notification settings - Fork 587
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 new argument to control variant output interval filtering. #6388
Changes from 6 commits
231be5a
e96d439
578a951
62e36c5
cec1af1
27beb55
edd6df2
2104c0e
fa1f0ee
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 |
---|---|---|
|
@@ -16,8 +16,11 @@ | |
import java.util.*; | ||
import java.util.stream.Stream; | ||
|
||
|
||
import org.broadinstitute.barclay.argparser.Advanced; | ||
import org.broadinstitute.barclay.argparser.Argument; | ||
import org.broadinstitute.barclay.argparser.ArgumentCollection; | ||
import org.broadinstitute.barclay.argparser.CommandLineException; | ||
import org.broadinstitute.barclay.argparser.CommandLinePluginDescriptor; | ||
import org.broadinstitute.hellbender.cmdline.CommandLineProgram; | ||
import org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKAnnotationPluginDescriptor; | ||
|
@@ -45,6 +48,7 @@ | |
import org.broadinstitute.hellbender.utils.reference.ReferenceUtils; | ||
import org.broadinstitute.hellbender.utils.variant.GATKVariantContextUtils; | ||
import org.broadinstitute.hellbender.utils.variant.writers.ShardingVCFWriter; | ||
import org.broadinstitute.hellbender.utils.variant.writers.IntervalFilteringVcfWriter; | ||
|
||
/** | ||
* Base class for all GATK tools. Tool authors that want to write a "GATK" tool but not use one of | ||
|
@@ -417,6 +421,13 @@ public int getDefaultCloudIndexPrefetchBufferSize() { | |
*/ | ||
public String getProgressMeterRecordLabel() { return ProgressMeter.DEFAULT_RECORD_LABEL; } | ||
|
||
/** | ||
* @return null for no output filtering of variants to the variant writer. Subclasses may override this to enforce other filtering schemes. | ||
*/ | ||
public IntervalFilteringVcfWriter.Mode getVariantFilteringOutputModeIfApplicable(){ | ||
return IntervalFilteringVcfWriter.Mode.ANYWHERE; | ||
} | ||
|
||
protected List<SimpleInterval> transformTraversalIntervals(final List<SimpleInterval> getIntervals, final SAMSequenceDictionary sequenceDictionary) { | ||
return getIntervals; | ||
} | ||
|
@@ -600,7 +611,7 @@ public boolean requiresIntervals() { | |
|
||
/** | ||
* Does this tool want to disable the progress meter? If so, override here to return true | ||
* | ||
* | ||
* @return true if this tools wants to disable progress meter output, otherwise false | ||
*/ | ||
public boolean disableProgressMeter() { | ||
|
@@ -727,12 +738,16 @@ protected void onStartup() { | |
|
||
initializeIntervals(); // Must be initialized after reference, reads and features, since intervals currently require a sequence dictionary from another data source | ||
|
||
if ( seqValidationArguments.performSequenceDictionaryValidation()) { | ||
if (seqValidationArguments.performSequenceDictionaryValidation()) { | ||
validateSequenceDictionaries(); | ||
} | ||
|
||
checkToolRequirements(); | ||
|
||
if ((getVariantFilteringOutputModeIfApplicable() != IntervalFilteringVcfWriter.Mode.ANYWHERE ) && userIntervals == null){ | ||
throw new CommandLineException.MissingArgument("-L or -XL", "Intervals are required if --" + StandardArgumentDefinitions.VARIANT_OUTPUT_INTERVAL_FILTERING_MODE_LONG_NAME + " was specified."); | ||
} | ||
|
||
initializeProgressMeter(getProgressMeterRecordLabel()); | ||
} | ||
|
||
|
@@ -911,20 +926,27 @@ public VariantContextWriter createVCFWriter(final Path outPath) { | |
if (outputSitesOnlyVCFs) { | ||
options.add(Options.DO_NOT_WRITE_GENOTYPES); | ||
} | ||
|
||
final VariantContextWriter unfilteredWriter; | ||
if (maxVariantsPerShard > 0) { | ||
return new ShardingVCFWriter( | ||
unfilteredWriter = new ShardingVCFWriter( | ||
outPath, | ||
maxVariantsPerShard, | ||
sequenceDictionary, | ||
createOutputVariantMD5, | ||
options.toArray(new Options[options.size()])); | ||
options.toArray(new Options[0])); | ||
} else { | ||
unfilteredWriter = GATKVariantContextUtils.createVCFWriter( | ||
jamesemery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
outPath, | ||
sequenceDictionary, | ||
createOutputVariantMD5, | ||
options.toArray(new Options[0])); | ||
} | ||
return GATKVariantContextUtils.createVCFWriter( | ||
outPath, | ||
sequenceDictionary, | ||
createOutputVariantMD5, | ||
options.toArray(new Options[options.size()])); | ||
|
||
return getVariantFilteringOutputModeIfApplicable() == IntervalFilteringVcfWriter.Mode.ANYWHERE ? | ||
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. I'm not quite sure this rename helps that much, it just adds another layer of indirection. It's then kind of confusing because tools below variantwalker might not be sure which to override. 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. changed to |
||
unfilteredWriter : | ||
new IntervalFilteringVcfWriter(unfilteredWriter, | ||
intervalArgumentCollection.getIntervals(getBestAvailableSequenceDictionary()), | ||
getVariantFilteringOutputModeIfApplicable()); | ||
} | ||
|
||
/** | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,11 +3,13 @@ | |
import htsjdk.samtools.SAMSequenceDictionary; | ||
import htsjdk.variant.variantcontext.VariantContext; | ||
import htsjdk.variant.vcf.VCFHeader; | ||
import org.broadinstitute.barclay.argparser.Advanced; | ||
import org.broadinstitute.barclay.argparser.Argument; | ||
import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions; | ||
import org.broadinstitute.hellbender.engine.filters.CountingReadFilter; | ||
import org.broadinstitute.hellbender.exceptions.GATKException; | ||
import org.broadinstitute.hellbender.utils.SimpleInterval; | ||
import org.broadinstitute.hellbender.utils.variant.writers.IntervalFilteringVcfWriter; | ||
|
||
import java.util.Spliterator; | ||
|
||
|
@@ -31,6 +33,28 @@ public abstract class VariantWalker extends VariantWalkerBase { | |
private FeatureDataSource<VariantContext> drivingVariants; | ||
private FeatureInput<VariantContext> drivingVariantsFeatureInput; | ||
|
||
@Argument(fullName = StandardArgumentDefinitions.VARIANT_OUTPUT_INTERVAL_FILTERING_MODE_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. I'm pretty sure all these changes need to go in VariantWalkerBase, not VariantWalker. I think that's why all the tests exploded. |
||
doc = "Restrict the output variants to ones that match the specified intervals according to the specified matching mode.", | ||
optional = true) | ||
@Advanced | ||
public IntervalFilteringVcfWriter.Mode outputVariantIntervalFilteringMode = getDefaultVariantOutputFilterMode(); | ||
|
||
/** | ||
* @return Default interval filtering mode for variant output. Subclasses may override this to set a different default. | ||
*/ | ||
public IntervalFilteringVcfWriter.Mode getDefaultVariantOutputFilterMode(){ | ||
return IntervalFilteringVcfWriter.Mode.ANYWHERE; | ||
} | ||
|
||
@Override | ||
public IntervalFilteringVcfWriter.Mode getVariantFilteringOutputModeIfApplicable() { | ||
if (outputVariantIntervalFilteringMode != null) { | ||
return outputVariantIntervalFilteringMode; | ||
} else { | ||
return super.getVariantFilteringOutputModeIfApplicable(); | ||
jamesemery marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} | ||
|
||
@Override | ||
protected SAMSequenceDictionary getSequenceDictionaryForDrivingVariants() { return drivingVariants.getSequenceDictionary(); } | ||
|
||
|
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.
If a tool overrides the default here its going to spit this message if the user doesn't provide intervals at all which i think is confusing about this message.... We should probably disambiguate the default and user supplied here...
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.
This is a good point. I'm not sure it's addressed by your changes though?
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.
Well pulling this down into variant walker base makes this a little more obnoxious to fix... I'm just going to add a comment clarifying but this is a head scratcher