From 75742e197da2b0db2779c9981a8eff33fb6aeeae Mon Sep 17 00:00:00 2001
From: DavyCats <davycats.dc@gmail.com>
Date: Wed, 4 Apr 2018 16:17:30 +0200
Subject: [PATCH] adjust memory

---
 biopet.wdl |  4 ++--
 gatk.wdl   | 45 ++++++++++++++++++++++++++++++++-------------
 htseq.wdl  |  4 +++-
 picard.wdl | 31 +++++++++++++++++++++++--------
 star.wdl   |  6 ++++--
 5 files changed, 64 insertions(+), 26 deletions(-)

diff --git a/biopet.wdl b/biopet.wdl
index d76a3cc..9d1a319 100644
--- a/biopet.wdl
+++ b/biopet.wdl
@@ -65,7 +65,7 @@ task SampleConfig {
         set -e -o pipefail
         ${preCommand}
         mkdir -p . ${"$(dirname " + jsonOutputPath + ")"} ${"$(dirname " + tsvOutputPath + ")"}
-        java -Xmx${true=""+memory false="3" defined(memory)}G -jar ${tool_jar} \
+        java -Xmx${true=""+memory false="4" defined(memory)}G -jar ${tool_jar} \
         -i ${sep="-i " inputFiles} \
         ${"--sample " + sample} \
         ${"--library " + library} \
@@ -82,7 +82,7 @@ task SampleConfig {
     }
 
     runtime {
-        memory: ceil(select_first([memory, 3.0]) * select_first([memoryMultiplier, 2.0]))
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 2.0]))
     }
 }
 
diff --git a/gatk.wdl b/gatk.wdl
index 6d05711..404a2c1 100644
--- a/gatk.wdl
+++ b/gatk.wdl
@@ -33,7 +33,7 @@ task BaseRecalibrator {
     }
 
     runtime {
-        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 2]))
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 1.5]))
     }
 }
 
@@ -50,10 +50,14 @@ task ApplyBQSR {
     File ref_fasta_index
     Int? compression_level
 
+    Float? memory
+    Float? memoryMultiplier
+
     command {
         set -e -o pipefail
         ${preCommand}
-        java ${"-Dsamjdk.compression_level=" + compression_level} -Xms4G -jar ${gatk_jar} \
+        java ${"-Dsamjdk.compression_level=" + compression_level} \
+        -Xms${true=memory false="4" defined(memory)}G -jar ${gatk_jar} \
           ApplyBQSR \
           --create-output-bam-md5 \
           --add-output-sam-program-record \
@@ -72,7 +76,7 @@ task ApplyBQSR {
     }
 
     runtime {
-        memory: 6
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 1.5]))
     }
 }
 
@@ -83,10 +87,13 @@ task GatherBqsrReports {
     Array[File] input_bqsr_reports
     String output_report_filepath
 
+    Float? memory
+    Float? memoryMultiplier
+
     command {
         set -e -o pipefail
         ${preCommand}
-        java -Xms3G -jar ${gatk_jar} \
+        java -Xms${true=memory false="3" defined(memory)}G -jar ${gatk_jar} \
         GatherBQSRReports \
         -I ${sep=' -I ' input_bqsr_reports} \
         -O ${output_report_filepath}
@@ -97,7 +104,7 @@ task GatherBqsrReports {
     }
 
     runtime {
-        memory: 4
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 1.5]))
     }
 }
 
@@ -115,10 +122,14 @@ task HaplotypeCallerGvcf {
     Int? compression_level
     String gatk_jar
 
+    Float? memory
+    Float? memoryMultiplier
+
     command {
         set -e -o pipefail
         ${preCommand}
-        java ${"-Dsamjdk.compression_level=" + compression_level} -Xmx4G -jar ${gatk_jar} \
+        java ${"-Dsamjdk.compression_level=" + compression_level} \
+        -Xmx${true=memory false="4" defined(memory)}G -jar ${gatk_jar} \
           HaplotypeCaller \
           -R ${ref_fasta} \
           -O ${gvcf_basename}.vcf.gz \
@@ -134,7 +145,7 @@ task HaplotypeCallerGvcf {
     }
 
     runtime {
-        memory: 6
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 1.5]))
     }
 }
 
