forked from ENCODE-DCC/atac-seq-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
atac.wdl
1662 lines (1528 loc) · 50.9 KB
/
atac.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
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# ENCODE DCC ATAC-Seq/DNase-Seq pipeline
# Author: Jin Lee ([email protected])
#CAPER docker quay.io/encode-dcc/atac-seq-pipeline:v1.4.2
#CAPER singularity docker://quay.io/encode-dcc/atac-seq-pipeline:v1.4.2
#CROO out_def https://storage.googleapis.com/encode-pipeline-output-definition/atac.out_def.json
workflow atac {
# pipeline version
String pipeline_ver = 'v1.4.2'
# general sample information
String title = 'Untitled'
String description = 'No description'
# endedness for input data
Boolean? paired_end # to define endedness for all replciates
# if defined, this will override individual endedness below
Array[Boolean] paired_ends = [] # to define endedness for individual replicate
# genome TSV
# you can define any genome parameters either in this TSV
# or individually in an input JSON file
# individually defined parameters will override those defined in this TSV
File? genome_tsv # reference genome data TSV file including
# all genome-specific file paths and parameters
# individual genome parameters
File? ref_fa # reference fasta (*.fa.gz)
File? bowtie2_idx_tar # bowtie2 index tar (uncompressed)
File? chrsz # 2-col chromosome sizes file
File? blacklist # blacklist BED (peaks overlapping will be filtered out)
String? gensz # genome sizes (hs for human, mm for mouse or sum of 2nd col in chrsz)
# individual genome parameters for ATAqC
File? tss # TSS BED file
File? dnase # open chromatin region BED file
File? prom # promoter region BED file
File? enh # enhancer region BED file
File? reg2map # file with cell type signals
File? reg2map_bed # file of regions used to generate reg2map signals
File? roadmap_meta # roadmap metedata
# parameters for pipeline
String pipeline_type = 'atac' # atac (default), dnase
# tn5 shiting will be enabled for atac only
Boolean align_only = false # disable all post-align analyses (peak-calling, overlap, idr, ...)
Boolean true_rep_only = false # disable all analyses for pseudo replicates
# if activated, overlap and idr will be disabled
# parameters for trim_adapter
Boolean auto_detect_adapter = false
# automatically detect/trim adapters
# can detect three adapters only
# see /src/detect_adapter.py for details
String cutadapt_param = '-e 0.1 -m 5'
# cutadapt parameters (err_rate=0.1, min_trim_len=5)
# parameters for align (align FASTQs and create raw BAM)
#String aligner = 'bowtie2' # bowtie2, custom
Int multimapping = 4 # for samples with multimapping reads
String bowtie2_param_se = '--local'
# params for bowtie2 (single-ended samples)
String bowtie2_param_pe = '-X2000 --mm --local'
# params for bowtie2 (paired-ended samples)
# parameters for filter (filter/dedup raw BAM)
String dup_marker = 'picard' # picard, sambamba
Int mapq_thresh = 30 # threshold for low MAPQ reads removal
Boolean no_dup_removal = false # keep all dupes in final BAM
# parameters for bam2ta (convert filtered/deduped BAM to TAG-ALIGN)
String mito_chr_name = 'chrM' # name of mito chromosome
# THIS IS NOT A REG-EX!
# you can define only one name for mito chrom
String regex_filter_reads = 'chrM'
# Perl-style regular expression pattern
# for chr name to filter out reads
# THIS IS A REG-EX!
# you can define multiple chrom names e.g. \(chrM\|chr21\|chr19\)
# make sure that you escape (, ) and | with \
Int subsample_reads = 0 # number of reads to subsample TAGALIGN
# 0 for no subsampling
# parameters for cross-correlation analysis
Boolean enable_xcor = false # enable cross-corr analysis
Int xcor_subsample_reads = 25000000
# number of reads to subsample TAG-ALIGN
# this will be used for cross-corr only
# will not affect any downstream analyses
# parameters for blacklist filtering peaks
Boolean keep_irregular_chr_in_bfilt_peak = false
# peaks with irregular chr name will not be filtered out
# in bfilt_peak (blacklist filtered peak) file
# (e.g. chr1_AABBCC, AABR07024382.1, ...)
# reg-ex pattern for "regular" chr name is chr[\dXY]+\b
# parameters for peak calling
String peak_type = 'narrowPeak'
Int cap_num_peak = 300000 # cap number of raw peaks called
Float pval_thresh = 0.01 # p.value threshold for peak caller
Int smooth_win = 73 # size of smoothing window for peak caller
# parameters for signal tracks
Boolean enable_count_signal_track = false # generate count signal track
# parameters for IDR
Boolean enable_idr = true # enable IDR analysis on raw peaks
Float idr_thresh = 0.05 # IDR threshold
String idr_rank = 'p.value' # IDR ranking method (p.value, q.value, score)
# parameters for ATAqC
Boolean disable_ataqc = false # disable ATAqC (extra annotation-based analysis)
# resources
# these variables will be automatically ignored if they are not supported by platform
# "disks" is for cloud platforms (Google Cloud Platform, DNAnexus) only
Int trim_adapter_cpu = 2
Int trim_adapter_mem_mb = 12000
Int trim_adapter_time_hr = 24
String trim_adapter_disks = "local-disk 100 HDD"
Int bowtie2_cpu = 4
Int bowtie2_mem_mb = 20000
Int bowtie2_time_hr = 48
String bowtie2_disks = "local-disk 200 HDD"
Int filter_cpu = 2
Int filter_mem_mb = 20000
Int filter_time_hr = 24
String filter_disks = "local-disk 400 HDD"
Int bam2ta_cpu = 2
Int bam2ta_mem_mb = 10000
Int bam2ta_time_hr = 6
String bam2ta_disks = "local-disk 100 HDD"
Int spr_mem_mb = 16000
Int xcor_cpu = 2
Int xcor_mem_mb = 16000
Int xcor_time_hr = 6
String xcor_disks = "local-disk 100 HDD"
Int macs2_mem_mb = 16000
Int macs2_time_hr = 24
String macs2_disks = "local-disk 200 HDD"
Int ataqc_mem_mb = 16000
Int ataqc_mem_java_mb = 15000
Int ataqc_time_hr = 24
String ataqc_disks = "local-disk 200 HDD"
# input file definition
# supported types: fastq, bam, nodup_bam (or filtered bam), ta (tagAlign), peak
# pipeline can start from any type of inputs
# leave all other types undefined
# you can define up to 10 replicates
# fastqs and adapters
# if auto_detect_adapter == true, undefined adapters will be detected/trimmed
# otherwise, only defined adapters will be trimmed
# so you can selectively detect/trim adapters for a specific fastq
Array[File] fastqs_rep1_R1 = [] # FASTQs to be merged for rep1 R1
Array[File] fastqs_rep1_R2 = [] # do not define if single-ended
Array[File] fastqs_rep2_R1 = [] # do not define if unreplicated
Array[File] fastqs_rep2_R2 = [] # ...
Array[File] fastqs_rep3_R1 = []
Array[File] fastqs_rep3_R2 = []
Array[File] fastqs_rep4_R1 = []
Array[File] fastqs_rep4_R2 = []
Array[File] fastqs_rep5_R1 = []
Array[File] fastqs_rep5_R2 = []
Array[File] fastqs_rep6_R1 = []
Array[File] fastqs_rep6_R2 = []
Array[File] fastqs_rep7_R1 = []
Array[File] fastqs_rep7_R2 = []
Array[File] fastqs_rep8_R1 = []
Array[File] fastqs_rep8_R2 = []
Array[File] fastqs_rep9_R1 = []
Array[File] fastqs_rep9_R2 = []
Array[File] fastqs_rep10_R1 = []
Array[File] fastqs_rep10_R2 = []
String? adapter
Array[String] adapters_rep1_R1 = []
Array[String] adapters_rep1_R2 = []
Array[String] adapters_rep2_R1 = []
Array[String] adapters_rep2_R2 = []
Array[String] adapters_rep3_R1 = []
Array[String] adapters_rep3_R2 = []
Array[String] adapters_rep4_R1 = []
Array[String] adapters_rep4_R2 = []
Array[String] adapters_rep5_R1 = []
Array[String] adapters_rep5_R2 = []
Array[String] adapters_rep6_R1 = []
Array[String] adapters_rep6_R2 = []
Array[String] adapters_rep7_R1 = []
Array[String] adapters_rep7_R2 = []
Array[String] adapters_rep8_R1 = []
Array[String] adapters_rep8_R2 = []
Array[String] adapters_rep9_R1 = []
Array[String] adapters_rep9_R2 = []
Array[String] adapters_rep10_R1 = []
Array[String] adapters_rep10_R2 = []
# other input types (bam, nodup_bam, ta). they are per replicate
Array[File?] trim_merged_fastqs_R1 = []
Array[File?] trim_merged_fastqs_R2 = []
Array[File?] bams = []
Array[File?] nodup_bams = []
Array[File?] tas = []
# other input types (peak)
Array[File?] peaks = [] # per replicate
Array[File?] peaks_pr1 = [] # per replicate. do not define if true_rep_only==true
Array[File?] peaks_pr2 = [] # per replicate. do not define if true_rep_only==true
File? peak_ppr1 # do not define if unreplicated or true_rep_only==true
File? peak_ppr2 # do not define if unreplicated or true_rep_only==true
File? peak_pooled # do not define if unreplicated or true_rep_only==true
####################### pipeline starts here #######################
# DO NOT DEFINE ANY VARIABLES DECLARED BELOW IN AN INPUT JSON FILE #
# THEY ARE TEMPORARY/INTERMEDIATE SYSTEM VARIABLES #
####################### pipeline starts here #######################
# read genome data and paths
if ( defined(genome_tsv) ) {
call read_genome_tsv { input: genome_tsv = genome_tsv }
}
File? ref_fa_ = if defined(ref_fa) then ref_fa
else read_genome_tsv.ref_fa
File? bowtie2_idx_tar_ = if defined(bowtie2_idx_tar) then bowtie2_idx_tar
else read_genome_tsv.bowtie2_idx_tar
File? chrsz_ = if defined(chrsz) then chrsz
else read_genome_tsv.chrsz
String? gensz_ = if defined(gensz) then gensz
else read_genome_tsv.gensz
File? blacklist_ = if defined(blacklist) then blacklist
else read_genome_tsv.blacklist
File? tss_ = if defined(tss) then tss
else read_genome_tsv.tss
File? dnase_ = if defined(dnase) then dnase
else read_genome_tsv.dnase
File? prom_ = if defined(prom) then prom
else read_genome_tsv.prom
File? enh_ = if defined(enh) then enh
else read_genome_tsv.enh
File? reg2map_ = if defined(reg2map) then reg2map
else read_genome_tsv.reg2map
File? reg2map_bed_ = if defined(reg2map_bed) then reg2map_bed
else read_genome_tsv.reg2map_bed
File? roadmap_meta_ = if defined(roadmap_meta) then roadmap_meta
else read_genome_tsv.roadmap_meta
# temporary 2-dim fastqs array [rep_id][merge_id]
Array[Array[File]] fastqs_R1 =
if length(fastqs_rep10_R1)>0 then
[fastqs_rep1_R1, fastqs_rep2_R1, fastqs_rep3_R1, fastqs_rep4_R1, fastqs_rep5_R1,
fastqs_rep6_R1, fastqs_rep7_R1, fastqs_rep8_R1, fastqs_rep9_R1, fastqs_rep10_R1]
else if length(fastqs_rep9_R1)>0 then
[fastqs_rep1_R1, fastqs_rep2_R1, fastqs_rep3_R1, fastqs_rep4_R1, fastqs_rep5_R1,
fastqs_rep6_R1, fastqs_rep7_R1, fastqs_rep8_R1, fastqs_rep9_R1]
else if length(fastqs_rep8_R1)>0 then
[fastqs_rep1_R1, fastqs_rep2_R1, fastqs_rep3_R1, fastqs_rep4_R1, fastqs_rep5_R1,
fastqs_rep6_R1, fastqs_rep7_R1, fastqs_rep8_R1]
else if length(fastqs_rep7_R1)>0 then
[fastqs_rep1_R1, fastqs_rep2_R1, fastqs_rep3_R1, fastqs_rep4_R1, fastqs_rep5_R1,
fastqs_rep6_R1, fastqs_rep7_R1]
else if length(fastqs_rep6_R1)>0 then
[fastqs_rep1_R1, fastqs_rep2_R1, fastqs_rep3_R1, fastqs_rep4_R1, fastqs_rep5_R1,
fastqs_rep6_R1]
else if length(fastqs_rep5_R1)>0 then
[fastqs_rep1_R1, fastqs_rep2_R1, fastqs_rep3_R1, fastqs_rep4_R1, fastqs_rep5_R1]
else if length(fastqs_rep4_R1)>0 then
[fastqs_rep1_R1, fastqs_rep2_R1, fastqs_rep3_R1, fastqs_rep4_R1]
else if length(fastqs_rep3_R1)>0 then
[fastqs_rep1_R1, fastqs_rep2_R1, fastqs_rep3_R1]
else if length(fastqs_rep2_R1)>0 then
[fastqs_rep1_R1, fastqs_rep2_R1]
else if length(fastqs_rep1_R1)>0 then
[fastqs_rep1_R1]
else []
# no need to do that for R2 (R1 array will be used to determine presense of fastq for each rep)
Array[Array[File]] fastqs_R2 =
[fastqs_rep1_R2, fastqs_rep2_R2, fastqs_rep3_R2, fastqs_rep4_R2, fastqs_rep5_R2,
fastqs_rep6_R2, fastqs_rep7_R2, fastqs_rep8_R2, fastqs_rep9_R2, fastqs_rep10_R2]
# temporary 2-dim adapters array [rep_id][merge_id]
Array[Array[String]] adapters_R1 =
[adapters_rep1_R1, adapters_rep2_R1, adapters_rep3_R1, adapters_rep4_R1, adapters_rep5_R1,
adapters_rep6_R1, adapters_rep7_R1, adapters_rep8_R1, adapters_rep9_R1, adapters_rep10_R1]
Array[Array[String]] adapters_R2 =
[adapters_rep1_R2, adapters_rep2_R2, adapters_rep3_R2, adapters_rep4_R2, adapters_rep5_R2,
adapters_rep6_R2, adapters_rep7_R2, adapters_rep8_R2, adapters_rep9_R2, adapters_rep10_R2]
# temporary variables to get number of replicates
# WDLic implementation of max(A,B,C,...)
Int num_rep_fastq = length(fastqs_R1)
Int num_rep_trim_merged_fastq = if length(trim_merged_fastqs_R1)<num_rep_fastq then num_rep_fastq
else length(trim_merged_fastqs_R1)
Int num_rep_bam = if length(bams)<num_rep_trim_merged_fastq then num_rep_trim_merged_fastq
else length(bams)
Int num_rep_nodup_bam = if length(nodup_bams)<num_rep_bam then num_rep_bam
else length(nodup_bams)
Int num_rep_ta = if length(tas)<num_rep_nodup_bam then num_rep_nodup_bam
else length(tas)
Int num_rep_peak = if length(peaks)<num_rep_ta then num_rep_ta
else length(peaks)
Int num_rep = num_rep_peak
# align each replicate
scatter(i in range(num_rep)) {
# to override endedness definition for individual replicate
# paired_end will override paired_ends[i]
Boolean? paired_end_ = if !defined(paired_end) && i<length(paired_ends) then paired_ends[i]
else paired_end
Boolean has_input_of_trim_adapter = i<length(fastqs_R1) && length(fastqs_R1[i])>0
Boolean has_output_of_trim_adapter = i<length(trim_merged_fastqs_R1) &&
defined(trim_merged_fastqs_R1[i])
# skip if we already have output of this step
if ( has_input_of_trim_adapter && !has_output_of_trim_adapter ) {
call trim_adapter { input :
fastqs_R1 = fastqs_R1[i],
fastqs_R2 = fastqs_R2[i],
adapter = adapter,
adapters_R1 = adapters_R1[i],
adapters_R2 = adapters_R2[i],
paired_end = paired_end_,
auto_detect_adapter = auto_detect_adapter,
cutadapt_param = cutadapt_param,
# resource
cpu = trim_adapter_cpu,
mem_mb = trim_adapter_mem_mb,
time_hr = trim_adapter_time_hr,
disks = trim_adapter_disks,
}
}
File? trim_merged_fastq_R1_ = if has_output_of_trim_adapter
then trim_merged_fastqs_R1[i]
else trim_adapter.trim_merged_fastq_R1
File? trim_merged_fastq_R2_ = if i<length(trim_merged_fastqs_R2) &&
defined(trim_merged_fastqs_R2[i])
then trim_merged_fastqs_R2[i]
else trim_adapter.trim_merged_fastq_R2
Boolean has_input_of_bowtie2 = has_output_of_trim_adapter ||
defined(trim_adapter.trim_merged_fastq_R1)
Boolean has_output_of_bowtie2 = i<length(bams) && defined(bams[i])
if ( has_input_of_bowtie2 && !has_output_of_bowtie2 ) {
call bowtie2 { input :
fastq_R1 = trim_merged_fastq_R1_,
fastq_R2 = trim_merged_fastq_R2_,
paired_end = paired_end_,
#aligner = aligner,
multimapping = multimapping,
idx_tar = bowtie2_idx_tar_,
bowtie2_param_se = bowtie2_param_se,
bowtie2_param_pe = bowtie2_param_pe,
# resource
cpu = bowtie2_cpu,
mem_mb = bowtie2_mem_mb,
time_hr = bowtie2_time_hr,
disks = bowtie2_disks,
}
}
File? bam_ = if has_output_of_bowtie2 then bams[i] else bowtie2.bam
Boolean has_input_of_filter = has_output_of_bowtie2 || defined(bowtie2.bam)
Boolean has_output_of_filter = i<length(nodup_bams) && defined(nodup_bams[i])
# skip if we already have output of this step
if ( has_input_of_filter && !has_output_of_filter ) {
call filter { input :
bam = bam_,
paired_end = paired_end_,
dup_marker = dup_marker,
mapq_thresh = mapq_thresh,
no_dup_removal = no_dup_removal,
multimapping = multimapping,
mito_chr_name = mito_chr_name,
cpu = filter_cpu,
mem_mb = filter_mem_mb,
time_hr = filter_time_hr,
disks = filter_disks,
}
}
File? nodup_bam_ = if has_output_of_filter then nodup_bams[i] else filter.nodup_bam
Boolean has_input_of_bam2ta = has_output_of_filter || defined(filter.nodup_bam)
Boolean has_output_of_bam2ta = i<length(tas) && defined(tas[i])
if ( has_input_of_bam2ta && !has_output_of_bam2ta ) {
call bam2ta { input :
bam = nodup_bam_,
disable_tn5_shift = if pipeline_type=='atac' then false else true,
regex_grep_v_ta = regex_filter_reads,
subsample = subsample_reads,
paired_end = paired_end_,
mito_chr_name = mito_chr_name,
cpu = bam2ta_cpu,
mem_mb = bam2ta_mem_mb,
time_hr = bam2ta_time_hr,
disks = bam2ta_disks,
}
}
File? ta_ = if has_output_of_bam2ta then tas[i] else bam2ta.ta
Boolean has_input_of_xcor = has_output_of_bam2ta || defined(bam2ta.ta)
if ( has_input_of_xcor && enable_xcor ) {
# subsample tagalign (non-mito) and cross-correlation analysis
call xcor { input :
ta = ta_,
subsample = xcor_subsample_reads,
paired_end = paired_end_,
mito_chr_name = mito_chr_name,
cpu = xcor_cpu,
mem_mb = xcor_mem_mb,
time_hr = xcor_time_hr,
disks = xcor_disks,
}
}
Boolean has_input_of_macs2_signal_track = has_output_of_bam2ta || defined(bam2ta.ta)
if ( has_input_of_macs2_signal_track ) {
# generate count signal track
call macs2_signal_track { input :
ta = ta_,
gensz = gensz_,
chrsz = chrsz_,
pval_thresh = pval_thresh,
smooth_win = smooth_win,
mem_mb = macs2_mem_mb,
disks = macs2_disks,
time_hr = macs2_time_hr,
}
}
Boolean has_input_of_macs2 = has_output_of_bam2ta || defined(bam2ta.ta)
Boolean has_output_of_macs2 = i<length(peaks) && defined(peaks[i])
if ( has_input_of_macs2 && !has_output_of_macs2 && !align_only ) {
# call peaks on tagalign
call macs2 { input :
ta = ta_,
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak,
pval_thresh = pval_thresh,
smooth_win = smooth_win,
blacklist = blacklist_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
mem_mb = macs2_mem_mb,
disks = macs2_disks,
time_hr = macs2_time_hr,
}
}
File? peak_ = if has_output_of_macs2 then peaks[i] else macs2.npeak
Boolean has_input_of_spr = has_output_of_bam2ta || defined(bam2ta.ta)
if ( has_input_of_spr && !align_only && !true_rep_only ) {
call spr { input :
ta = ta_,
paired_end = paired_end_,
mem_mb = spr_mem_mb,
}
}
Boolean has_input_of_macs2_pr1 = defined(spr.ta_pr1)
Boolean has_output_of_macs2_pr1 = i<length(peaks_pr1) && defined(peaks_pr1[i])
if ( has_input_of_macs2_pr1 && !has_output_of_macs2_pr1 &&
!align_only && !true_rep_only ) {
# call peaks on 1st pseudo replicated tagalign
call macs2 as macs2_pr1 { input :
ta = spr.ta_pr1,
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak,
pval_thresh = pval_thresh,
smooth_win = smooth_win,
blacklist = blacklist_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
mem_mb = macs2_mem_mb,
disks = macs2_disks,
time_hr = macs2_time_hr,
}
}
File? peak_pr1_ = if has_output_of_macs2_pr1 then peaks_pr1[i]
else macs2_pr1.npeak
Boolean has_input_of_macs2_pr2 = defined(spr.ta_pr2)
Boolean has_output_of_macs2_pr2 = i<length(peaks_pr2) && defined(peaks_pr2[i])
if ( has_input_of_macs2_pr2 && !has_output_of_macs2_pr2 &&
!align_only && !true_rep_only ) {
# call peaks on 2nd pseudo replicated tagalign
call macs2 as macs2_pr2 { input :
ta = spr.ta_pr2,
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak,
pval_thresh = pval_thresh,
smooth_win = smooth_win,
blacklist = blacklist_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
mem_mb = macs2_mem_mb,
disks = macs2_disks,
time_hr = macs2_time_hr,
}
}
File? peak_pr2_ = if has_output_of_macs2_pr2 then peaks_pr2[i]
else macs2_pr2.npeak
Boolean has_input_of_count_signal_track = has_output_of_bam2ta || defined(bam2ta.ta)
if ( has_input_of_count_signal_track && enable_count_signal_track ) {
# generate count signal track
call count_signal_track { input :
ta = ta_,
chrsz = chrsz_,
}
}
}
# if there are TAs for ALL replicates then pool them
Boolean has_all_inputs_of_pool_ta = length(select_all(ta_))==num_rep
if ( has_all_inputs_of_pool_ta && num_rep>1 ) {
# pool tagaligns from true replicates
call pool_ta { input :
tas = ta_,
}
}
# if there are pr1 TAs for ALL replicates then pool them
Boolean has_all_inputs_of_pool_ta_pr1 = length(select_all(spr.ta_pr1))==num_rep
if ( has_all_inputs_of_pool_ta_pr1 && num_rep>1 && !align_only && !true_rep_only ) {
# pool tagaligns from pseudo replicate 1
call pool_ta as pool_ta_pr1 { input :
tas = spr.ta_pr1,
}
}
# if there are pr2 TAs for ALL replicates then pool them
Boolean has_all_inputs_of_pool_ta_pr2 = length(select_all(spr.ta_pr2))==num_rep
if ( has_all_inputs_of_pool_ta_pr1 && num_rep>1 && !align_only && !true_rep_only ) {
# pool tagaligns from pseudo replicate 2
call pool_ta as pool_ta_pr2 { input :
tas = spr.ta_pr2,
}
}
Boolean has_input_of_macs2_pooled = defined(pool_ta.ta_pooled)
Boolean has_output_of_macs2_pooled = defined(peak_pooled)
if ( has_input_of_macs2_pooled && !has_output_of_macs2_pooled &&
!align_only && num_rep>1 ) {
# call peaks on pooled replicate
call macs2 as macs2_pooled { input :
ta = pool_ta.ta_pooled,
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak,
pval_thresh = pval_thresh,
smooth_win = smooth_win,
blacklist = blacklist_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
mem_mb = macs2_mem_mb,
disks = macs2_disks,
time_hr = macs2_time_hr,
}
}
File? peak_pooled_ = if has_output_of_macs2_pooled then peak_pooled
else macs2_pooled.npeak
Boolean has_input_of_count_signal_track_pooled = defined(pool_ta.ta_pooled)
if ( has_input_of_count_signal_track_pooled && enable_count_signal_track && num_rep>1 ) {
call count_signal_track as count_signal_track_pooled { input :
ta = pool_ta.ta_pooled,
chrsz = chrsz_,
}
}
Boolean has_input_of_macs2_signal_track_pooled = defined(pool_ta.ta_pooled)
if ( has_input_of_macs2_signal_track_pooled && num_rep>1 ) {
call macs2_signal_track as macs2_signal_track_pooled { input :
ta = pool_ta.ta_pooled,
gensz = gensz_,
chrsz = chrsz_,
pval_thresh = pval_thresh,
smooth_win = smooth_win,
mem_mb = macs2_mem_mb,
disks = macs2_disks,
time_hr = macs2_time_hr,
}
}
Boolean has_input_of_macs2_ppr1 = defined(pool_ta_pr1.ta_pooled)
Boolean has_output_of_macs2_ppr1 = defined(peak_ppr1)
if ( has_input_of_macs2_ppr1 && !has_output_of_macs2_ppr1 &&
!align_only && !true_rep_only && num_rep>1 ) {
# call peaks on 1st pooled pseudo replicates
call macs2 as macs2_ppr1 { input :
ta = pool_ta_pr1.ta_pooled,
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak,
pval_thresh = pval_thresh,
smooth_win = smooth_win,
blacklist = blacklist_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
mem_mb = macs2_mem_mb,
disks = macs2_disks,
time_hr = macs2_time_hr,
}
}
File? peak_ppr1_ = if has_output_of_macs2_ppr1 then peak_ppr1
else macs2_ppr1.npeak
Boolean has_input_of_macs2_ppr2 = defined(pool_ta_pr2.ta_pooled)
Boolean has_output_of_macs2_ppr2 = defined(peak_ppr2)
if ( has_input_of_macs2_ppr2 && !has_output_of_macs2_ppr2 &&
!align_only && !true_rep_only && num_rep>1 ) {
# call peaks on 2nd pooled pseudo replicates
call macs2 as macs2_ppr2 { input :
ta = pool_ta_pr2.ta_pooled,
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak,
pval_thresh = pval_thresh,
smooth_win = smooth_win,
blacklist = blacklist_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
mem_mb = macs2_mem_mb,
disks = macs2_disks,
time_hr = macs2_time_hr,
}
}
File? peak_ppr2_ = if has_output_of_macs2_ppr2 then peak_ppr2
else macs2_ppr2.npeak
# do IDR/overlap on all pairs of two replicates (i,j)
# where i and j are zero-based indices and 0 <= i < j < num_rep
Array[Pair[Int, Int]] pairs_ = cross(range(num_rep),range(num_rep))
scatter( pair in pairs_ ) {
Pair[Int, Int]? null_pair
Pair[Int, Int]? pairs__ = if pair.left<pair.right then pair else null_pair
}
Array[Pair[Int, Int]] pairs = select_all(pairs__)
if ( !align_only ) {
scatter( pair in pairs ) {
# pair.left = 0-based index of 1st replicate
# pair.right = 0-based index of 2nd replicate
# Naive overlap on every pair of true replicates
call overlap { input :
prefix = 'rep'+(pair.left+1)+"_rep"+(pair.right+1),
peak1 = peak_[pair.left],
peak2 = peak_[pair.right],
peak_pooled = peak_pooled_,
peak_type = peak_type,
blacklist = blacklist_,
chrsz = chrsz_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
ta = pool_ta.ta_pooled,
}
}
}
if ( enable_idr && !align_only ) {
scatter( pair in pairs ) {
# pair.left = 0-based index of 1st replicate
# pair.right = 0-based index of 2nd replicate
# IDR on every pair of true replicates
call idr { input :
prefix = 'rep'+(pair.left+1)+"_rep"+(pair.right+1),
peak1 = peak_[pair.left],
peak2 = peak_[pair.right],
peak_pooled = peak_pooled_,
idr_thresh = idr_thresh,
peak_type = peak_type,
rank = idr_rank,
blacklist = blacklist_,
chrsz = chrsz_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
ta = pool_ta.ta_pooled,
}
}
}
# overlap on pseudo-replicates (pr1, pr2) for each true replicate
scatter( i in range(num_rep) ) {
if ( !align_only && !true_rep_only ) {
call overlap as overlap_pr { input :
prefix = "rep"+(i+1)+"-pr",
peak1 = peak_pr1_[i],
peak2 = peak_pr2_[i],
peak_pooled = peak_[i],
peak_type = peak_type,
blacklist = blacklist_,
chrsz = chrsz_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
ta = ta_[i],
}
}
}
scatter( i in range(num_rep) ) {
if ( !align_only && !true_rep_only && enable_idr ) {
# IDR on pseduo replicates
call idr as idr_pr { input :
prefix = "rep"+(i+1)+"-pr",
peak1 = peak_pr1_[i],
peak2 = peak_pr2_[i],
peak_pooled = peak_[i],
idr_thresh = idr_thresh,
peak_type = peak_type,
rank = idr_rank,
blacklist = blacklist_,
chrsz = chrsz_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
ta = ta_[i],
}
}
}
if ( !align_only && !true_rep_only && num_rep>1 ) {
# Naive overlap on pooled pseudo replicates
call overlap as overlap_ppr { input :
prefix = "ppr",
peak1 = peak_ppr1_,
peak2 = peak_ppr2_,
peak_pooled = peak_pooled_,
peak_type = peak_type,
blacklist = blacklist_,
chrsz = chrsz_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
ta = pool_ta.ta_pooled,
}
}
if ( !align_only && !true_rep_only && num_rep>1 ) {
# IDR on pooled pseduo replicates
call idr as idr_ppr { input :
prefix = "ppr",
peak1 = peak_ppr1_,
peak2 = peak_ppr2_,
peak_pooled = peak_pooled_,
idr_thresh = idr_thresh,
peak_type = peak_type,
rank = idr_rank,
blacklist = blacklist_,
chrsz = chrsz_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
ta = pool_ta.ta_pooled,
}
}
# reproducibility QC for overlap/IDR peaks
if ( !align_only && !true_rep_only ) {
# reproducibility QC for overlapping peaks
call reproducibility as reproducibility_overlap { input :
prefix = 'overlap',
peaks = overlap.bfilt_overlap_peak,
peaks_pr = overlap_pr.bfilt_overlap_peak,
peak_ppr = overlap_ppr.bfilt_overlap_peak,
peak_type = peak_type,
chrsz = chrsz_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
}
}
if ( !align_only && !true_rep_only && enable_idr ) {
# reproducibility QC for IDR peaks
call reproducibility as reproducibility_idr { input :
prefix = 'idr',
peaks = idr.bfilt_idr_peak,
peaks_pr = idr_pr.bfilt_idr_peak,
peak_ppr = idr_ppr.bfilt_idr_peak,
peak_type = peak_type,
chrsz = chrsz_,
keep_irregular_chr_in_bfilt_peak = keep_irregular_chr_in_bfilt_peak,
}
}
# ATAqC
scatter( i in range(num_rep) ) {
if ( !disable_ataqc ) {
call ataqc { input :
paired_end = paired_end_[i],
read_len_log = bowtie2.read_len_log[i],
flagstat_qc = bowtie2.flagstat_qc[i],
bowtie2_log = bowtie2.align_log[i],
pbc_qc = filter.pbc_qc[i],
dup_qc = filter.dup_qc[i],
bam = bam_[i],
nodup_flagstat_qc = filter.flagstat_qc[i],
mito_dup_log = filter.mito_dup_log[i],
nodup_bam = nodup_bam_[i],
ta = ta_[i],
peak = if defined(idr_pr.bfilt_idr_peak[i]) then idr_pr.bfilt_idr_peak[i]
else reproducibility_overlap.optimal_peak,
idr_peak = reproducibility_idr.optimal_peak,
overlap_peak= reproducibility_overlap.optimal_peak,
pval_bw = macs2_signal_track.pval_bw[i],
ref_fa = ref_fa_,
chrsz = chrsz_,
tss = tss_,
blacklist = blacklist_,
dnase = dnase_,
prom = prom_,
enh = enh_,
reg2map_bed = reg2map_bed_,
reg2map = reg2map_,
roadmap_meta = roadmap_meta_,
mito_chr_name = mito_chr_name,
mem_mb = ataqc_mem_mb,
mem_java_mb = ataqc_mem_java_mb,
time_hr = ataqc_time_hr,
disks = ataqc_disks,
}
}
}
# Generate final QC report and JSON
call qc_report { input :
pipeline_ver = pipeline_ver,
title = title,
description = description,
genome = basename(select_first([genome_tsv, ref_fa_, chrsz_, 'None'])),
multimapping = multimapping,
paired_ends = paired_end_,
pipeline_type = pipeline_type,
peak_caller = 'macs2',
macs2_cap_num_peak = cap_num_peak,
idr_thresh = idr_thresh,
flagstat_qcs = bowtie2.flagstat_qc,
nodup_flagstat_qcs = filter.flagstat_qc,
dup_qcs = filter.dup_qc,
pbc_qcs = filter.pbc_qc,
xcor_plots = xcor.plot_png,
xcor_scores = xcor.score,
frip_macs2_qcs = macs2.frip_qc,
frip_macs2_qcs_pr1 = macs2_pr1.frip_qc,
frip_macs2_qcs_pr2 = macs2_pr2.frip_qc,
frip_macs2_qc_pooled = macs2_pooled.frip_qc,
frip_macs2_qc_ppr1 = macs2_ppr1.frip_qc,
frip_macs2_qc_ppr2 = macs2_ppr2.frip_qc,
idr_plots = idr.idr_plot,
idr_plots_pr = idr_pr.idr_plot,
idr_plot_ppr = idr_ppr.idr_plot,
frip_idr_qcs = idr.frip_qc,
frip_idr_qcs_pr = idr_pr.frip_qc,
frip_idr_qc_ppr = idr_ppr.frip_qc,
frip_overlap_qcs = overlap.frip_qc,
frip_overlap_qcs_pr = overlap_pr.frip_qc,
frip_overlap_qc_ppr = overlap_ppr.frip_qc,
idr_reproducibility_qc = reproducibility_idr.reproducibility_qc,
overlap_reproducibility_qc = reproducibility_overlap.reproducibility_qc,
ataqc_txts = ataqc.txt,
ataqc_htmls = ataqc.html,
}
output {
File report = qc_report.report
File qc_json = qc_report.qc_json
Boolean qc_json_ref_match = qc_report.qc_json_ref_match
}
}
# trim adapters and merge trimmed fastqs
task trim_adapter {
Array[File] fastqs_R1 # [merge_id]
Array[File] fastqs_R2
String? adapter # adapter for all fastqs,
# this will override individual adapters in adapters_R1/R2
Array[String] adapters_R1
Array[String] adapters_R2
Boolean paired_end
Boolean auto_detect_adapter
String cutadapt_param
# resource
Int cpu
Int mem_mb
Int time_hr
String disks
# tmp vars
File? null_f
Array[Array[File]] tmp_fastqs = if paired_end then transpose([fastqs_R1, fastqs_R2])
else transpose([fastqs_R1])
Array[Array[String]] tmp_adapters = if paired_end then transpose([adapters_R1, adapters_R2])
else transpose([adapters_R1])
command {
python $(which encode_trim_adapter.py) \
${write_tsv(tmp_fastqs)} \
${"--adapter " + adapter} \
--adapters ${write_tsv(tmp_adapters)} \
${if paired_end then "--paired-end" else ""} \
${if auto_detect_adapter then "--auto-detect-adapter" else ""} \
--cutadapt-param ' ${cutadapt_param}' \
${"--nth " + cpu}
}
output {
File trim_merged_fastq_R1 = glob("R1/*.fastq.gz")[0]
File? trim_merged_fastq_R2 = if paired_end then glob("R2/*.fastq.gz")[0] else null_f
}
runtime {
cpu : cpu
memory : "${mem_mb} MB"
time : time_hr
disks : disks
}
}
task bowtie2 {
File idx_tar # reference bowtie2 index tar
File? fastq_R1 # [read_end_id]
File? fastq_R2
Boolean paired_end
Int multimapping
String bowtie2_param_se
String bowtie2_param_pe
Int cpu
Int mem_mb
Int time_hr
String disks
command {
python $(which encode_bowtie2.py) \
${idx_tar} \
${fastq_R1} ${fastq_R2} \
${if paired_end then "--paired-end" else ""} \
${"--multimapping " + multimapping} \
--bowtie2-param-se ' ${bowtie2_param_se}' \
--bowtie2-param-pe ' ${bowtie2_param_pe}' \
${"--nth " + cpu}
}
output {
File bam = glob("*.bam")[0]
File bai = glob("*.bai")[0]
File align_log = glob("*.align.log")[0]
File flagstat_qc = glob("*.flagstat.qc")[0]
File read_len_log = glob("*.read_length.txt")[0] # read_len
}
runtime {
cpu : cpu
memory : "${mem_mb} MB"
time : time_hr
disks : disks
preemptible: 0
}
}
task filter {
File bam
Boolean paired_end
Int multimapping
String dup_marker # picard.jar MarkDuplicates (picard) or
# sambamba markdup (sambamba)
Int mapq_thresh # threshold for low MAPQ reads removal
Boolean no_dup_removal # no dupe reads removal when filtering BAM
String mito_chr_name
Int cpu
Int mem_mb
Int time_hr
String disks
command {
python $(which encode_filter.py) \
${bam} \
${if paired_end then "--paired-end" else ""} \
${"--multimapping " + multimapping} \
${"--dup-marker " + dup_marker} \
${"--mapq-thresh " + mapq_thresh} \
${if no_dup_removal then "--no-dup-removal" else ""} \
${"--mito-chr-name " + mito_chr_name} \
${"--nth " + cpu}
}
output {
File nodup_bam = glob("*.bam")[0]
File nodup_bai = glob("*.bai")[0]
File flagstat_qc = glob("*.flagstat.qc")[0]
File dup_qc = glob("*.dup.qc")[0]
File pbc_qc = glob("*.pbc.qc")[0]
File mito_dup_log = glob("*.mito_dup.txt")[0] # mito_dups, fract_dups_from_mito
}
runtime {
cpu : cpu