forked from ENCODE-DCC/chip-seq-pipeline2
-
Notifications
You must be signed in to change notification settings - Fork 0
/
chip.wdl
2030 lines (1862 loc) · 66.3 KB
/
chip.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 TF/Histone ChIP-Seq pipeline
# Author: Jin Lee ([email protected])
#CAPER docker quay.io/encode-dcc/chip-seq-pipeline:v1.3.4
#CAPER singularity docker://quay.io/encode-dcc/chip-seq-pipeline:v1.3.4
#CROO out_def https://storage.googleapis.com/encode-pipeline-output-definition/chip.croo.json
workflow chip {
String pipeline_ver = 'v1.3.4'
### sample name, description
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
Boolean? ctl_paired_end
Array[Boolean] ctl_paired_ends = []
### mandatory genome param
File? genome_tsv # reference genome data TSV file including
# all genome-specific file paths and parameters
# individual genome parameters
String? genome_name # genome name
File? ref_fa # reference fasta (*.fa.gz)
File? bwa_idx_tar # bwa index tar (uncompressed .tar)
File? bowtie2_idx_tar # bowtie2 index tar (uncompressed .tar)
File? custom_aligner_idx_tar # custom aligner's index tar (uncompressed .tar)
File? chrsz # 2-col chromosome sizes file
File? blacklist # blacklist BED (peaks overlapping will be filtered out)
File? blacklist2 # 2nd blacklist (will be merged with 1st one)
String? mito_chr_name
String? regex_bfilt_peak_chr_name
String? gensz # genome sizes (hs for human, mm for mouse or sum of 2nd col in chrsz)
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
### pipeline type
String pipeline_type # tf or histone chip-seq
String aligner = 'bowtie2'
File? custom_align_py # custom align python script
String? peak_caller # default: (spp for tf) and (macs2 for histone)
# this will override the above defaults
String? peak_type # default: narrowPeak for macs2, regionPeak for spp
# this will override the above defaults
File? custom_call_peak_py # custom call_peak python script
## parameters for alignment
Boolean align_only = false # disable all post-align analysis (peak-calling, overlap, idr, ...)
Boolean true_rep_only = false # disable all analyses involving pseudo replicates (including overlap/idr)
Boolean enable_count_signal_track = false # generate count signal track
Boolean enable_jsd = true # enable JSD plot generation (deeptools fingerprint)
Boolean enable_gc_bias = true
# parameters for aligner and filter
Boolean use_bwa_mem_for_pe = false # THIS IS EXPERIMENTAL and BWA ONLY (use bwa mem instead of bwa aln/sam)
# available only for PE dataset with READ_LEN>=70bp
Int xcor_pe_trim_bp = 50 # for cross-correlation analysis only (R1 of paired-end fastqs)
Boolean use_filt_pe_ta_for_xcor = false # PE only. use filtered PE BAM for cross-corr.
String dup_marker = 'picard' # picard, sambamba
Boolean no_dup_removal = false # keep all dups in final BAM
Int? mapq_thresh # threshold for low MAPQ reads removal
Int mapq_thresh_bwa = 30
Int mapq_thresh_bowtie2 = 30
Array[String] filter_chrs = [] # array of chromosomes to be removed from nodup/filt BAM
# chromosomes will be removed from both BAM header/contents
# e.g. ['chrM', 'MT']
Int subsample_reads = 0 # number of reads to subsample TAGALIGN
# 0 for no subsampling. this affects all downstream analysis
Int ctl_subsample_reads = 0 # number of reads to subsample control TAGALIGN
Int xcor_subsample_reads = 15000000 # subsample TAG-ALIGN for xcor only (not used for other downsteam analyses)
Int xcor_exclusion_range_min = -500
Int? xcor_exclusion_range_max
# parameters for peak calling
Boolean always_use_pooled_ctl = false # always use pooled control for all exp rep.
Float ctl_depth_ratio = 1.2 # if ratio between controls is higher than this
# then always use pooled control for all exp rep.
Int? cap_num_peak
Int cap_num_peak_spp = 300000 # cap number of raw peaks called from SPP
Int cap_num_peak_macs2 = 500000 # cap number of raw peaks called from MACS2
Float pval_thresh = 0.01 # p.value threshold
Float idr_thresh = 0.05 # IDR threshold
### resources
Int align_cpu = 4
Int align_mem_mb = 20000
Int align_time_hr = 48
String align_disks = 'local-disk 400 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 jsd_cpu = 2
Int jsd_mem_mb = 12000
Int jsd_time_hr = 6
String jsd_disks = 'local-disk 200 HDD'
Int xcor_cpu = 2
Int xcor_mem_mb = 16000
Int xcor_time_hr = 24
String xcor_disks = 'local-disk 100 HDD'
Int macs2_signal_track_mem_mb = 16000
Int macs2_signal_track_time_hr = 24
String macs2_signal_track_disks = 'local-disk 400 HDD'
Int call_peak_cpu = 2
Int call_peak_mem_mb = 16000
Int call_peak_time_hr = 72
String call_peak_disks = 'local-disk 200 HDD'
String filter_picard_java_heap = '4G'
String gc_bias_picard_java_heap = '6G'
#### input file definition
# pipeline can start from any type of inputs and then leave all other types undefined
# supported types: fastq, bam, nodup_bam (filtered bam), ta (tagAlign), peak
# define up to 4 replicates
# [rep_id] is for each replicate
### fastqs
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 = []
Array[File] ctl_fastqs_rep1_R1 = [] # Control FASTQs to be merged for rep1 R1
Array[File] ctl_fastqs_rep1_R2 = [] # do not define if single-ended
Array[File] ctl_fastqs_rep2_R1 = [] # do not define if unreplicated
Array[File] ctl_fastqs_rep2_R2 = [] # ...
Array[File] ctl_fastqs_rep3_R1 = []
Array[File] ctl_fastqs_rep3_R2 = []
Array[File] ctl_fastqs_rep4_R1 = []
Array[File] ctl_fastqs_rep4_R2 = []
Array[File] ctl_fastqs_rep5_R1 = []
Array[File] ctl_fastqs_rep5_R2 = []
Array[File] ctl_fastqs_rep6_R1 = []
Array[File] ctl_fastqs_rep6_R2 = []
Array[File] ctl_fastqs_rep7_R1 = []
Array[File] ctl_fastqs_rep7_R2 = []
Array[File] ctl_fastqs_rep8_R1 = []
Array[File] ctl_fastqs_rep8_R2 = []
Array[File] ctl_fastqs_rep9_R1 = []
Array[File] ctl_fastqs_rep9_R2 = []
Array[File] ctl_fastqs_rep10_R1 = []
Array[File] ctl_fastqs_rep10_R2 = []
### other input types (bam, nodup_bam, ta)
Array[File?] bams = [] # [rep_id]
Array[File?] ctl_bams = [] # [rep_id]
Array[File?] nodup_bams = [] # [rep_id]
Array[File?] ctl_nodup_bams = [] # [rep_id]
Array[File?] tas = [] # [rep_id]
Array[File?] ctl_tas = [] # [rep_id]
### other input types (peak)
Array[Int?] fraglen = [] # [rep_id]. fragment length if inputs are peaks
Array[File?] peaks = [] # [PAIR(rep_id1,rep_id2)]. example for 3 reps: [rep1_rep2, rep1_rep3, rep2_rep3]
Array[File?] peaks_pr1 = [] # [rep_id]. do not define if true_rep=true
Array[File?] peaks_pr2 = [] # [rep_id]. do not define if true_rep=true
File? peak_ppr1 # do not define if you have a single replicate or true_rep=true
File? peak_ppr2 # do not define if you have a single replicate or true_rep=true
File? peak_pooled # do not define if you have a single replicate or true_rep=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? bwa_idx_tar_ = if defined(bwa_idx_tar) then bwa_idx_tar
else read_genome_tsv.bwa_idx_tar
File? bowtie2_idx_tar_ = if defined(bowtie2_idx_tar) then bowtie2_idx_tar
else read_genome_tsv.bowtie2_idx_tar
File? custom_aligner_idx_tar_ = if defined(custom_aligner_idx_tar) then custom_aligner_idx_tar
else read_genome_tsv.custom_aligner_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? blacklist1_ = if defined(blacklist) then blacklist
else read_genome_tsv.blacklist
File? blacklist2_ = if defined(blacklist2) then blacklist2
else read_genome_tsv.blacklist2
# merge multiple blacklists
# two blacklists can have different number of columns (3 vs 6)
# so we limit merged blacklist's columns to 3
Array[File] blacklists = select_all([blacklist1_, blacklist2_])
if ( length(blacklists) > 1 ) {
call pool_ta as pool_blacklist { input:
tas = blacklists,
col = 3,
}
}
File? blacklist_ = if length(blacklists) > 1 then pool_blacklist.ta_pooled
else if length(blacklists) > 0 then blacklists[0]
else blacklist2_
String? mito_chr_name_ = if defined(mito_chr_name) then mito_chr_name
else read_genome_tsv.mito_chr_name
String? regex_bfilt_peak_chr_name_ = if defined(regex_bfilt_peak_chr_name) then regex_bfilt_peak_chr_name
else read_genome_tsv.regex_bfilt_peak_chr_name
String? genome_name_ = if defined(genome_name) then genome_name
else if defined(read_genome_tsv.genome_name) then read_genome_tsv.genome_name
else basename(select_first([genome_tsv, ref_fa_, chrsz_, 'None']))
# read additional annotation data
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
### temp vars (do not define these)
String aligner_ = if defined(custom_align_py) then 'custom' else aligner
String peak_caller_ = if defined(custom_call_peak_py) then 'custom'
else if pipeline_type=='tf' then select_first([peak_caller, 'spp'])
else select_first([peak_caller, 'macs2'])
String peak_type_ = if peak_caller_=='spp' then select_first([peak_type, 'regionPeak'])
else if peak_caller_=='macs2' then select_first([peak_type, 'narrowPeak'])
else select_first([peak_type, 'narrowPeak'])
Boolean enable_idr = pipeline_type=='tf' # enable_idr for TF chipseq only
String idr_rank_ = if peak_caller_=='spp' then 'signal.value'
else if peak_caller_=='macs2' then 'p.value'
else 'p.value'
Int cap_num_peak_ = if peak_caller_ == 'spp' then select_first([cap_num_peak, cap_num_peak_spp])
else select_first([cap_num_peak, cap_num_peak_macs2])
Int mapq_thresh_ = if aligner=='bowtie2' then select_first([mapq_thresh, mapq_thresh_bowtie2])
else select_first([mapq_thresh, mapq_thresh_bwa])
# 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 ctl fastqs array [rep_id][merge_id]
Array[Array[File]] ctl_fastqs_R1 =
if length(ctl_fastqs_rep10_R1)>0 then
[ctl_fastqs_rep1_R1, ctl_fastqs_rep2_R1, ctl_fastqs_rep3_R1, ctl_fastqs_rep4_R1, ctl_fastqs_rep5_R1,
ctl_fastqs_rep6_R1, ctl_fastqs_rep7_R1, ctl_fastqs_rep8_R1, ctl_fastqs_rep9_R1, ctl_fastqs_rep10_R1]
else if length(ctl_fastqs_rep9_R1)>0 then
[ctl_fastqs_rep1_R1, ctl_fastqs_rep2_R1, ctl_fastqs_rep3_R1, ctl_fastqs_rep4_R1, ctl_fastqs_rep5_R1,
ctl_fastqs_rep6_R1, ctl_fastqs_rep7_R1, ctl_fastqs_rep8_R1, ctl_fastqs_rep9_R1]
else if length(ctl_fastqs_rep8_R1)>0 then
[ctl_fastqs_rep1_R1, ctl_fastqs_rep2_R1, ctl_fastqs_rep3_R1, ctl_fastqs_rep4_R1, ctl_fastqs_rep5_R1,
ctl_fastqs_rep6_R1, ctl_fastqs_rep7_R1, ctl_fastqs_rep8_R1]
else if length(ctl_fastqs_rep7_R1)>0 then
[ctl_fastqs_rep1_R1, ctl_fastqs_rep2_R1, ctl_fastqs_rep3_R1, ctl_fastqs_rep4_R1, ctl_fastqs_rep5_R1,
ctl_fastqs_rep6_R1, ctl_fastqs_rep7_R1]
else if length(ctl_fastqs_rep6_R1)>0 then
[ctl_fastqs_rep1_R1, ctl_fastqs_rep2_R1, ctl_fastqs_rep3_R1, ctl_fastqs_rep4_R1, ctl_fastqs_rep5_R1,
ctl_fastqs_rep6_R1]
else if length(ctl_fastqs_rep5_R1)>0 then
[ctl_fastqs_rep1_R1, ctl_fastqs_rep2_R1, ctl_fastqs_rep3_R1, ctl_fastqs_rep4_R1, ctl_fastqs_rep5_R1]
else if length(ctl_fastqs_rep4_R1)>0 then
[ctl_fastqs_rep1_R1, ctl_fastqs_rep2_R1, ctl_fastqs_rep3_R1, ctl_fastqs_rep4_R1]
else if length(ctl_fastqs_rep3_R1)>0 then
[ctl_fastqs_rep1_R1, ctl_fastqs_rep2_R1, ctl_fastqs_rep3_R1]
else if length(ctl_fastqs_rep2_R1)>0 then
[ctl_fastqs_rep1_R1, ctl_fastqs_rep2_R1]
else if length(ctl_fastqs_rep1_R1)>0 then
[ctl_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]] ctl_fastqs_R2 =
[ctl_fastqs_rep1_R2, ctl_fastqs_rep2_R2, ctl_fastqs_rep3_R2, ctl_fastqs_rep4_R2, ctl_fastqs_rep5_R2,
ctl_fastqs_rep6_R2, ctl_fastqs_rep7_R2, ctl_fastqs_rep8_R2, ctl_fastqs_rep9_R2, ctl_fastqs_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_bam = if length(bams)<num_rep_fastq then num_rep_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
# temporary variables to get number of controls
Int num_ctl_fastq = length(ctl_fastqs_R1)
Int num_ctl_bam = if length(ctl_bams)<num_ctl_fastq then num_ctl_fastq
else length(ctl_bams)
Int num_ctl_nodup_bam = if length(ctl_nodup_bams)<num_ctl_bam then num_ctl_bam
else length(ctl_nodup_bams)
Int num_ctl_ta = if length(ctl_tas)<num_ctl_nodup_bam then num_ctl_nodup_bam
else length(ctl_tas)
Int num_ctl = num_ctl_ta
# sanity check for inputs
if ( num_rep == 0 && num_ctl == 0 ) {
call raise_exception as error_input_data { input:
msg = 'No FASTQ/BAM/TAG-ALIGN/PEAK defined in your input JSON. Check if your FASTQs are defined as "chip.fastqs_repX_RY". DO NOT MISS suffix _R1 even for single ended FASTQ.'
}
}
if ( !defined(chrsz_) ) {
call raise_exception as error_genome_database { input:
msg = 'No genome database found in your input JSON. Did you define "chip.genome_tsv" correctly?'
}
}
if ( peak_caller_ == 'spp' && num_ctl == 0 ) {
call raise_exception as error_control_required { input:
msg = 'SPP requires control inputs. Define control input files ("chip.ctl_*") in an input JSON file.'
}
}
# 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_align = i<length(fastqs_R1) && length(fastqs_R1[i])>0
Boolean has_output_of_align = i<length(bams) && defined(bams[i])
if ( has_input_of_align && !has_output_of_align ) {
call align { input :
fastqs_R1 = fastqs_R1[i],
fastqs_R2 = fastqs_R2[i],
aligner = aligner_,
mito_chr_name = mito_chr_name_,
custom_align_py = custom_align_py,
idx_tar = if aligner=='bwa' then bwa_idx_tar_
else if aligner=='bowtie2' then bowtie2_idx_tar_
else custom_aligner_idx_tar_,
paired_end = paired_end_,
use_bwa_mem_for_pe = use_bwa_mem_for_pe,
cpu = align_cpu,
mem_mb = align_mem_mb,
time_hr = align_time_hr,
disks = align_disks,
}
}
File? bam_ = if has_output_of_align then bams[i] else align.bam
Boolean has_input_of_filter = has_output_of_align || defined(align.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_,
filter_chrs = filter_chrs,
chrsz = chrsz_,
no_dup_removal = no_dup_removal,
mito_chr_name = mito_chr_name_,
cpu = filter_cpu,
mem_mb = filter_mem_mb,
picard_java_heap = filter_picard_java_heap,
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_,
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_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_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 ( enable_gc_bias && defined(nodup_bam_) && defined(ref_fa_) ) {
call gc_bias { input :
nodup_bam = nodup_bam_,
ref_fa = ref_fa_,
picard_java_heap = gc_bias_picard_java_heap,
}
}
# special trimming/mapping for xcor (when starting from FASTQs)
if ( has_input_of_align ) {
call align as align_R1 { input :
fastqs_R1 = fastqs_R1[i],
fastqs_R2 = fastqs_R2[i],
trim_bp = xcor_pe_trim_bp,
aligner = aligner_,
mito_chr_name = mito_chr_name_,
custom_align_py = custom_align_py,
idx_tar = if aligner=='bwa' then bwa_idx_tar_
else if aligner=='bowtie2' then bowtie2_idx_tar_
else custom_aligner_idx_tar_,
paired_end = false,
use_bwa_mem_for_pe = use_bwa_mem_for_pe,
cpu = align_cpu,
mem_mb = align_mem_mb,
time_hr = align_time_hr,
disks = align_disks,
}
# no bam deduping for xcor
call filter as filter_R1 { input :
bam = align_R1.bam,
paired_end = false,
dup_marker = dup_marker,
mapq_thresh = mapq_thresh_,
filter_chrs = filter_chrs,
chrsz = chrsz_,
no_dup_removal = true,
mito_chr_name = mito_chr_name_,
cpu = filter_cpu,
mem_mb = filter_mem_mb,
picard_java_heap = filter_picard_java_heap,
time_hr = filter_time_hr,
disks = filter_disks,
}
call bam2ta as bam2ta_no_dedup_R1 { input :
bam = filter_R1.nodup_bam, # it's named as nodup bam but it's not deduped but just filtered
paired_end = false,
subsample = 0,
mito_chr_name = mito_chr_name_,
cpu = bam2ta_cpu,
mem_mb = bam2ta_mem_mb,
time_hr = bam2ta_time_hr,
disks = bam2ta_disks,
}
}
# special trimming/mapping for xcor (when starting from BAMs)
Boolean has_input_of_bam2ta_no_dedup = (has_output_of_align || defined(align.bam))
&& !defined(bam2ta_no_dedup_R1.ta)
if ( has_input_of_bam2ta_no_dedup ) {
call filter as filter_no_dedup { input :
bam = bam_,
paired_end = paired_end_,
dup_marker = dup_marker,
mapq_thresh = mapq_thresh_,
filter_chrs = filter_chrs,
chrsz = chrsz_,
no_dup_removal = true,
mito_chr_name = mito_chr_name_,
cpu = filter_cpu,
mem_mb = filter_mem_mb,
picard_java_heap = filter_picard_java_heap,
time_hr = filter_time_hr,
disks = filter_disks,
}
call bam2ta as bam2ta_no_dedup { input :
bam = filter_no_dedup.nodup_bam, # output name is nodup but it's not deduped
paired_end = paired_end_,
subsample = 0,
mito_chr_name = mito_chr_name_,
cpu = bam2ta_cpu,
mem_mb = bam2ta_mem_mb,
time_hr = bam2ta_time_hr,
disks = bam2ta_disks,
}
}
# use trimmed/unfilitered R1 tagAlign for paired end dataset
# if not starting from fastqs, keep using old method
# (mapping with both ends for tag-aligns to be used for xcor)
# subsample tagalign (non-mito) and cross-correlation analysis
File? ta_xcor = if defined(bam2ta_no_dedup_R1.ta) then bam2ta_no_dedup_R1.ta
else if defined(bam2ta_no_dedup.ta) then bam2ta_no_dedup.ta
else ta_
Boolean? paired_end_xcor = if defined(bam2ta_no_dedup_R1.ta) then false
else paired_end_
Boolean has_input_of_xcor = defined(ta_xcor)
if ( has_input_of_xcor ) {
call xcor { input :
ta = ta_xcor,
paired_end = paired_end_xcor,
subsample = xcor_subsample_reads,
mito_chr_name = mito_chr_name_,
chip_seq_type = pipeline_type,
exclusion_range_min = xcor_exclusion_range_min,
exclusion_range_max = xcor_exclusion_range_max,
cpu = xcor_cpu,
mem_mb = xcor_mem_mb,
time_hr = xcor_time_hr,
disks = xcor_disks,
}
}
# before peak calling, get fragment length from xcor analysis or given input
# if fraglen [] is defined in the input JSON, fraglen from xcor will be ignored
Int? fraglen_ = if i<length(fraglen) && defined(fraglen[i]) then fraglen[i]
else xcor.fraglen
}
# align each control
scatter(i in range(num_ctl)) {
# to override endedness definition for individual control
# ctl_paired_end will override ctl_paired_ends[i]
Boolean? ctl_paired_end_ = if !defined(ctl_paired_end) && i<length(ctl_paired_ends) then ctl_paired_ends[i]
else if defined(ctl_paired_end) then ctl_paired_end
else paired_end
Boolean has_input_of_align_ctl = i<length(ctl_fastqs_R1) && length(ctl_fastqs_R1[i])>0
Boolean has_output_of_align_ctl = i<length(ctl_bams) && defined(ctl_bams[i])
if ( has_input_of_align_ctl && !has_output_of_align_ctl ) {
call align as align_ctl { input :
fastqs_R1 = ctl_fastqs_R1[i],
fastqs_R2 = ctl_fastqs_R2[i],
aligner = aligner_,
mito_chr_name = mito_chr_name_,
custom_align_py = custom_align_py,
idx_tar = if aligner=='bwa' then bwa_idx_tar_
else if aligner=='bowtie2' then bowtie2_idx_tar_
else custom_aligner_idx_tar_,
paired_end = ctl_paired_end_,
use_bwa_mem_for_pe = use_bwa_mem_for_pe,
cpu = align_cpu,
mem_mb = align_mem_mb,
time_hr = align_time_hr,
disks = align_disks,
}
}
File? ctl_bam_ = if has_output_of_align_ctl then ctl_bams[i] else align_ctl.bam
Boolean has_input_of_filter_ctl = has_output_of_align_ctl || defined(align_ctl.bam)
Boolean has_output_of_filter_ctl = i<length(ctl_nodup_bams) && defined(ctl_nodup_bams[i])
# skip if we already have output of this step
if ( has_input_of_filter_ctl && !has_output_of_filter_ctl ) {
call filter as filter_ctl { input :
bam = ctl_bam_,
paired_end = ctl_paired_end_,
dup_marker = dup_marker,
mapq_thresh = mapq_thresh_,
filter_chrs = filter_chrs,
chrsz = chrsz_,
no_dup_removal = no_dup_removal,
mito_chr_name = mito_chr_name_,
cpu = filter_cpu,
mem_mb = filter_mem_mb,
picard_java_heap = filter_picard_java_heap,
time_hr = filter_time_hr,
disks = filter_disks,
}
}
File? ctl_nodup_bam_ = if has_output_of_filter_ctl then ctl_nodup_bams[i] else filter_ctl.nodup_bam
Boolean has_input_of_bam2ta_ctl = has_output_of_filter_ctl || defined(filter_ctl.nodup_bam)
Boolean has_output_of_bam2ta_ctl = i<length(ctl_tas) && defined(ctl_tas[i])
if ( has_input_of_bam2ta_ctl && !has_output_of_bam2ta_ctl ) {
call bam2ta as bam2ta_ctl { input :
bam = ctl_nodup_bam_,
subsample = subsample_reads,
paired_end = ctl_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? ctl_ta_ = if has_output_of_bam2ta_ctl then ctl_tas[i] else bam2ta_ctl.ta
}
# 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,
}
}
# if there are CTL TAs for ALL replicates then pool them
Boolean has_all_inputs_of_pool_ta_ctl = length(select_all(ctl_ta_))==num_ctl
if ( has_all_inputs_of_pool_ta_ctl && num_ctl>1 ) {
# pool tagaligns from true replicates
call pool_ta as pool_ta_ctl { input :
tas = ctl_ta_,
}
}
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_jsd = defined(blacklist_) && length(select_all(nodup_bam_))==num_rep
if ( has_input_of_jsd && num_rep > 0 && enable_jsd ) {
# fingerprint and JS-distance plot
call jsd { input :
nodup_bams = nodup_bam_,
ctl_bams = ctl_nodup_bam_, # use first control only
blacklist = blacklist_,
mapq_thresh = mapq_thresh_,
cpu = jsd_cpu,
mem_mb = jsd_mem_mb,
time_hr = jsd_time_hr,
disks = jsd_disks,
}
}
Boolean has_all_input_of_choose_ctl = length(select_all(ta_))==num_rep
&& length(select_all(ctl_ta_))==num_ctl && num_ctl > 0
if ( has_all_input_of_choose_ctl ) {
# choose appropriate control for each exp IP replicate
# outputs:
# choose_ctl.idx : control replicate index for each exp replicate
# -1 means pooled ctl replicate
call choose_ctl { input:
tas = ta_,
ctl_tas = ctl_ta_,
ta_pooled = pool_ta.ta_pooled,
ctl_ta_pooled = pool_ta_ctl.ta_pooled,
always_use_pooled_ctl = always_use_pooled_ctl,
ctl_depth_ratio = ctl_depth_ratio,
}
}
# make control ta array [[1,2,3,4]] -> [[1],[2],[3],[4]], will be zipped with exp ta array latter
Array[Array[File]] chosen_ctl_tas =
if has_all_input_of_choose_ctl then transpose(select_all([choose_ctl.chosen_ctl_tas]))
else [[],[],[],[],[],[],[],[],[],[]]
# workaround for dx error (Unsupported combination: womType: Int womValue: ([225], Array[Int]))
Array[Int] fraglen_tmp = select_all(fraglen_)
# we have all tas and ctl_tas (optional for histone chipseq) ready, let's call peaks
scatter(i in range(num_rep)) {
Boolean has_input_of_call_peak = defined(ta_[i])
Boolean has_output_of_call_peak = i<length(peaks) && defined(peaks[i])
if ( has_input_of_call_peak && !has_output_of_call_peak && !align_only ) {
call call_peak { input :
peak_caller = peak_caller_,
peak_type = peak_type_,
custom_call_peak_py = custom_call_peak_py,
tas = flatten([[ta_[i]], chosen_ctl_tas[i]]),
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak_,
pval_thresh = pval_thresh,
fraglen = fraglen_tmp[i],
blacklist = blacklist_,
regex_bfilt_peak_chr_name = regex_bfilt_peak_chr_name_,
cpu = call_peak_cpu,
mem_mb = call_peak_mem_mb,
disks = call_peak_disks,
time_hr = call_peak_time_hr,
}
}
File? peak_ = if has_output_of_call_peak then peaks[i]
else call_peak.peak
# signal track
if ( has_input_of_call_peak && !align_only ) {
call macs2_signal_track { input :
tas = flatten([[ta_[i]], chosen_ctl_tas[i]]),
gensz = gensz_,
chrsz = chrsz_,
pval_thresh = pval_thresh,
fraglen = fraglen_tmp[i],
mem_mb = macs2_signal_track_mem_mb,
disks = macs2_signal_track_disks,
time_hr = macs2_signal_track_time_hr,
}
}
# call peaks on 1st pseudo replicated tagalign
Boolean has_input_of_call_peak_pr1 = defined(spr.ta_pr1[i])
Boolean has_output_of_call_peak_pr1 = i<length(peaks_pr1) && defined(peaks_pr1[i])
if ( has_input_of_call_peak_pr1 && !has_output_of_call_peak_pr1 && !true_rep_only ) {
call call_peak as call_peak_pr1 { input :
peak_caller = peak_caller_,
peak_type = peak_type_,
custom_call_peak_py = custom_call_peak_py,
tas = flatten([[spr.ta_pr1[i]], chosen_ctl_tas[i]]),
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak_,
pval_thresh = pval_thresh,
fraglen = fraglen_tmp[i],
blacklist = blacklist_,
regex_bfilt_peak_chr_name = regex_bfilt_peak_chr_name_,
cpu = call_peak_cpu,
mem_mb = call_peak_mem_mb,
disks = call_peak_disks,
time_hr = call_peak_time_hr,
}
}
File? peak_pr1_ = if has_output_of_call_peak_pr1 then peaks_pr1[i]
else call_peak_pr1.peak
# call peaks on 2nd pseudo replicated tagalign
Boolean has_input_of_call_peak_pr2 = defined(spr.ta_pr2[i])
Boolean has_output_of_call_peak_pr2 = i<length(peaks_pr2) && defined(peaks_pr2[i])
if ( has_input_of_call_peak_pr2 && !has_output_of_call_peak_pr2 && !true_rep_only ) {
call call_peak as call_peak_pr2 { input :
peak_caller = peak_caller_,
peak_type = peak_type_,
custom_call_peak_py = custom_call_peak_py,
tas = flatten([[spr.ta_pr2[i]], chosen_ctl_tas[i]]),
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak_,
pval_thresh = pval_thresh,
fraglen = fraglen_tmp[i],
blacklist = blacklist_,
regex_bfilt_peak_chr_name = regex_bfilt_peak_chr_name_,
cpu = call_peak_cpu,
mem_mb = call_peak_mem_mb,
disks = call_peak_disks,
time_hr = call_peak_time_hr,
}
}
File? peak_pr2_ = if has_output_of_call_peak_pr2 then peaks_pr2[i]
else call_peak_pr2.peak
}
# if ( !align_only && num_rep > 1 ) {
# rounded mean of fragment length, which will be used for
# 1) calling peaks for pooled true/pseudo replicates
# 2) calculating FRiP
call rounded_mean as fraglen_mean { input :
ints = fraglen_tmp,
}
# }
# actually not an array
Array[File?] chosen_ctl_ta_pooled = if !has_all_input_of_choose_ctl then []
else if num_ctl < 2 then [ctl_ta_[0]] # choose first (only) control
else select_all([pool_ta_ctl.ta_pooled]) # choose pooled control
Boolean has_input_of_call_peak_pooled = defined(pool_ta.ta_pooled)
Boolean has_output_of_call_peak_pooled = defined(peak_pooled)
if ( has_input_of_call_peak_pooled && !has_output_of_call_peak_pooled && !align_only && num_rep>1 ) {
# call peaks on pooled replicate
# always call peaks for pooled replicate to get signal tracks
call call_peak as call_peak_pooled { input :
peak_caller = peak_caller_,
peak_type = peak_type_,
custom_call_peak_py = custom_call_peak_py,
tas = flatten([select_all([pool_ta.ta_pooled]), chosen_ctl_ta_pooled]),
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak_,
pval_thresh = pval_thresh,
fraglen = fraglen_mean.rounded_mean,
blacklist = blacklist_,
regex_bfilt_peak_chr_name = regex_bfilt_peak_chr_name_,
cpu = call_peak_cpu,
mem_mb = call_peak_mem_mb,
disks = call_peak_disks,
time_hr = call_peak_time_hr,
}
}
File? peak_pooled_ = if has_output_of_call_peak_pooled then peak_pooled
else call_peak_pooled.peak
# macs2 signal track for pooled rep
if ( has_input_of_call_peak_pooled && !align_only && num_rep>1 ) {
call macs2_signal_track as macs2_signal_track_pooled { input :
tas = flatten([select_all([pool_ta.ta_pooled]), chosen_ctl_ta_pooled]),
gensz = gensz_,
chrsz = chrsz_,
pval_thresh = pval_thresh,
fraglen = fraglen_mean.rounded_mean,
mem_mb = macs2_signal_track_mem_mb,
disks = macs2_signal_track_disks,
time_hr = macs2_signal_track_time_hr,
}
}
Boolean has_input_of_call_peak_ppr1 = defined(pool_ta_pr1.ta_pooled)
Boolean has_output_of_call_peak_ppr1 = defined(peak_ppr1)
if ( has_input_of_call_peak_ppr1 && !has_output_of_call_peak_ppr1 && !align_only && !true_rep_only && num_rep>1 ) {
# call peaks on 1st pooled pseudo replicates
call call_peak as call_peak_ppr1 { input :
peak_caller = peak_caller_,
peak_type = peak_type_,
custom_call_peak_py = custom_call_peak_py,
tas = flatten([select_all([pool_ta_pr1.ta_pooled]), chosen_ctl_ta_pooled]),
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak_,
pval_thresh = pval_thresh,
fraglen = fraglen_mean.rounded_mean,
blacklist = blacklist_,
regex_bfilt_peak_chr_name = regex_bfilt_peak_chr_name_,
cpu = call_peak_cpu,
mem_mb = call_peak_mem_mb,
disks = call_peak_disks,
time_hr = call_peak_time_hr,
}
}
File? peak_ppr1_ = if has_output_of_call_peak_ppr1 then peak_ppr1
else call_peak_ppr1.peak
Boolean has_input_of_call_peak_ppr2 = defined(pool_ta_pr2.ta_pooled)
Boolean has_output_of_call_peak_ppr2 = defined(peak_ppr2)
if ( has_input_of_call_peak_ppr2 && !has_output_of_call_peak_ppr2 && !align_only && !true_rep_only && num_rep>1 ) {
# call peaks on 2nd pooled pseudo replicates
call call_peak as call_peak_ppr2 { input :
peak_caller = peak_caller_,
peak_type = peak_type_,
custom_call_peak_py = custom_call_peak_py,
tas = flatten([select_all([pool_ta_pr2.ta_pooled]), chosen_ctl_ta_pooled]),
gensz = gensz_,
chrsz = chrsz_,
cap_num_peak = cap_num_peak_,
pval_thresh = pval_thresh,
fraglen = fraglen_mean.rounded_mean,
blacklist = blacklist_,
regex_bfilt_peak_chr_name = regex_bfilt_peak_chr_name_,
cpu = call_peak_cpu,
mem_mb = call_peak_mem_mb,
disks = call_peak_disks,
time_hr = call_peak_time_hr,
}
}
File? peak_ppr2_ = if has_output_of_call_peak_ppr2 then peak_ppr2
else call_peak_ppr2.peak
# 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)+'_vs_rep'+(pair.right+1),
peak1 = peak_[pair.left],
peak2 = peak_[pair.right],
peak_pooled = peak_pooled_,
fraglen = fraglen_mean.rounded_mean,
peak_type = peak_type_,
blacklist = blacklist_,
chrsz = chrsz_,
regex_bfilt_peak_chr_name = regex_bfilt_peak_chr_name_,
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)+'_vs_rep'+(pair.right+1),
peak1 = peak_[pair.left],
peak2 = peak_[pair.right],
peak_pooled = peak_pooled_,
fraglen = fraglen_mean.rounded_mean,
idr_thresh = idr_thresh,
peak_type = peak_type_,
rank = idr_rank_,
blacklist = blacklist_,
chrsz = chrsz_,