@@ -156,12 +167,15 @@ task GenotypeGVCFs {
     File dbsnp_vcf_index
 
     Int? compression_level
+    Float? memory
+    Float? memoryMultiplier
 
     command {
         set -e -o pipefail
         ${preCommand}
 
-        java ${"-Dsamjdk.compression_level=" + compression_level} -Xmx4G -jar ${gatk_jar} \
+        java ${"-Dsamjdk.compression_level=" + compression_level} \
+        -Xmx${true=memory false="4" defined(memory)}G -jar ${gatk_jar} \
          GenotypeGVCFs \
          -R ${ref_fasta} \
          -O ${output_basename + ".vcf.gz"} \
@@ -179,7 +193,7 @@ task GenotypeGVCFs {
     }
 
     runtime{
-        memory: 6
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 1.5]))
     }
 }
 
@@ -198,13 +212,16 @@ task CombineGVCFs {
     File ref_dict
 
     Int? compression_level
+    Float? memory
+    Float? memoryMultiplier
 
     command {
         set -e -o pipefail
         ${preCommand}
 
         if [ ${length(gvcf_files)} -gt 1 ]; then
-            java ${"-Dsamjdk.compression_level=" + compression_level} -Xmx4G -jar ${gatk_jar} \
+            java ${"-Dsamjdk.compression_level=" + compression_level} \
+            -Xmx${true=memory false="4" defined(memory)}G -jar ${gatk_jar} \
              CombineGVCFs \
              -R ${ref_fasta} \
              -O ${output_basename + ".vcf.gz"} \
@@ -222,7 +239,7 @@ task CombineGVCFs {
     }
 
     runtime {
-        memory: 6
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 1.5]))
     }
 }
 
@@ -237,11 +254,13 @@ task SplitNCigarReads {
     String gatk_jar
     Array[File]+ intervals
 
+    Float? memory
+    Float? memoryMultiplier
 
     command {
         set -e -o pipefail
         ${preCommand}
-        java -Xms4G -jar ${gatk_jar} \
+        java -Xms${true=memory false="4" defined(memory)}G -jar ${gatk_jar} \
         -I ${input_bam} \
         -R ${ref_fasta} \
         -O ${output_bam} # might have to be -o depending on GATK version \
@@ -254,6 +273,6 @@ task SplitNCigarReads {
     }
 
     runtime {
-        memory: 6
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 1.5]))
     }
 }
diff --git a/htseq.wdl b/htseq.wdl
index 62091ff..bccbdd2 100644
--- a/htseq.wdl
+++ b/htseq.wdl
@@ -7,6 +7,8 @@ task HTSeqCount {
     String? order
     String? stranded
 
+    Int? memory
+
     command {
         set -e -o pipefail
         ${preCommand}
@@ -24,6 +26,6 @@ task HTSeqCount {
     }
 
     runtime {
-        memory: 3
+        memory: select_first([memory, 3])
     }
 }
\ No newline at end of file
diff --git a/picard.wdl b/picard.wdl
index 24e8a51..d394ee0 100644
--- a/picard.wdl
+++ b/picard.wdl
@@ -4,11 +4,14 @@ task ScatterIntervalList {
     Int scatter_count
     String picard_jar
 
+    Float? memory
+    Float? memoryMultiplier
+
     command {
         set -e -o pipefail
         ${preCommand}
         mkdir scatter_list
-        java -Xmx4G -jar ${picard_jar} \
+        java -Xmx${true=memory false="4" defined(memory)}G -jar ${picard_jar} \
           IntervalListTools \
           SCATTER_COUNT=${scatter_count} \
           SUBDIVISION_MODE=BALANCING_WITHOUT_INTERVAL_SUBDIVISION_WITH_OVERFLOW \
@@ -24,7 +27,7 @@ task ScatterIntervalList {
     }
 
     runtime {
-        memory: 6
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 1.5]))
     }
 }
 
