-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.wdl
450 lines (377 loc) · 11.3 KB
/
main.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
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
version 1.0
workflow amr_analysis {
input {
Array[File] fastqFiles
Array[Array[File]] pairedReads
File resfinderDB
}
scatter (fastqFile in fastqFiles) {
call fastqc as fastqcRaw {
input:
fastqFile = fastqFile
}
}
call multiqc as multiqcRaw {
input:
input_files = fastqcRaw.outZip
}
scatter (pairRead in pairedReads) {
call cutadapt {
input: read1 = pairRead[0], read2 = pairRead[1]
}
}
scatter (fastqFileTrimmed in flatten([cutadapt.outFwd, cutadapt.outRev])) {
call fastqc as fastqcTrim {
input:
fastqFile = fastqFileTrimmed
}
}
Array[File] fastqcTrimzip = fastqcTrim.outZip
call multiqc as multiqcTrim {
input:
input_files = fastqcTrimzip
}
call buildDatabase as resFinder{
input:
database = resfinderDB,
referenceName = "resfinder"
}
scatter (i in range(length(pairedReads))){
call Bowtie2 as resfinderBowtie2{
input:
R1 = cutadapt.outFwd[i],
R2 = cutadapt.outRev[i],
database = resFinder.outFile,
indexPrefix = resFinder.indexPrefix
}
call filterBam as resfinderfilterBam{
input:
samFile = resfinderBowtie2.alignment,
indexPrefix = resFinder.indexPrefix
}
call SortandIndexBam as resfinderSortandIndex{
input:
bamFile = resfinderfilterBam.bamFile,
referenceName = resFinder.indexPrefix
}
}
call CombineResults1 as resfindercombineResults1{
input:
sortedBam = resfinderSortandIndex.sortedBam[0],
referenceName = resFinder.indexPrefix,
}
scatter (samples in resfinderSortandIndex.sortedBam){
call CombineResults2 as resfindercombineResults2{
input:
sortedReads = samples,
referenceName = resFinder.indexPrefix,
}
call AddSampleNames as resfindersampleNames{
input:
sample = resfindercombineResults2.out,
referenceName =resFinder.indexPrefix
}
}
call Create_ARG_Genemat{
input:
geneNames = resfindercombineResults1.out,
renamedSampleCounts = resfindersampleNames.renamedSampleCount,
referenceName = resFinder.indexPrefix
}
}
task fastqc {
input {
File fastqFile
}
Int numCores = 8
String dockerImage = "quay.io/staphb/fastqc:0.11.9"
command <<<
set -euo pipefail
fastqc -o . ~{fastqFile}
>>>
output {
File outHtml = basename(fastqFile, ".fastq.gz") + "_fastqc.html"
File outZip = basename(fastqFile, ".fastq.gz") + "_fastqc.zip"
}
runtime {
docker: dockerImage
disks: "local-disk 500 HDD"
cpu: numCores
memory: "16 GB"
}
}
task multiqc {
input {
Array[File] input_files
Boolean force = false
Boolean full_names = false
String? title
String? comment
String? file_name
String out_dir = "./multiqc-output"
String? template
String? tag
String? ignore_analysis_files
String? ignore_sample_names
File? sample_names
Array[String]? exclude_modules
Array[String]? module_to_use
Boolean data_dir = false
Boolean no_data_dir = false
String? output_data_format
Boolean zip_data_dir = false
Boolean export = false
Boolean flat = false
Boolean interactive = true
Boolean lint = false
Boolean pdf = false
Boolean megaQC_upload = false # Upload generated report to MegaQC if MegaQC options are found
File? config # directory
String? config_yaml
String docker = "quay.io/biocontainers/multiqc:1.8--py_2"
}
# get the basename in all wdl use the filename specified (sans ".html" extension, if specified)
String report_filename = if (defined(file_name)) then basename(select_first([file_name]), ".html") else "multiqc"
command {
set -ex -o pipefail
echo "${sep='\n' input_files}" > input-filename.txt
echo "" >> input-filename.txt
multiqc \
--file-list input-filename.txt \
--dirs \
--outdir "${out_dir}" \
${true="--force" false="" force} \
${true="--fullnames" false="" full_names} \
${"--title " + title} \
${"--comment " + comment} \
${"--filename " + file_name} \
${"--template " + template} \
${"--tag " + tag} \
${"--ignore " + ignore_analysis_files} \
${"--ignore-samples" + ignore_sample_names} \
${"--sample-names " + sample_names} \
${true="--exclude " false="" defined(exclude_modules)}${sep=' --exclude ' select_first([exclude_modules,[]])} \
${true="--module " false="" defined(module_to_use)}${sep=' --module ' select_first([module_to_use,[]])} \
${true="--data-dir" false="" data_dir} \
${true="--no-data-dir" false="" no_data_dir} \
${"--data-format " + output_data_format} \
${true="--zip-data-dir" false="" zip_data_dir} \
${true="--export" false="" export} \
${true="--flat" false="" flat} \
${true="--interactive" false="" interactive} \
${true="--lint" false="" lint} \
${true="--pdf" false="" pdf} \
${false="--no-megaqc-upload" true="" megaQC_upload} \
${"--config " + config} \
${"--cl-config " + config_yaml }
if [ -z "${file_name}" ]; then
mv "${out_dir}/${report_filename}_report.html" "${out_dir}/${report_filename}.html"
fi
tar -c "${out_dir}/${report_filename}_data" | gzip -c > "${report_filename}_data.tar.gz"
}
output {
File multiqc_report = "${out_dir}/${report_filename}.html"
File multiqc_data_dir_tarball = "${report_filename}_data.tar.gz"
}
runtime {
memory: "16 GB"
cpu: 8
docker: "${docker}"
disks: "local-disk 500 HDD"
dx_instance_type: "mem1_ssd1_v2_x2"
}
}
task cutadapt {
input {
File read1
File read2
}
Int numCores = 8
String dockerImage = "pegi3s/cutadapt"
String outfw = basename(read1, "001.fastq.gz") + "trimmed.fastq.gz"
String outrv = basename(read2, "001.fastq.gz") + "trimmed.fastq.gz"
command {
set -euo pipefail
cutadapt -a CTGTCTCTTATACACATCT -A CTGTCTCTTATACACATCT -O 10 -m 30 -q 20 ~{read1} ~{read2} -o ~{outfw} -p ~{outrv}
}
output {
File outFwd = outfw
File outRev = outrv
File outlog = stdout()
}
runtime {
docker: dockerImage
disks: "local-disk 500 HDD"
cpu: numCores
memory: "16 GB"
}
}
task buildDatabase{
input{
File database
String referenceName
}
command{
bowtie2-build ~{database} ${referenceName}
}
output {
Array[File] outFile = glob("~{referenceName}.*.bt2")
String indexPrefix = referenceName
}
runtime {
docker: "quay.io/biocontainers/bowtie2:2.4.2--py38h1c8e9b9_1"
}
}
task Bowtie2 {
input {
File R1
File R2
Array[File] database
String indexPrefix
}
String outFile = "${indexPrefix}_alignment.sam"
command {
for f in ~{sep=" " database}; do cp $f .; done
bowtie2 -x ~{indexPrefix} -1 ~{R1} -2 ~{R2} \
-D 20 -R 3 -N 1 -L 20 -i S,1,0.50 --threads 6 | \
samtools view -Sb - > ~{outFile}
}
output {
File alignment = outFile
}
runtime {
docker: "ummidock/innuca"
}
}
task filterBam {
input {
File samFile
String indexPrefix
}
String outfile = basename(samFile, ".sam") + "_filtered.bam"
command <<<
samtools view -h ~{samFile} | gawk 'BEGIN {{FS="\t"; OFS="\t"}} \
{{if (/^@/ && substr($2, 3, 1)==":") {{print}} \
else if (($7!="=" || $7=="=") && and($2, 0x40)) {{print}}}}' | \
samtools view -Shu - > ~{outfile}
>>>
output {
File bamFile = outfile
}
runtime {
docker:"quay.io/staphb/samtools:1.15"
}
}
task SortBam {
input {
File bamFile
String referenceName
}
String outFile = basename(bamFile, "_filtered.bam")+ "sorted.bam"
command {
samtools sort -o ~{outFile} ~{bamFile}
}
output {
File sortedBam = outFile
}
runtime {
docker: "quay.io/staphb/samtools:1.15"
}
}
# follow https://hcc.unl.edu/docs/applications/app_specific/bioinformatics_tools/data_manipulation_tools/samtools/running_samtools_commands/
task IndexBam{
input{
File bamFile
String referenceName
}
String outBai = basename(bamFile, "sorted.bam") +".bai"
command{
samtools index -b ~{bamFile} ~{outBai}
}
output{
File baiIndex = outBai
}
runtime{
docker: "quay.io/staphb/samtools:1.15"
}
}
task SortandIndexBam{
input{
File bamFile
String referenceName
}
String outFile = basename(bamFile, "_filtered.bam")+ "sorted.bam"
command<<<
samtools sort -o ~{outFile} ~{bamFile}
samtools index ~{outFile}
>>>
output{
File sortedBam = outFile
}
runtime{
docker: "quay.io/staphb/samtools:1.15"
}
}
task CombineResults1{
input{
File sortedBam
String referenceName
}
String outFile = basename(sortedBam, ".bam") + "gene_names.txt"
command<<<
samtools view -F 4 ~{sortedBam} |
awk -F '\t' '!/\*/ && !seen[$3]++ { print $3 }' |
sed '1 i\GENE' > ~{outFile}
>>>
output{
File out = outFile
}
runtime {
docker: "quay.io/staphb/samtools:1.15"
}
}
task CombineResults2{
input{
File sortedReads
String referenceName
}
String outFile = basename(sortedReads, ".bam")+ "_counts.txt"
command<<<
samtools view -F 4 ~{sortedReads} | awk -F '\t' '!/\*/ { count[$3]++ } END { for (i in count) print i }' > ~{outFile}
>>>
output{
File out = outFile
}
runtime {
docker: "quay.io/staphb/samtools:1.15"
}
}
task AddSampleNames {
input {
File sample
String referenceName
}
String baseName = basename(sample, "_counts")
String outFile = basename(sample, "_counts") + "renamed_counts.txt"
command {
sed '1 i\${baseName}' ~{sample} > ~{outFile}
}
output {
File renamedSampleCount = outFile
}
}
task Create_ARG_Genemat {
input {
File geneNames
Array[File] renamedSampleCounts
String referenceName
}
File outFile = "${referenceName}_ARG_genemat.txt"
command <<<
echo "-- Creating ARG_genemat --"
paste ${geneNames} ${sep=' '} ${renameSampleCounts.join(" ")} > ${outFile}
>>>
output {
File ARG_genemat = outFile
}
}