From f22018dfe8d283e3a945de0560f0986fcc90f74b Mon Sep 17 00:00:00 2001
From: DavyCats <davycats.dc@gmail.com>
Date: Thu, 5 Apr 2018 15:42:56 +0200
Subject: [PATCH] link instead of merge if one bam file

---
 common.wdl   | 13 +++++++++++++
 samtools.wdl |  7 ++++++-
 2 files changed, 19 insertions(+), 1 deletion(-)

diff --git a/common.wdl b/common.wdl
index a780747..79be387 100644
--- a/common.wdl
+++ b/common.wdl
@@ -102,4 +102,17 @@ task appendToStringArray {
     runtime {
         memory: 1
     }
+}
+
+task createLink {
+    File inputFile
+    String outputPath
+
+    command {
+        ln -sf ${inputFile} ${outputPath}
+    }
+
+    output {
+        File link = outputPath
+    }
 }
\ No newline at end of file
diff --git a/samtools.wdl b/samtools.wdl
index 4dd5e29..249143f 100644
--- a/samtools.wdl
+++ b/samtools.wdl
@@ -21,7 +21,12 @@ task Merge {
     command {
         set -e -o pipefail
         ${preCommand}
-        samtools merge ${outputBamPath} ${sep=' ' bamFiles}
+        if [ ${length(bamFiles)} -gt 1 ]
+          then
+            samtools merge ${outputBamPath} ${sep=' ' bamFiles}
+          else
+            ln -sf ${bamFiles} ${outputBamPath}
+        fi
     }
 
     output {
-- 
GitLab