@@ -36,10 +39,14 @@ task GatherBamFiles {
     Int? compression_level
     String picard_jar
 
+    Float? memory
+    Float? memoryMultiplier
+
     command {
         set -e -o pipefail
         ${preCommand}
-        java ${"-Dsamjdk.compression_level=" + compression_level} -Xmx4G -jar ${picard_jar} \
+        java ${"-Dsamjdk.compression_level=" + compression_level} \
+        -Xmx${true=memory false="4" defined(memory)}G -jar ${picard_jar} \
           GatherBamFiles \
           INPUT=${sep=' INPUT=' input_bams} \
           OUTPUT=${output_bam_path} \
@@ -54,7 +61,7 @@ task GatherBamFiles {
     }
 
     runtime {
-        memory: 6
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 1.5]))
     }
 }
 
@@ -67,6 +74,9 @@ task MarkDuplicates {
     Int? compression_level
     String picard_jar
 
+    Float? memory
+    Float? memoryMultiplier
+
     # The program default for READ_NAME_REGEX is appropriate in nearly every case.
     # Sometimes we wish to supply "null" in order to turn off optical duplicate detection
     # This can be desirable if you don't mind the estimated library size being wrong and optical duplicate detection is taking >7 days and failing
@@ -79,7 +89,8 @@ task MarkDuplicates {
         set -e -o pipefail
         ${preCommand}
         mkdir -p $(dirname ${output_bam_path})
-        java ${"-Dsamjdk.compression_level=" + compression_level} -Xmx4G -jar ${picard_jar} \
+        java ${"-Dsamjdk.compression_level=" + compression_level} \
+        -Xmx${true=memory false="4" defined(memory)}G -jar ${picard_jar} \
           MarkDuplicates \
           INPUT=${sep=' INPUT=' input_bams} \
           OUTPUT=${output_bam_path} \
@@ -99,7 +110,7 @@ task MarkDuplicates {
     }
 
     runtime {
-        memory: 6
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 1.5]))
     }
 }
 
@@ -112,12 +123,16 @@ task MergeVCFs {
     Int? compression_level
     String picard_jar
 
+    Float? memory
+    Float? memoryMultiplier
+
     # Using MergeVcfs instead of GatherVcfs so we can create indices
     # See https://github.com/broadinstitute/picard/issues/789 for relevant GatherVcfs ticket
     command {
         set -e -o pipefail
         ${preCommand}
-        java ${"-Dsamjdk.compression_level=" + compression_level} -Xmx4G -jar ${picard_jar} \
+        java ${"-Dsamjdk.compression_level=" + compression_level} \
+        -Xmx${true=memory false="4" defined(memory)}G -jar ${picard_jar} \
           MergeVcfs \
           INPUT=${sep=' INPUT=' input_vcfs} \
           OUTPUT=${output_vcf_path}
@@ -129,6 +144,6 @@ task MergeVCFs {
     }
 
     runtime {
-        memory: 6
+        memory: ceil(select_first([memory, 4.0]) * select_first([memoryMultiplier, 1.5]))
     }
 }
\ No newline at end of file
diff --git a/star.wdl b/star.wdl
index 1ba1545..8b9f435 100644
--- a/star.wdl
+++ b/star.wdl
@@ -13,6 +13,8 @@ task Star {
     String? twopassMode
     Array[String]? outSAMattrRGline
 
+    Float? memory
+
     #TODO needs to be extended for all possible output extensions
     Map[String, String] samOutputNames = {"BAM SortedByCoordinate": "sortedByCoord.out.bam"}
 
@@ -37,7 +39,7 @@ task Star {
     }
 
     runtime {
-        threads: select_first([runThreadN])
-        memory: 10
+        threads: select_first([runThreadN, 1])
+        memory: select_first([memory, 10])
     }
 }
\ No newline at end of file
-- 
GitLab