From 63202c731561890fc23fc6a451dd69cdae879108 Mon Sep 17 00:00:00 2001
From: Ruben Vorderman <r.h.p.vorderman@lumc.nl>
Date: Thu, 28 May 2020 10:35:52 +0200
Subject: [PATCH] add bcftools stats

---
 bcftools.wdl | 88 ++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 file changed, 88 insertions(+)

diff --git a/bcftools.wdl b/bcftools.wdl
index 53165c6..8281deb 100644
--- a/bcftools.wdl
+++ b/bcftools.wdl
@@ -55,3 +55,91 @@ task Bcf2Vcf {
         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
+        File? compareVcf
+        String? afBins
+        String? afTag
+        Boolean firstAlleleOnly = false 
+        String? collapse
+        String? depth
+        String? exclude
+        File? exons 
+        String? applyFilters
+        File? fastaRef
+        File? fastaRefIndex
+        String? include 
+        Boolean splitByID = false 
+        String? regions
+        File? regionsFile
+        Array[String] samples = []
+        File? samplesFile 
+        String? targets 
+        File? targetsFile
+        String? userTsTv
+        Boolean verbose = false
+
+        Int threads = 0
+        Int timeMinutes = 1 + 2* ceil(size(select_all([inputVcf, compareVcf]), "G"))  # TODO: Estimate, 2 minutes per GB, refine later.
+        String memory = "2G"  # TODO: Safe estimate, refine later.  
+    }
+    
+    command {
+        bcftools \
+        ~{"--af-bins " + afBins} \
+        ~{"--af-tag " + afTag} \
+        ~{true="--1st-allele-only" false="" firstAlleleOnly} \
+        ~{"--collapse " + collapse} \
+        ~{"--depth " + depth} \
+        ~{"--exclude " + exclude} \
+        ~{"--exons " + exons} \
+        ~{"--apply-filters " + applyFilters} \
+        ~{"--fasta-ref " + fastaRef} \
+        ~{"--include " + include} \
+        ~{true="--split-by-ID" false="" splitByID} \
+        ~{"--regions " + regions} \
+        ~{"--regions-file " + regionsFile} \
+        ~{true="--samples" false="" length(samples) > 0} ~{sep="," samples} \
+        ~{"--samples-file " + samplesFile} \
+        ~{"--targets " + targets} \
+        ~{"--targets-file " + targetsFile} \
+        ~{"--user-tstv " + userTsTv} \
+        --threads ~{threads} \
+        ~{true="--verbose" false="" verbose} \
+        ~{inputVcf} ~{compareVcf}
+    }
+
+    runtime {
+        cpu: threads + 1
+        time_minutes: timeMinutes
+        memory: memory
+    }
+
+    parameter_meta {
+        inputVcf: {description: "The vcf to be analysed.", category: "required"}
+        compareVcf: {description: "When inputVcf and compareVCF are given, the program generates separate stats for intersection and the complements. By default only sites are compared, samples must be given to include also sample columns.", category: "common"}
+        afBins: {description: "Allele frequency bins, a list (0.1,0.5,1) or a file (0.1\n0.5\n1).", category: "advanced"}
+        afTag: {description: "Allele frequency tag to use, by default estimated from AN,AC or GT.", category: "advanded"}
+        firstAlleleOnly: {description: "Include only 1st allele at multiallelic sites." category: "advanced"}
+        collapse: {description: "Treat as identical records with <snps|indels|both|all|some|none>, see man page for details.", category: "advanced"}
+        depth: {description: "Depth distribution: min,max,bin size [0,500,1].", category: "advanced"}
+        exclude: {description: "Exclude sites for which the expression is true (see man page for details)." category: "advanced"}
+        exons: {description: "Tab-delimited file with exons for indel frameshifts (chr,from,to; 1-based, inclusive, bgzip compressed).", category: "advanced"}
+        applyFilters: {description: "Require at least one of the listed FILTER strings (e.g. \"PASS,.\").", category: "advanced"}
+        fastaRef: {description: "Faidx indexed reference sequence file to determine INDEL context.", category: "advanced"}
+        fastaRefIndex: {description: "Index file (.fai) for fastaRef. Must be supplied if fastaRef is supplied.", category: "advanced"}
+        include: {description: "Select sites for which the expression is true (see man page for details).", category: "advanced"}
+        splitByID: {description: "Collect stats for sites with ID separately (known vs novel).", category: "advanced"}
+        regions: {description: "Restrict to comma-separated list of regions.", category: "advanced"}
+        regionsFile: {description: "Restrict to regions listed in a file.", category: "advanced"}
+        samples: {description: "List of samples for sample stats, \"-\" to include all samples.", category: "advanced"}
+        samplesFile: {description: "File of samples to include.", category: "advanced"}
+        targets: {description: "Similar to regions but streams rather than index-jumps.", category: "advanced"}
+        targetsFile: {description: "Similar to regionsFile but streams rather than index-jumps.", category: "advanced"}
+        userTsTv: {description: "<TAG[:min:max:n]>. Collect Ts/Tv stats for any tag using the given binning [0:1:100].", category: "advanced"}
+        threads: {description: "Number of extra decompression threads [0].", category: "advanced"}
+        verbose: {description: "Produce verbose per-site and per-sample output.", category: "advanced"}
+    }
+}
\ No newline at end of file
-- 
GitLab