-
Notifications
You must be signed in to change notification settings - Fork 5
/
peaseq-case.wdl
executable file
·1464 lines (1312 loc) · 74.6 KB
/
peaseq-case.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
import "workflows/tasks/fastqc.wdl"
import "workflows/tasks/bedtools.wdl"
import "workflows/tasks/bowtie.wdl"
import "workflows/tasks/samtools.wdl"
import "workflows/tasks/macs.wdl"
import "workflows/workflows/bamtogff.wdl"
import "workflows/tasks/sicer.wdl"
import "workflows/workflows/motifs.wdl"
import "workflows/tasks/rose.wdl"
import "workflows/tasks/seaseq_util.wdl" as util
import "workflows/workflows/visualization.wdl" as viz
import "workflows/workflows/mapping.wdl"
import "workflows/tasks/runspp.wdl"
import "workflows/tasks/sortbed.wdl"
import "workflows/tasks/sratoolkit.wdl" as sra
import "workflows/tasks/peaseq_util.wdl"
workflow peaseq {
String pipeline_ver = 'v1.0.0'
meta {
title: 'PEAseq Analysis'
summary: 'Paired-End Antibody Sequencing (PEAseq) Pipeline'
description: 'A comprehensive automated computational pipeline for all ChIP-Seq/CUT&RUN data analysis.'
version: '1.0.0'
details: {
citation: 'https://doi.org/10.1186/s12859-022-04588-z',
contactEmail: 'modupeore.adetunji@stjude.org',
contactOrg: "St Jude Children's Research Hospital",
contactUrl: "",
upstreamLicenses: "MIT",
upstreamUrl: 'https://github.com/stjude/seaseq',
whatsNew: [
{
version: "1.0",
changes: ["Initial release"]
}
]
}
parameter_group: {
reference_genome: {
title: 'Reference genome',
description: 'Genome specific files. e.g. reference FASTA, GTF, blacklist, motif databases, FASTA index, bowtie index .',
help: 'Input reference genome files as defined. If some genome data are missing then analyses using such data will be skipped.'
},
input_genomic_data: {
title: 'Input FASTQ data',
description: 'Genomic input files for experiment.',
help: 'Input one or more sample data and/or SRA identifiers.'
},
analysis_parameter: {
title: 'Analysis parameter',
description: 'Analysis settings needed for experiment.',
help: 'Analysis settings; such output analysis file name.'
}
}
}
input {
# group: reference_genome
File reference
File? spikein_reference
File? blacklist
File gtf
Array[File]? bowtie_index
Array[File]? spikein_bowtie_index
Array[File]? motif_databases
# group: input_genomic_data
Array[String]? sample_sraid
Array[File]? sample_R1_fastq
Array[File]? sample_R2_fastq
# group: analysis_parameter
# Read Mapping parameters for bowtie
Int? insertsize = 600
String? strandedness = "fr"
# Additional options
String? results_name
Boolean run_motifs=true
}
parameter_meta {
reference: {
description: 'Reference FASTA file',
group: 'reference_genome',
patterns: ["*.fa", "*.fasta", "*.fa.gz", "*.fasta.gz"]
}
blacklist: {
description: 'Blacklist file in BED format',
group: 'reference_genome',
help: 'If defined, blacklist regions listed are excluded after reference alignment.',
patterns: ["*.bed", "*.bed.gz"]
}
gtf: {
description: 'gene annotation file (.gtf)',
group: 'reference_genome',
help: 'Input gene annotation file from RefSeq or GENCODE (.gtf).',
patterns: ["*.gtf", "*.gtf.gz", "*.gff", "*.gff.gz", "*.gff3", "*.gff3.gz"]
}
bowtie_index: {
description: 'bowtie v1 index files (*.ebwt)',
group: 'reference_genome',
help: 'If not defined, bowtie v1 index files are generated, will take a longer compute time.',
patterns: ["*.ebwt"]
}
motif_databases: {
description: 'One or more of the MEME suite motif databases (*.meme)',
group: 'reference_genome',
help: 'Input one or more motif databases available from the MEME suite (https://meme-suite.org/meme/db/motifs).',
patterns: ["*.meme"]
}
sample_sraid: {
description: 'One or more sample SRA (Sequence Read Archive) run identifiers',
group: 'input_genomic_data',
help: 'Input publicly available FASTQs (SRRs). Multiple SRRs are separated by commas (,).',
example: 'SRR12345678'
}
sample_R1_fastq: {
description: 'One or more sample R1 FASTQs',
group: 'input_genomic_data',
help: 'Upload zipped FASTQ files.',
patterns: ["*.fq.gz", "*.fastq.gz"]
}
sample_R2_fastq: {
description: 'One or more sample R2 FASTQs',
group: 'input_genomic_data',
help: 'Upload zipped FASTQ files.',
patterns: ["*.fq.gz", "*.fastq.gz"]
}
results_name: {
description: 'Experiment results custom name',
group: 'analysis_parameter',
help: 'Input preferred analysis results name (recommended if multiple FASTQs are provided).',
example: 'AllMerge_mapped'
}
run_motifs: {
description: 'Perform Motif Analysis',
group: 'analysis_parameter',
help: 'Setting this means Motif Discovery and Enrichment analysis will be performed.',
example: true
}
insertsize: {
description: 'Bowtie v1 maximum insert size (-X/--maxins <int>).',
group: 'analysis_parameter',
help: 'Specify maximum insert size for paired-end alignment (default: 600).',
example: 600
}
strandedness: {
description: 'Bowtie v1 mate orientation (--fr/--rf/--ff).',
group: 'analysis_parameter',
help: 'The upstream/downstream mate orientation for paired-end alignment (default: --fr).',
example: 'fr'
}
}
### ------------------------------------------------- ###
### ---------------- S E C T I O N 1 ---------------- ###
### ----------- Pre-process Analysis Files ---------- ###
### ------------------------------------------------- ###
# Process SRRs
if ( defined(sample_sraid) ) {
# Download sample file(s) from SRA database
# outputs:
# fastqdump.fastqfile : downloaded sample files in fastq.gz format
Array[String] string_sra = [1] #buffer to allow for sra_id optionality
Array[String] s_sraid = select_first([sample_sraid, string_sra])
scatter (eachsra in s_sraid) {
call sra.fastqdump {
input :
sra_id=eachsra,
cloud=false
}
File R1end = select_first([fastqdump.R1end, string_sra[0]])
File R2end = select_first([fastqdump.R2end, string_sra[0]])
} # end scatter each sra
Array[File] sample_R1_srafile = R1end
Array[File] sample_R2_srafile = R2end
} # end if sample_sraid
# Generating INDEX files
#1. Bowtie INDEX files if not provided
if ( !defined(bowtie_index) ) {
# create bowtie index when not provided
call bowtie.index as bowtie_idx {
input :
reference=reference
}
}
#2. Make sure indexes are six else build indexes
if ( defined(bowtie_index) ) {
# check total number of bowtie indexes provided
Array[String] string_bowtie_index = [1] #buffer to allow for bowtie_index optionality
Array[File] int_bowtie_index = select_first([bowtie_index, string_bowtie_index])
if ( length(int_bowtie_index) != 6 ) {
# create bowtie index if 6 index files aren't provided
call bowtie.index as bowtie_idx_2 {
input :
reference=reference
}
}
}
Array[File] actual_bowtie_index = select_first([bowtie_idx_2.bowtie_indexes, bowtie_idx.bowtie_indexes, bowtie_index])
# Spike-in DNA
#3. Bowtie INDEX files if not provided
String string_spikein = "1"
Array[String] string_spikein_buffer = [1]
if ( !defined(spikein_bowtie_index) && defined(spikein_reference) ) {
# create bowtie index on spikein genome
call bowtie.index as spikein_bowtie_idx {
input :
reference=select_first([spikein_reference, string_spikein])
}
}
#4. Make sure indexes are six else build indexes for Spike-in DNA
if ( defined(spikein_bowtie_index) ) {
# check total number of bowtie indexes provided
Array[File] int_spikein_bowtie_index = select_first([spikein_bowtie_index, string_spikein_buffer])
if ( length(int_spikein_bowtie_index) != 6 ) {
# create bowtie index if 6 index files aren't provided
call bowtie.index as spikein_bowtie_idx_2 {
input :
reference=select_first([spikein_reference, string_spikein])
}
}
}
Array[File] actual_spikein_bowtie_index = select_first([spikein_bowtie_idx_2.bowtie_indexes, spikein_bowtie_idx.bowtie_indexes, spikein_bowtie_index, string_spikein_buffer])
# FASTA faidx and chromsizes and effective genome size
call samtools.faidx as samtools_faidx {
# create FASTA index and chrom sizes files
input :
reference=reference
}
call util.effective_genome_size as egs {
# effective genome size for FASTA
input :
reference=reference
}
# Process FASTQs
if ( defined(sample_R1_fastq) ) {
Array[String] string_fastq = [1] #buffer to allow for fastq optionality
Array[File] s_R1_fastq = select_first([sample_R1_fastq, string_fastq])
Array[File] sample_R1_fastqfile = s_R1_fastq
Array[File] s_R2_fastq = select_first([sample_R2_fastq, string_fastq])
Array[File] sample_R2_fastqfile = s_R2_fastq
# Order FASTQs
if (length(sample_R1_fastqfile) > 1) {
call peaseq_util.sortfiles as R1_sorted { input: fastqfiles=sample_R1_fastqfile }
call peaseq_util.sortfiles as R2_sorted { input: fastqfiles=sample_R2_fastqfile }
}
Array[File] sample_R1_fastqfiles = select_first([R1_sorted.allfiles, sample_R1_fastqfile])
Array[File] sample_R2_fastqfiles = select_first([R2_sorted.allfiles, sample_R2_fastqfile])
}
# collate all fastqfiles
Array[File] original_sample_R1 = flatten(select_all([sample_R1_srafile, sample_R1_fastqfiles]))
Array[File] original_sample_R2 = flatten(select_all([sample_R2_srafile, sample_R2_fastqfiles]))
Array[File] original_all_sample_fastqfiles = flatten(select_all([sample_R1_srafile, sample_R1_fastqfiles,sample_R2_srafile, sample_R2_fastqfiles]))
# transpose to paired-end tuples
Array[Pair[File, File]] original_sample_fastqfiles = zip(original_sample_R1, original_sample_R2)
### ------------------------------------------------- ###
### ---------------- S E C T I O N 1 ---------------- ###
### ----------- B: remove Spike-IN reads ------------ ###
### ------------------------------------------------- ###
# if multiple fastqfiles are provided
Boolean multi_fastqpair = if length(original_sample_fastqfiles) > 1 then true else false
Boolean one_fastqpair = if length(original_sample_fastqfiles) == 1 then true else false
if ( defined(spikein_bowtie_index) || defined(spikein_reference) ) {
scatter (eachfastq in original_all_sample_fastqfiles) {
call fastqc.fastqc as spikein_indv_fastqc {
input :
inputfile=eachfastq,
default_location=if multi_fastqpair then 'SAMPLE/' + sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/SpikeIn/FastQC' else if defined(results_name) then results_name + '/SpikeIn/FastQC' else sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/SpikeIn/FastQC'
}
}
scatter (fastqpair in original_sample_fastqfiles) {
call util.basicfastqstats as spikein_indv_R1_bfs {
input :
fastqfile=fastqpair.left,
default_location=if multi_fastqpair then 'SAMPLE/' + sub(basename(fastqpair.left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/SpikeIn/SummaryStats' else if defined(results_name) then results_name + '/SpikeIn/SummaryStats' else sub(basename(fastqpair.left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/SpikeIn/SummaryStats'
}
call bowtie.spikein_PE as spikein_indv_map {
input :
fastqfile=fastqpair.left,
fastqfile_R2=fastqpair.right,
metricsfile=spikein_indv_R1_bfs.metrics_out,
insert_size=insertsize,
strandedness=strandedness,
index_files=actual_spikein_bowtie_index,
default_location=if multi_fastqpair then 'SAMPLE/' + sub(basename(fastqpair.left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/SpikeIn/SummaryStats' else if defined(results_name) then results_name + '/SpikeIn/SummaryStats' else sub(basename(fastqpair.left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/SpikeIn/SummaryStats'
}
}
if (length(original_sample_R1) > 1) {
call peaseq_util.sortfiles as spikein_R1_sorted { input: fastqfiles=spikein_indv_map.unaligned_1 }
call peaseq_util.sortfiles as spikein_R2_sorted { input: fastqfiles=spikein_indv_map.unaligned_2 }
}
Array[File] spikein_sample_R1 = select_first([spikein_R1_sorted.allfiles, spikein_indv_map.unaligned_1])
Array[File] spikein_sample_R2 = select_first([spikein_R2_sorted.allfiles, spikein_indv_map.unaligned_2])
Array[File] spikein_all_sample_fastqfiles = flatten(select_all([spikein_sample_R1, spikein_sample_R2]))
Array[Pair[File, File]] spikein_sample_fastqfiles = zip(spikein_sample_R1, spikein_sample_R2)
}
Array[File] all_sample_fastqfiles = select_first([spikein_all_sample_fastqfiles, original_all_sample_fastqfiles])
Array[Pair[File, File]] sample_fastqfiles = select_first([spikein_sample_fastqfiles, original_sample_fastqfiles])
### ------------------------------------------------- ###
### ---------------- S E C T I O N 2 ---------------- ###
### ---- Single End (SE) Mode for all fastqfiles ---- ###
### ------------------------------------------------- ###
scatter (eachfastq in all_sample_fastqfiles) {
call fastqc.fastqc as indv_fastqc {
input :
inputfile=eachfastq,
default_location=if multi_fastqpair then 'SAMPLE/' + sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/QC/FastQC' else if defined(results_name) then results_name + '/single-end_mode/QC/FastQC' else sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/QC/FastQC'
}
call util.basicfastqstats as indv_bfs {
input :
fastqfile=eachfastq,
default_location=if multi_fastqpair then 'SAMPLE/' + sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/QC/SummaryStats' else if defined(results_name) then results_name + '/single-end_mode/QC/SummaryStats' else sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/QC/SummaryStats'
}
call mapping.mapping as indv_mapping {
input :
fastqfile=eachfastq,
index_files=actual_bowtie_index,
metricsfile=indv_bfs.metrics_out,
blacklist=blacklist,
default_location=if multi_fastqpair then 'SAMPLE/' + sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/BAM_files' else if defined(results_name) then results_name + '/single-end_mode/BAM_files' else sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/BAM_files'
}
call fastqc.fastqc as indv_bamfqc {
input :
inputfile=indv_mapping.sorted_bam,
default_location=if multi_fastqpair then 'SAMPLE/' + sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/QC/FastQC' else if defined(results_name) then results_name + '/single-end_mode/QC/FastQC' else sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/QC/FastQC'
}
call runspp.runspp as indv_runspp {
input:
bamfile=select_first([indv_mapping.bklist_bam, indv_mapping.sorted_bam])
}
call bedtools.bamtobed as indv_bamtobed {
input:
bamfile=select_first([indv_mapping.bklist_bam, indv_mapping.sorted_bam])
}
call util.evalstats as indv_summarystats {
input:
fastq_type="PEAseq Sample FASTQ",
bambed=indv_bamtobed.bedfile,
sppfile=indv_runspp.spp_out,
fastqczip=indv_fastqc.zipfile,
bamflag=indv_mapping.bam_stats,
rmdupflag=indv_mapping.mkdup_stats,
bkflag=indv_mapping.bklist_stats,
fastqmetrics=indv_bfs.metrics_out,
default_location=if multi_fastqpair then 'SAMPLE/' + sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/QC/SummaryStats' else if defined(results_name) then results_name + '/single-end_mode/QC/SummaryStats' else sub(basename(eachfastq),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/QC/SummaryStats'
}
} # end scatter (for eachfastq)
# MERGE BAM files
# Execute analysis on merge bam file
# Analysis executed:
# Merge BAM (SE mode : for each fastq paired-end)
call util.mergehtml {
input:
htmlfiles=indv_summarystats.xhtml,
txtfiles=indv_summarystats.textfile,
default_location='SAMPLE',
outputfile = 'AllSamples-summary-stats.html'
}
call samtools.mergebam as SE_mergebam {
input:
bamfiles=indv_mapping.sorted_bam,
metricsfiles=indv_bfs.metrics_out,
default_location = if defined(results_name) then results_name + '/single-end_mode/BAM_files' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/BAM_files' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/BAM_files',
outputfile = 'AllMapped_' + length(all_sample_fastqfiles) + 'fastqs_SE.sorted.bam'
}
call fastqc.fastqc as SE_mergebamfqc {
input:
inputfile=SE_mergebam.mergebam,
default_location=if defined(results_name) then results_name + '/single-end_mode/QC/FastQC' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/QC/FastQC' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/QC/FastQC'
}
call samtools.indexstats as SE_mergeindexstats {
input:
bamfile=SE_mergebam.mergebam,
default_location=if defined(results_name) then results_name + '/single-end_mode/BAM_files' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/BAM_files' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/BAM_files'
}
if ( defined(blacklist) ) {
# remove blacklist regions
String string_blacklist = "" #buffer to allow for blacklist optionality
File blacklist_file = select_first([blacklist, string_blacklist])
call bedtools.intersect as SE_merge_rmblklist {
input :
fileA=SE_mergebam.mergebam,
fileB=blacklist_file,
default_location=if defined(results_name) then results_name + '/single-end_mode/BAM_files' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/BAM_files' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/BAM_files',
nooverlap=true
}
call samtools.indexstats as SE_merge_bklist {
input :
bamfile=SE_merge_rmblklist.intersect_out,
default_location=if defined(results_name) then results_name + '/single-end_mode/BAM_files' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/BAM_files' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/BAM_files'
}
} # end if blacklist provided
File SE_mergebam_afterbklist = select_first([SE_merge_rmblklist.intersect_out, SE_mergebam.mergebam])
call samtools.markdup as SE_merge_markdup {
input :
bamfile=SE_mergebam_afterbklist,
default_location=if defined(results_name) then results_name + '/single-end_mode/BAM_files' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/BAM_files' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/BAM_files'
}
call samtools.indexstats as SE_merge_mkdup {
input :
bamfile=SE_merge_markdup.mkdupbam,
default_location=if defined(results_name) then results_name + '/single-end_mode/BAM_files' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/BAM_files' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/BAM_files'
}
### ------------------------------------------------- ###
### ---------------- S E C T I O N 3 ---------------- ###
### ---- Paired End (PE) Mode for all fastqfiles ---- ###
### ---- A: analysis if multiple FASTQs provided ---- ###
### ------------------------------------------------- ###
if ( multi_fastqpair ) {
scatter (fastqpair in sample_fastqfiles) {
# Execute analysis on each fastq file provided
# Analysis executed:
# Reference Alignment using Bowtie (-k2 -m2)
# Convert SAM to BAM
# FastQC on BAM files
# Remove Blacklists (if provided)
# Remove read duplicates
# Summary statistics on FASTQs
# Combine html files into one for easy viewing
call util.basicfastqstats as indv_R1_bfs {
input :
fastqfile=fastqpair.left,
default_location='SAMPLE/' + sub(basename(fastqpair.left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/QC/SummaryStats'
}
call mapping.mapping as indv_PE_mapping {
input :
fastqfile=fastqpair.left,
fastqfile_R2=fastqpair.right,
metricsfile=indv_R1_bfs.metrics_out,
insert_size=insertsize,
strandedness=strandedness,
index_files=actual_bowtie_index,
blacklist=blacklist,
paired_end=true,
default_location='SAMPLE/' + sub(basename(fastqpair.left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/BAM_files'
}
call fastqc.fastqc as indv_PE_bamfqc {
input :
inputfile=indv_PE_mapping.sorted_bam,
default_location='SAMPLE/' + sub(basename(fastqpair.left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/QC/FastQC'
}
call runspp.runspp as indv_PE_runspp {
input:
bamfile=select_first([indv_PE_mapping.bklist_bam, indv_PE_mapping.sorted_bam])
}
call peaseq_util.pe_bamtobed as indv_PE_bamtobed {
input:
bamfile=select_first([indv_PE_mapping.bklist_bam, indv_PE_mapping.sorted_bam])
}
call util.evalstats as indv_PE_summarystats {
input:
fastq_type="PEAseq Sample FASTQ",
bambed=indv_PE_bamtobed.bedfile,
sppfile=indv_PE_runspp.spp_out,
fastqczip=indv_PE_bamfqc.zipfile,
bamflag=indv_PE_mapping.bam_stats,
rmdupflag=indv_PE_mapping.mkdup_stats,
bkflag=indv_PE_mapping.bklist_stats,
default_location='SAMPLE/' + sub(basename(fastqpair.left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/QC/SummaryStats'
}
} # end scatter (for each sample fastq)
# MERGE BAM FILES
# Execute analysis on merge bam file
# Analysis executed:
# Merge BAM (if more than 1 fastq is provided)
# FastQC on Merge BAM (AllMapped_<number>_mapped)
# merge bam files and perform fasTQC if more than one is provided
call util.mergehtml as PE_mergehtml {
input:
htmlfiles=indv_PE_summarystats.xhtml,
txtfiles=indv_PE_summarystats.textfile,
default_location='SAMPLE',
outputfile = 'AllMapped_PEmode_peaseq-summary-stats.html'
}
call peaseq_util.pe_mergehtml as final_mergehtml {
input:
pe_htmlfiles=indv_PE_summarystats.xhtml,
pe_txtfiles=indv_PE_summarystats.textfile,
se_htmlfiles=indv_summarystats.xhtml,
se_txtfiles=indv_summarystats.textfile,
default_location='SAMPLE',
outputfile = 'AllSamples-summary-stats.html'
}
call samtools.mergebam as PE_mergebam {
input:
bamfiles=indv_PE_mapping.as_sortedbam,
metricsfiles=indv_bfs.metrics_out,
paired_end=true,
default_location = if defined(results_name) then results_name + '/BAM_files' else 'AllMapped_' + length(indv_PE_mapping.sorted_bam) + 'fastqpairs/BAM_files',
outputfile = if defined(results_name) then results_name + '.sorted.bam' else 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs.sorted.bam',
fixmatefile = if defined(results_name) then results_name + '.fixmate.bam' else 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs.fixmate.bam'
}
call fastqc.fastqc as PE_mergebamfqc {
input:
inputfile=PE_mergebam.mergebam,
default_location=sub(basename(PE_mergebam.mergebam),'.sorted.b.*$','') + '/QC/FastQC'
}
call samtools.indexstats as PE_mergeindexstats {
input:
bamfile=PE_mergebam.mergebam,
default_location=sub(basename(PE_mergebam.mergebam),'.sorted.b.*$','') + '/BAM_files'
}
if ( defined(blacklist) ) {
# remove blacklist regions
String string_pe_blacklist = "" #buffer to allow for blacklist optionality
File blacklist_pe = select_first([blacklist, string_pe_blacklist])
String string_pe_fixmate = "" #buffer to allow for blacklist optionality
File fixmate_pe = select_first([PE_mergebam.fixmatemergebam, string_pe_fixmate])
call bedtools.pairtobed as PE_merge_rmblklist {
input :
fileA=fixmate_pe,
fileB=blacklist_pe,
default_location=sub(basename(PE_mergebam.mergebam),'.sorted.b.*$','') + '/BAM_files'
}
call samtools.indexstats as PE_merge_bklist {
input :
bamfile=PE_merge_rmblklist.pairtobed_out,
default_location=sub(basename(PE_mergebam.mergebam),'.sorted.b.*$','') + '/BAM_files'
}
} # end if blacklist provided
File PE_mergebam_afterbklist = select_first([PE_merge_rmblklist.pairtobed_out, PE_mergebam.mergebam])
call samtools.markdup as PE_merge_markdup {
input :
bamfile=PE_mergebam_afterbklist,
default_location=sub(basename(PE_mergebam.mergebam),'.sorted.b.*$','') + '/BAM_files'
}
call samtools.indexstats as PE_merge_mkdup {
input :
bamfile=PE_merge_markdup.mkdupbam,
default_location=sub(basename(PE_mergebam.mergebam),'.sorted.b.*$','') + '/BAM_files'
}
} # end if length(fastqfiles) > 1: multi_fastqpair
### ------------------------------------------------- ###
### ---------------- S E C T I O N 3 ---------------- ###
### ---- Paired End (PE) Mode for all fastqfiles ---- ###
### ------- B: analysis if one FASTQ provided ------- ###
### ------------------------------------------------- ###
# if only one fastqfile is provided
if ( one_fastqpair ) {
# Execute analysis on each fastq file provided
# Analysis executed:
# FastQC
# FASTQ read length distribution
# Reference Alignment using Bowtie (-k2 -m2)
# Convert SAM to BAM
# FastQC on BAM files
# Remove Blacklists (if provided)
# Remove read duplicates
# Summary statistics on FASTQs
# Combine html files into one for easy viewing
call util.basicfastqstats as R1_bfs {
input :
fastqfile=sample_fastqfiles[0].left,
default_location=if defined(results_name) then results_name + '/BAM_files' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/QC/SummaryStats'
}
call mapping.mapping as uno_PE_mapping {
input :
fastqfile=sample_fastqfiles[0].left,
fastqfile_R2=sample_fastqfiles[0].right,
metricsfile=R1_bfs.metrics_out,
insert_size=insertsize,
strandedness=strandedness,
index_files=actual_bowtie_index,
blacklist=blacklist,
paired_end=true,
results_name=results_name,
default_location=if defined(results_name) then results_name + '/BAM_files' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/BAM_files'
}
call fastqc.fastqc as uno_PE_bamfqc {
input :
inputfile=uno_PE_mapping.sorted_bam,
default_location=sub(basename(uno_PE_mapping.sorted_bam),'.sorted.bam','') + '/QC/FastQC'
}
call runspp.runspp as uno_PE_runspp {
input:
bamfile=select_first([uno_PE_mapping.bklist_bam, uno_PE_mapping.sorted_bam])
}
call peaseq_util.pe_bamtobed as uno_PE_bamtobed {
input:
bamfile=select_first([uno_PE_mapping.bklist_bam, uno_PE_mapping.sorted_bam])
}
} # end if length(fastqfiles) == 1: one_fastqpair
### ------------------------------------------------- ###
### ---------------- S E C T I O N 4 ---------------- ###
### --------------- ChIP-seq Analysis --------------- ###
### ------------ A: analysis for SE mode ----------- ###
### ------------------------------------------------- ###
# ChIP-seq and downstream analysis
# Execute analysis on merge bam file
# Analysis executed:
# Peaks identification (SICER, MACS, ROSE)
# Motif analysis
call macs.macs as SE_macs {
input :
bamfile=SE_mergebam_afterbklist,
pvalue="1e-9",
keep_dup="auto",
egs=egs.genomesize,
default_location = if defined(results_name) then results_name + '/single-end_mode/PEAKS/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '-p9_kd-auto' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/PEAKS/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '-p9_kd-auto' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/PEAKS/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '-p9_kd-auto',
coverage_location = if defined(results_name) then results_name + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '_p9_kd-auto' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '_p9_kd-auto' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '_p9_kd-auto'
}
call util.addreadme as SE_addreadme {
input :
default_location = if defined(results_name) then results_name + '/single-end_mode/PEAKS' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/PEAKS' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/PEAKS'
}
call macs.macs as SE_all {
input :
bamfile=SE_mergebam_afterbklist,
pvalue="1e-9",
keep_dup="all",
egs=egs.genomesize,
default_location = if defined(results_name) then results_name + '/single-end_mode/PEAKS/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '-p9_kd-all' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/PEAKS/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '-p9_kd-all' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/PEAKS/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '-p9_kd-all',
coverage_location = if defined(results_name) then results_name + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '_p9_kd-all' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '_p9_kd-all' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '_p9_kd-all'
}
call macs.macs as SE_nomodel {
input :
bamfile=SE_mergebam_afterbklist,
nomodel=true,
egs=egs.genomesize,
default_location = if defined(results_name) then results_name + '/single-end_mode/PEAKS/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '-nm' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/PEAKS/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '-nm' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/PEAKS/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '-nm',
coverage_location = if defined(results_name) then results_name + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '_nm' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '_nm' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + basename(SE_mergebam_afterbklist,'.bam') + '_nm'
}
call bamtogff.bamtogff as SE_bamtogff {
input :
gtffile=gtf,
chromsizes=samtools_faidx.chromsizes,
bamfile=SE_merge_markdup.mkdupbam,
bamindex=SE_merge_mkdup.indexbam,
default_location = if defined(results_name) then results_name + '/single-end_mode/BAM_Density' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/BAM_Density' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/BAM_Density'
}
call bedtools.bamtobed as SE_forsicerbed {
input :
bamfile=SE_merge_markdup.mkdupbam
}
call sicer.sicer as SE_sicer {
input :
bedfile=SE_forsicerbed.bedfile,
chromsizes=samtools_faidx.chromsizes,
genome_fraction=egs.genomefraction,
fragmentlength=SE_mergebam.avg_readlength,
default_location = if defined(results_name) then results_name + '/single-end_mode/PEAKS/BROAD_peaks' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/PEAKS/BROAD_peaks' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/PEAKS/BROAD_peaks',
coverage_location = if defined(results_name) then results_name + '/single-end_mode/COVERAGE_files/BROAD_peaks' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/COVERAGE_files/BROAD_peaks' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/COVERAGE_files/BROAD_peaks'
}
call rose.rose as SE_rose {
input :
gtffile=gtf,
bamfile=SE_merge_markdup.mkdupbam,
bamindex=SE_merge_mkdup.indexbam,
bedfile_auto=SE_macs.peakbedfile,
bedfile_all=SE_all.peakbedfile,
default_location = if defined(results_name) then results_name + '/single-end_mode/PEAKS/STITCHED_peaks' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/PEAKS/STITCHED_peaks' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/PEAKS/STITCHED_peaks'
}
call runspp.runspp as SE_runspp {
input:
bamfile=SE_mergebam_afterbklist
}
call util.peaksanno as SE_peaksanno {
input :
gtffile=gtf,
bedfile=SE_macs.peakbedfile,
chromsizes=samtools_faidx.chromsizes,
summitfile=SE_macs.summitsfile,
default_location = if defined(results_name) then results_name + '/single-end_mode/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(SE_macs.peakbedfile),'_peaks.bed','') else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(SE_macs.peakbedfile),'_peaks.bed','') else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(SE_macs.peakbedfile),'_peaks.bed','')
}
call util.peaksanno as SE_all_peaksanno {
input :
gtffile=gtf,
bedfile=SE_all.peakbedfile,
chromsizes=samtools_faidx.chromsizes,
summitfile=SE_all.summitsfile,
default_location = if defined(results_name) then results_name + '/single-end_mode/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(SE_all.peakbedfile),'_peaks.bed','') else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(SE_all.peakbedfile),'_peaks.bed','') else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(SE_all.peakbedfile),'_peaks.bed','')
}
call util.peaksanno as SE_nomodel_peaksanno {
input :
gtffile=gtf,
bedfile=SE_nomodel.peakbedfile,
chromsizes=samtools_faidx.chromsizes,
summitfile=SE_nomodel.summitsfile,
default_location = if defined(results_name) then results_name + '/single-end_mode/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(SE_nomodel.peakbedfile),'_peaks.bed','') else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(SE_nomodel.peakbedfile),'_peaks.bed','') else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(SE_nomodel.peakbedfile),'_peaks.bed','')
}
call util.peaksanno as SE_sicer_peaksanno {
input :
gtffile=gtf,
bedfile=SE_sicer.scoreisland,
chromsizes=samtools_faidx.chromsizes,
default_location = if defined(results_name) then results_name + '/single-end_mode/PEAKS_Annotation/BROAD_peaks' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/PEAKS_Annotation/BROAD_peaks' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/PEAKS_Annotation/BROAD_peaks'
}
# Motif Analysis
if (run_motifs) {
call motifs.motifs as SE_motifs {
input:
reference=reference,
reference_index=samtools_faidx.faidx_file,
bedfile=SE_macs.peakbedfile,
motif_databases=motif_databases,
default_location = if defined(results_name) then results_name + '/single-end_mode/MOTIFS' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/MOTIFS' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/MOTIFS'
}
call util.flankbed as SE_flankbed {
input :
bedfile=SE_macs.summitsfile,
default_location = if defined(results_name) then results_name + '/single-end_mode/MOTIFS' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/MOTIFS' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/MOTIFS'
}
call motifs.motifs as SE_flank {
input:
reference=reference,
reference_index=samtools_faidx.faidx_file,
bedfile=SE_flankbed.flankbedfile,
motif_databases=motif_databases,
default_location = if defined(results_name) then results_name + '/single-end_mode/MOTIFS' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/MOTIFS' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/MOTIFS'
}
}
call viz.visualization as SE_visualization {
input:
wigfile=SE_macs.wigfile,
chromsizes=samtools_faidx.chromsizes,
xlsfile=SE_macs.peakxlsfile,
default_location = if defined(results_name) then results_name + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + sub(basename(SE_macs.peakbedfile),'_peaks.bed','') else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + sub(basename(SE_macs.peakbedfile),'_peaks.bed','') else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + sub(basename(SE_macs.peakbedfile),'_peaks.bed','')
}
call viz.visualization as SE_vizall {
input:
wigfile=SE_all.wigfile,
chromsizes=samtools_faidx.chromsizes,
xlsfile=SE_all.peakxlsfile,
default_location = if defined(results_name) then results_name + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + sub(basename(SE_all.peakbedfile),'_peaks.bed','') else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + sub(basename(SE_all.peakbedfile),'_peaks.bed','') else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + sub(basename(SE_all.peakbedfile),'_peaks.bed','')
}
call viz.visualization as SE_viznomodel {
input:
wigfile=SE_nomodel.wigfile,
chromsizes=samtools_faidx.chromsizes,
xlsfile=SE_nomodel.peakxlsfile,
default_location = if defined(results_name) then results_name + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + sub(basename(SE_nomodel.peakbedfile),'_peaks.bed','') else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + sub(basename(SE_nomodel.peakbedfile),'_peaks.bed','') else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/COVERAGE_files/NARROW_peaks' + '/' + sub(basename(SE_nomodel.peakbedfile),'_peaks.bed','')
}
call viz.visualization as SE_vizsicer {
input:
wigfile=SE_sicer.wigfile,
chromsizes=samtools_faidx.chromsizes,
default_location = if defined(results_name) then results_name + '/single-end_mode/COVERAGE_files/BROAD_peaks' else if multi_fastqpair then 'AllMapped_' + length(sample_fastqfiles) + 'fastqpairs' + '/single-end_mode/COVERAGE_files/BROAD_peaks' else sub(basename(sample_fastqfiles[0].left),'_R?[12]_....f.*q.gz|_R?[12].f.*q.gz','') + '/single-end_mode/COVERAGE_files/BROAD_peaks'
}
call bedtools.bamtobed as SE_finalbed {
input:
bamfile=SE_mergebam_afterbklist
}
call sortbed.sortbed as SE_sortbed {
input:
bedfile=SE_finalbed.bedfile
}
call bedtools.intersect as SE_intersect {
input:
fileA=SE_macs.peakbedfile,
fileB=SE_sortbed.sortbed_out,
countoverlap=true,
sorted=true
}
### ------------------------------------------------- ###
### ---------------- S E C T I O N 4 ---------------- ###
### --------------- ChIP-seq Analysis --------------- ###
### ------------ B: analysis for PE mode ----------- ###
### ------------------------------------------------- ###
# ChIP-seq and downstream analysis
# Execute analysis on merge bam file
# Analysis executed:
# Peaks identification (SICER, MACS, ROSE)
# Motif analysis
#collate correct files for downstream analysis
File PE_sample_bam = select_first([PE_mergebam_afterbklist, uno_PE_mapping.bklist_bam, uno_PE_mapping.sorted_bam])
call macs.macs as PE_macs {
input :
bamfile=PE_sample_bam,
pvalue="1e-9",
keep_dup="auto",
egs=egs.genomesize,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/PEAKS/NARROW_peaks' + '/' + basename(PE_sample_bam,'.bam') + '-p9_kd-auto',
coverage_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/COVERAGE_files/NARROW_peaks' + '/' + basename(PE_sample_bam,'.bam') + '_p9_kd-auto'
}
call util.addreadme as PE_addreadme {
input :
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/PEAKS'
}
call macs.macs as PE_all {
input :
bamfile=PE_sample_bam,
pvalue="1e-9",
keep_dup="all",
egs=egs.genomesize,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/PEAKS/NARROW_peaks' + '/' + basename(PE_sample_bam,'.bam') + '-p9_kd-all',
coverage_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/COVERAGE_files/NARROW_peaks' + '/' + basename(PE_sample_bam,'.bam') + '_p9_kd-all'
}
call macs.macs as PE_nomodel {
input :
bamfile=PE_sample_bam,
nomodel=true,
egs=egs.genomesize,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/PEAKS/NARROW_peaks' + '/' + basename(PE_sample_bam,'.bam') + '-nm',
coverage_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/COVERAGE_files/NARROW_peaks' + '/' + basename(PE_sample_bam,'.bam') + '_nm'
}
call peaseq_util.fraggraph {
input :
bamfile=select_first([PE_merge_markdup.mkdupbam, uno_PE_mapping.mkdup_bam]),
chromsizes=samtools_faidx.chromsizes,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/COVERAGE_files/BAM_Fragments',
bam_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/BAM_files',
annotation_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/QC/Fragments'
}
call samtools.indexstats as frag_index {
input :
bamfile=fraggraph.fragbamfile,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/BAM_files'
}
call bamtogff.bamtogff as PE_bamtogff {
input :
gtffile=gtf,
chromsizes=samtools_faidx.chromsizes,
bamfile=fraggraph.fragbamfile,
bamindex=frag_index.indexbam,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/BAM_Density'
}
call sicer.sicer as PE_sicer {
input :
bedfile=fraggraph.bedpefile,
paired_end=true,
gap_size=600,
chromsizes=samtools_faidx.chromsizes,
genome_fraction=egs.genomefraction,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/PEAKS/BROAD_peaks',
coverage_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/COVERAGE_files/BROAD_peaks'
}
call rose.rose as PE_rose {
input :
gtffile=gtf,
bamfile=fraggraph.fragbamfile,
bamindex=frag_index.indexbam,
bedfile_auto=PE_macs.peakbedfile,
bedfile_all=PE_all.peakbedfile,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/PEAKS/STITCHED_peaks'
}
call runspp.runspp as PE_runspp {
input:
bamfile=PE_sample_bam
}
call util.peaksanno as PE_peaksanno {
input :
gtffile=gtf,
bedfile=PE_macs.peakbedfile,
chromsizes=samtools_faidx.chromsizes,
summitfile=PE_macs.summitsfile,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(PE_macs.peakbedfile),'_peaks.bed','')
}
call util.peaksanno as PE_all_peaksanno {
input :
gtffile=gtf,
bedfile=PE_all.peakbedfile,
chromsizes=samtools_faidx.chromsizes,
summitfile=PE_all.summitsfile,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(PE_all.peakbedfile),'_peaks.bed','')
}
call util.peaksanno as PE_nomodel_peaksanno {
input :
gtffile=gtf,
bedfile=PE_nomodel.peakbedfile,
chromsizes=samtools_faidx.chromsizes,
summitfile=PE_nomodel.summitsfile,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/PEAKS_Annotation/NARROW_peaks' + '/' + sub(basename(PE_nomodel.peakbedfile),'_peaks.bed','')
}
call util.peaksanno as PE_sicer_peaksanno {
input :
gtffile=gtf,
bedfile=PE_sicer.scoreisland,
chromsizes=samtools_faidx.chromsizes,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/PEAKS_Annotation/BROAD_peaks'
}
# Motif Analysis
if (run_motifs) {
call motifs.motifs as PE_motifs {
input:
reference=reference,
reference_index=samtools_faidx.faidx_file,
bedfile=PE_macs.peakbedfile,
motif_databases=motif_databases,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/MOTIFS'
}
call util.flankbed as PE_flankbed {
input :
bedfile=PE_macs.summitsfile,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/MOTIFS'
}
call motifs.motifs as PE_flank {
input:
reference=reference,
reference_index=samtools_faidx.faidx_file,
bedfile=PE_flankbed.flankbedfile,
motif_databases=motif_databases,
default_location=sub(basename(PE_sample_bam),'.sorted.b.*$','') + '/MOTIFS'