forked from ENCODE-DCC/hic-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
/
hic.wdl
1260 lines (1127 loc) · 37.8 KB
/
hic.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
version 1.0
struct FastqPair {
File read_1
File? read_2
String? read_group
}
struct BamAndLigationCount {
File bam
File ligation_count
Boolean single_ended
}
struct RuntimeEnvironment {
String docker
String singularity
}
workflow hic {
meta {
version: "1.11.0"
caper_docker: "encodedcc/hic-pipeline:1.11.0"
caper_singularity: "docker://encodedcc/hic-pipeline:1.11.0"
croo_out_def: "https://raw.githubusercontent.com/ENCODE-DCC/hic-pipeline/dev/croo_out_def.json"
description: "ENCODE Hi-C pipeline, see https://github.com/ENCODE-DCC/hic-pipeline for details."
}
input {
# Main entrypoint, need to specify all five of these values except read_groups when running from fastqs
Array[Array[FastqPair]] fastq = []
Array[String] restriction_enzymes = []
String? ligation_site_regex
File? restriction_sites
File? chrsz
File? reference_index
# Entrypoint for loop and TAD calls
File? input_hic
# Parameters controlling delta calls
Boolean no_delta = false
Boolean intact = false
Array[String] normalization_methods = []
Boolean no_pairs = false
Boolean no_call_loops = false
Boolean no_call_tads = false
Boolean no_eigenvectors = false
Boolean no_slice = false
Int align_num_cpus = 32
Int align_disk_size_gb = 1000
Int? dedup_disk_size_gb
Int? create_hic_num_cpus
Int? add_norm_num_cpus
Int? create_accessibility_track_ram_gb
Int? create_accessibility_track_disk_size_gb
String assembly_name = "undefined"
String docker = "encodedcc/hic-pipeline:1.11.0"
String singularity = "docker://encodedcc/hic-pipeline:1.11.0"
String delta_docker = "encodedcc/hic-pipeline:1.11.0_delta"
String hiccups_docker = "encodedcc/hic-pipeline:1.11.0_hiccups"
}
RuntimeEnvironment runtime_environment = {
"docker": docker,
"singularity": singularity
}
RuntimeEnvironment hiccups_runtime_environment = {
"docker": hiccups_docker,
"singularity": singularity
}
RuntimeEnvironment delta_runtime_environment = {
"docker": delta_docker,
"singularity": singularity
}
String delta_models_path = if intact then "ultimate-models" else "beta-models"
Array[Int] delta_resolutions = if intact then [5000, 2000, 1000] else [5000, 10000]
Array[Int] create_hic_in_situ_resolutions = [2500000, 1000000, 500000, 250000, 100000, 50000, 25000, 10000, 5000, 2000, 1000, 500, 200, 100]
Array[Int] create_hic_intact_resolutions = [2500000, 1000000, 500000, 250000, 100000, 50000, 25000, 10000, 5000, 2000, 1000, 500, 200, 100, 50, 20, 10]
Array[Int] create_hic_resolutions = if intact then create_hic_intact_resolutions else create_hic_in_situ_resolutions
# Default MAPQ thresholds for generating .hic contact maps
Array[Int] DEFAULT_HIC_QUALITIES = [1, 30]
Boolean is_nonspecific = length(restriction_enzymes) > 0 && restriction_enzymes[0] == "none"
if (!defined(input_hic)) {
if (!defined(ligation_site_regex)) {
call get_ligation_site_regex { input:
restriction_enzymes = restriction_enzymes,
runtime_environment = runtime_environment,
}
}
String ligation_site = select_first([ligation_site_regex, get_ligation_site_regex.ligation_site_regex])
if (!is_nonspecific && !defined(restriction_sites)) {
call exit_early { input:
message = "Must provide restriction sites file if enzyme is not `none`",
runtime_environment = runtime_environment,
}
}
}
call normalize_assembly_name { input:
assembly_name = assembly_name,
runtime_environment = runtime_environment,
}
scatter(i in range(length(fastq))) {
Array[FastqPair] replicate = fastq[i]
scatter(fastq_pair in replicate) {
call align { input:
fastq_pair = fastq_pair,
idx_tar = select_first([reference_index]),
ligation_site = select_first([ligation_site]),
num_cpus = align_num_cpus,
disk_size_gb = align_disk_size_gb,
runtime_environment = runtime_environment,
}
}
if (is_nonspecific) {
scatter(bam_and_ligation_count in align.bam_and_ligation_count) {
call chimeric_sam_nonspecific { input:
bam = bam_and_ligation_count.bam,
ligation_count = bam_and_ligation_count.ligation_count,
single_ended = bam_and_ligation_count.single_ended,
runtime_environment = runtime_environment,
}
}
}
if (!is_nonspecific) {
scatter(bam_and_ligation_count in align.bam_and_ligation_count) {
call chimeric_sam_specific { input:
bam = bam_and_ligation_count.bam,
ligation_count = bam_and_ligation_count.ligation_count,
restriction_sites = select_first([restriction_sites]),
single_ended = bam_and_ligation_count.single_ended,
runtime_environment = runtime_environment,
}
}
}
call merge { input:
bams = flatten(
select_all(
[
chimeric_sam_specific.output_bam,
chimeric_sam_nonspecific.output_bam,
]
)
),
output_bam_filename = "merged_" + i,
runtime_environment = runtime_environment,
}
call dedup { input:
bam = merge.bam,
disk_size_gb = dedup_disk_size_gb,
runtime_environment = runtime_environment,
}
call bam_to_pre as bam_to_pre_for_stats { input:
bam = dedup.deduped_bam,
quality = 1,
output_filename_suffix = "_lib" + i,
runtime_environment = runtime_environment,
}
call calculate_stats as calculate_stats_on_library { input:
alignment_stats = flatten(
select_all([chimeric_sam_specific.stats, chimeric_sam_nonspecific.stats])
),
bam = dedup.deduped_bam,
pre = bam_to_pre_for_stats.pre,
restriction_sites = restriction_sites,
chrom_sizes = select_first([chrsz]),
ligation_site = select_first([ligation_site]),
output_filename_suffix = "_lib" + i,
single_ended = align.bam_and_ligation_count[0].single_ended,
runtime_environment = runtime_environment,
}
}
if (!defined(input_hic)) {
call merge as merge_replicates { input:
bams = dedup.deduped_bam,
runtime_environment = runtime_environment,
}
# convert alignable bam to pairs to be consistent with 4DN
if ( !no_pairs && defined(chrsz)) {
call bam_to_pre as bam_to_pre_mapq0 { input:
bam = merge_replicates.bam,
quality = 0,
runtime_environment = runtime_environment,
}
call pre_to_pairs { input:
pre = bam_to_pre_mapq0.pre,
chrom_sizes = select_first([chrsz]),
runtime_environment = runtime_environment,
}
}
}
Array[Int] qualities = if !defined(input_hic) then DEFAULT_HIC_QUALITIES else []
scatter(i in range(length(qualities))) {
call bam_to_pre { input:
bam = select_first([merge_replicates.bam]),
quality = qualities[i],
runtime_environment = runtime_environment,
}
if (intact && qualities[i] == 30) {
call create_accessibility_track { input:
pre = bam_to_pre.pre,
chrom_sizes = select_first([chrsz]),
ram_gb = create_accessibility_track_ram_gb,
disk_size_gb = create_accessibility_track_disk_size_gb,
runtime_environment = runtime_environment,
}
}
call calculate_stats { input:
alignment_stats = flatten(
select_all(
flatten(
[chimeric_sam_specific.stats, chimeric_sam_nonspecific.stats]
)
)
),
bam = select_first([merge_replicates.bam]),
pre = bam_to_pre.pre,
restriction_sites = restriction_sites,
chrom_sizes = select_first([chrsz]),
ligation_site = select_first([ligation_site]),
quality = qualities[i],
single_ended = align.bam_and_ligation_count[0][0].single_ended,
runtime_environment = runtime_environment,
}
# If Juicer Tools doesn't support the assembly then need to pass chrom sizes
if (!normalize_assembly_name.assembly_is_supported) {
call create_hic as create_hic_with_chrom_sizes { input:
pre = bam_to_pre.pre,
pre_index = bam_to_pre.index,
chrsz = select_first([chrsz]),
restriction_sites = restriction_sites,
quality = qualities[i],
stats = calculate_stats.stats,
stats_hists = calculate_stats.stats_hists,
resolutions = create_hic_resolutions,
assembly_name = assembly_name,
num_cpus = create_hic_num_cpus,
runtime_environment = runtime_environment,
}
}
if (normalize_assembly_name.assembly_is_supported) {
call create_hic { input:
pre = bam_to_pre.pre,
pre_index = bam_to_pre.index,
restriction_sites = restriction_sites,
quality = qualities[i],
stats = calculate_stats.stats,
stats_hists = calculate_stats.stats_hists,
resolutions = create_hic_resolutions,
assembly_name = normalize_assembly_name.normalized_assembly_name,
num_cpus = create_hic_num_cpus,
runtime_environment = runtime_environment,
}
}
File unnormalized_hic_file = select_first([
if (defined(create_hic.output_hic))
then create_hic.output_hic
else create_hic_with_chrom_sizes.output_hic
])
call add_norm { input:
hic = unnormalized_hic_file,
normalization_methods = normalization_methods,
quality = qualities[i],
num_cpus = add_norm_num_cpus,
runtime_environment = runtime_environment,
}
if (!no_call_tads) {
call arrowhead { input:
hic_file = add_norm.output_hic,
quality = qualities[i],
runtime_environment = runtime_environment,
}
}
if (!no_call_loops) {
if (!intact) {
call hiccups { input:
hic_file = add_norm.output_hic,
quality = qualities[i],
runtime_environment = hiccups_runtime_environment,
}
}
if (intact) {
call hiccups_2 { input:
hic = add_norm.output_hic,
quality = qualities[i],
runtime_environment = hiccups_runtime_environment,
}
call localizer as localizer_intact { input:
hic = add_norm.output_hic,
loops = hiccups_2.merged_loops,
quality = qualities[i],
runtime_environment = runtime_environment,
}
}
}
if (defined(chrsz) && !no_eigenvectors) {
call create_eigenvector { input:
hic_file = add_norm.output_hic,
chrom_sizes = select_first([chrsz]),
output_filename_suffix = "_" + qualities[i],
runtime_environment = runtime_environment,
}
call create_eigenvector as create_eigenvector_10kb { input:
hic_file = add_norm.output_hic,
chrom_sizes = select_first([chrsz]),
resolution = 10000,
output_filename_suffix = "_" + qualities[i],
runtime_environment = runtime_environment,
}
}
}
if (!no_delta) {
call delta { input:
# Only run delta on MAPQ >= 30
hic = if length(add_norm.output_hic) > 1 then add_norm.output_hic[1] else select_first([input_hic]),
resolutions = delta_resolutions,
models_path = delta_models_path,
runtime_environment = delta_runtime_environment,
}
call localizer as localizer_delta { input:
hic = if length(add_norm.output_hic) > 1 then add_norm.output_hic[1] else select_first([input_hic]),
loops = delta.loops,
runtime_environment = runtime_environment,
}
}
if (defined(input_hic)) {
if (!no_call_tads) {
call arrowhead as arrowhead_input_hic { input:
hic_file = select_first([input_hic]),
runtime_environment = runtime_environment,
}
}
if (!no_call_loops) {
if (!intact) {
call hiccups as hiccups_input_hic { input:
hic_file = select_first([input_hic]),
runtime_environment = hiccups_runtime_environment,
}
}
if (intact) {
call hiccups_2 as hiccups_2_input_hic { input:
hic = select_first([input_hic]),
runtime_environment = hiccups_runtime_environment,
}
call localizer as localizer_intact_input_hic { input:
hic = select_first([input_hic]),
loops = hiccups_2_input_hic.merged_loops,
runtime_environment = runtime_environment,
}
}
}
}
if (!no_slice) {
File hic_file = if length(add_norm.output_hic) > 1 then add_norm.output_hic[1] else select_first([input_hic])
call slice as slice_25kb { input:
hic_file = hic_file,
resolution = 25000,
runtime_environment = runtime_environment,
}
call slice as slice_50kb { input:
hic_file = hic_file,
resolution = 50000,
runtime_environment = runtime_environment,
}
call slice as slice_100kb { input:
hic_file = hic_file,
resolution = 100000,
runtime_environment = runtime_environment,
}
}
}
task get_ligation_site_regex {
input {
Array[String] restriction_enzymes
RuntimeEnvironment runtime_environment
}
String output_path = "ligation_site_regex.txt"
command <<<
set -euo pipefail
python3 "$(which get_ligation_site_regex.py)" \
--enzymes ~{sep=" " restriction_enzymes} \
--outfile ~{output_path}
>>>
output {
String ligation_site_regex = read_string("~{output_path}")
# Surface the original file for testing purposes
File ligation_site_regex_file = "~{output_path}"
}
runtime {
cpu : "1"
memory: "500 MB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task normalize_assembly_name {
input {
String assembly_name
String normalized_assembly_name_output_path = "normalized_assembly_name.txt"
String assembly_is_supported_output_path = "is_supported.txt"
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
python3 "$(which normalize_assembly_name.py)" \
~{assembly_name} \
~{normalized_assembly_name_output_path} \
~{assembly_is_supported_output_path}
>>>
output {
String normalized_assembly_name = read_string("~{normalized_assembly_name_output_path}")
Boolean assembly_is_supported = read_boolean("~{assembly_is_supported_output_path}")
}
runtime {
cpu : "1"
memory: "500 MB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task align {
input {
FastqPair fastq_pair
File idx_tar # reference bwa index tar
String ligation_site
Int num_cpus = 32
Int disk_size_gb = 1000
RuntimeEnvironment runtime_environment
}
command {
set -euo pipefail
echo "Starting align"
mkdir reference
cd reference && tar -xvf ${idx_tar}
index_folder=$(ls)
reference_fasta=$(ls | head -1)
reference_folder=$(pwd)
reference_index_path=$reference_folder/$reference_fasta
cd ..
usegzip=1
name="result"
ligation="${ligation_site}"
name1=${fastq_pair.read_1}
name2=${fastq_pair.read_2}
ext=""
singleend=~{if(defined(fastq_pair.read_2)) then "0" else "1"}
#count ligations
# Need to unset the -e option, when ligation site is XXXX grep will exit with
# non-zero status
set +e
source /opt/scripts/common/countligations.sh
set -e
# Align reads
echo "Running bwa command"
bwa \
mem \
~{if defined(fastq_pair.read_2) then "-SP5M" else "-5M"} \
~{if defined(fastq_pair.read_group) then "-R '" + fastq_pair.read_group + "'" else ""} \
-t ~{num_cpus} \
-K 320000000 \
$reference_index_path \
${fastq_pair.read_1} \
~{default="" fastq_pair.read_2} | \
samtools view -hbS - > aligned.bam
mv result_norm.txt.res.txt ligation_count.txt
}
output {
BamAndLigationCount bam_and_ligation_count = object {
bam: "aligned.bam",
ligation_count: "ligation_count.txt",
single_ended: length(select_all([fastq_pair.read_2])) == 0,
}
}
runtime {
cpu : "~{num_cpus}"
memory: "64 GB"
disks: "local-disk ~{disk_size_gb} HDD"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task chimeric_sam_specific {
input {
File bam
File ligation_count
File restriction_sites
Boolean single_ended
Int num_cpus = 8
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
RESTRICTION_SITES_FILENAME=restriction_sites.txt
gzip -dc ~{restriction_sites} > $RESTRICTION_SITES_FILENAME
cp ~{ligation_count} result_norm.txt.res.txt
samtools view -h -@ ~{num_cpus - 1} ~{bam} > result.sam
awk \
-v stem=result_norm \
-v site_file=$RESTRICTION_SITES_FILENAME \
~{if(single_ended) then "-v singleend=1" else ""} \
-f "$(which chimeric_sam.awk)" \
result.sam | \
samtools sort -t cb -n --threads ~{num_cpus} > chimeric_sam_specific.bam
>>>
output {
File output_bam = "chimeric_sam_specific.bam"
File stats = "result_norm.txt.res.txt"
}
runtime {
cpu : "~{num_cpus}"
disks: "local-disk 1000 HDD"
memory: "16 GB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task chimeric_sam_nonspecific {
input {
File bam
File ligation_count
Boolean single_ended
Int num_cpus = 8
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
cp ~{ligation_count} result_norm.txt.res.txt
samtools view -h -@ ~{num_cpus - 1} ~{bam} > result.sam
awk \
-v stem=result_norm \
~{if(single_ended) then "-v singleend=1" else ""} \
-f "$(which chimeric_sam.awk)" \
result.sam > result.sam2
~{if(single_ended) then "samtools sort -t cb -n --threads " + num_cpus + " result.sam2 > chimeric_sam_nonspecific.bam && exit 0" else ""}
awk \
-v avgInsertFile=result_norm.txt.res.txt \
-f "$(which adjust_insert_size.awk)" \
result.sam2 | \
samtools sort -t cb -n --threads ~{num_cpus} > chimeric_sam_nonspecific.bam
>>>
output {
File output_bam = "chimeric_sam_nonspecific.bam"
File stats = "result_norm.txt.res.txt"
}
runtime {
cpu : "~{num_cpus}"
disks: "local-disk ~{if(single_ended) then 6000 else 1000} HDD"
memory: "16 GB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task merge {
input {
Array[File] bams
Int num_cpus = 8
String output_bam_filename = "merged"
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
samtools merge \
-c \
-t cb \
-n \
--threads ~{num_cpus - 1} \
~{output_bam_filename}.bam \
~{sep=' ' bams}
>>>
output {
File bam = "~{output_bam_filename}.bam"
}
runtime {
cpu : "~{num_cpus}"
memory: "16 GB"
disks: "local-disk 6000 HDD"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task dedup {
input {
File bam
Int num_cpus = 8
Int disk_size_gb = 5000
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
samtools view \
-h \
-@ ~{num_cpus - 1} \
~{bam} | \
awk -f "$(which dups_sam.awk)" > merged_dedup.sam
samtools view -b -@ ~{num_cpus - 1} merged_dedup.sam > merged_dedup.bam
>>>
output {
File deduped_bam = "merged_dedup.bam"
}
runtime {
cpu : "~{num_cpus}"
disks: "local-disk ~{disk_size_gb} HDD"
memory: "32 GB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task pre_to_pairs {
input {
File pre
File chrom_sizes
RuntimeEnvironment runtime_environment
}
command {
set -euo pipefail
PRE_FILENAME=pre.txt
gzip -dc ~{pre} > $PRE_FILENAME
perl "$(which juicer_shortform2pairs.pl)" $PRE_FILENAME ~{chrom_sizes} pairix
}
output {
File out_file = "pairix.bsorted.pairs.gz"
}
runtime {
cpu : "8"
memory: "16 GB"
disks: "local-disk 3000 HDD"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task bam_to_pre {
input {
File bam
Int quality
Int num_cpus = 8
String output_filename_suffix = ""
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
MERGED_NODUPS_FILENAME=merged_nodups_~{quality}~{output_filename_suffix}.txt
MERGED_NODUPS_INDEX_FILENAME=merged_nodups_~{quality}~{output_filename_suffix}_index.txt
samtools view \
-h \
-F 1024 \
-O sam \
~{bam} \
-@ ~{num_cpus - 1} | \
awk -v mapq=~{quality} -f "$(which sam_to_pre.awk)" > $MERGED_NODUPS_FILENAME
$(which index_by_chr.awk) $MERGED_NODUPS_FILENAME 500000 > $MERGED_NODUPS_INDEX_FILENAME
gzip -n $MERGED_NODUPS_FILENAME
gzip -n $MERGED_NODUPS_INDEX_FILENAME
>>>
output {
File pre = "merged_nodups_~{quality}~{output_filename_suffix}.txt.gz"
File index = "merged_nodups_~{quality}~{output_filename_suffix}_index.txt.gz"
}
runtime {
cpu : "~{num_cpus}"
disks: "local-disk 3000 HDD"
memory : "64 GB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task calculate_stats {
input {
Array[File] alignment_stats
File pre
File chrom_sizes
File bam
File? restriction_sites
String ligation_site
String output_filename_suffix = ""
Boolean single_ended = false
Int quality = 0
RuntimeEnvironment runtime_environment
}
command <<<
PRE_FILE=pre.txt
RESTRICTION_SITES_FILENAME=restriction_sites.txt
STATS_FILENAME=stats_~{quality}~{output_filename_suffix}.txt
gzip -dc ~{pre} > $PRE_FILE
~{if defined(restriction_sites) then "gzip -dc " + restriction_sites + " > $RESTRICTION_SITES_FILENAME" else ""}
if [ ~{if(single_ended) then "1" else "0"} -eq 1 ]
then
RET=$(samtools view -f 1024 -F 256 ~{bam} | awk '{if ($0~/rt:A:7/){singdup++}else{dup++}}END{print dup,singdup}')
DUPS=$(echo $RET | awk '{print $1}')
SINGDUPS=$(echo $RET | awk '{print $2}')
awk \
-f "$(which stats_sub.awk)" \
-v dups=$DUPS \
-v singdups=$SINGDUPS \
-v ligation="~{ligation_site}" \
-v singleend=1 \
~{sep=" " alignment_stats} >> $STATS_FILENAME
else
DUPS=$(samtools view -c -f 1089 -F 256 ~{bam})
awk \
-f "$(which stats_sub.awk)" \
-v dups=$DUPS \
-v ligation=$ligation \
~{sep=" " alignment_stats} >> $STATS_FILENAME
fi
java \
-Ddevelopment=false \
-Djava.awt.headless=true \
-Xmx16g \
-jar /opt/scripts/common/juicer_tools.jar \
statistics \
~{if defined(restriction_sites) then "$RESTRICTION_SITES_FILENAME" else "none"} \
$STATS_FILENAME \
~{pre} \
~{chrom_sizes}
python3 \
"$(which jsonify_stats.py)" \
$STATS_FILENAME \
stats_~{quality}~{output_filename_suffix}.json
>>>
output {
File stats = "stats_~{quality}~{output_filename_suffix}.txt"
File stats_json = "stats_~{quality}~{output_filename_suffix}.json"
File stats_hists = "stats_~{quality}~{output_filename_suffix}_hists.m"
}
runtime {
cpu : "1"
disks: "local-disk 4000 HDD"
memory : "16 GB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task create_hic {
input {
File pre
File pre_index
File stats
File stats_hists
Int quality
Array[Int] resolutions
String? assembly_name
File? chrsz
File? restriction_sites
Int num_cpus = 24
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
PRE_FILE=pre.txt
PRE_INDEX_FILE=pre_index.txt
RESTRICTION_SITES_FILENAME=restriction_sites.txt
gzip -dc ~{pre} > $PRE_FILE
gzip -dc ~{pre_index} > $PRE_INDEX_FILE
~{if defined(restriction_sites) then "gzip -dc " + restriction_sites + " > $RESTRICTION_SITES_FILENAME" else ""}
# If the assembly name is empty, then we write chrsz path into file as usual, otherwise, use the assembly name instead of the path
java \
-Ddevelopment=false \
-Djava.awt.headless=true \
-Xmx240g \
-jar /opt/scripts/common/juicer_tools.jar \
pre \
-n \
~{if defined(restriction_sites) then "-f $RESTRICTION_SITES_FILENAME" else ""} \
-s ~{stats} \
-g ~{stats_hists} \
~{if defined(assembly_name) then "-y " + assembly_name else ""} \
-r ~{sep="," resolutions} \
-i $PRE_INDEX_FILE \
--block-capacity 1000000 \
--threads ~{num_cpus} \
$PRE_FILE \
inter_~{quality}_unnormalized.hic \
~{if defined(chrsz) then chrsz else assembly_name}
>>>
output {
File output_hic = "inter_~{quality}_unnormalized.hic"
}
runtime {
cpu : "~{num_cpus}"
disks: "local-disk 2000 HDD"
memory : "256 GB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task add_norm {
input {
File hic
Array[String] normalization_methods = []
Int quality
Int num_cpus = 24
RuntimeEnvironment runtime_environment
}
command {
set -euo pipefail
cp ~{hic} inter_~{quality}.hic
java \
-Ddevelopment=false \
-Djava.awt.headless=true \
-Xmx60g \
-jar /opt/scripts/common/juicer_tools.jar \
addNorm \
~{if length(normalization_methods) > 0 then "-k" else ""} ~{sep="," normalization_methods} \
--threads ~{num_cpus} \
inter_~{quality}.hic
}
output {
File output_hic = "inter_~{quality}.hic"
}
runtime {
cpu : "~{num_cpus}"
disks: "local-disk 128 HDD"
memory : "72 GB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task arrowhead {
input {
File hic_file
Int quality = 0
RuntimeEnvironment runtime_environment
}
command <<<
set -euo pipefail
java \
-Ddevelopment=false \
-Djava.awt.headless=true \
-Xmx16g \
-jar /opt/scripts/common/juicer_tools.jar \
arrowhead \
~{hic_file} \
contact_domains
gzip -n contact_domains/*
STEM=$(basename contact_domains/*.bedpe.gz .bedpe.gz)
mv contact_domains/*.bedpe.gz "${STEM}_~{quality}.bedpe.gz"
>>>
output {
File out_file = glob('*_~{quality}.bedpe.gz')[0]
}
runtime {
cpu : "1"
disks: "local-disk 100 HDD"
memory : "32 GB"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
}
}
task hiccups {
input {
File hic_file
Int quality = 0
RuntimeEnvironment runtime_environment
}
command {
set -euo pipefail
java \
-Ddevelopment=false \
-Djava.awt.headless=true \
-jar /opt/scripts/common/juicer_tools.jar \
hiccups \
${hic_file} \
loops
gzip -n loops/merged_loops.bedpe
mv loops/merged_loops.bedpe.gz merged_loops_~{quality}.bedpe.gz
}
output {
File merged_loops = "merged_loops_~{quality}.bedpe.gz"
}
runtime {
cpu : "1"
bootDiskSizeGb: "20"
disks: "local-disk 100 HDD"
docker: runtime_environment.docker
singularity: runtime_environment.singularity
gpuType: "nvidia-tesla-p100"
gpuCount: 1
memory: "8 GB"
zones: [
"us-central1-c",
"us-central1-f",
"us-east1-b",
"us-east1-c",
"us-west1-a",
"us-west1-b",
]
}
}
task hiccups_2 {
input {
File hic
Int quality = 0
Int num_cpus = 2
RuntimeEnvironment runtime_environment
}
command {
set -euo pipefail
java \
-Ddevelopment=false \
-Djava.awt.headless=true \