-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathChipseq.wdl
488 lines (399 loc) · 10.2 KB
/
Chipseq.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
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
version 1.0
workflow Chipseq {
input {
String Name
String ID
String SM
String LB
String PU
String PL = "illumina"
String OutputDir
String JobGroup
String Queue = "timley"
File? Fastq1
File? Fastq2
File? AlignedReads
String? AlignedReadsReference
String Reference
String ReferenceIndex
String Dictionary
String Blacklist
String Annotation
}
if (defined(AlignedReads)) {
call revert_aligned_reads {
input:
Bam = AlignedReads,
Reference = select_first([AlignedReadsReference, Reference]),
queue = Queue,
jobGroup = JobGroup
}
}
call trim_fastqs {
input:
F1 = select_first([revert_aligned_reads.read1, Fastq1]),
F2 = select_first([revert_aligned_reads.read2, Fastq2]),
queue = Queue,
jobGroup = JobGroup
}
call align_and_tag {
input:
F1 = trim_fastqs.read1,
F2 = trim_fastqs.read2,
refFasta = Reference,
label = Name,
readGroup = '@RG' + '\\tID:' + ID + '\\tLB:' + LB + '\\tSM:' + SM + '\\tPU:' + PU + '\\tPL:' + PL,
queue = Queue,
jobGroup = JobGroup
}
call collect_insert_metrics {
input:
in = align_and_tag.bamfile,
label = Name,
ref = Reference,
queue = Queue,
jobGroup = JobGroup
}
call fingerprint {
input:
in = align_and_tag.bamfile,
label = Name,
queue = Queue,
jobGroup = JobGroup
}
call flagstat {
input:
in = align_and_tag.bamfile,
label = Name,
queue = Queue,
jobGroup = JobGroup
}
call gene_coverage {
input:
BW = make_bw.bigwig_file,
GTF = Annotation,
Name = Name,
queue = Queue,
jobGroup = JobGroup
}
call make_bw {
input:
in = align_and_tag.bamfile,
label = Name,
queue = Queue,
jobGroup = JobGroup,
Blacklist = Blacklist
}
call gather_result as gather_files {
input:
dir = OutputDir,
files = [trim_fastqs.report, align_and_tag.bamfile,align_and_tag.bamindex, collect_insert_metrics.isOut, collect_insert_metrics.isPDF, fingerprint.fingerprint_table, fingerprint.fingerprint_plot, gene_coverage.profile, gene_coverage.plot, flagstat.fsOut, make_bw.bigwig_file],
queue = Queue,
jobGroup = JobGroup
}
call remove_files as rm_files {
input:
files = select_all([revert_aligned_reads.read1, revert_aligned_reads.read2, trim_fastqs.read1, trim_fastqs.read2]),
order_by = align_and_tag.bamfile,
queue = Queue,
jobGroup = JobGroup
}
}
task make_bw {
input {
String in
String label
String queue
String jobGroup
String Blacklist
Int? genome_size
}
output {
File bigwig_file = "~{label}.bw"
}
command <<<
export PYTHONPATH=/opt/conda/lib/python3.6/site-packages/ && \
/opt/conda/bin/bamCoverage --bam ~{in} -o "~{label}.bw" --effectiveGenomeSize ~{default="2451960000" genome_size} --normalizeUsing RPGC --ignoreDuplicates -bl ~{Blacklist} --binSize 10 --minMappingQuality 1 --extendReads -p 4 -ignore X Y MT
>>>
runtime {
queue: queue
docker_image: "dhspence/docker-deeptools"
cpu: "4"
job_group: jobGroup
memory: "32 G"
}
}
task fingerprint {
input {
String in
String label
String queue
String jobGroup
}
output {
File fingerprint_table = "~{label}_fingerprint.tab"
File fingerprint_plot = "~{label}_fingerprint.png"
}
command <<<
export PYTHONPATH=/opt/conda/lib/python3.6/site-packages/ && \
/opt/conda/bin/plotFingerprint -b ~{in} --minMappingQuality 10 --skipZeros -T "~{label}_fingerprint" --plotFile "~{label}_fingerprint.png" \
--outRawCounts "~{label}_fingerprint.tab" -p 2
>>>
runtime {
queue: queue
docker_image: "dhspence/docker-deeptools"
cpu: "2"
job_group: jobGroup
memory: "16 G"
}
}
task align_and_tag {
input {
String F1
String F2
String refFasta
String label
String readGroup
String queue
String jobGroup
}
command <<<
set -eo pipefail && \
/usr/local/bin/bwa-mem2 mem -K 100000000 -t 8 -Y -R '~{readGroup}' ~{refFasta} ~{F1} ~{F2} | \
/usr/local/bin/samblaster --addMateTags | samtools view -Sb - > out.bam && \
/usr/local/bin/samtools sort -@ 4 --write-index -T bamsort -O BAM -o "~{label}.bam##idx##~{label}.bam.bai" out.bam && \
rm -f out.bam
>>>
runtime {
queue: queue
docker_image: "henrycwong/chipseq:tagged-alignment"
cpu: "8"
job_group: jobGroup
memory: "64 G"
}
output {
File bamfile = "~{label}.bam"
File bamindex = "~{label}.bam.bai"
}
}
task convert_to_cram {
input {
String refFasta
String bam
String label
String queue
String jobGroup
}
output {
File cramfile = "~{label}.cram"
File cramindex = "~{label}.cram.crai"
}
command <<<
/usr/local/bin/samtools view -C -T ~{refFasta} ~{bam} > "~{label}.cram"; /usr/local/bin/samtools index "~{label}.cram"
>>>
runtime {
queue: queue
docker_image: "registry.gsc.wustl.edu/genome/samtools-1.3.1-2:2"
cpu: "1"
job_group: jobGroup
memory: "8 G"
}
}
task exit_early {
input {
String message
String queue
String jobGroup
String docker
}
command <<<
echo ~{message}
>>>
runtime {
queue: queue
docker_image: docker
cpu: "1"
job_group: jobGroup
memory: "1 G"
}
}
task revert_aligned_reads {
input {
String? Bam
String Reference
String queue
String jobGroup
}
output {
File read1 = "R1.fastq.gz"
File read2 = "R2.fastq.gz"
Array[String] readgroup = read_lines("read_group.txt")
}
command <<<
set -eo pipefail && \
/usr/local/bin/samtools view -H ~{Bam} | /usr/bin/awk '/^@RG/' | sed "s/\"//g" | sed 's/\t/\\t/g' > "read_group.txt" && \
(set -eo pipefail && /usr/bin/java -Xmx16g -jar /usr/picard/picard.jar RevertSam INPUT=~{Bam} OUTPUT=/dev/stdout SORT_ORDER=queryname VALIDATION_STRINGENCY=SILENT | \
/usr/bin/java -Xmx16g -jar /usr/picard/picard.jar SamToFastq I=/dev/stdin F="R1.fastq.gz" F2="R2.fastq.gz" NON_PF=true VALIDATION_STRINGENCY=SILENT)
>>>
runtime {
queue: queue
docker_image: "dhspence/docker-trimgalore"
cpu: "1"
job_group: jobGroup
memory: "32 G"
}
}
task flagstat {
input {
String in
String label
String queue
String jobGroup
}
output {
File fsOut = "~{label}.flagstat.txt"
}
command <<<
/usr/local/bin/samtools flagstat ~{in} > "~{label}.flagstat.txt"
>>>
runtime {
queue: queue
docker_image: "registry.gsc.wustl.edu/genome/tagged-alignment:2"
cpu: "1"
job_group: jobGroup
memory: "10 G"
}
}
task gene_coverage {
input {
String BW
String GTF
String Name
String queue
String jobGroup
}
output {
File profile = "~{Name}.genes.tab.gz"
File plot = "~{Name}.genes.png"
}
command <<<
/opt/conda/bin/computeMatrix scale-regions -S ~{BW} -R ~{GTF} -p 4 -b 2000 -m 2000 -a 2000 -bs 100 -o "~{Name}.genes.tab.gz" && \
/opt/conda/bin/plotProfile -m "~{Name}.genes.tab.gz" -o "~{Name}.genes.png" && \
echo -e "# title: 'Normalized coverage across genes'\n# description: 'This plot shows normalized coverage across gene bodies and 2kb upstream and downstream of gene starts and ends, respectively'\n# section: 'Custom Data File'\n# format: 'tsv'\n# plot_type: 'linegraph'\n# pconfig:\n# id: 'gene_coverage_graph'\n# categories: True\n# ylab: 'Normalized coverage'\n# xlab: 'Relative gene position'" > "~{Name}.gene_coverage_mqc.tsv" && \
/usr/bin/Rscript --quiet -e 'require(rjson); args <- commandArgs(T); pars <- fromJSON(gsub("@","",readLines(args[1],n=1))); dat <- colMeans(read.table(args[1],sep="\t",skip=1)[,-c(1:6)],na.rm=T); labs <- c(seq(-pars$upstream+pars[[4]],-pars[[4]],by=pars[[4]]),paste0(seq(0,100,length=pars[[3]]/pars[[4]]+1),"%"),paste0("+",seq(pars[[4]],pars$downstream,by=pars[[4]]))); write.table(cbind(labs,dat),file=args[2],quote=F,sep="\t",append=T,col.names=F,row.names=F)' "~{Name}.genes.tab.gz" "~{Name}.gene_coverage_mqc.tsv"
>>>
runtime {
queue: queue
docker_image: "dhspence/docker-deeptools"
cpu: "4"
job_group: jobGroup
memory: "8 G"
}
}
task collect_insert_metrics {
input {
String in
String label
String ref
String queue
String jobGroup
}
output {
File isOut = "~{label}.insert_size_summary.txt"
File isPDF = "~{label}.insert_size.pdf"
}
command <<<
/usr/bin/java -Xmx16g -jar /usr/picard/picard.jar CollectInsertSizeMetrics INPUT=~{in} OUTPUT="~{label}.insert_size_summary.txt" \
HISTOGRAM_FILE="~{label}.insert_size.pdf" ASSUME_SORTED=true
>>>
runtime {
queue: queue
docker_image: "registry.gsc.wustl.edu/genome/picard-2.4.1-r:2"
cpu: "2"
job_group: jobGroup
memory: "10 G"
}
}
task gather_result {
input {
String dir
Array[String] files
String queue
String jobGroup
}
output {
String out = stdout()
}
command <<<
/bin/mv -t ~{dir}/ ~{sep=" " files}
>>>
runtime {
docker_image: "ubuntu:xenial"
queue: queue
job_group: jobGroup
memory: "2 G"
}
}
task trim_fastqs {
input {
String F1
String F2
String queue
String jobGroup
}
output {
File report = glob("*.html")[0]
File read1 = glob("*R1*trim.fastq.gz")[0]
File read2 = glob("*R2*trim.fastq.gz")[0]
}
command <<<
fastp -w 8 -i ~{F1} -o $(basename ~{F1})".trim.fastq.gz" -I ~{F2} -O $(basename ~{F2})".trim.fastq.gz"
>>>
runtime {
queue: queue
docker_image: "dhspence/docker-fastp"
cpu: "8"
job_group: jobGroup
memory: "32 G"
}
}
task remove_file {
input {
String file
String order_by
String queue
String jobGroup
}
output {
String out = stdout()
}
command <<<
/bin/rm ~{file}
>>>
runtime {
docker_image: "ubuntu:xenial"
memory: "2 G"
queue: queue
job_group: jobGroup
}
}
task remove_files {
input {
Array[String] files
String order_by
String queue
String jobGroup
}
output {
String out = stdout()
}
command <<<
/bin/rm ~{sep=" " files}
>>>
runtime {
docker_image: "ubuntu:xenial"
memory: "2 G"
queue: queue
job_group: jobGroup
}
}