From 7bc3c58d309fcb20d9769180f471d79432d2e350 Mon Sep 17 00:00:00 2001
From: cagaser <c.agaser@lumc.nl>
Date: Mon, 7 Sep 2020 17:26:42 +0200
Subject: [PATCH] make bcftools indexing optional

---
 bcftools.wdl | 102 +++++++++++++++++++++++++++------------------------
 1 file changed, 54 insertions(+), 48 deletions(-)

diff --git a/bcftools.wdl b/bcftools.wdl
index 520bcf1..5d5a1ea 100644
--- a/bcftools.wdl
+++ b/bcftools.wdl
@@ -52,6 +52,8 @@ task Annotate {
         String dockerImage = "quay.io/biocontainers/bcftools:1.10.2--h4f4756c_2"
     }
 
+    Boolean indexing = if outputType == "z" then true else false
+
     command {
         set -e 
         mkdir -p "$(dirname ~{outputPath})"
@@ -77,13 +79,14 @@ task Annotate {
         ~{true="--single-overlaps" false="" singleOverlaps} \
         ~{true="--remove" false="" length(removeAnns) > 0} ~{sep="," removeAnns} \
         ~{inputFile}
-        bcftools index --tbi ~{outputPath}
+
+        ~{if indexing then 'bcftools index --tbi ~{outputPath}' else ''}
 
     }
     
     output {
         File outputVcf = outputPath
-        File outputVcfIndex = outputPath + ".tbi"
+        File? outputVcfIndex = outputPath + ".tbi"
     }
 
     runtime {
@@ -132,6 +135,8 @@ task Sort {
         String outputType = "z"
     }
 
+    Boolean indexing = if outputType == "z" then true else false
+
     command {
         set -e
         mkdir -p "$(dirname ~{outputPath})"
@@ -139,12 +144,13 @@ task Sort {
         -o ~{outputPath} \
         -O ~{outputType} \
         ~{inputFile}
-        bcftools index --tbi ~{outputPath}
+
+        ~{if indexing then 'bcftools index --tbi ~{outputPath}' else ''}
     }
 
     output {
         File outputVcf = outputPath
-        File outputVcfIndex = outputPath + ".tbi"
+        File? outputVcfIndex = outputPath + ".tbi"
     }
     
     runtime {
@@ -165,50 +171,6 @@ task Sort {
     
 }
 
-task View {
-    input {
-        File inputFile
-        String outputPath = "output.vcf.gz"
-        String memory = "256M"
-        Int timeMinutes = 1 + ceil(size(inputFile, "G"))
-        String dockerImage = "quay.io/biocontainers/bcftools:1.10.2--h4f4756c_2"
-        String outputType = "z"
-        Int compressionLevel = 1
-    }
-
-    command {
-        set -e
-        mkdir -p "$(dirname ~{outputPath})"
-        bcftools view \
-        -o ~{outputPath} \
-        -O ~{outputType} \
-        -l ~{compressionLevel} \
-        ~{inputFile}
-        bcftools index --tbi ~{outputPath}
-    }
-
-    output {
-        File outputVcf = outputPath
-        File outputVcfIndex = outputPath + ".tbi"
-    }
-
-    runtime {
-        memory: memory
-        time_minutes: timeMinutes
-        docker: dockerImage
-    }
-
-    parameter_meta {
-        inputFile: {description: "A vcf or bcf file.", category: "required"}
-        outputPath: {description: "The location the output VCF file should be written.", category: "common"}
-        outputType: {description: "Output type: v=vcf, z=vcf.gz, b=bcf, u=uncompressed bcf", category: "advanced"}
-        memory: {description: "The amount of memory this job will use.", category: "advanced"}
-        compressionLevel: {description: "Compression level from 0 (uncompressed) to 9 (best).", category: "advanced"}
-        timeMinutes: {description: "The maximum amount of time the job will run in minutes.", category: "advanced"}
-        dockerImage: {description: "The docker image used for this task. Changing this may result in errors which the developers may choose not to address.", category: "advanced"}
-    }
-}
-
 task Stats {
     input {
         File inputVcf
@@ -313,3 +275,47 @@ task Stats {
         timeMinutes: {description: "The maximum amount of time the job will run in minutes.", category: "advanced"}
     }
 }
+
+task View {
+    input {
+        File inputFile
+        String outputPath = "output.vcf"
+        Int compressionLevel = 0
+        String memory = "256M"
+        Int timeMinutes = 1 + ceil(size(inputFile, "G"))
+        String dockerImage = "quay.io/biocontainers/bcftools:1.10.2--h4f4756c_2"
+    }
+
+    String outputType = if compressionLevel > 0 then "z" else "v"
+    Boolean indexing = if compressionLevel > 0 then true else false
+
+    command {
+        set -e
+        mkdir -p "$(dirname ~{outputPath})"
+        bcftools view \
+        -o ~{outputPath} \
+        -l ~{compressionLevel} \
+        -O ~{outputType} \
+        ~{inputFile}
+
+        ~{if indexing then 'bcftools index --tbi ~{outputPath}' else ''}
+    }
+    output {
+        File outputVcf = outputPath
+        File? outputVcfIndex = outputPath + ".tbi"
+    }
+
+    runtime {
+        memory: memory
+        time_minutes: timeMinutes
+        docker: dockerImage
+    }
+
+    parameter_meta {
+        inputFile: {description: "A vcf or bcf file.", category: "required"}
+        outputPath: {description: "The location the output VCF file should be written.", category: "common"}
+        memory: {description: "The amount of memory this job will use.", category: "advanced"}
+        timeMinutes: {description: "The maximum amount of time the job will run in minutes.", category: "advanced"}
+        dockerImage: {description: "The docker image used for this task. Changing this may result in errors which the developers may choose not to address.", category: "advanced"}
+    }
+}
-- 
GitLab