From e1b5f95134d34f1a6693f087abb866a305058b40 Mon Sep 17 00:00:00 2001 From: jamesemery Date: Tue, 24 Sep 2024 10:08:42 -0400 Subject: [PATCH] Swapped mito mode in Mutect to use the mode argument utils, providing better override behavior and documentation (#8986) --- .../walkers/mutect/M2ArgumentCollection.java | 38 +++++++++++-------- .../tools/walkers/mutect/Mutect2.java | 19 ++++------ 2 files changed, 30 insertions(+), 27 deletions(-) diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/M2ArgumentCollection.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/M2ArgumentCollection.java index a6c619f1b17..a3e04a2f02a 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/M2ArgumentCollection.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/M2ArgumentCollection.java @@ -6,8 +6,13 @@ import org.broadinstitute.barclay.argparser.Argument; import org.broadinstitute.barclay.argparser.ArgumentCollection; import org.broadinstitute.barclay.argparser.DeprecatedFeature; +import org.broadinstitute.hellbender.cmdline.GATKPlugin.DefaultGATKVariantAnnotationArgumentCollection; import org.broadinstitute.hellbender.cmdline.ReadFilterArgumentDefinitions; +import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions; import org.broadinstitute.hellbender.engine.FeatureInput; +import org.broadinstitute.hellbender.engine.spark.AssemblyRegionArgumentCollection; +import org.broadinstitute.hellbender.tools.walkers.genotyper.GenotypeAssignmentMethod; +import org.broadinstitute.hellbender.tools.walkers.genotyper.GenotypeCalculationArgumentCollection; import org.broadinstitute.hellbender.tools.walkers.haplotypecaller.FlowBasedAlignmentArgumentCollection; import org.broadinstitute.hellbender.tools.walkers.haplotypecaller.*; import org.broadinstitute.hellbender.tools.walkers.haplotypecaller.readthreading.ReadThreadingAssembler; @@ -95,18 +100,6 @@ protected ReadThreadingAssemblerArgumentCollection getReadThreadingAssemblerArgu return new MutectReadThreadingAssemblerArgumentCollection(); } - @Override - public ReadThreadingAssembler createReadThreadingAssembler(){ - if(mitochondria ) { - assemblerArgs.recoverAllDanglingBranches = true; - if (assemblerArgs.pruningLogOddsThreshold == ReadThreadingAssemblerArgumentCollection.DEFAULT_PRUNING_LOG_ODDS_THRESHOLD) { - assemblerArgs.pruningLogOddsThreshold = DEFAULT_MITO_PRUNING_LOG_ODDS_THRESHOLD; - } - } - - return super.createReadThreadingAssembler(); - } - @ArgumentCollection public CollectF1R2CountsArgumentCollection f1r2Args = new CollectF1R2CountsArgumentCollection(); @@ -164,8 +157,7 @@ public ReadThreadingAssembler createReadThreadingAssembler(){ public double getDefaultAlleleFrequency() { return afOfAllelesNotInGermlineResource >= 0 ? afOfAllelesNotInGermlineResource : - (mitochondria ? DEFAULT_AF_FOR_MITO_CALLING: - (normalSamples.isEmpty() ? DEFAULT_AF_FOR_TUMOR_ONLY_CALLING : DEFAULT_AF_FOR_TUMOR_NORMAL_CALLING)); + (normalSamples.isEmpty() ? DEFAULT_AF_FOR_TUMOR_ONLY_CALLING : DEFAULT_AF_FOR_TUMOR_NORMAL_CALLING); } /** @@ -176,6 +168,20 @@ public double getDefaultAlleleFrequency() { @Argument(fullName = MITOCHONDRIA_MODE_LONG_NAME, optional = true, doc="Mitochondria mode sets emission and initial LODs to 0.") public Boolean mitochondria = false; + /** + * List of arguments to be set when a user specifies mitochondria mode. Each argument will be displayed in the help message. + */ + public String[] getMitochondriaModeNameValuePairs() { + return new String[]{ + DEFAULT_AF_LONG_NAME, String.valueOf(DEFAULT_AF_FOR_MITO_CALLING), + EMISSION_LOD_LONG_NAME, String.valueOf(DEFAULT_MITO_EMISSION_LOD), + INITIAL_TUMOR_LOG_10_ODDS_LONG_NAME, String.valueOf(DEFAULT_MITO_INITIAL_LOG_10_ODDS), + ReadThreadingAssemblerArgumentCollection.RECOVER_ALL_DANGLING_BRANCHES_LONG_NAME, "true", + ReadThreadingAssemblerArgumentCollection.PRUNING_LOD_THRESHOLD_LONG_NAME, String.valueOf(DEFAULT_MITO_PRUNING_LOG_ODDS_THRESHOLD), + StandardArgumentDefinitions.ANNOTATION_LONG_NAME, "OriginalAlignment" + }; + } + /** * If true, collect Mutect3 data for learning; otherwise collect data for generating calls with a pre-trained model */ @@ -250,7 +256,7 @@ public double getEmissionLogOdds() { if (emitReferenceConfidence != ReferenceConfidenceMode.NONE) { return MathUtils.log10ToLog(DEFAULT_GVCF_LOG_10_ODDS); } - return MathUtils.log10ToLog(mitochondria && emissionLog10Odds == DEFAULT_EMISSION_LOG_10_ODDS ? DEFAULT_MITO_EMISSION_LOD : emissionLog10Odds); + return MathUtils.log10ToLog(emissionLog10Odds); } /** @@ -263,7 +269,7 @@ public double getInitialLogOdds() { if (emitReferenceConfidence != ReferenceConfidenceMode.NONE) { return MathUtils.log10ToLog(DEFAULT_GVCF_LOG_10_ODDS); } - return MathUtils.log10ToLog(mitochondria && initialLog10Odds == DEFAULT_INITIAL_LOG_10_ODDS ? DEFAULT_MITO_INITIAL_LOG_10_ODDS : initialLog10Odds); + return MathUtils.log10ToLog(initialLog10Odds); } diff --git a/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/Mutect2.java b/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/Mutect2.java index 0120fa9dae3..d6073a6c7d8 100644 --- a/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/Mutect2.java +++ b/src/main/java/org/broadinstitute/hellbender/tools/walkers/mutect/Mutect2.java @@ -7,9 +7,11 @@ import org.broadinstitute.barclay.argparser.CommandLineException; import org.broadinstitute.barclay.argparser.CommandLineProgramProperties; import org.broadinstitute.barclay.help.DocumentedFeature; +import org.broadinstitute.hellbender.cmdline.GATKPlugin.GATKReadFilterPluginDescriptor; import org.broadinstitute.hellbender.cmdline.StandardArgumentDefinitions; import org.broadinstitute.hellbender.cmdline.programgroups.ShortVariantDiscoveryProgramGroup; import org.broadinstitute.hellbender.engine.*; +import org.broadinstitute.hellbender.engine.filters.MappingQualityReadFilter; import org.broadinstitute.hellbender.engine.filters.ReadFilter; import org.broadinstitute.hellbender.exceptions.UserException; import org.broadinstitute.hellbender.tools.walkers.annotator.*; @@ -283,17 +285,6 @@ public void onTraversalStart() { m2Engine.writeHeader(vcfWriter, getDefaultToolVCFHeaderLines()); } - @Override - public Collection makeVariantAnnotations(){ - final Collection annotations = super.makeVariantAnnotations(); - - if (MTAC.mitochondria) { - annotations.add(new OriginalAlignment()); - } - - return annotations; - } - @Override public Object onTraversalSuccess() { m2Engine.writeExtraOutputs(new File(outputVCF + DEFAULT_STATS_EXTENSION)); @@ -322,6 +313,12 @@ public void closeTool() { */ @Override protected String[] customCommandLineValidation() { + if (MTAC.mitochondria) { + ModeArgumentUtils.setArgValues( + getCommandLineParser(), + MTAC.getMitochondriaModeNameValuePairs(), + M2ArgumentCollection.MITOCHONDRIA_MODE_LONG_NAME); + } if (MTAC.flowMode != M2ArgumentCollection.FlowMode.NONE) { ModeArgumentUtils.setArgValues( getCommandLineParser(),