From 7db21a6481522746b0699c2756083d57326be164 Mon Sep 17 00:00:00 2001
From: Redmar van den Berg <RedmarvandenBerg@lumc.nl>
Date: Tue, 27 Oct 2020 16:02:35 +0100
Subject: [PATCH] Add support for outputPrefix with or without folder

---
 chunked-scatter.wdl |  3 +++
 lima.wdl            | 10 ++++++++++
 2 files changed, 13 insertions(+)

diff --git a/chunked-scatter.wdl b/chunked-scatter.wdl
index b54a7d2..8895c2a 100644
--- a/chunked-scatter.wdl
+++ b/chunked-scatter.wdl
@@ -24,6 +24,7 @@ task ChunkedScatter {
     input {
         File inputFile
         String prefix = "./scatter"
+        Boolean splitContigs = false
         Int? chunkSize
         Int? overlap
         Int? minimumBasesPerFile
@@ -40,6 +41,7 @@ task ChunkedScatter {
         ~{"-c " + chunkSize} \
         ~{"-o " + overlap} \
         ~{"-m " + minimumBasesPerFile} \
+        ~{true="--split-contigs " false="" splitContigs} \
         ~{inputFile}
     }
 
@@ -108,6 +110,7 @@ task ScatterRegions {
         splitContigs: {description: "If set, contigs are allowed to be split up over multiple files.", category: "advanced"}
         scatterSizeMillions: {description: "Over how many million base pairs should be scattered.", category: "common"}
         scatterSize: {description: "Overrides scatterSizeMillions with a smaller value if set.", category: "advanced"}
+        splitContigs: {description: "Allow contigs to be split during scattering.", category: "advanced"}
 
         timeMinutes: {description: "The maximum amount of time the job will run in minutes.", category: "advanced"}
         memory: {description: "The amount of memory this job will use.", category: "advanced"}
diff --git a/lima.wdl b/lima.wdl
index 38cf2d6..7ef9d4a 100644
--- a/lima.wdl
+++ b/lima.wdl
@@ -58,6 +58,7 @@ task Lima {
 
     command {
         set -e
+        mkdir -p "$(dirname ~{outputPrefix})"
         lima \
         ~{libraryDesignOptions[libraryDesign]} \
         ~{true="--score-full-pass" false="" scoreFullPass} \
@@ -86,6 +87,15 @@ task Lima {
         ~{inputBamFile} \
         ~{barcodeFile} \
         ~{outputPrefix + ".bam"}
+
+        # copy the files with the default filename to the folder specified in
+        # outputPrefix.
+        if [ "~{basename(outputPrefix)}.json" != "~{outputPrefix}.json" ]; then
+            cp "~{basename(outputPrefix)}.json" "~{outputPrefix}.json"
+            cp "~{basename(outputPrefix)}.lima.counts" "~{outputPrefix}.lima.counts"
+            cp "~{basename(outputPrefix)}.lima.report" "~{outputPrefix}.lima.report"
+            cp "~{basename(outputPrefix)}.lima.summary" "~{outputPrefix}.lima.summary"
+        fi
     }
 
     output {
-- 
GitLab