forked from blanpainlab/atac-seq-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathatac.wdl
2008 lines (1799 loc) · 64.7 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 (leepc12@gmail.com)
workflow atac {
# pipeline version
String pipeline_ver = 'v1.3.0'
# 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 = 0 # 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 = 150 # 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 = false # enable IDR analysis on raw peaks
Float idr_thresh = 0.1 # 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 100 HDD"
Int filter_cpu = 2
Int filter_mem_mb = 20000
Int filter_time_hr = 24
String filter_disks = "local-disk 100 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 100 HDD"
Int ataqc_mem_mb = 16000
Int ataqc_mem_java_mb = 15000
Int ataqc_time_hr = 24
String ataqc_disks = "local-disk 400 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 files used for resumer, output from task align
Array[File?] bowtie2__align_log = []
Array[File?] bowtie2__flagstat_qc = []
Array[File?] bowtie2__read_len_log = []
Array[File?] filter__flagstat_qc = []
Array[File?] filter__dup_qc = []
Array[File?] filter__pbc_qc = []
Array[File?] filter__mito_dup_log = []
Array[File?] spr__ta_pr1 = []
Array[File?] spr__ta_pr2 = []
Array[File?] xcor__plot_png = []
Array[File?] xcor__score = []
Array[File?] count_signal_track__pos_bw = []
Array[File?] count_signal_track__neg_bw = []
Array[File?] macs2_signal_track__pval_bw = []
Array[File?] macs2_signal_track__fc_bw = []
Array[File?] macs2__frip_qc = []
Array[File?] macs2_pr1__frip_qc = []
Array[File?] macs2_pr2__frip_qc = []
Array[File?] idr__idr_peak = [] # per pair of replicate
Array[File?] idr__bfilt_idr_peak = []
Array[File?] idr__idr_plot = []
Array[File?] idr__frip_qc = []
Array[File?] idr_pr__idr_peak = [] # per replicate
Array[File?] idr_pr__bfilt_idr_peak = []
Array[File?] idr_pr__idr_plot = []
Array[File?] idr_pr__frip_qc = []
Array[File?] overlap__overlap_peak = [] # per pair of replicate
Array[File?] overlap__bfilt_overlap_peak = []
Array[File?] overlap__frip_qc = []
Array[File?] overlap_pr__overlap_peak = [] # per replicate
Array[File?] overlap_pr__bfilt_overlap_peak = []
Array[File?] overlap_pr__frip_qc = []
Array[File?] ataqc__html = []
Array[File?] ataqc__txt = []
File? pool_ta__ta_pooled
File? pool_ta_pr1__ta_pooled
File? pool_ta_pr2__ta_pooled
File? count_signal_track_pooled__pos_bw
File? count_signal_track_pooled__neg_bw
File? macs2_signal_track_pooled__pval_bw
File? macs2_signal_track_pooled__fc_bw
File? macs2_pooled__frip_qc
File? macs2_ppr1__frip_qc
File? macs2_ppr2__frip_qc
File? idr_ppr__idr_peak
File? idr_ppr__bfilt_idr_peak
File? idr_ppr__idr_plot
File? idr_ppr__frip_qc
File? overlap_ppr__overlap_peak
File? overlap_ppr__bfilt_overlap_peak
File? overlap_ppr__frip_qc
File? reproducibility_idr__optimal_peak
File? reproducibility_idr__reproducibility_qc
File? reproducibility_overlap__optimal_peak
File? reproducibility_overlap__reproducibility_qc
# 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
File? flagstat_qc_ = if i<length(bowtie2__flagstat_qc) &&
defined(bowtie2__flagstat_qc[i]) then bowtie2__flagstat_qc[i]
else bowtie2.flagstat_qc
File? align_log_ = if i<length(bowtie2__align_log) &&
defined(bowtie2__align_log[i]) then bowtie2__align_log[i]
else bowtie2.align_log
File? read_len_log_ = if i<length(bowtie2__read_len_log) &&
defined(bowtie2__read_len_log[i]) then bowtie2__read_len_log[i]
else bowtie2.read_len_log
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
File? nodup_flagstat_qc_ = if i<length(filter__flagstat_qc) &&
defined(filter__flagstat_qc[i]) then filter__flagstat_qc[i]
else filter.flagstat_qc
File? dup_qc_ = if i<length(filter__dup_qc) &&
defined(filter__dup_qc[i]) then filter__dup_qc[i]
else filter.dup_qc
File? pbc_qc_ = if i<length(filter__pbc_qc) &&
defined(filter__pbc_qc[i]) then filter__pbc_qc[i]
else filter.pbc_qc
File? mito_dup_log_ = if i<length(filter__mito_dup_log) &&
defined(filter__mito_dup_log[i]) then filter__mito_dup_log[i]
else filter.mito_dup_log
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)
Boolean has_output_of_xcor = i<length(xcor__score) && defined(xcor__score[i])
if ( has_input_of_xcor && !has_output_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,
}
}
File? xcor_score_ = if has_output_of_xcor then xcor__score[i] else xcor.score
File? xcor_plot_ = if i<length(xcor__plot_png) &&
defined(xcor__plot_png[i]) then xcor__plot_png[i] else xcor.plot_png
Boolean has_input_of_macs2_signal_track = has_output_of_bam2ta || defined(bam2ta.ta)
Boolean has_output_of_macs2_signal_track = i<length(macs2_signal_track__pval_bw) &&
defined(macs2_signal_track__pval_bw[i])
if ( has_input_of_macs2_signal_track && !has_output_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,
}
}
File? pval_bw_ = if has_output_of_macs2_signal_track then macs2_signal_track__pval_bw[i]
else macs2_signal_track.pval_bw
File? fc_bw_ = if i<length(macs2_signal_track__fc_bw) &&
defined(macs2_signal_track__fc_bw[i]) then macs2_signal_track__fc_bw[i]
else macs2_signal_track.fc_bw
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
File? macs2_frip_qc_ = if i<length(macs2__frip_qc) &&
defined(macs2__frip_qc[i]) then macs2__frip_qc[i] else macs2.frip_qc
Boolean has_input_of_spr = has_output_of_bam2ta || defined(bam2ta.ta)
Boolean has_output_of_spr = i<length(spr__ta_pr1) && defined(spr__ta_pr1[i])
if ( has_input_of_spr && !has_output_of_spr &&
!align_only && !true_rep_only ) {
call spr { input :
ta = ta_,
paired_end = paired_end_,
mem_mb = spr_mem_mb,
}
}
File? ta_pr1_ = if has_output_of_spr then spr__ta_pr1[i] else spr.ta_pr1
File? ta_pr2_ = if i<length(spr__ta_pr2) &&
defined(spr__ta_pr2[i]) then spr__ta_pr2[i]
else spr.ta_pr2
Boolean has_input_of_macs2_pr1 = has_output_of_spr || 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 = 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
File? macs2_pr1_frip_qc_ = if i<length(macs2_pr1__frip_qc) &&
defined(macs2_pr1__frip_qc[i]) then macs2_pr1__frip_qc[i]
else macs2_pr1.frip_qc
Boolean has_input_of_macs2_pr2 = has_output_of_spr || 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 = 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
File? macs2_pr2_frip_qc_ = if i<length(macs2_pr2__frip_qc) &&
defined(macs2_pr2__frip_qc[i]) then macs2_pr2__frip_qc[i]
else macs2_pr2.frip_qc
Boolean has_input_of_count_signal_track = has_output_of_bam2ta || defined(bam2ta.ta)
Boolean has_output_of_count_signal_track = i<length(count_signal_track__pos_bw) &&
defined(count_signal_track__pos_bw[i])
if ( has_input_of_count_signal_track && !has_output_of_count_signal_track &&
enable_count_signal_track ) {
# generate count signal track
call count_signal_track { input :
ta = ta_,
chrsz = chrsz_,
}
}
File? pos_bw_ = if has_output_of_count_signal_track then count_signal_track__pos_bw[i]
else count_signal_track.pos_bw
File? neg_bw_ = if i<length(count_signal_track__neg_bw) &&
defined(count_signal_track__neg_bw[i]) then count_signal_track__neg_bw[i]
else count_signal_track.neg_bw
}
# if there are TAs for ALL replicates then pool them
Boolean has_all_inputs_of_pool_ta = length(select_all(ta_))==num_rep
Boolean has_output_of_pool_ta = defined(pool_ta__ta_pooled)
if ( has_all_inputs_of_pool_ta && !has_output_of_pool_ta &&
num_rep>1 ) {
# pool tagaligns from true replicates
call pool_ta { input :
tas = ta_,
}
}
File? ta_pooled_ = if has_output_of_pool_ta then pool_ta__ta_pooled
else pool_ta.ta_pooled
# if there are pr1 TAs for ALL replicates then pool them
Boolean has_all_inputs_of_pool_ta_pr1 = length(select_all(ta_pr1_))==num_rep
Boolean has_output_of_pool_ta_pr1 = defined(pool_ta_pr1__ta_pooled)
if ( has_all_inputs_of_pool_ta_pr1 && !has_output_of_pool_ta_pr1 &&
!align_only && !true_rep_only && num_rep>1 ) {
# pool tagaligns from pseudo replicate 1
call pool_ta as pool_ta_pr1 { input :
tas = ta_pr1_,
}
}
File? ta_ppr1_ = if has_output_of_pool_ta_pr1 then pool_ta_pr1__ta_pooled
else pool_ta_pr1.ta_pooled
# if there are pr2 TAs for ALL replicates then pool them
Boolean has_all_inputs_of_pool_ta_pr2 = length(select_all(ta_pr2_))==num_rep
Boolean has_output_of_pool_ta_pr2 = defined(pool_ta_pr2__ta_pooled)
if ( has_all_inputs_of_pool_ta_pr1 && !has_output_of_pool_ta_pr1 &&
!align_only && !true_rep_only && num_rep>1 ) {
# pool tagaligns from pseudo replicate 2
call pool_ta as pool_ta_pr2 { input :
tas = ta_pr2_,
}
}
File? ta_ppr2_ = if has_output_of_pool_ta_pr2 then pool_ta_pr2__ta_pooled
else pool_ta_pr2.ta_pooled
Boolean has_input_of_macs2_pooled = has_output_of_pool_ta || 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 = 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
File? frip_macs2_qc_pooled_ = if defined(macs2_pooled__frip_qc) then macs2_pooled__frip_qc
else macs2_pooled.frip_qc
Boolean has_input_of_count_signal_track_pooled = has_output_of_pool_ta || defined(pool_ta.ta_pooled)
Boolean has_output_of_count_signal_track_pooled = defined(count_signal_track_pooled__pos_bw)
if ( has_input_of_count_signal_track_pooled && !has_output_of_count_signal_track_pooled &&
enable_count_signal_track && num_rep>1 ) {
call count_signal_track as count_signal_track_pooled { input :
ta = ta_pooled_,
chrsz = chrsz_,
}
}
Boolean has_input_of_macs2_signal_track_pooled = has_output_of_pool_ta || defined(pool_ta.ta_pooled)
Boolean has_output_of_macs2_signal_track_pooled = defined(macs2_signal_track_pooled__pval_bw)
if ( has_input_of_macs2_signal_track_pooled && !has_output_of_macs2_signal_track_pooled &&
num_rep>1 ) {
call macs2_signal_track as macs2_signal_track_pooled { input :
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 = has_output_of_pool_ta_pr1 || 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 = ta_ppr1_,
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
File? frip_macs2_qc_ppr1_ = if defined(macs2_ppr1__frip_qc) then macs2_ppr1__frip_qc
else macs2_ppr1.frip_qc
Boolean has_input_of_macs2_ppr2 = has_output_of_pool_ta_pr2 || 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 = ta_ppr2_,
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
File? frip_macs2_qc_ppr2_ = if defined(macs2_ppr2__frip_qc) then macs2_ppr2__frip_qc
else macs2_ppr2.frip_qc
# IDR/overlap (post-peak-call analyses)
# pipeline cannot resume from here
# code will get too complicated for that
# 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__)
scatter( pair in pairs ) {
# pair.left = 0-based index of 1st replicate
# pair.right = 0-based index of 2nd replicate
Boolean has_input_of_overlap =
defined(peak_[pair.left]) && defined(peak_[pair.right]) && defined(peak_pooled_)
Boolean has_output_of_overlap = pair.left<length(overlap__overlap_peak) &&
defined(overlap__overlap_peak[pair.left])
# for the case without frip_qc
# where pipeline starts from peaks so tag-align is missing
Boolean has_output_of_overlap_frip_qc = pair.left<length(overlap__frip_qc) &&
defined(overlap__frip_qc[pair.left])
if ( has_input_of_overlap && !has_output_of_overlap &&
pair.left<pair.right && !align_only ) { # only for repX-repY where X<Y
# 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 = ta_pooled_,
}
}
}
scatter( pair in pairs ) {
# pair.left = 0-based index of 1st replicate
# pair.right = 0-based index of 2nd replicate
Boolean has_input_of_idr =
defined(peak_[pair.left]) && defined(peak_[pair.right]) && defined(peak_pooled_)
Boolean has_output_of_idr = pair.left<length(idr__idr_peak) &&
defined(idr__idr_peak[pair.left])
Boolean has_output_of_idr_frip_qc = pair.left<length(idr__frip_qc) &&
defined(idr__frip_qc[pair.left])
if ( has_input_of_idr && !has_output_of_idr &&
pair.left<pair.right && !align_only && enable_idr) {
# 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 = ta_pooled_,
}
}
}
scatter( i in range(length(pairs)) ) {
# take raw peak if blacklist doesn't exist
File? overlap_overlap_peak_ =
if has_output_of_overlap[i] && defined(blacklist_) then overlap__bfilt_overlap_peak[i]
else if has_output_of_overlap[i] && !defined(blacklist_) then overlap__overlap_peak[i]
else if defined(blacklist_) then overlap.bfilt_overlap_peak[i]
else overlap.overlap_peak[i]
File? overlap_frip_qc_ = if has_output_of_overlap_frip_qc[i] then overlap__frip_qc[i]
else overlap.frip_qc[i]
# take raw peak if blacklist doesn't exist
File? idr_idr_peak_ =
if has_output_of_idr[i] && defined(blacklist_) then idr__bfilt_idr_peak[i]
else if has_output_of_idr[i] && !defined(blacklist_) then idr__idr_peak[i]
else if defined(blacklist_) then idr.bfilt_idr_peak[i]
else idr.idr_peak[i]
File? idr_idr_plot_ = if has_output_of_idr[i] then idr__idr_plot[i]
else idr.idr_plot[i]
File? idr_frip_qc_ = if has_output_of_idr_frip_qc[i] then idr__frip_qc[i]
else idr.frip_qc[i]
}
# overlap on pseudo-replicates (pr1, pr2) for each true replicate
scatter( i in range(num_rep) ) {
Boolean has_input_of_overlap_pr =
defined(peak_pr1_[i]) && defined(peak_pr2_[i]) && defined(peak_[i])
Boolean has_output_of_overlap_pr = i<length(overlap_pr__overlap_peak) &&
defined(overlap_pr__overlap_peak[i])
Boolean has_output_of_overlap_pr_frip_qc = i<length(overlap_pr__frip_qc) &&
defined(overlap_pr__frip_qc[i])
if ( has_input_of_overlap_pr && !has_output_of_overlap_pr &&
!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) ) {
Boolean has_input_of_idr_pr =
defined(peak_pr1_[i]) && defined(peak_pr2_[i]) && defined(peak_[i])
Boolean has_output_of_idr_pr = i<length(idr_pr__idr_peak) &&
defined(idr_pr__idr_peak[i])
Boolean has_output_of_idr_pr_frip_qc = i<length(idr_pr__frip_qc) &&
defined(idr_pr__frip_qc[i])
if ( has_input_of_idr_pr && !has_output_of_idr_pr &&
!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],
}
}
}
# gather outputs
scatter( i in range(num_rep) ) {
File? overlap_pr_overlap_peak_ =
if has_output_of_overlap_pr[i] && defined(blacklist_) then overlap_pr__bfilt_overlap_peak[i]
else if has_output_of_overlap_pr[i] && !defined(blacklist_) then overlap_pr__overlap_peak[i]
else if defined(blacklist_) then overlap_pr.bfilt_overlap_peak[i]
else overlap_pr.overlap_peak[i]
File? overlap_pr_frip_qc_ =
if has_output_of_overlap_pr_frip_qc[i] then overlap_pr__frip_qc[i]
else overlap_pr.frip_qc[i]
File? idr_pr_idr_peak_ =
if has_output_of_idr_pr[i] && defined(blacklist_) then idr_pr__bfilt_idr_peak[i]
else if has_output_of_idr_pr[i] && !defined(blacklist_) then idr_pr__idr_peak[i]
else if defined(blacklist_) then idr_pr.bfilt_idr_peak[i]
else idr_pr.idr_peak[i]
File? idr_pr_idr_plot_ =
if has_output_of_idr_pr[i] then idr_pr__idr_plot[i]
else idr_pr.idr_plot[i]
File? idr_pr_frip_qc_ =
if has_output_of_idr_pr_frip_qc[i] then idr_pr__frip_qc[i]