-
Notifications
You must be signed in to change notification settings - Fork 17
/
Copy pathRNA-seq.wdl
362 lines (331 loc) · 18.9 KB
/
RNA-seq.wdl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
version 1.0
# Copyright (c) 2018 Leiden University Medical Center
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import "expression-quantification/multi-bam-quantify.wdl" as expressionQuantification
import "gatk-preprocess/gatk-preprocess.wdl" as preprocess
import "gatk-variantcalling/calculate-regions.wdl" as calcRegions
import "gatk-variantcalling/single-sample-variantcalling.wdl" as variantCallingWorkflow
import "sample.wdl" as sampleWorkflow
import "structs.wdl" as structs
import "tasks/biowdl.wdl" as biowdl
import "tasks/chunked-scatter.wdl" as chunkedScatter
import "tasks/common.wdl" as common
import "tasks/CPAT.wdl" as cpat
import "tasks/gffcompare.wdl" as gffcompare
import "tasks/gffread.wdl" as gffread
import "tasks/multiqc.wdl" as multiqc
import "tasks/prepareShiny.wdl" as shiny
import "tasks/star.wdl" as star
workflow RNAseq {
input {
File sampleConfigFile
String outputDir = "."
File referenceFasta
File referenceFastaFai
File referenceFastaDict
String platform = "illumina"
String strandedness
Array[File] lncRNAdatabases = []
Boolean variantCalling = false
Boolean lncRNAdetection = false
Boolean detectNovelTranscripts = false
Boolean dgeFiles = false
Boolean umiDeduplication = false
Boolean collectUmiStats = false
Int scatterSizeMillions = 1000
Boolean runStringtieQuantification = true
File? dbsnpVCF
File? dbsnpVCFIndex
Array[File]+? starIndex
Array[File]+? hisat2Index
String? adapterForward
String? adapterReverse
File? refflatFile
File? referenceGtfFile
File? cpatLogitModel
File? cpatHex
Int? scatterSize
File? XNonParRegions
File? YNonParRegions
File? variantCallingRegions
File dockerImagesFile
}
meta {allowNestedInputs: true}
String expressionDir = outputDir + "/expression_measures/"
String genotypingDir = outputDir + "/multisample_variants/"
# Parse docker Tags configuration and sample sheet.
call common.YamlToJson as convertDockerTagsFile {
input:
yaml = dockerImagesFile,
outputJson = outputDir + "/dockerImages.json"
}
Map[String, String] dockerImages = read_json(convertDockerTagsFile.json)
call biowdl.InputConverter as convertSampleConfig {
input:
samplesheet = sampleConfigFile,
outputFile = outputDir + "/samples.json"
}
SampleConfig sampleConfig = read_json(convertSampleConfig.json)
if (dgeFiles) {
# Create design matrix template.
call shiny.CreateDesignMatrix as createDesign {
input:
countTable = expression.fragmentsPerGeneTable,
dockerImage = dockerImages["predex"],
shinyDir = outputDir + "/dgeAnalysis/"
}
# Create annotation file.
if (defined(referenceGtfFile)) {
call shiny.CreateAnnotation as createAnnotation {
input:
referenceFasta = referenceFasta,
referenceGtfFile = select_first([referenceGtfFile]),
dockerImage = dockerImages["predex"],
shinyDir = outputDir + "/dgeAnalysis/"
}
}
}
# Generate STAR index of no indexes are given.
if (!defined(starIndex) && !defined(hisat2Index)) {
call star.GenomeGenerate as makeStarIndex {
input:
referenceFasta = referenceFasta,
referenceGtf = referenceGtfFile,
dockerImage = dockerImages["star"]
}
}
if (variantCalling) {
# Prepare variantcalling scatters.
call calcRegions.CalculateRegions as calculateRegions {
input:
referenceFasta = referenceFasta,
referenceFastaFai = referenceFastaFai,
referenceFastaDict = referenceFastaDict,
XNonParRegions = XNonParRegions,
YNonParRegions = YNonParRegions,
regions = variantCallingRegions,
scatterSize = scatterSize,
scatterSizeMillions = scatterSizeMillions,
dockerImages = dockerImages
}
# Prepare GATK preprocessing scatters.
call chunkedScatter.ScatterRegions as scatterList {
input:
inputFile = select_first([variantCallingRegions, referenceFastaFai]),
scatterSize = scatterSize,
scatterSizeMillions = scatterSizeMillions,
dockerImage = dockerImages["chunked-scatter"]
}
}
# Start processing of data.
scatter (sample in sampleConfig.samples) {
call sampleWorkflow.SampleWorkflow as sampleJobs {
input:
sample = sample,
outputDir = outputDir + "/samples/" + sample.id,
referenceFasta = referenceFasta,
referenceFastaFai = referenceFastaFai,
referenceFastaDict = referenceFastaDict,
starIndex = if defined(starIndex) then starIndex else makeStarIndex.starIndex,
hisat2Index = hisat2Index,
strandedness = strandedness,
refflatFile = refflatFile,
umiDeduplication = umiDeduplication,
collectUmiStats = collectUmiStats,
adapterForward = adapterForward,
adapterReverse = adapterReverse,
platform = platform,
dockerImages = dockerImages
}
IndexedBamFile markdupBams = {"file": sampleJobs.outputBam, "index": sampleJobs.outputBamIndex}
if (variantCalling) {
call preprocess.GatkPreprocess as preprocessing {
input:
bam = sampleJobs.outputBam,
bamIndex = sampleJobs.outputBamIndex,
outputDir = outputDir + "/samples/" + sample.id + "/",
bamName = sample.id + ".markdup.bqsr",
splitSplicedReads = true,
dbsnpVCF = select_first([dbsnpVCF]),
dbsnpVCFIndex = select_first([dbsnpVCFIndex]),
referenceFasta = referenceFasta,
referenceFastaFai = referenceFastaFai,
referenceFastaDict = referenceFastaDict,
dockerImages = dockerImages,
scatters = select_first([scatterList.scatters])
}
call variantCallingWorkflow.SingleSampleCalling as variantcalling {
input:
bam = preprocessing.recalibratedBam,
bamIndex = preprocessing.recalibratedBamIndex,
gender = select_first([sample.gender, "unknown"]),
sampleName = sample.id,
outputDir = outputDir + "/samples/" + sample.id,
referenceFasta = referenceFasta,
referenceFastaFai = referenceFastaFai,
referenceFastaDict = referenceFastaDict,
dbsnpVCF = select_first([dbsnpVCF]),
dbsnpVCFIndex = select_first([dbsnpVCFIndex]),
XNonParRegions = calculateRegions.Xregions,
YNonParRegions = calculateRegions.Yregions,
dontUseSoftClippedBases = true, # This is necessary for RNA
standardMinConfidenceThresholdForCalling = 20.0, # GATK best practice
autosomalRegionScatters = select_first([calculateRegions.autosomalRegionScatters]),
dockerImages = dockerImages
}
}
}
call expressionQuantification.MultiBamExpressionQuantification as expression {
input:
bams = zip(sampleJobs.sampleName, markdupBams),
outputDir = expressionDir,
strandedness = strandedness,
referenceGtfFile = referenceGtfFile,
detectNovelTranscripts = lncRNAdetection || detectNovelTranscripts,
runStringtieQuantification = runStringtieQuantification,
dockerImages = dockerImages
}
if (lncRNAdetection) {
call gffread.GffRead as gffreadTask {
input:
inputGff = select_first([expression.mergedGtfFile]),
genomicSequence = referenceFasta,
genomicIndex = referenceFastaFai,
exonsFastaPath = outputDir + "/lncrna/coding-potential/transcripts.fasta",
dockerImage = dockerImages["gffread"]
}
call cpat.CPAT as CPAT {
input:
gene = select_first([gffreadTask.exonsFasta]),
referenceGenome = referenceFasta,
referenceGenomeIndex = referenceFastaFai,
hex = select_first([cpatHex]),
logitModel = select_first([cpatLogitModel]),
outputPrefix = outputDir + "/lncrna/coding-potential/cpat",
dockerImage = dockerImages["cpat"]
}
scatter (database in lncRNAdatabases) {
call gffcompare.GffCompare as GffCompare {
input:
inputGtfFiles = select_all([expression.mergedGtfFile]),
referenceAnnotation = database,
outputDir = outputDir + "/lncrna/" + basename(database) + ".d",
dockerImage = dockerImages["gffcompare"]
}
}
Array[File] gffComparisonFiles = flatten(GffCompare.allFiles)
}
Array[File] sampleJobReports = flatten(sampleJobs.reports)
Array[File] baseRecalibrationReports = select_all(flatten([preprocessing.BQSRreport]))
Array[File] quantificationReports = flatten([expression.sampleFragmentsPerGeneTables, [expression.fragmentsPerGeneTable]])
Array[File] variantCallingReports = flatten(select_all(variantcalling.reports))
Array[File] allReports = flatten([sampleJobReports, baseRecalibrationReports, quantificationReports, variantCallingReports])
call multiqc.MultiQC as multiqcTask {
input:
reports = allReports,
outDir = outputDir,
dockerImage = dockerImages["multiqc"]
}
output {
File report = multiqcTask.multiqcReport
File dockerImagesList = convertDockerTagsFile.json
File fragmentsPerGeneTable = expression.fragmentsPerGeneTable
File? dgeDesign = createDesign.dgeDesign
File? dgeAnnotation = createAnnotation.dgeAnnotation
File? FPKMTable = expression.FPKMTable
File? TPMTable = expression.TPMTable
File? mergedGtfFile = expression.mergedGtfFile
Array[File] singleSampleVcfs = select_all(variantcalling.outputVcf)
Array[File] singleSampleVcfsIndex = select_all(variantcalling.outputVcfIndex)
File? orfSeqs = CPAT.orfSeqs
File? orfProb = CPAT.orfProb
File? orfProbBest = CPAT.orfProbBest
File? noOrf = CPAT.noOrf
File? rScript = CPAT.rScript
Array[File]? annotatedGtf = GffCompare.annotated
Array[File] bamFiles = sampleJobs.outputBam
Array[File] bamFilesIndex = sampleJobs.outputBamIndex
Array[File] recalibratedBamFiles = select_all(preprocessing.recalibratedBam)
Array[File] recalibratedBamFilesIndex = select_all(preprocessing.recalibratedBamIndex)
Array[File?] umiEditDistance = sampleJobs.umiEditDistance
Array[File?] umiStats = sampleJobs.umiStats
Array[File?] umiPositionStats = sampleJobs.umiPositionStats
Array[File]? generatedStarIndex = makeStarIndex.starIndex
Array[File] reports = allReports
Array[File]? gffCompareFiles = gffComparisonFiles
}
parameter_meta {
# inputs
sampleConfigFile: {description: "The samplesheet, including sample ids, library ids, readgroup ids and fastq file locations.", category: "required"}
outputDir: {description: "The output directory.", category: "required"}
referenceFasta: {description: "The reference fasta file.", category: "required"}
referenceFastaFai: {description: "Fasta index (.fai) file of the reference.", category: "required"}
referenceFastaDict: {description: "Sequence dictionary (.dict) file of the reference.", category: "required"}
platform: {description: "The platform used for sequencing.", category: "advanced"}
strandedness: {description: "The strandedness of the RNA sequencing library preparation. One of \"None\" (unstranded), \"FR\" (forward-reverse: first read equal transcript) or \"RF\" (reverse-forward: second read equals transcript).", category: "required"}
lncRNAdatabases: {description: "A set of GTF files the assembled GTF file should be compared with. Only used if lncRNAdetection is set to `true`.", category: "common"}
variantCalling: {description: "Whether or not variantcalling should be performed.", category: "common"}
lncRNAdetection: {description: "Whether or not lncRNA detection should be run. This will enable detectNovelTranscript (this cannot be disabled by setting detectNovelTranscript to false). This will require cpatLogitModel and cpatHex to be defined.", category: "common"}
detectNovelTranscripts: {description: "Whether or not a transcripts assembly should be used. If set to true Stringtie will be used to create a new GTF file based on the BAM files. This generated GTF file will be used for expression quantification. If `referenceGtfFile` is also provided this reference GTF will be used to guide the assembly.", category: "common"}
dgeFiles: {description: "Whether or not input files for DGE should be generated.", category: "common"}
umiDeduplication: {description: "Whether or not UMI based deduplication should be performed.", category: "common"}
collectUmiStats: {description: "Whether or not UMI deduplication stats should be collected. This will potentially cause a massive increase in memory usage of the deduplication step.", category: "advanced"}
scatterSizeMillions: {description: "Same as scatterSize, but is multiplied by 1000000 to get scatterSize. This allows for setting larger values more easily.", category: "advanced"}
runStringtieQuantification: {description: "Option to disable running stringtie for quantification. This does not affect the usage of stringtie for novel transcript detection.", category: "common"}
dbsnpVCF: {description: "dbsnp VCF file used for checking known sites.", category: "common"}
dbsnpVCFIndex: {description: "Index (.tbi) file for the dbsnp VCF.", category: "common"}
starIndex: {description: "The star index files. Defining this will cause the star aligner to run and be used for downstream analyses. May be ommited if hisat2Index is defined.", category: "required"}
hisat2Index: {description: "The hisat2 index files. Defining this will cause the hisat2 aligner to run. Note that is starIndex is also defined the star results will be used for downstream analyses. May be omitted in starIndex is defined.", category: "required"}
adapterForward: {description: "The adapter to be removed from the reads first or single end reads.", category: "common"}
adapterReverse: {description: "The adapter to be removed from the reads second end reads.", category: "common"}
refflatFile: {description: "A refflat files describing the genes. If this is defined RNAseq metrics will be collected.", category: "common"}
referenceGtfFile: {description: "A reference GTF file. Used for expression quantification or to guide the transcriptome assembly if detectNovelTranscripts is set to `true` (this GTF won't be be used directly for the expression quantification in that case.", category: "common"}
cpatLogitModel: {description: "A logit model for CPAT. Required if lncRNAdetection is `true`.", category: "common"}
cpatHex: {description: "A hexamer frequency table for CPAT. Required if lncRNAdetection is `true`.", category: "common"}
scatterSize: {description: "The size of the scattered regions in bases for the GATK subworkflows. Scattering is used to speed up certain processes. The genome will be seperated into multiple chunks (scatters) which will be processed in their own job, allowing for parallel processing. Higher values will result in a lower number of jobs. The optimal value here will depend on the available resources.", category: "advanced"}
XNonParRegions: {description: "Bed file with the non-PAR regions of X for variant calling.", category: "advanced"}
YNonParRegions: {description: "Bed file with the non-PAR regions of Y for variant calling.", category: "advanced"}
variantCallingRegions: {description: "A bed file describing the regions to operate on for variant calling.", category: "common"}
dockerImagesFile: {description: "A YAML file describing the docker image used for the tasks. The dockerImages.yml provided with the pipeline is recommended.", category: "advanced"}
# outputs
report: {description: "The MultiQC report."}
dockerImagesList: {description: "Json file describing the docker images used by the pipeline."}
dgeDesign: {description: "Design matrix template to add sample information for DGE analysis."}
dgeAnnotation: {description: "Annotation file for DGE analysis."}
fragmentsPerGeneTable: {description: ""}
FPKMTable: {description: ""}
TMPTable: {description: ""}
mergedGtfFile: {description: ""}
singleSampleVcfs: {description: ""}
singleSampleVcfsIndex: {description: ""}
cpatOutput: {description: ""}
annotatedGtf: {description: ""}
bamFiles: {description: ""}
bamFilesIndex: {description: ""}
recalibratedBamFiles: {description: ""}
recalibratedBamFilesIndex: {description: ""}
umiEditDistance: {description: ""}
umiStats: {description: ""}
umiPositionStats: {description: ""}
generatedStarIndex: {description: ""}
reports: {description: ""}
gffCompareFiles: {description: ""}
}
}