@@ -275,8 +275,6 @@ workflow Mutect2 {
275275
276276 Int merged_vcf_size = ceil (size (M2 .unfiltered_vcf , "GB" ))
277277 Int merged_bamout_size = ceil (size (M2 .output_bamOut , "GB" ))
278- Int merged_tumor_pileups_size = ceil (size (M2 .tumor_pileups , "GB" ))
279- Int merged_normal_pileups_size = ceil (size (M2 .tumor_pileups , "GB" ))
280278
281279 if (run_ob_filter ) {
282280 call LearnReadOrientationModel {
@@ -314,7 +312,7 @@ workflow Mutect2 {
314312 if (defined (variants_for_contamination )) {
315313 call MergePileupSummaries as MergeTumorPileups {
316314 input :
317- input_tables = M2 .tumor_pileups ,
315+ input_tables = flatten ( M2 .tumor_pileups ) ,
318316 output_name = output_basename ,
319317 ref_dict = ref_dict ,
320318 runtime_params = standard_runtime
@@ -323,7 +321,7 @@ workflow Mutect2 {
323321 if (defined (normal_bam )){
324322 call MergePileupSummaries as MergeNormalPileups {
325323 input :
326- input_tables = M2 .normal_pileups ,
324+ input_tables = flatten ( M2 .normal_pileups ) ,
327325 output_name = output_basename ,
328326 ref_dict = ref_dict ,
329327 runtime_params = standard_runtime
@@ -596,10 +594,15 @@ task M2 {
596594 ~{true ='--f1r2-tar-gz f1r2.tar.gz' false ='' run_ob_filter } \
597595 ~{m2_extra_args }
598596
597+ m2_exit_code = $?
598+
599599 ### GetPileupSummaries
600- # These must be created, even if they remain empty, as cromwell doesn't support optional output
601- touch tumor-pileups.table
602- touch normal-pileups.table
600+
601+ # If the variants for contamination and the intervals for this scatter don't intersect, GetPileupSummaries
602+ # throws an error. However, there is nothing wrong with an empty intersection for our purposes; it simply doesn't
603+ # contribute to the merged pileup summaries that we create downstream. We implement this by with array outputs.
604+ # If the tool errors, no table is created and the glob yields an empty array.
605+ set +e
603606
604607 if [[ ! -z "~{variants_for_contamination}" ]]; then
605608 gatk --java-options "-Xmx~{command_mem}m" GetPileupSummaries -R ~{ref_fasta } -I ~{tumor_bam } ~{"--interval-set-rule INTERSECTION -L " + intervals } \
@@ -610,6 +613,9 @@ task M2 {
610613 -V ~{variants_for_contamination } -L ~{variants_for_contamination } -O normal-pileups.table
611614 fi
612615 fi
616+
617+ # the script only fails if Mutect2 itself fails
618+ exit $m2_exit_code
613619 >>>
614620
615621 runtime {
@@ -630,8 +636,8 @@ task M2 {
630636 String normal_sample = read_string ("normal_name.txt" )
631637 File stats = "~{output_stats }"
632638 File f1r2_counts = "f1r2.tar.gz"
633- File tumor_pileups = " tumor-pileups.table"
634- File normal_pileups = " normal-pileups.table"
639+ Array [ File ] tumor_pileups = glob ( "* tumor-pileups.table")
640+ Array [ File ] normal_pileups = glob ( "* normal-pileups.table")
635641 }
636642}
637643
@@ -726,7 +732,6 @@ task MergeStats {
726732 set -e
727733 export GATK_LOCAL_JAR = ~{default ="/root/gatk.jar" runtime_params .gatk_override }
728734
729-
730735 gatk --java-options "-Xmx~{runtime_params.command_mem}m" MergeMutectStats \
731736 -stats ~{sep =" -stats " stats } -O merged.stats
732737 }
0 commit comments