From a5d696686cb496a0a2bc60c74dda1f52490d44c1 Mon Sep 17 00:00:00 2001
From: Ruben Vorderman <r.h.p.vorderman@lumc.nl>
Date: Fri, 4 May 2018 13:31:07 +0200
Subject: [PATCH] added bwa index and samtools fastq

---
 bwa.wdl      | 34 ++++++++++++++++++++++++++++++++++
 samtools.wdl |  5 +++++
 2 files changed, 39 insertions(+)

diff --git a/bwa.wdl b/bwa.wdl
index 0a8b37f..5839a9c 100644
--- a/bwa.wdl
+++ b/bwa.wdl
@@ -3,6 +3,7 @@ task BwaMem {
     File inputR1
     File? inputR2
     String referenceFasta
+    Array[File] indexFiles # These indexFiles need to be added, otherwise cromwell will not find them.
     String outputPath
     String? readgroup
 
@@ -26,3 +27,36 @@ task BwaMem {
         memory: if defined(memory) then memory else 8
     }
 }
+
+task index {
+    File fasta
+    String? preCommand
+    String? constructionAlgorithm
+    Int? blockSize
+    String? outputDir
+    String fastaFilename = basename(fasta)
+
+    command {
+        set -e -o pipefail
+        ${"mkdir -p " + outputDir}
+        ${preCommand}
+        ln -sf ${fasta} ${outputDir + "/"}${fastaFilename}
+        bwa index \
+        ${"-a " + constructionAlgorithm} \
+        ${"-b" + blockSize} \
+        ${outputDir + "/"}${fastaFilename}
+    }
+
+    output {
+        File indexBase = if (defined(outputDir)) then select_first([outputDir]) + "/" + fastaFilename else fastaFilename
+        File indexedFasta = indexBase
+        Array[File] indexFiles = [indexBase + ".bwt",indexBase + ".pac",indexBase + ".sa",indexBase + ".amb",indexBase + ".ann"]
+    }
+    parameter_meta {
+        fasta: "Fasta file to be indexed"
+        constructionAlgorithm: "-a STR    BWT construction algorithm: bwtsw, is or rb2 [auto]"
+        blockSize: "-b INT    block size for the bwtsw algorithm (effective with -a bwtsw) [10000000]"
+        outputDir: "index will be created in this output directory"
+    }
+}
+
diff --git a/samtools.wdl b/samtools.wdl
index f425d2e..c9207d3 100644
--- a/samtools.wdl
+++ b/samtools.wdl
@@ -97,6 +97,11 @@ task fastq {
         ${"--threads " + totalThreads} \
 
     }
+    output {
+        File read1 = outputRead1
+        File? read2 = outputRead2
+        File? read0 = outputRead0
+    }
     runtime {
         cpu: totalThreads
         memory: select_first([memory, 1])
-- 
GitLab