From 0dc72531cf98e5190ae630e071e0bc8a1e013521 Mon Sep 17 00:00:00 2001
From: DavyCats <davycats.dc@gmail.com>
Date: Thu, 2 Aug 2018 15:19:38 +0200
Subject: [PATCH] fix somatic tasks and add supporting tasks

---
 gatk.wdl        |  3 ++-
 samplesheet.wdl |  6 +++--
 samtools.wdl    | 35 +++++++++++++++++++++++++++++
 strelka.wdl     | 60 ++++++++++++++++++++++++++++++++++++++++++++++++-
 vardict.wdl     | 22 ++++++++++--------
 5 files changed, 113 insertions(+), 13 deletions(-)

diff --git a/gatk.wdl b/gatk.wdl
index 75e45e5..7697ffa 100644
--- a/gatk.wdl
+++ b/gatk.wdl
@@ -298,7 +298,7 @@ task MuTect2 {
         String? preCommand
 
         Array[File]+ inputBams
-        File inputBamIndex
+        Array[File]+ inputBamIndex
         File refFasta
         File refFastaIndex
         File refDict
@@ -331,6 +331,7 @@ task MuTect2 {
 
     output {
         File vcfFile = outputVcf
+        File vcfIndex = outputVcf + ".tbi"
     }
 
     runtime {
diff --git a/samplesheet.wdl b/samplesheet.wdl
index 4bec92c..d036f4d 100644
--- a/samplesheet.wdl
+++ b/samplesheet.wdl
@@ -1,4 +1,5 @@
 version 1.0
+
 struct Readgroup {
     String id
     File R1
@@ -15,9 +16,10 @@ struct Library {
 struct Sample {
     String id
     Array[Library]+ libraries
+    String? control
 }
 
-task sampleConfigFileToStruct {
+task SampleConfigFileToStruct {
     input {
         File sampleConfigFile
         String outputJson = "output.json"
@@ -69,5 +71,5 @@ task sampleConfigFileToStruct {
     output {
         Map[String,Array[Sample]] map = read_json(outputJson)
         Array[Sample] samples = map["samples"]
-     }
+    }
 }
diff --git a/samtools.wdl b/samtools.wdl
index 2d91037..76cf5a4 100644
--- a/samtools.wdl
+++ b/samtools.wdl
@@ -1,5 +1,25 @@
 version 1.0
 
+task BgzipAndIndex {
+    input {
+        File inputFile
+        String outputDir
+        String type = "vcf"
+    }
+
+    String outputGz = outputDir + "/" + basename(inputFile) + ".gz"
+
+    command {
+        bgzip -c ~{inputFile} > ~{outputGz}
+        tabix ~{outputGz} -p ~{type}
+    }
+
+    output {
+        File compressed = outputGz
+        File index = outputGz + ".tbi"
+    }
+}
+
 task Index {
     input {
         String? preCommand
@@ -131,6 +151,21 @@ task Fastq {
     }
 }
 
+task Tabix {
+    input {
+        String inputFile
+        String type = "vcf"
+    }
+
+    command {
+        tabix ~{inputFile} -p ~{type}
+    }
+
+    output {
+        File index = inputFile + ".tbi"
+    }
+}
+
 task View {
     input {
         String? preCommand
diff --git a/strelka.wdl b/strelka.wdl
index 29e2a07..6094350 100644
--- a/strelka.wdl
+++ b/strelka.wdl
@@ -1,13 +1,69 @@
 version 1.0
 
+task Germline {
+    input {
+        String? preCommand
+        String? installDir
+        String runDir
+        Array[File]+ bams
+        Array[File]+ indexes
+        File refFasta
+        File? callRegions
+        File? callRegionsIndex
+        Boolean exome = false
+        Boolean rna = false
+
+        Int cores = 1
+        Int memory = 4
+    }
+
+    String toolCommand = if defined(installDir)
+        then installDir + "bin/configureStrelkaGermlineWorkflow.py"
+        else "configureStrelkaGermlineWorkflow.py"
+
+    command {
+        set -e -o pipefail
+        ~{preCommand}
+        ~{toolCommand} \
+        --bam ~{sep=" --bam " bams} \
+        --ref ~{refFasta} \
+        --runDir ~{runDir} \
+        ~{"--callRegions" + callRegions} \
+        ~{true="--exome" false="" exome} \
+        ~{true="--rna" false="" rna}
+
+        ~{runDir}/runWorkflow.py \
+        -m local \
+        -J ~{cores} \
+        -g ~{memory}
+    }
+
+    output {
+        File variants = runDir + "/results/variants.vcf.gz"
+        File variantsIndex = runDir + "/results/variants.vcf.gz.tbi"
+    }
+
+    runtime {
+        cpu: cores
+        memory: memory
+    }
+}
+
+
 task Somatic {
     input {
         String? preCommand
         String? installDir
         String runDir
         File normalBam
+        File normalIndex
         File tumorBam
+        File tumorIndex
         File refFasta
+        File? callRegions
+        File? callRegionsIndex
+        Boolean exome = false
+        Boolean rna = false
 
         Int cores = 1
         Int memory = 4
@@ -24,7 +80,9 @@ task Somatic {
         --normalBam ~{normalBam} \
         --tumorBam ~{tumorBam} \
         --ref ~{refFasta} \
-        --runDir ~{runDir}
+        --runDir ~{runDir} \
+        ~{"--callRegions" + callRegions} \
+        ~{true="--exome" false="" exome} \
 
         ~{runDir}/runWorkflow.py \
         -m local \
diff --git a/vardict.wdl b/vardict.wdl
index 9dbb0ac..849f3ff 100644
--- a/vardict.wdl
+++ b/vardict.wdl
@@ -4,12 +4,14 @@ task VarDict {
     input {
         String? installDir
 
+        String tumorSampleName
         File tumorBam
-        File normalBam
+        File tumorIndex
+        String? normalSampleName
+        File? normalBam
+        File? normalIndex
         File refFasta
         File bedFile
-        String tumorSampleName
-        String normalSampleName
         String outputVcf
 
         Int chromosomeColumn = 1
@@ -30,19 +32,21 @@ task VarDict {
         ~{toolCommand} \
         -G ~{refFasta} \
         -N ~{tumorSampleName} \
-        -b "~{tumorBam}|~{normalBam}" \
+        -b "~{tumorBam}~{"|" + normalBam}" \
         -c ~{chromosomeColumn} \
         -S ~{startColumn} \
         -E ~{endColumn} \
         -g ~{geneColumn} \
         ~{bedFile} | \
-        ~{installDir + "/"}testsomatic.R | \
-        ~{installDir + "/"}var2vcf_paired.pl \
-        -N "~{tumorSampleName}|~{normalSampleName}" \
-        > ~{outputVcf}
+        ~{installDir + "/"}~{true="testsomatic.R" false="teststrandbias.R" defined(normalBam)} | \
+        ~{installDir + "/"}~{true="var2vcf_paired.pl"
+            false="var2vcf_valid.pl" defined(normalBam)} \
+        -N "~{tumorSampleName}~{"|" + normalSampleName}" \
+        ~{true="" false="-E" defined(normalBam)} | \
+        bgzip -c > ~{outputVcf}
     }
 
     output {
         File vcfFile = outputVcf
     }
-}
\ No newline at end of file
+}
-- 
GitLab