modified: openstmerge.py
[GalaxyCodeBases.git] / etc / gatk-wdl / fm2gatk / sample.wdl
blob6d4496b52b609a738ae8794eed7818febbc0dd5c
1 version 1.0
3 # Copyright (c) 2018 Leiden University Medical Center
5 # Permission is hereby granted, free of charge, to any person obtaining a copy
6 # of this software and associated documentation files (the "Software"), to deal
7 # in the Software without restriction, including without limitation the rights
8 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9 # copies of the Software, and to permit persons to whom the Software is
10 # furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included in
13 # all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21 # SOFTWARE.
23 import "BamMetrics/bammetrics.wdl" as bammetrics
24 import "gatk-preprocess/gatk-preprocess.wdl" as preprocess
25 import "structs.wdl" as structs
26 import "tasks/bwa.wdl" as bwa
27 import "tasks/sambamba.wdl" as sambamba
28 import "QC/QC.wdl" as qc
31 workflow SampleWorkflow {
32     input {
33         Sample sample
34         String sampleDir
35         File referenceFasta
36         File referenceFastaFai
37         File referenceFastaDict
38         BwaIndex bwaIndex
39         File dbsnpVCF
40         File dbsnpVCFIndex
41         Map[String, String] dockerImages
42         String platform = "illumina"
43         Boolean useBwaKit = false
44         Array[File] scatters
45         Int bwaThreads = 4
46         String? adapterForward
47         String? adapterReverse
48     }
49     meta {allowNestedInputs: true}
51     scatter (readgroup in sample.readgroups) {
52         String readgroupDir = sampleDir + "/lib_" + readgroup.lib_id + "--rg_" + readgroup.id
54         call qc.QC as QC {
55             input:
56                 outputDir = readgroupDir,
57                 read1 = readgroup.R1,
58                 read2 = readgroup.R2,
59                 adapterForward = adapterForward,
60                 adapterReverse = adapterReverse,
61                 dockerImages = dockerImages
62         }
64         if (! useBwaKit) {
65             call bwa.Mem as bwaMem {
66                 input:
67                     read1 = QC.qcRead1,
68                     read2 = QC.qcRead2,
69                     outputPath = readgroupDir + "/" + sample.id + "-" + readgroup.lib_id + "-" + readgroup.id + ".bam",
70                     readgroup = "@RG\\tID:~{sample.id}-~{readgroup.lib_id}-~{readgroup.id}\\tLB:~{readgroup.lib_id}\\tSM:~{sample.id}\\tPL:~{platform}",
71                     bwaIndex = bwaIndex,
72                     threads = bwaThreads,
73                     dockerImage = dockerImages["bwa+samtools"]
74             }
75         }
77         if (useBwaKit) {
78             call bwa.Kit as bwakit {
79                 input:
80                     read1 = QC.qcRead1,
81                     read2 = QC.qcRead2,
82                     outputPrefix = readgroupDir + "/" + sample.id + "-" + readgroup.lib_id + "-" + readgroup.id,
83                     readgroup = "@RG\\tID:~{sample.id}-~{readgroup.lib_id}-~{readgroup.id}\\tLB:~{readgroup.lib_id}\\tSM:~{sample.id}\\tPL:~{platform}",
84                     bwaIndex = bwaIndex,
85                     threads = bwaThreads,
86                     dockerImage = dockerImages["bwakit+samtools"]
87             }
88         }
89     }
91     call sambamba.Markdup as markdup {
92         input:
93             inputBams = if useBwaKit
94                 then select_all(bwakit.outputBam)
95                 else select_all(bwaMem.outputBam),
96             outputPath = sampleDir + "/" + sample.id + ".markdup.bam",
97             dockerImage = dockerImages["sambamba"]
98     }
100     call preprocess.GatkPreprocess as bqsr {
101         input:
102             bam = markdup.outputBam,
103             bamIndex = markdup.outputBamIndex,
104             outputDir = sampleDir,
105             bamName =  sample.id + ".bqsr",
106             referenceFasta = referenceFasta,
107             referenceFastaFai = referenceFastaFai,
108             referenceFastaDict = referenceFastaDict,
109             dbsnpVCF = dbsnpVCF,
110             dbsnpVCFIndex = dbsnpVCFIndex,
111             dockerImages = dockerImages,
112             scatters = scatters
113     }
115     call bammetrics.BamMetrics as metrics {
116         input:
117             bam = markdup.outputBam,
118             bamIndex = markdup.outputBamIndex,
119             outputDir = sampleDir,
120             referenceFasta = referenceFasta,
121             referenceFastaFai = referenceFastaFai,
122             referenceFastaDict = referenceFastaDict,
123             dockerImages = dockerImages
124     }
126     output {
127         File markdupBam = markdup.outputBam
128         File markdupBamIndex = markdup.outputBamIndex
129         File recalibratedBam = bqsr.recalibratedBam
130         File recalibratedBamIndex = bqsr.recalibratedBamIndex
131         Array[File] reports = flatten([flatten(QC.reports), 
132                                        metrics.reports,
133                                        [bqsr.BQSRreport]
134                                        ])
135     }
137     parameter_meta {
138         sample: {description: "The sample information: sample id, readgroups, etc.", category: "required"}
139         sampleDir: {description: "The directory the output should be written to.", category: "required"}
140         bwaIndex: {description: "The BWA index files.", category: "required"}
141         referenceFasta: { description: "The reference fasta file", category: "required" }
142         referenceFastaFai: { description: "Fasta index (.fai) file of the reference", category: "required" }
143         referenceFastaDict: { description: "Sequence dictionary (.dict) file of the reference", category: "required" }
144         dbsnpVCF: { description: "dbsnp VCF file used for checking known sites", category: "required"}
145         dbsnpVCFIndex: { description: "Index (.tbi) file for the dbsnp VCF", category: "required"}
146         dockerImages: {description: "The docker images used.", category: "required"}
147         platform: {description: "The platform used for sequencing.", category: "advanced"}
148         useBwaKit: {description: "Whether or not BWA kit should be used. If false BWA mem will be used.", category: "advanced"}
149         adapterForward: {description: "The adapter to be removed from the reads first or single end reads.", category: "common"}
150         adapterReverse: {description: "The adapter to be removed from the reads second end reads.", category: "common"}
151         scatters: {description: "List of bed files to be used for scattering", category: "advanced"}
152         bwaThreads: {description: "The amount of threads for the alignment process", category: "advanced"}
153     }