-
Notifications
You must be signed in to change notification settings - Fork 5
/
seaseq-control.wdl
executable file
·1436 lines (1275 loc) · 63.7 KB
/
seaseq-control.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
workflow seaseq {
String pipeline_ver = 'v2.0.0'
meta {
title: 'SEAseq Analysis'
summary: 'Single-End Antibody Sequencing (SEAseq) Pipeline'
description: 'A comprehensive automated computational pipeline for all ChIP-Seq/CUT&RUN data analysis.'
version: '2.0.0'
details: {
citation: 'pending',
contactEmail: '[email protected]',
contactOrg: "St Jude Children's Research Hospital",
contactUrl: "",
upstreamLicenses: "MIT",
upstreamUrl: 'https://github.com/stjude/seaseq',
whatsNew: [
{
version: "2.0",
changes: ["version of case/sample + control", "single-end sequencing with input/control sequencing data", "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_fastq
Array[String]? control_sraid
Array[File]? control_fastq
# group: analysis_parameter
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_fastq: {
description: 'One or more sample FASTQs',
group: 'input_genomic_data',
help: 'Upload zipped FASTQ files.',
patterns: ["*.fq.gz", "*.fastq.gz"]
}
control_sraid: {
description: 'One or more input/control SRA (Sequence Read Archive) run identifiers',
group: 'input_genomic_data',
help: 'Input publicly available FASTQs (SRRs). Multiple SRRs are separated by commas (,).',
example: 'SRR12345678'
}
control_fastq: {
description: 'One or more input/control FASTQs',
group: 'input_genomic_data',
help: 'Upload zipped FASTQ files.',
patterns: ["*fq", "*.fq.gz", "*.fastq", "*.fastq.gz"]
}
results_name: {
description: 'Experiment results custom name',
group: 'analysis_parameter',
help: 'Input preferred analysis results name.',
example: 'AllMerge_mapped'
}
}
### ---------------------------------------- ###
### ------------ 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
}
} # end scatter each sra
Array[File] sample_srafile = flatten(fastqdump.fastqfile)
} # end if sample_sraid
if ( defined(control_sraid) ) {
# Download control file(s) from SRA database
# outputs:
# fastqdump.fastqfile : downloaded sample files in fastq.gz format
Array[String] c_sra = [1] #buffer to allow for sra_id optionality
Array[String] c_sraid = select_first([control_sraid, c_sra])
scatter (eachsra in c_sraid) {
call sra.fastqdump as c_fastqdump{
input :
sra_id=eachsra,
cloud=false
}
} # end scatter each sra
Array[File] control_srafile = flatten(c_fastqdump.fastqfile)
} # 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
}
}
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_fastq) ) {
Array[String] string_fastq = [1] #buffer to allow for fastq optionality
Array[File] s_fastq = select_first([sample_fastq, string_fastq])
Array[File] sample_fastqfile = s_fastq
}
if ( defined(control_fastq) ) {
Array[String] c_string_fastq = [1] #buffer to allow for fastq optionality
Array[File] c_fastq = select_first([control_fastq, c_string_fastq])
Array[File] control_fastqfile = c_fastq
}
Array[File] original_s_fastqfiles = flatten(select_all([sample_fastqfile, sample_srafile]))
Array[File] original_c_fastqfiles = flatten(select_all([control_fastqfile, control_srafile]))
### ------------------------------------------------- ###
### ---------------- S E C T I O N 1 ---------------- ###
### ----------- B: remove Spike-IN reads ------------ ###
### ------------------------------------------------- ###
# if multiple fastqfiles are provided
Boolean multi_sample_fastq = if length(original_s_fastqfiles) > 1 then true else false
Boolean one_sample_fastq = if length(original_s_fastqfiles) == 1 then true else false
Boolean multi_control_fastq = if length(original_c_fastqfiles) > 1 then true else false
Boolean one_control_fastq = if length(original_c_fastqfiles) == 1 then true else false
if ( defined(spikein_bowtie_index) || defined(spikein_reference) ) {
scatter (eachfastq in original_s_fastqfiles) {
call fastqc.fastqc as spikein_indv_s_fastqc {
input :
inputfile=eachfastq,
default_location='SAMPLE/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/SpikeIn/FastQC'
}
call util.basicfastqstats as spikein_indv_s_bfs {
input :
fastqfile=eachfastq,
default_location='SAMPLE/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/SpikeIn/SummaryStats'
}
call bowtie.spikein_SE as spikein_indv_s_map {
input :
fastqfile=eachfastq,
index_files=actual_spikein_bowtie_index,
metricsfile=spikein_indv_s_bfs.metrics_out,
default_location='SAMPLE/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/SpikeIn/SummaryStats'
}
}
scatter (eachfastq in original_c_fastqfiles) {
call fastqc.fastqc as spikein_indv_c_fastqc {
input :
inputfile=eachfastq,
default_location='CONTROL/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/SpikeIn/FastQC'
}
call util.basicfastqstats as spikein_indv_c_bfs {
input :
fastqfile=eachfastq,
default_location='CONTROL/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/SpikeIn/SummaryStats'
}
call bowtie.spikein_SE as spikein_indv_c_map {
input :
fastqfile=eachfastq,
index_files=actual_spikein_bowtie_index,
metricsfile=spikein_indv_c_bfs.metrics_out,
default_location='CONTROL/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/SpikeIn/SummaryStats'
}
}
Array[File] spikein_s_fastqfiles = spikein_indv_s_map.unaligned
Array[File] spikein_c_fastqfiles = spikein_indv_c_map.unaligned
}
Array[File] s_fastqfiles = select_first([spikein_s_fastqfiles, original_s_fastqfiles])
Array[File] c_fastqfiles = select_first([spikein_c_fastqfiles, original_c_fastqfiles])
### ------------------------------------------------- ###
### ---------------- S E C T I O N 2 ---------------- ###
### ---- A: analysis if multiple FASTQs provided ---- ###
### ------------------------------------------------- ###
if ( multi_sample_fastq ) {
scatter (eachfastq in s_fastqfiles) {
# 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 fastqc.fastqc as indv_s_fastqc {
input :
inputfile=eachfastq,
default_location='SAMPLE/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/QC/FastQC'
}
call util.basicfastqstats as indv_s_bfs {
input :
fastqfile=eachfastq,
default_location='SAMPLE/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/QC/SummaryStats'
}
call mapping.mapping as indv_s_mapping {
input :
fastqfile=eachfastq,
index_files=actual_bowtie_index,
metricsfile=indv_s_bfs.metrics_out,
blacklist=blacklist,
default_location='SAMPLE/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/BAM_files'
}
call fastqc.fastqc as indv_s_bamfqc {
input :
inputfile=indv_s_mapping.sorted_bam,
default_location='SAMPLE/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/QC/FastQC'
}
call runspp.runspp as indv_s_runspp {
input:
bamfile=select_first([indv_s_mapping.bklist_bam, indv_s_mapping.sorted_bam])
}
call bedtools.bamtobed as indv_s_bamtobed {
input:
bamfile=select_first([indv_s_mapping.bklist_bam, indv_s_mapping.sorted_bam])
}
call util.evalstats as indv_s_summarystats {
input:
fastq_type="SEAseq Sample FASTQ",
bambed=indv_s_bamtobed.bedfile,
sppfile=indv_s_runspp.spp_out,
fastqczip=indv_s_fastqc.zipfile,
bamflag=indv_s_mapping.bam_stats,
rmdupflag=indv_s_mapping.mkdup_stats,
bkflag=indv_s_mapping.bklist_stats,
fastqmetrics=indv_s_bfs.metrics_out,
default_location='SAMPLE/' + sub(basename(eachfastq),'.fastq.gz|.fq.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 (AllCasesMerge_<number>_mapped)
# merge bam files and perform fasTQC if more than one is provided
call util.mergehtml as s_mergehtml {
input:
htmlfiles=indv_s_summarystats.xhtml,
txtfiles=indv_s_summarystats.textfile,
default_location='SAMPLE',
outputfile = 'AllCases_' + length(s_fastqfiles) + '_seaseq-summary-stats.html'
}
call samtools.mergebam as s_mergebam {
input:
bamfiles=indv_s_mapping.sorted_bam,
metricsfiles=indv_s_bfs.metrics_out,
default_location = 'SAMPLE/AllCasesMerge_' + length(indv_s_mapping.sorted_bam) + '_mapped' + '/BAM_files',
outputfile = 'AllCasesMerge_' + length(s_fastqfiles) + '_mapped.sorted.bam'
}
call fastqc.fastqc as s_mergebamfqc {
input:
inputfile=s_mergebam.mergebam,
default_location='SAMPLE/' + sub(basename(s_mergebam.mergebam),'.sorted.b.*$','') + '/QC/FastQC'
}
call samtools.indexstats as s_mergeindexstats {
input:
bamfile=s_mergebam.mergebam,
default_location='SAMPLE/' + sub(basename(s_mergebam.mergebam),'.sorted.b.*$','') + '/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 s_merge_rmblklist {
input :
fileA=s_mergebam.mergebam,
fileB=blacklist_file,
default_location='SAMPLE/' + sub(basename(s_mergebam.mergebam),'.sorted.b.*$','') + '/BAM_files',
nooverlap=true
}
call samtools.indexstats as s_merge_bklist {
input :
bamfile=s_merge_rmblklist.intersect_out,
default_location='SAMPLE/' + sub(basename(s_mergebam.mergebam),'.sorted.b.*$','') + '/BAM_files'
}
} # end if blacklist provided
File s_mergebam_afterbklist = select_first([s_merge_rmblklist.intersect_out, s_mergebam.mergebam])
call samtools.markdup as s_merge_markdup {
input :
bamfile=s_mergebam_afterbklist,
default_location='SAMPLE/' + sub(basename(s_mergebam_afterbklist),'.sorted.b.*$','') + '/BAM_files'
}
call samtools.indexstats as s_merge_mkdup {
input :
bamfile=s_merge_markdup.mkdupbam,
default_location='SAMPLE/' + sub(basename(s_mergebam_afterbklist),'.sorted.b.*$','') + '/BAM_files'
}
} # end if length(fastqfiles) > 1: multi_sample_fastq
# CONTROL FASTQ files
if ( multi_control_fastq ) {
scatter (eachfastq in c_fastqfiles) {
# 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 fastqc.fastqc as indv_c_fastqc {
input :
inputfile=eachfastq,
default_location='CONTROL/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/QC/FastQC'
}
call util.basicfastqstats as indv_c_bfs {
input :
fastqfile=eachfastq,
default_location='CONTROL/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/QC/SummaryStats'
}
call mapping.mapping as indv_c_mapping {
input :
fastqfile=eachfastq,
index_files=actual_bowtie_index,
metricsfile=indv_c_bfs.metrics_out,
blacklist=blacklist,
default_location='CONTROL/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/BAM_files'
}
call fastqc.fastqc as indv_c_bamfqc {
input :
inputfile=indv_c_mapping.sorted_bam,
default_location='CONTROL/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/QC/FastQC'
}
call runspp.runspp as indv_c_runspp {
input:
bamfile=select_first([indv_c_mapping.bklist_bam, indv_c_mapping.sorted_bam])
}
call bedtools.bamtobed as indv_c_bamtobed {
input:
bamfile=select_first([indv_c_mapping.bklist_bam, indv_c_mapping.sorted_bam])
}
call util.evalstats as indv_c_summarystats {
input:
fastq_type="SEAseq Control FASTQ",
bambed=indv_c_bamtobed.bedfile,
sppfile=indv_c_runspp.spp_out,
fastqczip=indv_c_fastqc.zipfile,
bamflag=indv_c_mapping.bam_stats,
rmdupflag=indv_c_mapping.mkdup_stats,
bkflag=indv_c_mapping.bklist_stats,
fastqmetrics=indv_c_bfs.metrics_out,
default_location='CONTROL/' + sub(basename(eachfastq),'.fastq.gz|.fq.gz','') + '/QC/SummaryStats'
}
} # end scatter (for each control 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 (AllCtrlsMerge_<number>_mapped)
# merge bam files and perform fasTQC if more than one is provided
call util.mergehtml as c_mergehtml {
input:
fastq_type="SEAseq Control FASTQs",
htmlfiles=indv_c_summarystats.xhtml,
txtfiles=indv_c_summarystats.textfile,
default_location='CONTROL',
outputfile = 'AllCtrls_' + length(c_fastqfiles) + '_seaseq-summary-stats.html'
}
call samtools.mergebam as c_mergebam {
input:
bamfiles=indv_c_mapping.sorted_bam,
metricsfiles=indv_c_bfs.metrics_out,
default_location = 'CONTROL/' + 'AllCtrlsMerge_' + length(indv_c_mapping.sorted_bam) + '_mapped' + '/BAM_files',
outputfile = 'AllCtrlsMerge_' + length(c_fastqfiles) + '_mapped.sorted.bam'
}
call fastqc.fastqc as c_mergebamfqc {
input:
inputfile=c_mergebam.mergebam,
default_location='CONTROL/' + sub(basename(c_mergebam.mergebam),'.sorted.b.*$','') + '/QC/FastQC'
}
call samtools.indexstats as c_mergeindexstats {
input:
bamfile=c_mergebam.mergebam,
default_location='CONTROL/' + sub(basename(c_mergebam.mergebam),'.sorted.b.*$','') + '/BAM_files'
}
if ( defined(blacklist) ) {
# remove blacklist regions
String c_string_blacklist = "" #buffer to allow for blacklist optionality
File c_blacklist_file = select_first([blacklist, c_string_blacklist])
call bedtools.intersect as c_merge_rmblklist {
input :
fileA=c_mergebam.mergebam,
fileB=c_blacklist_file,
default_location='CONTROL/' + sub(basename(c_mergebam.mergebam),'.sorted.b.*$','') + '/BAM_files',
nooverlap=true
}
call samtools.indexstats as c_merge_bklist {
input :
bamfile=c_merge_rmblklist.intersect_out,
default_location='CONTROL/' + sub(basename(c_mergebam.mergebam),'.sorted.b.*$','') + '/BAM_files'
}
} # end if blacklist provided
File c_mergebam_afterbklist = select_first([c_merge_rmblklist.intersect_out, c_mergebam.mergebam])
call samtools.markdup as c_merge_markdup {
input :
bamfile=c_mergebam_afterbklist,
default_location='CONTROL/' + sub(basename(c_mergebam_afterbklist),'.sorted.b.*$','') + '/BAM_files'
}
call samtools.indexstats as c_merge_mkdup {
input :
bamfile=c_merge_markdup.mkdupbam,
default_location='CONTROL/' + sub(basename(c_mergebam_afterbklist),'.sorted.b.*$','') + '/BAM_files'
}
} # end if length(fastqfiles) > 1: multi_control_fastq
### ---------------------------------------- ###
### ------------ S E C T I O N 2 ----------- ###
### -- B: analysis if one FASTQ provided --- ###
### ---------------------------------------- ###
# if only one fastqfile is provided
if ( one_sample_fastq ) {
# 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 fastqc.fastqc as uno_s_fastqc {
input :
inputfile=s_fastqfiles[0],
default_location='SAMPLE/' + sub(basename(s_fastqfiles[0]),'.fastq.gz|.fq.gz','') + '/QC/FastQC'
}
call util.basicfastqstats as uno_s_bfs {
input :
fastqfile=s_fastqfiles[0],
default_location='SAMPLE/' + sub(basename(s_fastqfiles[0]),'.fastq.gz|.fq.gz','') + '/QC/SummaryStats'
}
call mapping.mapping as s_mapping {
input :
fastqfile=s_fastqfiles[0],
index_files=actual_bowtie_index,
metricsfile=uno_s_bfs.metrics_out,
blacklist=blacklist,
default_location='SAMPLE/' + sub(basename(s_fastqfiles[0]),'.fastq.gz|.fq.gz','') + '/BAM_files'
}
call fastqc.fastqc as uno_s_bamfqc {
input :
inputfile=s_mapping.sorted_bam,
default_location='SAMPLE/' + sub(basename(s_fastqfiles[0]),'.fastq.gz|.fq.gz','') + '/QC/FastQC'
}
call runspp.runspp as uno_s_runspp {
input:
bamfile=select_first([s_mapping.bklist_bam, s_mapping.sorted_bam])
}
call bedtools.bamtobed as uno_s_bamtobed {
input:
bamfile=select_first([s_mapping.bklist_bam, s_mapping.sorted_bam])
}
call util.evalstats as uno_s_summarystats {
input:
fastq_type="SEAseq Sample FASTQ",
bambed=uno_s_bamtobed.bedfile,
sppfile=uno_s_runspp.spp_out,
fastqczip=uno_s_fastqc.zipfile,
bamflag=s_mapping.bam_stats,
rmdupflag=s_mapping.mkdup_stats,
bkflag=s_mapping.bklist_stats,
fastqmetrics=uno_s_bfs.metrics_out,
default_location='SAMPLE/' + sub(basename(s_fastqfiles[0]),'.fastq.gz|.fq.gz','') + '/QC/SummaryStats'
}
} # end if length(fastqfiles) == 1: one_sample_fastq
# CONTROL FASTQ file
if ( one_control_fastq ) {
# 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 fastqc.fastqc as uno_c_fastqc {
input :
inputfile=c_fastqfiles[0],
default_location='CONTROL/' + sub(basename(c_fastqfiles[0]),'.fastq.gz|.fq.gz','') + '/QC/FastQC'
}
call util.basicfastqstats as uno_c_bfs {
input :
fastqfile=c_fastqfiles[0],
default_location='CONTROL/' + sub(basename(c_fastqfiles[0]),'.fastq.gz|.fq.gz','') + '/QC/SummaryStats'
}
call mapping.mapping as c_mapping {
input :
fastqfile=c_fastqfiles[0],
index_files=actual_bowtie_index,
metricsfile=uno_c_bfs.metrics_out,
blacklist=blacklist,
default_location='CONTROL/' + sub(basename(c_fastqfiles[0]),'.fastq.gz|.fq.gz','') + '/BAM_files'
}
call fastqc.fastqc as uno_c_bamfqc {
input :
inputfile=c_mapping.sorted_bam,
default_location='CONTROL/' + sub(basename(c_fastqfiles[0]),'.fastq.gz|.fq.gz','') + '/QC/FastQC'
}
call runspp.runspp as uno_c_runspp {
input:
bamfile=select_first([c_mapping.bklist_bam, c_mapping.sorted_bam])
}
call bedtools.bamtobed as uno_c_bamtobed {
input:
bamfile=select_first([c_mapping.bklist_bam, c_mapping.sorted_bam])
}
call util.evalstats as uno_c_summarystats {
input:
fastq_type="SEAseq Control FASTQ",
bambed=uno_c_bamtobed.bedfile,
sppfile=uno_c_runspp.spp_out,
fastqczip=uno_c_fastqc.zipfile,
bamflag=c_mapping.bam_stats,
rmdupflag=c_mapping.mkdup_stats,
bkflag=c_mapping.bklist_stats,
fastqmetrics=uno_c_bfs.metrics_out,
default_location='CONTROL/' + sub(basename(c_fastqfiles[0]),'.fastq.gz|.fq.gz','') + '/QC/SummaryStats'
}
} # end if length(fastqfiles) == 1: one_control_fastq
### ---------------------------------------- ###
### ------------ S E C T I O N 3 ----------- ###
### ----------- ChIP-seq analysis ---------- ###
### ---------------------------------------- ###
# ChIP-seq and downstream analysis
# Execute analysis on merge bam file
# Analysis executed:
# FIRST: Check if reads are mapped
# Peaks identification (SICER, MACS, ROSE)
# Motif analysis
# Complete Summary statistics
#collate correct files for downstream analysis
File sample_bam = select_first([s_mergebam_afterbklist, s_mapping.bklist_bam, s_mapping.sorted_bam])
File control_bam = select_first([c_mergebam_afterbklist, c_mapping.bklist_bam, c_mapping.sorted_bam])
call macs.macs {
input :
bamfile=sample_bam,
control=control_bam,
pvalue="1e-9",
keep_dup="auto",
egs=egs.genomesize,
output_name = if defined(results_name) then results_name + '-p9_kd-auto' else basename(sample_bam,'.bam') + '+control-p9_kd-auto',
default_location = if defined(results_name) then results_name + '/PEAKS/NARROW_peaks/' + results_name + '-p9_kd-auto' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/PEAKS/NARROW_peaks/' + basename(sample_bam,'.bam') + '+control-p9_kd-auto',
coverage_location = if defined(results_name) then results_name + '/COVERAGE_files/NARROW_peaks/' + results_name + '-p9_kd-auto' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/COVERAGE_files/NARROW_peaks/' + basename(sample_bam,'.bam') + '+control-p9_kd-auto'
}
call util.addreadme {
input :
default_location = if defined(results_name) then results_name + '/PEAKS' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/PEAKS'
}
call macs.macs as all {
input :
bamfile=sample_bam,
control=control_bam,
pvalue="1e-9",
keep_dup="all",
egs=egs.genomesize,
output_name = if defined(results_name) then results_name + '-p9_kd-all' else basename(sample_bam,'.bam') + '+control-p9_kd-all',
default_location = if defined(results_name) then results_name + '/PEAKS/NARROW_peaks/' + results_name + '-p9_kd-all' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/PEAKS/NARROW_peaks/' + basename(sample_bam,'.bam') + '+control-p9_kd-all',
coverage_location = if defined(results_name) then results_name + '/COVERAGE_files/NARROW_peaks/' + results_name + '-p9_kd-all' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/COVERAGE_files/NARROW_peaks/' + basename(sample_bam,'.bam') + '+control-p9_kd-all'
}
call macs.macs as nomodel {
input :
bamfile=sample_bam,
control=control_bam,
nomodel=true,
egs=egs.genomesize,
output_name = if defined(results_name) then results_name + '-nm' else basename(sample_bam,'.bam') + '+control-nm',
default_location = if defined(results_name) then results_name + '/PEAKS/NARROW_peaks/' + results_name + '-nm' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/PEAKS/NARROW_peaks/' + basename(sample_bam,'.bam') + '+control-nm',
coverage_location = if defined(results_name) then results_name + '/COVERAGE_files/NARROW_peaks/' + results_name + '-nm' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/COVERAGE_files/NARROW_peaks/' + basename(sample_bam,'.bam') + '+control-nm'
}
call bamtogff.bamtogff {
input :
gtffile=gtf,
chromsizes=samtools_faidx.chromsizes,
bamfile=select_first([s_merge_markdup.mkdupbam, s_mapping.mkdup_bam]),
bamindex=select_first([s_merge_mkdup.indexbam, s_mapping.mkdup_index]),
control_bamfile=select_first([c_merge_markdup.mkdupbam, c_mapping.mkdup_bam]),
control_bamindex=select_first([c_merge_mkdup.indexbam, c_mapping.mkdup_index]),
samplename=if defined(results_name) then results_name else basename((select_first([s_merge_markdup.mkdupbam, s_mapping.mkdup_bam])),'.bam') + '+control',
default_location=if defined(results_name) then results_name + '/BAM_Density' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/BAM_Density'
}
call bedtools.bamtobed as s_forsicerbed {
input :
bamfile=select_first([s_merge_markdup.mkdupbam, s_mapping.mkdup_bam])
}
call bedtools.bamtobed as c_forsicerbed {
input :
bamfile=select_first([c_merge_markdup.mkdupbam, c_mapping.mkdup_bam])
}
call sicer.sicer {
input :
bedfile=s_forsicerbed.bedfile,
control_bed=c_forsicerbed.bedfile,
chromsizes=samtools_faidx.chromsizes,
genome_fraction=egs.genomefraction,
fragmentlength=select_first([uno_s_bfs.readlength, s_mergebam.avg_readlength]),
outputname=if defined(results_name) then results_name else basename(s_forsicerbed.bedfile,'.bed') + '+control',
default_location=if defined(results_name) then results_name + '/PEAKS/BROAD_peaks' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/PEAKS/BROAD_peaks',
coverage_location=if defined(results_name) then results_name + '/COVERAGE_files/BROAD_peaks' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/COVERAGE_files/BROAD_peaks'
}
call rose.rose {
input :
gtffile=gtf,
bamfile=select_first([s_merge_markdup.mkdupbam, s_mapping.mkdup_bam]),
bamindex=select_first([s_merge_mkdup.indexbam, s_mapping.mkdup_index]),
control=select_first([c_merge_markdup.mkdupbam, c_mapping.mkdup_bam]),
controlindex=select_first([c_merge_mkdup.indexbam, c_mapping.mkdup_index]),
bedfile_auto=macs.peakbedfile,
bedfile_all=all.peakbedfile,
default_location=if defined(results_name) then results_name + '/PEAKS/STITCHED_peaks' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/PEAKS/STITCHED_peaks'
}
call runspp.runspp {
input:
bamfile=sample_bam,
control=control_bam
}
call runspp.runspp as only_s_runspp {
input:
bamfile=sample_bam
}
call runspp.runspp as only_c_runspp {
input:
bamfile=control_bam
}
String string_ctrlwig = ""
call viz.visualization as c_visualization {
input:
wigfile=select_first([macs.ctrlwigfile, string_ctrlwig]),
chromsizes=samtools_faidx.chromsizes,
control=true,
xlsfile=macs.peakxlsfile,
default_location=if defined(results_name) then results_name + '/COVERAGE_files/NARROW_peaks/' + sub(basename(macs.peakbedfile),'_peaks.bed','') + '/control' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/COVERAGE_files/NARROW_peaks/' + sub(basename(macs.peakbedfile),'_peaks.bed','') + '/control'
}
call viz.visualization as c_vizall {
input:
wigfile=select_first([all.ctrlwigfile, string_ctrlwig]),
chromsizes=samtools_faidx.chromsizes,
control=true,
xlsfile=all.peakxlsfile,
default_location=if defined(results_name) then results_name + '/COVERAGE_files/NARROW_peaks/' + sub(basename(all.peakbedfile),'_peaks.bed','') + '/control' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/COVERAGE_files/NARROW_peaks/' + sub(basename(all.peakbedfile),'_peaks.bed','') + '/control'
}
call viz.visualization as c_viznomodel {
input:
wigfile=select_first([nomodel.ctrlwigfile, string_ctrlwig]),
chromsizes=samtools_faidx.chromsizes,
control=true,
xlsfile=nomodel.peakxlsfile,
default_location=if defined(results_name) then results_name + '/COVERAGE_files/NARROW_peaks/' + sub(basename(nomodel.peakbedfile),'_peaks.bed','') + '/control' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/COVERAGE_files/NARROW_peaks/' + sub(basename(nomodel.peakbedfile),'_peaks.bed','') + '/control'
}
call util.peaksanno {
input :
gtffile=gtf,
bedfile=macs.peakbedfile,
chromsizes=samtools_faidx.chromsizes,
summitfile=macs.summitsfile,
default_location=if defined(results_name) then results_name + '/PEAKS_Annotation/NARROW_peaks/' + sub(basename(macs.peakbedfile),'_peaks.bed','') else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/PEAKS_Annotation/NARROW_peaks/' + sub(basename(macs.peakbedfile),'_peaks.bed','')
}
call util.peaksanno as all_peaksanno {
input :
gtffile=gtf,
bedfile=all.peakbedfile,
chromsizes=samtools_faidx.chromsizes,
summitfile=all.summitsfile,
default_location=if defined(results_name) then results_name + '/PEAKS_Annotation/NARROW_peaks/' + sub(basename(all.peakbedfile),'_peaks.bed','') else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/PEAKS_Annotation/NARROW_peaks/' + sub(basename(all.peakbedfile),'_peaks.bed','')
}
call util.peaksanno as nomodel_peaksanno {
input :
gtffile=gtf,
bedfile=nomodel.peakbedfile,
chromsizes=samtools_faidx.chromsizes,
summitfile=nomodel.summitsfile,
default_location=if defined(results_name) then results_name + '/PEAKS_Annotation/NARROW_peaks/' + sub(basename(nomodel.peakbedfile),'_peaks.bed','') else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/PEAKS_Annotation/NARROW_peaks/' + sub(basename(nomodel.peakbedfile),'_peaks.bed','')
}
call util.peaksanno as sicer_peaksanno {
input :
gtffile=gtf,
bedfile=select_first([sicer.fdrisland, string_ctrlwig]),
chromsizes=samtools_faidx.chromsizes,
default_location=if defined(results_name) then results_name + '/PEAKS_Annotation/BROAD_peaks' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/PEAKS_Annotation/BROAD_peaks'
}
# Motif Analysis
if (run_motifs) {
call motifs.motifs {
input:
reference=reference,
reference_index=samtools_faidx.faidx_file,
bedfile=macs.peakbedfile,
motif_databases=motif_databases,
default_location=if defined(results_name) then results_name + '/MOTIFS' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/MOTIFS'
}
call util.flankbed {
input :
bedfile=macs.summitsfile,
default_location=if defined(results_name) then results_name + '/MOTIFS' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/MOTIFS'
}
call motifs.motifs as flank {
input:
reference=reference,
reference_index=samtools_faidx.faidx_file,
bedfile=flankbed.flankbedfile,
motif_databases=motif_databases,
default_location=if defined(results_name) then results_name + '/MOTIFS' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/MOTIFS'
}
}
call viz.visualization {
input:
wigfile=macs.wigfile,
chromsizes=samtools_faidx.chromsizes,
xlsfile=macs.peakxlsfile,
default_location=if defined(results_name) then results_name + '/COVERAGE_files/NARROW_peaks/' + sub(basename(macs.peakbedfile),'_peaks.bed','') else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/COVERAGE_files/NARROW_peaks/' + sub(basename(macs.peakbedfile),'_peaks.bed','')
}
call viz.visualization as vizall {
input:
wigfile=all.wigfile,
chromsizes=samtools_faidx.chromsizes,
xlsfile=all.peakxlsfile,
default_location=if defined(results_name) then results_name + '/COVERAGE_files/NARROW_peaks/' + sub(basename(all.peakbedfile),'_peaks.bed','') else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/COVERAGE_files/NARROW_peaks/' + sub(basename(all.peakbedfile),'_peaks.bed','')
}
call viz.visualization as viznomodel {
input:
wigfile=nomodel.wigfile,
chromsizes=samtools_faidx.chromsizes,
xlsfile=nomodel.peakxlsfile,
default_location=if defined(results_name) then results_name + '/COVERAGE_files/NARROW_peaks/' + sub(basename(nomodel.peakbedfile),'_peaks.bed','') else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/COVERAGE_files/NARROW_peaks/' + sub(basename(nomodel.peakbedfile),'_peaks.bed','')
}
call viz.visualization as vizsicer {
input:
wigfile=sicer.wigfile,
chromsizes=samtools_faidx.chromsizes,
default_location=if defined(results_name) then results_name + '/COVERAGE_files/BROAD_peaks' else sub(basename(sample_bam),'.sorted.b.*$','') + '+control/COVERAGE_files/BROAD_peaks'
}
#Peak Calling for Sample BAM only
call macs.macs as only_s_macs {
input :
bamfile=sample_bam,
pvalue="1e-9",
keep_dup="auto",
egs=egs.genomesize,
default_location='SAMPLE/' + sub(basename(sample_bam),'.sorted.b.*$','') + '/PEAKS_forQC/' + basename(sample_bam,'.bam') + '-p9_kd-auto',
coverage_location='SAMPLE/' + sub(basename(sample_bam),'.sorted.b.*$','') + '/PEAKS_forQC/' + basename(sample_bam,'.bam') + '-p9_kd-auto'
}
#Peak Calling for Control BAM only
call macs.macs as only_c_macs {
input :
bamfile=control_bam,
pvalue="1e-9",
keep_dup="auto",
egs=egs.genomesize,
default_location='CONTROL/' + sub(basename(control_bam),'.sorted.b.*$','') + '/PEAKS_forQC/' + basename(control_bam,'.bam') + '-p9_kd-auto',
coverage_location='CONTROL/' + sub(basename(control_bam),'.sorted.b.*$','') + '/PEAKS_forQC/' + basename(control_bam,'.bam') + '-p9_kd-auto'
}
call bedtools.bamtobed as only_c_finalbed {
input:
bamfile=control_bam
}