-
Notifications
You must be signed in to change notification settings - Fork 2
/
simple_innuca.nf
1104 lines (833 loc) · 40.5 KB
/
simple_innuca.nf
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
#!/usr/bin/env nextflow
import Helper
import CollectInitialMetadata
// Pipeline version
if (workflow.commitId){
version = "0.1 $workflow.revision"
} else {
version = "0.1 (local version)"
}
params.help = false
if (params.help){
Help.print_help(params)
exit 0
}
def infoMap = [:]
if (params.containsKey("fastq")){
infoMap.put("fastq", file(params.fastq).size())
}
if (params.containsKey("fasta")){
if (file(params.fasta) instanceof LinkedList){
infoMap.put("fasta", file(params.fasta).size())
} else {
infoMap.put("fasta", 1)
}
}
if (params.containsKey("accessions")){
// checks if params.accessions is different from null
if (params.accessions) {
BufferedReader reader = new BufferedReader(new FileReader(params.accessions));
int lines = 0;
while (reader.readLine() != null) lines++;
reader.close();
infoMap.put("accessions", lines)
}
}
Help.start_info(infoMap, "$workflow.start", "$workflow.profile")
CollectInitialMetadata.print_metadata(workflow)
// Placeholder for main input channels
if (!params.accessions){ exit 1, "'accessions' parameter missing" }
IN_accessions_raw = Channel.fromPath(params.accessions).ifEmpty { exit 1, "No accessions file provided with path:'${params.accessions}'" }
// Placeholder for secondary input channels
// Placeholder for extra input channels
// Placeholder to fork the raw input channel
IN_accessions_raw.set{ reads_download_in_1_0 }
if (params.asperaKey_1_1){
if (file(params.asperaKey_1_1).exists()){
IN_asperaKey_1_1 = Channel.fromPath(params.asperaKey_1_1)
} else {
IN_asperaKey_1_1 = Channel.value("")
}
} else {
IN_asperaKey_1_1 = Channel.value("")
}
process reads_download_1_1 {
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_1 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_1 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_1 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId reads_download_1_1 \"$params.platformSpecies\" true"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { accession_id }
publishDir "reads", pattern: "${accession_id}/*fq.gz"
maxRetries 1
input:
set val(accession_id), val(name) from reads_download_in_1_0.splitText(){ it.trim() }.unique().filter{ it != "" }.map{ it.split().length > 1 ? ["accession": it.split()[0], "name": it.split()[1]] : [it.split()[0], null] }
each file(aspera_key) from IN_asperaKey_1_1
output:
set val({ "$name" != "null" ? "$name" : "$accession_id" }), file("${accession_id}/*fq.gz") optional true into reads_download_out_1_0
set accession_id, val("1_1_reads_download"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_reads_download_1_1
set accession_id, val("reads_download_1_1"), val("1_1"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_reads_download_1_1
file ".versions"
script:
"""
{
# getSeqENA requires accession numbers to be provided as a text file
echo "${accession_id}" >> accession_file.txt
# Set default status value. It will be overwritten if anything goes wrong
echo "pass" > ".status"
if [ -f $aspera_key ]; then
asperaOpt="-a $aspera_key"
else
asperaOpt=""
fi
getSeqENA.py -l accession_file.txt \$asperaOpt -o ./ --SRAopt --downloadCramBam
# If a name has been provided along with the accession, rename the
# fastq files.
if [ $name != null ];
then
echo renaming pattern '${accession_id}' to '${name}' && cd ${accession_id} && rename "s/${accession_id}/${name}/" *.gz
fi
} || {
# If exit code other than 0
if [ \$? -eq 0 ]
then
echo "pass" > .status
else
echo "fail" > .status
echo "Could not download accession $accession_id" > .fail
fi
}
version_str="{'version':[{'program':'getSeqENA.py','version':'1.3'}]}"
echo \$version_str > .versions
"""
}
IN_genome_size_1_2 = Channel.value(params.genomeSize_1_2)
.map{it -> it.toString().isNumber() ? it : exit(1, "The genomeSize parameter must be a number or a float. Provided value: '${params.genomeSize_1_2}'")}
IN_depth_1_2 = Channel.value(params.depth_1_2)
.map{it -> it.toString().isNumber() ? it : exit(1, "The depth parameter must be a number or a float. Provided value: '${params.depth_1_2}'")}
IN_seed_1_2 = Channel.value(params.seed_1_2)
.map{it -> it.toString().isNumber() ? it : exit(1, "The seed parameter must be a number or a float. Provided value: '${params.seed_1_2}'")}
clear = params.clearInput_1_2 ? "true" : "false"
checkpointClear_1_2 = Channel.value(clear)
process downsample_fastq_1_2 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_2 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_2 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_2 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId downsample_fastq_1_2 \"$params.platformSpecies\" true"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { "${sample_id}" }
publishDir "results/downsample_fastq_1_2/", pattern: "_ss.*"
input:
set sample_id, file(fastq_pair) from reads_download_out_1_0
val gsize from IN_genome_size_1_2
val depth from IN_depth_1_2
val seed from IN_seed_1_2
val clear from checkpointClear_1_2
output:
set sample_id, file('*_ss.*') into downsample_fastq_out_1_1
set sample_id, val("1_2_downsample_fastq"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_downsample_fastq_1_2
set sample_id, val("downsample_fastq_1_2"), val("1_2"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_downsample_fastq_1_2
file ".versions"
script:
template "downsample_fastq.py"
}
IN_genome_size_1_3 = Channel.value(params.genomeSize_1_3)
.map{it -> it.toString().isNumber() ? it : exit(1, "The genomeSize parameter must be a number or a float. Provided value: '${params.genomeSize__1_3}'")}
IN_min_coverage_1_3 = Channel.value(params.minCoverage_1_3)
.map{it -> it.toString().isNumber() ? it : exit(1, "The minCoverage parameter must be a number or a float. Provided value: '${params.minCoverage__1_3}'")}
process integrity_coverage_1_3 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_3 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_3 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_3 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId integrity_coverage_1_3 \"$params.platformSpecies\" true"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
// This process can only use a single CPU
cpus 1
input:
set sample_id, file(fastq_pair) from downsample_fastq_out_1_1
val gsize from IN_genome_size_1_3
val cov from IN_min_coverage_1_3
// This channel is for the custom options of the integrity_coverage.py
// script. See the script's documentation for more information.
val opts from Channel.value('')
output:
set sample_id,
file(fastq_pair),
file('*_encoding'),
file('*_phred'),
file('*_coverage'),
file('*_max_len') into MAIN_integrity_1_3
file('*_report') optional true into LOG_report_coverage1_1_3
set sample_id, val("1_3_integrity_coverage"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_integrity_coverage_1_3
set sample_id, val("integrity_coverage_1_3"), val("1_3"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_integrity_coverage_1_3
file ".versions"
script:
template "integrity_coverage.py"
}
// TRIAGE OF CORRUPTED SAMPLES
LOG_corrupted_1_3 = Channel.create()
MAIN_PreCoverageCheck_1_3 = Channel.create()
// Corrupted samples have the 2nd value with 'corrupt'
MAIN_integrity_1_3.choice(LOG_corrupted_1_3, MAIN_PreCoverageCheck_1_3) {
a -> a[2].text == "corrupt" ? 0 : 1
}
// TRIAGE OF LOW COVERAGE SAMPLES
integrity_coverage_out_1_2 = Channel.create()
SIDE_phred_1_3 = Channel.create()
SIDE_max_len_1_3 = Channel.create()
MAIN_PreCoverageCheck_1_3
// Low coverage samples have the 4th value of the Channel with 'fail'
.filter{ it[4].text != "fail" }
// For the channel to proceed with FastQ in 'sample_good' and the
// Phred scores for each sample in 'SIDE_phred'
.separate(integrity_coverage_out_1_2, SIDE_phred_1_3, SIDE_max_len_1_3){
a -> [ [a[0], a[1]], [a[0], a[3].text], [a[0], a[5].text] ]
}
/** REPORT_COVERAGE - PLUG-IN
This process will report the expected coverage for each non-corrupted sample
and write the results to 'reports/coverage/estimated_coverage_initial.csv'
*/
process report_coverage_1_3 {
// This process can only use a single CPU
cpus 1
publishDir 'reports/coverage_1_3/'
input:
file(report) from LOG_report_coverage1_1_3.filter{ it.text != "corrupt" }.collect()
output:
file 'estimated_coverage_initial.csv'
"""
echo Sample,Estimated coverage,Status >> estimated_coverage_initial.csv
cat $report >> estimated_coverage_initial.csv
"""
}
/** REPORT_CORRUPT - PLUG-IN
This process will report the corrupted samples and write the results to
'reports/corrupted/corrupted_samples.txt'
*/
process report_corrupt_1_3 {
// This process can only use a single CPU
cpus 1
publishDir 'reports/corrupted_1_3/'
input:
val sample_id from LOG_corrupted_1_3.collect{it[0]}
output:
file 'corrupted_samples.txt'
"""
echo ${sample_id.join(",")} | tr "," "\n" >> corrupted_samples.txt
"""
}
SIDE_phred_1_3.set{ SIDE_phred_1_4 }
// Check sliding window parameter
if ( params.trimSlidingWindow_1_4.toString().split(":").size() != 2 ){
exit 1, "'trimSlidingWindow_1_4' parameter must contain two values separated by a ':'. Provided value: '${params.trimSlidingWindow_1_4}'"
}
if ( !params.trimLeading_1_4.toString().isNumber() ){
exit 1, "'trimLeading_1_4' parameter must be a number. Provide value: '${params.trimLeading_1_4}'"
}
if ( !params.trimTrailing_1_4.toString().isNumber() ){
exit 1, "'trimTrailing_1_4' parameter must be a number. Provide value: '${params.trimTrailing_1_4}'"
}
if ( !params.trimMinLength_1_4.toString().isNumber() ){
exit 1, "'trimMinLength_1_4' parameter must be a number. Provide value: '${params.trimMinLength_1_4}'"
}
IN_trimmomatic_opts_1_4 = Channel.value([params.trimSlidingWindow_1_4,params.trimLeading_1_4,params.trimTrailing_1_4,params.trimMinLength_1_4])
IN_adapters_1_4 = Channel.value(params.adapters_1_4)
clear = params.clearInput_1_4 ? "true" : "false"
checkpointClear_1_4 = Channel.value(clear)
process fastqc_1_4 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_4 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_4 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_4 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId fastqc_trimmomatic_1_4 \"$params.platformSpecies\" true"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
publishDir "reports/fastqc_1_4/", pattern: "*.html"
input:
set sample_id, file(fastq_pair) from integrity_coverage_out_1_2
val ad from Channel.value('None')
output:
set sample_id, file(fastq_pair), file('pair_1*'), file('pair_2*') into MAIN_fastqc_out_1_4
file "*html"
set sample_id, val("1_4_fastqc"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_fastqc_1_4
set sample_id, val("fastqc_1_4"), val("1_4"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_fastqc_1_4
file ".versions"
script:
template "fastqc.py"
}
/** FASTQC_REPORT - MAIN
This process will parse the result files from a FastQC analyses and output
the optimal_trim information for Trimmomatic
*/
process fastqc_report_1_4 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_4 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_4 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_4 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId fastqc_trimmomatic_1_4 \"$params.platformSpecies\" false"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
// This process can only use a single CPU
cpus 1
publishDir 'reports/fastqc_1_4/run_1/', pattern: '*summary.txt', mode: 'copy'
input:
set sample_id, file(fastq_pair), file(result_p1), file(result_p2) from MAIN_fastqc_out_1_4
val opts from Channel.value("--ignore-tests")
output:
set sample_id, file(fastq_pair), 'optimal_trim', ".status" into _MAIN_fastqc_trim_1_4
file '*_trim_report' into LOG_trim_1_4
file "*_status_report" into LOG_fastqc_report_1_4
file "${sample_id}_*_summary.txt" optional true
set sample_id, val("1_4_fastqc_report"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_fastqc_report_1_4
set sample_id, val("fastqc_report_1_4"), val("1_4"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_fastqc_report_1_4
file ".versions"
script:
template "fastqc_report.py"
}
MAIN_fastqc_trim_1_4 = Channel.create()
_MAIN_fastqc_trim_1_4
.filter{ it[3].text == "pass" }
.map{ [it[0], it[1], file(it[2]).text] }
.into(MAIN_fastqc_trim_1_4)
/** TRIM_REPORT - PLUG-IN
This will collect the optimal trim points assessed by the fastqc_report
process and write the results of all samples in a single csv file
*/
process trim_report_1_4 {
publishDir 'reports/fastqc_1_4/', mode: 'copy'
input:
file trim from LOG_trim_1_4.collect()
output:
file "FastQC_trim_report.csv"
"""
echo Sample,Trim begin, Trim end >> FastQC_trim_report.csv
cat $trim >> FastQC_trim_report.csv
"""
}
process compile_fastqc_status_1_4 {
publishDir 'reports/fastqc_1_4/', mode: 'copy'
input:
file rep from LOG_fastqc_report_1_4.collect()
output:
file 'FastQC_1run_report.csv'
"""
echo Sample, Failed? >> FastQC_1run_report.csv
cat $rep >> FastQC_1run_report.csv
"""
}
/** TRIMMOMATIC - MAIN
This process will execute trimmomatic. Currently, the main channel requires
information on the trim_range and phred score.
*/
process trimmomatic_1_4 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_4 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_4 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_4 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId fastqc_trimmomatic_1_4 \"$params.platformSpecies\" false"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
publishDir "results/trimmomatic_1_4", pattern: "*.gz"
input:
set sample_id, file(fastq_pair), trim_range, phred from MAIN_fastqc_trim_1_4.join(SIDE_phred_1_4)
val opts from IN_trimmomatic_opts_1_4
val ad from IN_adapters_1_4
val clear from checkpointClear_1_4
output:
set sample_id, "${sample_id}_*trim.fastq.gz" into fastqc_trimmomatic_out_1_3
file 'trimmomatic_report.csv'
set sample_id, val("1_4_trimmomatic"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_trimmomatic_1_4
set sample_id, val("trimmomatic_1_4"), val("1_4"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_trimmomatic_1_4
file ".versions"
script:
template "trimmomatic.py"
}
IN_genome_size_1_5 = Channel.value(params.genomeSize_1_5)
.map{it -> it.toString().isNumber() ? it : exit (1, "The genomeSize parameter must be a number or a float. Provided value: '${params.genomeSize_1_5}'")}
IN_min_coverage_1_5 = Channel.value(params.minCoverage_1_5)
.map{it -> it.toString().isNumber() ? it : exit (1, "The minCoverage parameter must be a number or a float. Provided value: '${params.minCoverage_1_5}'")}
process integrity_coverage2_1_5 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_5 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_5 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_5 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId check_coverage_1_5 \"$params.platformSpecies\" true"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
cpus 1
input:
set sample_id, file(fastq_pair) from fastqc_trimmomatic_out_1_3
val gsize from IN_genome_size_1_5
val cov from IN_min_coverage_1_5
// Use -e option for skipping encoding guess
val opts from Channel.value('-e')
output:
set sample_id,
file(fastq_pair),
file('*_coverage'),
file('*_max_len') optional true into MAIN_integrity_1_5
file('*_report') into LOG_report_coverage_1_5
set sample_id, val("1_5_check_coverage"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_check_coverage_1_5
set sample_id, val("check_coverage_1_5"), val("1_5"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_check_coverage_1_5
file ".versions"
script:
template "integrity_coverage.py"
}
check_coverage_out_1_4 = Channel.create()
SIDE_max_len_1_5 = Channel.create()
MAIN_integrity_1_5
.filter{ it[2].text != "fail" }
.separate(check_coverage_out_1_4, SIDE_max_len_1_5){
a -> [ [a[0], a[1]], [a[0], a[3].text]]
}
process report_coverage2_1_5 {
// This process can only use a single CPU
cpus 1
publishDir 'reports/coverage_1_5/'
input:
file(report) from LOG_report_coverage_1_5.filter{ it.text != "corrupt" }.collect()
output:
file 'estimated_coverage_second.csv'
"""
echo Sample,Estimated coverage,Status >> estimated_coverage_second.csv
cat $report >> estimated_coverage_second.csv
"""
}
SIDE_max_len_1_5.set{ SIDE_max_len_1_7 }
IN_adapters_1_6 = Channel.value(params.adapters_1_6)
process fastqc2_1_6 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_6 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_6 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_6 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId fastqc_1_6 \"$params.platformSpecies\" true"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
publishDir "reports/fastqc_1_6/", pattern: "*.html"
input:
set sample_id, file(fastq_pair) from check_coverage_out_1_4
val ad from IN_adapters_1_6
output:
set sample_id, file(fastq_pair), file('pair_1*'), file('pair_2*') into MAIN_fastqc_out_1_6
file "*html"
set sample_id, val("1_6_fastqc2"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_fastqc2_1_6
set sample_id, val("fastqc2_1_6"), val("1_6"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_fastqc2_1_6
file ".versions"
script:
template "fastqc.py"
}
process fastqc2_report_1_6 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_6 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_6 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_6 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId fastqc_1_6 \"$params.platformSpecies\" false"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
// This process can only use a single CPU
cpus 1
publishDir 'reports/fastqc_1_6/run_2/', pattern: '*summary.txt', mode: 'copy'
input:
set sample_id, file(fastq_pair), file(result_p1), file(result_p2) from MAIN_fastqc_out_1_6
val opts from Channel.value("")
output:
set sample_id, file(fastq_pair), '.status' into MAIN_fastqc_report_1_6
file "*_status_report" into LOG_fastqc_report_1_6
file "${sample_id}_*_summary.txt" optional true
set sample_id, val("1_6_fastqc2_report"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_fastqc2_report_1_6
set sample_id, val("fastqc2_report_1_6"), val("1_6"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_fastqc2_report_1_6
file ".versions"
script:
template "fastqc_report.py"
}
process compile_fastqc_status2_1_6 {
publishDir 'reports/fastqc_1_6/', mode: 'copy'
input:
file rep from LOG_fastqc_report_1_6.collect()
output:
file 'FastQC_2run_report.csv'
"""
echo Sample, Failed? >> FastQC_2run_report.csv
cat $rep >> FastQC_2run_report.csv
"""
}
_fastqc_out_1_5 = Channel.create()
MAIN_fastqc_report_1_6
.filter{ it[2].text == "pass" }
.map{ [it[0], it[1]] }
.into(_fastqc_out_1_5)
_fastqc_out_1_5.into{ fastqc_out_1_5;_LAST_fastq_1_8 }
if ( !params.spadesMinCoverage_1_7.toString().isNumber() ){
exit 1, "'spadesMinCoverage_1_7' parameter must be a number. Provided value: '${params.spadesMinCoverage_1_7}'"
}
if ( !params.spadesMinKmerCoverage_1_7.toString().isNumber()){
exit 1, "'spadesMinKmerCoverage_1_7' parameter must be a number. Provided value: '${params.spadesMinKmerCoverage_1_7}'"
}
IN_spades_opts_1_7 = Channel.value(
[params.spadesMinCoverage_1_7,
params.spadesMinKmerCoverage_1_7
])
if ( params.spadesKmers_1_7.toString().split(" ").size() <= 1 ){
if (params.spadesKmers_1_7.toString() != 'auto'){
exit 1, "'spadesKmers_1_7' parameter must be a sequence of space separated numbers or 'auto'. Provided value: ${params.spadesKmers_1_7}"
}
}
IN_spades_kmers_1_7 = Channel.value(params.spadesKmers_1_7)
clear = params.clearInput_1_7 ? "true" : "false"
disable_rr = params.disableRR_1_7 ? "true" : "false"
checkpointClear_1_7 = Channel.value(clear)
disableRR_1_7 = Channel.value(disable_rr)
process spades_1_7 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_7 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_7 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_7 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId spades_1_7 \"$params.platformSpecies\" true"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
publishDir 'results/assembly/spades_1_7/', pattern: '*_spades*.fasta', mode: 'copy'
publishDir "results/assembly/spades_1_7/$sample_id", pattern: "*.gfa", mode: "copy"
publishDir "results/assembly/spades_1_7/$sample_id", pattern: "*.fastg", mode: "copy"
input:
set sample_id, file(fastq_pair), max_len from fastqc_out_1_5.join(SIDE_max_len_1_7)
val opts from IN_spades_opts_1_7
val kmers from IN_spades_kmers_1_7
val clear from checkpointClear_1_7
val disable_rr from disableRR_1_7
output:
set sample_id, file('*_spades*.fasta') into spades_out_1_6
file "*.fastg" optional true
file "*.gfa" into gfa1_1_7
set sample_id, val("1_7_spades"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_spades_1_7
set sample_id, val("spades_1_7"), val("1_7"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_spades_1_7
file ".versions"
script:
template "spades.py"
}
if ( !params.minAssemblyCoverage_1_8.toString().isNumber() ){
if (params.minAssemblyCoverage_1_8.toString() != 'auto'){
exit 1, "'minAssemblyCoverage_1_8' parameter must be a number or 'auto'. Provided value: ${params.minAssemblyCoverage_1_8}"
}
}
if ( !params.AMaxContigs_1_8.toString().isNumber() ){
exit 1, "'AMaxContigs_1_8' parameter must be a number. Provide value: '${params.AMaxContigs_1_8}'"
}
IN_assembly_mapping_opts_1_8 = Channel.value([params.minAssemblyCoverage_1_8,params.AMaxContigs_1_8])
IN_genome_size_1_8 = Channel.value(params.genomeSize_1_8)
process assembly_mapping_1_8 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_8 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_8 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_8 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId assembly_mapping_1_8 \"$params.platformSpecies\" true"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
input:
set sample_id, file(assembly), file(fastq) from spades_out_1_6.join(_LAST_fastq_1_8)
output:
set sample_id, file(assembly), 'coverages.tsv', 'coverage_per_bp.tsv', 'sorted.bam', 'sorted.bam.bai' into MAIN_am_out_1_8
set sample_id, file("coverage_per_bp.tsv") optional true into SIDE_BpCoverage_1_8
set sample_id, val("1_8_assembly_mapping"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_assembly_mapping_1_8
set sample_id, val("assembly_mapping_1_8"), val("1_8"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_assembly_mapping_1_8
file ".versions"
script:
"""
{
echo [DEBUG] BUILDING BOWTIE INDEX FOR ASSEMBLY: $assembly >> .command.log 2>&1
bowtie2-build --threads ${task.cpus} $assembly genome_index >> .command.log 2>&1
echo [DEBUG] MAPPING READS FROM $fastq >> .command.log 2>&1
bowtie2 -q --very-sensitive-local --threads ${task.cpus} -x genome_index -1 ${fastq[0]} -2 ${fastq[1]} -S mapping.sam >> .command.log 2>&1
echo [DEBUG] CONVERTING AND SORTING SAM TO BAM >> .command.log 2>&1
samtools sort -o sorted.bam -O bam -@ ${task.cpus} mapping.sam && rm *.sam >> .command.log 2>&1
echo [DEBUG] CREATING BAM INDEX >> .command.log 2>&1
samtools index sorted.bam >> .command.log 2>&1
echo [DEBUG] ESTIMATING READ DEPTH >> .command.log 2>&1
parallel -j ${task.cpus} samtools depth -ar {} sorted.bam \\> {}.tab ::: \$(grep ">" $assembly | cut -c 2- | tr " " "_")
# Insert 0 coverage count in empty files. See Issue #2
echo [DEBUG] REMOVING EMPTY FILES >> .command.log 2>&1
find . -size 0 -print0 | xargs -0 -I{} sh -c 'echo -e 0"\t"0"\t"0 > "{}"'
echo [DEBUG] COMPILING COVERAGE REPORT >> .command.log 2>&1
parallel -j ${task.cpus} echo -n {.} '"\t"' '&&' cut -f3 {} '|' paste -sd+ '|' bc >> coverages.tsv ::: *.tab
cat *.tab > coverage_per_bp.tsv
rm *.tab
if [ -f "coverages.tsv" ]
then
echo pass > .status
else
echo fail > .status
fi
echo -n "" > .report.json
echo -n "" > .versions
} || {
echo fail > .status
}
"""
}
/** PROCESS_ASSEMBLY_MAPPING - MAIN
Processes the results from the assembly_mapping process and filters the
assembly contigs based on coverage and length thresholds.
*/
process process_assembly_mapping_1_8 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_8 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_8 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_8 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId assembly_mapping_1_8 \"$params.platformSpecies\" false"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
// This process can only use a single CPU
cpus 1
input:
set sample_id, file(assembly), file(coverage), file(coverage_bp), file(bam_file), file(bam_index) from MAIN_am_out_1_8
val opts from IN_assembly_mapping_opts_1_8
val gsize from IN_genome_size_1_8
output:
set sample_id, '*_filt.fasta', 'filtered.bam', 'filtered.bam.bai' into assembly_mapping_out_1_7
set sample_id, val("1_8_process_am"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_process_am_1_8
set sample_id, val("process_am_1_8"), val("1_8"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_process_am_1_8
file ".versions"
script:
template "process_assembly_mapping.py"
}
SIDE_BpCoverage_1_8.set{ SIDE_BpCoverage_1_9 }
clear = params.clearInput_1_9 ? "true" : "false"
checkpointClear_1_9 = Channel.value(clear)
process pilon_1_9 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_9 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_9 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_9 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId pilon_1_9 \"$params.platformSpecies\" true"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
echo false
publishDir 'results/assembly/pilon_1_9/', mode: 'copy', pattern: "*.fasta"
input:
set sample_id, file(assembly), file(bam_file), file(bam_index) from assembly_mapping_out_1_7
val clear from checkpointClear_1_9
output:
set sample_id, '*_polished.fasta' into pilon_out_1_8, pilon_report_1_9
set sample_id, val("1_9_pilon"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_pilon_1_9
set sample_id, val("pilon_1_9"), val("1_9"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_pilon_1_9
file ".versions"
script:
"""
{
pilon_mem=${String.valueOf(task.memory).substring(0, String.valueOf(task.memory).length() - 1).replaceAll("\\s", "")}
java -jar -Xms256m -Xmx\${pilon_mem} /NGStools/pilon-1.22.jar --genome $assembly --frags $bam_file --output ${assembly.name.replaceFirst(~/\.[^\.]+$/, '')}_polished --changes --threads $task.cpus >> .command.log 2>&1
echo pass > .status
if [ "$clear" = "true" ];
then
work_regex=".*/work/.{2}/.{30}/.*"
assembly_file=\$(readlink -f \$(pwd)/${assembly})
bam_file=\$(readlink -f \$(pwd)/${bam_file})
if [[ "\$assembly_file" =~ \$work_regex ]]; then
rm \$assembly_file \$bam_file
fi
fi
} || {
echo fail > .status
}
"""
}
process pilon_report_1_9 {
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh"
afterScript "report_POST.sh $params.projectId $params.pipelineId 1_9 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId pilon_1_9 \"$params.platformSpecies\" false"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh"
}
tag { sample_id }
input:
set sample_id, file(assembly), file(coverage_bp) from pilon_report_1_9.join(SIDE_BpCoverage_1_9)
output:
file "*_assembly_report.csv" into pilon_report_out_1_9
set sample_id, val("1_9_pilon_report"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_pilon_report_1_9
set sample_id, val("pilon_report_1_9"), val("1_9"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_pilon_report_1_9
file ".versions"
script:
template "assembly_report.py"
}
process compile_pilon_report_1_9 {
publishDir "reports/assembly/pilon_1_9/", mode: 'copy'
input:
file(report) from pilon_report_out_1_9.collect()
output:
file "pilon_assembly_report.csv"
"""
echo Sample,Number of contigs,Average contig size,N50,Total assembly length,GC content,Missing data > pilon_assembly_report.csv
cat $report >> pilon_assembly_report.csv
"""
}
process mlst_1_10 {
// Send POST request to platform
if ( params.platformHTTP != null ) {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; export PATH; set_dotfiles.sh; startup_POST.sh $params.projectId $params.pipelineId 1_10 $params.platformHTTP"
afterScript "final_POST.sh $params.projectId $params.pipelineId 1_10 $params.platformHTTP; report_POST.sh $params.projectId $params.pipelineId 1_10 $params.sampleName $params.reportHTTP $params.currentUserName $params.currentUserId mlst_1_10 \"$params.platformSpecies\" true"
} else {
beforeScript "PATH=${workflow.projectDir}/bin:\$PATH; set_dotfiles.sh"
}
tag { sample_id }
// This process can only use a single CPU
cpus 1
input:
set sample_id, file(assembly) from pilon_out_1_8
output:
file '*.mlst.txt' into LOG_mlst_1_10
set sample_id, file(assembly), file(".status") into MAIN_mlst_out_1_10
set sample_id, val("1_10_mlst"), file(".status"), file(".warning"), file(".fail"), file(".command.log") into STATUS_mlst_1_10
set sample_id, val("mlst_1_10"), val("1_10"), file(".report.json"), file(".versions"), file(".command.trace") into REPORT_mlst_1_10
file ".versions"
script:
"""
{
expectedSpecies=${params.mlstSpecies_1_10}
mlst $assembly >> ${sample_id}.mlst.txt
mlstSpecies=\$(cat *.mlst.txt | cut -f2)
json_str="{'expectedSpecies':\'\$expectedSpecies\',\
'species':'\$mlstSpecies',\
'st':'\$(cat *.mlst.txt | cut -f3)',\
'tableRow':[{'sample':'${sample_id}','data':[\
{'header':'MLST species','value':'\$mlstSpecies','table':'typing'},\
{'header':'MLST ST','value':'\$(cat *.mlst.txt | cut -f3)','table':'typing'}]}]}"
echo \$json_str > .report.json
if [ ! \$mlstSpecies = \$expectedSpecies ];
then
printf fail > .status
else
printf pass > .status
fi
} || {
printf fail > .status
}
"""
}
process compile_mlst_1_10 {
publishDir "results/annotation/mlst_1_10/"
input:
file res from LOG_mlst_1_10.collect()
output:
file "mlst_report.tsv"
script:
"""
cat $res >> mlst_report.tsv
"""
}
mlst_out_1_9 = Channel.create()
MAIN_mlst_out_1_10
.filter{ it[2].text != "fail" }
.map{ [it[0], it[1]] }
.set{ mlst_out_1_9 }
/** STATUS
Reports the status of a sample in any given process.
*/
process status {
tag { sample_id }
publishDir "pipeline_status/$task_name"
input:
set sample_id, task_name, status, warning, fail, file(log) from STATUS_reads_download_1_1.mix(STATUS_downsample_fastq_1_2,STATUS_integrity_coverage_1_3,STATUS_fastqc_1_4,STATUS_fastqc_report_1_4,STATUS_trimmomatic_1_4,STATUS_check_coverage_1_5,STATUS_fastqc2_1_6,STATUS_fastqc2_report_1_6,STATUS_spades_1_7,STATUS_assembly_mapping_1_8,STATUS_process_am_1_8,STATUS_pilon_1_9,STATUS_pilon_report_1_9,STATUS_mlst_1_10)
output:
file '*.status' into master_status
file '*.warning' into master_warning
file '*.fail' into master_fail
file '*.log'
"""
echo $sample_id, $task_name, \$(cat $status) > ${sample_id}_${task_name}.status
echo $sample_id, $task_name, \$(cat $warning) > ${sample_id}_${task_name}.warning
echo $sample_id, $task_name, \$(cat $fail) > ${sample_id}_${task_name}.fail
echo "\$(cat .command.log)" > ${sample_id}_${task_name}.log
"""