-
Notifications
You must be signed in to change notification settings - Fork 15
/
TransPi.nf
3029 lines (2287 loc) · 146 KB
/
TransPi.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
/*
========================================================================================
TransPi
========================================================================================
Transcriptome Analysis Pipeline
Author: Ramón E. Rivera-Vicéns
GitHub: rivera10
----------------------------------------------------------------------------------------
*/
def helpMessage() {
log.info """
====================================================
TransPi - Transcriptome Analysis Pipeline v${workflow.manifest.version}
====================================================
Steps:
1- Run the `precheck_TransPi.sh` to set up the databases and tools (if neccesary) used by TransPi
2- Run TransPi
Usage:
nextflow run TransPi.nf TransPi_analysis_option other_options
Example usage:
nextflow run TransPi.nf --all --reads "/PATH/TO/READS/*_R[1,2].fastq.gz" --k 25,41,53 --maxReadLen 75
Manadatory arguments:
--all Run the entire pipeline (Assemblies, EvidentialGene, Annotation, etc.)
This option also requires arguments --reads, --k, and --maxReadLen
Example:
--reads "/PATH/TO/READS/*_R[1,2].fastq.gz" --k 25,35,55,75,85 --maxReadLen 150
NOTE: Use of quotes is needed for the reads PATH. Kmer list depends on read length.
--onlyAsm Run only the Assemblies and EvidentialGene analysis
This option also requires arguments --reads, --k, --maxReadLen
--onlyEvi Run only the Evidential Gene analysis
Transcriptome expected to be in a directory called "onlyEvi"
--onlyAnn Run only the Annotation analysis (starting from a final assembly)
Transcriptome expected to be in a directory called "onlyAnn"
Other options:
-profile Configuration profile to use. Can use multiple (comma separated)
test Run TransPi with a test dataset
conda Run TransPi with conda.
docker Run TransPi with docker container
singularity Run TransPi with singularity container with all the neccesary tools
TransPiContainer Run TransPi with a single container with all tools
--help Display this message
--fullHelp Display this message and examples for running TransPi
Output options:
--outdir Name of output directory. Default "results"
-w, -work Name of working directory. Default "work". Only one dash is needed for -work since it is a nextflow function.
--tracedir Name for directory to save pipeline trace files. Default "pipeline_info"
Additional analyses:
--rRNAfilter Remove rRNA from sequences. Requires option --rRNAdb
--rRNAdb PATH to database of rRNA sequences to use for filtering of rRNA. Default ""
--filterSpecies Perform psytrans filtering of transcriptome. Default "false" Requires options --host and --symbiont
--host PATH to host (or similar) protein file. Default ""
--symbiont PATH to symbionts (or similar) protein files. Default ""
--psyval Psytrans value to train model. Default "160"
--allBuscos Run BUSCO analysis in all assemblies. Default "false"
--buscoDist Generate BUSCO distribution analysis. Default "false"
--minPerc Mininmum percentage of assemblers require for the BUSCO distribution. Default ".70"
--shortTransdecoder Run Transdecoder without the homology searches. Default "false"
--withSignalP Include SignalP for the annotation. Needs manual installation of CBS-DTU tools. Default "false". Requires --signalp
--signalp PATH to SignalP software. Default ""
--withTMHMM Include TMHMM for the annotation. Needs manual installation of CBS-DTU tools. Default "false". Requires --tmhmm
--tmhmm PATH to TMHMM software. Default ""
--withRnammer Include Rnammer for the annotation. Needs manual installation of CBS-DTU tools. Default "false". Requires --rnam
--rnam PATH to Rnammer software. Default ""
Skip options:
--skipFastQC Skip FastQC step. Default "false"
--skipFilter Skip fastp filtering step. Default "false"
--skipKegg Skip kegg analysis. Default "false"
--skipReport Skip generation of final TransPi report. Default "false"
Others:
--minQual Minimum quality score for fastp filtering. Default "25"
--normMaxCov Normalization step maximun coverage. Default "100"
--normMinCov Normalization step minimum coverage. Default "1"
--pipeInstall PATH to TransPi directory. Default "". If precheck is used this will be added to the nextflow.config automatically.
--envCacheDir PATH for environment cache directory (either conda or containers). Default "Launch directory of pipeline"
--getRunInfo Get software versions and nexftflow run info. Default "false"
""".stripIndent()
}
def fullHelpMessage() {
log.info """
====================================================
TransPi - Transcriptome Analysis Pipeline v${workflow.manifest.version}
====================================================
Steps:
1- Run the `precheck_TransPi.sh` to set up the databases and tools (if neccesary) used by TransPi
2- Run TransPi
Usage:
nextflow run TransPi.nf TransPi_analysis_option other_options
Example usage:
nextflow run TransPi.nf --all --reads "/PATH/TO/READS/*_R[1,2].fastq.gz" --k 25,41,53 --maxReadLen 75
Manadatory arguments:
--all Run the entire pipeline (Assemblies, EvidentialGene, Annotation, etc.)
This option also requires arguments --reads, --k, and --maxReadLen
Example:
--reads "/PATH/TO/READS/*_R[1,2].fastq.gz" --k 25,35,55,75,85 --maxReadLen 150
NOTE: Use of quotes is needed for the reads PATH. Kmer list depends on read length.
--onlyAsm Run only the Assemblies and EvidentialGene analysis
This option also requires arguments --reads, --k, --maxReadLen
--onlyEvi Run only the Evidential Gene analysis
Transcriptome expected to be in a directory called "onlyEvi"
--onlyAnn Run only the Annotation analysis (starting from a final assembly)
Transcriptome expected to be in a directory called "onlyAnn"
Other options:
-profile Configuration profile to use. Can use multiple (comma separated)
test Run TransPi with a test dataset
conda Run TransPi with conda.
docker Run TransPi with docker container
singularity Run TransPi with singularity container with all the neccesary tools
TransPiContainer Run TransPi with a single container with all tools
--help Display this message
--fullHelp Display this message and examples for running TransPi
Output options:
--outdir Name of output directory. Default "results"
-w, -work Name of working directory. Default "work". Only one dash is needed for -work since it is a nextflow function.
--tracedir Name for directory to save pipeline trace files. Default "pipeline_info"
Additional analyses:
--rRNAfilter Remove rRNA from sequences. Requires option --rRNAdb
--rRNAdb PATH to database of rRNA sequences to use for filtering of rRNA. Default ""
--filterSpecies Perform psytrans filtering of transcriptome. Default "false" Requires options --host and --symbiont
--host PATH to host (or similar) protein file. Default ""
--symbiont PATH to symbionts (or similar) protein files. Default ""
--psyval Psytrans value to train model. Default "160"
--allBuscos Run BUSCO analysis in all assemblies. Default "false"
--buscoDist Generate BUSCO distribution analysis. Default "false"
--minPerc Mininmum percentage of assemblers require for the BUSCO distribution. Default ".70"
--shortTransdecoder Run Transdecoder without the homology searches. Default "false"
--withSignalP Include SignalP for the annotation. Needs manual installation of CBS-DTU tools. Default "false". Requires --signalp
--signalp PATH to SignalP software. Default ""
--withTMHMM Include TMHMM for the annotation. Needs manual installation of CBS-DTU tools. Default "false". Requires --tmhmm
--tmhmm PATH to TMHMM software. Default ""
--withRnammer Include Rnammer for the annotation. Needs manual installation of CBS-DTU tools. Default "false". Requires --rnam
--rnam PATH to Rnammer software. Default ""
Skip options:
--skipFastQC Skip FastQC step. Default "false"
--skipFilter Skip fastp filtering step. Default "false"
--skipKegg Skip kegg analysis. Default "false"
--skipReport Skip generation of final TransPi report. Default "false"
Others:
--minQual Minimum quality score for fastp filtering. Default "25"
--normMaxCov Normalization step maximun coverage. Default "100"
--normMinCov Normalization step minimum coverage. Default "1"
--pipeInstall PATH to TransPi directory. Default "". If precheck is used this will be added to the nextflow.config automatically.
--envCacheDir PATH for environment cache directory (either conda or containers). Default "Launch directory of pipeline"
--getRunInfo Get software versions and nexftflow run info. Default "false"
#################################################################################################
Various examples on how to deploy TransPi
#################################################################################################
I. Steps for running on a local cluster and individual conda installation by Nextflow
1- Run the `precheck_TransPi.sh` to set up the databases for TransPi
2- Run TransPi
Usage:
nextflow run TransPi.nf --all -profile conda OTHER_PARAMETERS_HERE
NOTE:
A conda environment will be created for each process.
#################################################################################################
II. Steps for running with docker
1- Run the `container_precheck_TransPi.sh` to set up the databases for TransPi
2- Run TransPi
Usage:
nextflow run TransPi.nf --all -profile docker OTHER_PARAMETERS_HERE
NOTE:
All necesary tools for running TransPi are pre-installed in the container
#################################################################################################
III. Steps for running with singualarity
1- Run the `container_precheck_TransPi.sh` to set up the databases for TransPi
2- Run TransPi
Usage:
nextflow run TransPi.nf --all -profile singularity OTHER_PARAMETERS_HERE
NOTE:
All necesary tools for running TransPi are pre-installed in the container
#################################################################################################
IV. Steps for running with a container engine and TransPi container.
1- Run the `precheck_TransPi.sh` to install tools, set up the databases and directories for TransPi
2- Run TransPi
Usage:
nextflow run TransPi.nf --all -profile singularity,TransPiContainer
NOTE:
This will run TransPi using a single container only.
#################################################################################################
V. Steps for running with multiple profiles.
1- Run the `precheck_TransPi.sh` to set up the databases for TransPi
2- Run TransPi
Usage:
nextflow run TransPi.nf --all -profile singularity,TransPiContainer,test
NOTE:
This will run TransPi using a test dataset, with singularity and the TransPi container.
#################################################################################################
""".stripIndent()
}
def workdir = System.getProperty("user.dir");
if (params.help) {
helpMessage()
exit 0
} else if (params.fullHelp) {
fullHelpMessage()
exit 0
}
def hasExtension(it, extension) {
it.toString().toLowerCase().endsWith(extension.toLowerCase())
}
def checkArgs() {
if (!params.k) {
println("\n\t\033[0;31mKmer list not specified.\n\tFor more info use `nextflow run TransPi.nf --help`\n\033[0m")
exit 0
}
if (!params.reads && !params.readsTest) {
println("\n\t\033[0;31mReads mandatory argument not specified.\n\tFor more info use `nextflow run TransPi.nf --help`\n\033[0m")
exit 0
}
if (!params.maxReadLen) {
println("\n\t\033[0;31mMax read length argument not specified.\n\tFor more info use `nextflow run TransPi.nf --help`\n\033[0m")
exit 0
}
}
if ((params.condaActivate && params.myConda) && (params.myCondaInstall == "" || params.cenv == "")) {
println("\n\t\033[0;31mNeed to specify the local conda installation in parameter \"myCondaInstall\" and \"cenv\" in the config file.\n\tFor more info use `nextflow run TransPi.nf --help`\n\033[0m")
exit 0
}
if (params.rRNAfilter) {
if (params.rRNAdb == "" || params.rRNAdb == true) {
println("\n\t\033[0;31mNeed to provide the PATH to the rRNA database.\n\tFor more info use `nextflow run TransPi.nf --help`\n\033[0m")
exit 0
}
}
if (params.all) {
log.info """\
====================================================
TransPi - Transcriptome Analysis Pipeline v${workflow.manifest.version}
====================================================
TransPi.nf Directory: ${projectDir}/TransPi.nf
Launch Directory: ${launchDir}
Results Directory: ${params.outdir}
Work Directory: ${workDir}
TransPi DBs: ${params.pipeInstall}
Uniprot DB: ${params.uniprot}
Busco DB: ${params.busco4db}
Reads Directory: ${params.reads}
Read Length: ${params.maxReadLen}
Kmers: ${params.k}
""".stripIndent()
checkArgs()
} else if (params.onlyAnn) {
log.info """\
====================================================
TransPi - Transcriptome Analysis Pipeline v${workflow.manifest.version}
====================================================
TransPi.nf Directory: ${projectDir}/TransPi.nf
Launch Directory: ${launchDir}
Results Directory: ${params.outdir}
Work Directory: ${workDir}
TransPi DBs: ${params.pipeInstall}
Uniprot DB: ${params.uniprot}
""".stripIndent()
} else if (params.onlyAsm) {
log.info """\
====================================================
TransPi - Transcriptome Analysis Pipeline v${workflow.manifest.version}
====================================================
TransPi.nf Directory: ${projectDir}/TransPi.nf
Launch Directory: ${launchDir}
Results Directory: ${params.outdir}
Work Directory: ${workDir}
TransPi DBs: ${params.pipeInstall}
Busco DB: ${params.busco4db}
Reads Directory: ${params.reads}
Read Length: ${params.maxReadLen}
Kmers: ${params.k}
""".stripIndent()
checkArgs()
} else if (params.onlyEvi){
log.info """\
====================================================
TransPi - Transcriptome Analysis Pipeline v${workflow.manifest.version}
====================================================
TransPi.nf Directory: ${projectDir}/TransPi.nf
Launch Directory: ${launchDir}
Results Directory: ${params.outdir}
Work Directory: ${workDir}
TransPi DBs: ${params.pipeInstall}
Busco DB: ${params.busco4db}
""".stripIndent()
}
if (params.readsTest) {
println("\n\tRunning TransPi with TEST dataset\n")
Channel
.from(params.readsTest)
.map{ row -> [ row[0], [ file(row[1][0],checkIfExists: true),file(row[2][0],checkIfExists: true) ] ] }
.ifEmpty{ exit 1, "params.readsTest was empty - no input files supplied" }
.into{ reads_ch; reads_qc_ch; report_reads }
} else {
println("\n\tRunning TransPi with your dataset\n")
if ( ( params.all || params.onlyAsm ) && !params.readsTest) {
Channel
.fromFilePairs("${params.reads}", checkIfExists: true)
.into{ reads_ch; reads_qc_ch; report_reads }
}
}
if (params.onlyAsm || params.onlyAnn || params.onlyEvi || params.all) {
if (params.onlyAsm || params.all) {
if (params.onlyAsm ) {
println("\n\tRunning assemblies and Evidential Gene analysis only \n")
} else if (params.all) {
println("\n\tRunning the full TransPi analysis\n")
}
if (!params.skipQC) {
process fasqc {
label 'low_cpus'
tag "${sample_id}"
publishDir "${params.outdir}/fastqc", mode: "copy", overwrite: true
publishDir "${workDir}/.versions", mode: "copy", overwrite: true, pattern: "*.version.txt"
conda (params.condaActivate && params.myConda ? params.localConda : params.condaActivate ? "-c conda-forge bioconda::fastqc=0.11.9=0" : null)
if (params.oneContainer){ container "${params.TPcontainer}" } else {
container (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container ? "https://depot.galaxyproject.org/singularity/fastqc:0.11.9--0" : "quay.io/biocontainers/fastqc:0.11.9--0")
}
input:
tuple sample_id, file(reads) from reads_qc_ch
output:
tuple sample_id, file("*_fastqc.{zip,html}") into fastqc_results
file("fastqc.version.txt") into fastqc_version
script:
"""
fastqc --quiet --threads $task.cpus $reads
v=\$( fastqc --version | sed -e "s/FastQC v//g" )
echo "FastQC: \$v" >fastqc.version.txt
"""
}
}
skip_filter_ch = Channel.create()
skip_filter_only_ch = Channel.create()
skip_norm_ch = Channel.create()
skip_busco_dist = Channel.create()
report_reads.into( skip_filter_ch, skip_filter_only_ch, skip_norm_ch, skip_busco_dist )
if (!params.skipFilter) {
process fastp {
label 'med_cpus'
tag "${sample_id}"
publishDir "${params.outdir}/filter", mode: "copy", overwrite: true, pattern: "*.fastp.{json,html}"
publishDir "${workDir}/.versions", mode: "copy", overwrite: true, pattern: "*.version.txt"
conda (params.condaActivate && params.myConda ? params.localConda : params.condaActivate ? "bioconda::fastp=0.20.1=h8b12597_0" : null)
if (params.oneContainer){ container "${params.TPcontainer}" } else {
container (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container ? "https://depot.galaxyproject.org/singularity/fastp:0.20.1--h8b12597_0" : "quay.io/biocontainers/fastp:0.20.1--h8b12597_0")
}
input:
tuple sample_id, file(reads) from reads_ch
output:
tuple sample_id, file("*.fastp.{json,html}") into fastp_results
tuple sample_id, file("${sample_id}.fastp.json") into fastp_stats_ch
tuple sample_id, file("*${sample_id}.filter.fq") into reads_rna_ch
tuple sample_id, file("left-${sample_id}.filter.fq"), file("right-${sample_id}.filter.fq") into save_filter_reads
file("fastp.version.txt") into fastp_version
script:
"""
fastp -i ${reads[0]} -I ${reads[1]} -o left-${sample_id}.filter.fq -O right-${sample_id}.filter.fq --detect_adapter_for_pe \
--average_qual ${params.minQual} --overrepresentation_analysis --html ${sample_id}.fastp.html --json ${sample_id}.fastp.json \
--thread ${task.cpus} --report_title ${sample_id}
v=\$( fastp --version 2>&1 | awk '{print \$2}' )
echo "fastp: \$v" >fastp.version.txt
"""
}
process fastp_stats {
label 'low_cpus'
tag "${sample_id}"
publishDir "${params.outdir}/filter", mode: "copy", overwrite: true, pattern: "*.fastp.{json,html}"
conda (params.condaActivate && params.myConda ? params.localConda : params.condaActivate ? "conda-forge::jq=1.6=h14c3975_1000 " : null)
if (params.oneContainer){ container "${params.TPcontainer}" } else {
container (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container ? "https://depot.galaxyproject.org/singularity/jq:1.6" : "quay.io/biocontainers/jq:1.6")
}
input:
tuple sample_id, file(json) from fastp_stats_ch
output:
tuple sample_id, file("*.csv") into fastp_csv
script:
"""
echo ${sample_id}
bash get_readstats.sh ${json}
bash get_readqual.sh ${json}
"""
}
if (params.saveReads) {
process save_filter_reads {
label 'med_cpus'
tag "${sample_id}"
publishDir "${params.outdir}/saveReads/filter", mode: "copy", overwrite: true, pattern: "*_R{1,2}.filter.fq.gz"
conda (params.condaActivate && params.myConda ? params.localConda : params.condaActivate ? "conda-forge::pigz=2.3.4=hed695b0_1" : null)
if (params.oneContainer){ container "${params.TPcontainer}" } else {
container (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container ? "https://depot.galaxyproject.org/singularity/pigz:2.3.4" : "quay.io/biocontainers/pigz:2.3.4")
}
input:
tuple sample_id, file(r1), file(r2) from save_filter_reads
output:
tuple sample_id, file("*.filter.fq.gz") into save_filter_reads_out
script:
"""
cat $r1 >${sample_id}_filter.R1.fq
cat $r2 >${sample_id}_filter.R2.fq
pigz --best --force -p ${task.cpus} -r ${sample_id}_filter.R1.fq
pigz --best --force -p ${task.cpus} -r ${sample_id}_filter.R2.fq
"""
}
}
} else {
reads_ch
.set{ reads_rna_ch }
fastp_results = Channel.empty()
}
if (params.rRNAfilter) {
process remove_rrna {
label 'med_mem'
tag "${sample_id}"
publishDir "${params.outdir}/rRNA_reads", mode: "copy", overwrite: true, pattern: "*.log"
publishDir "${workDir}/.versions", mode: "copy", overwrite: true, pattern: "*.version.txt"
conda (params.condaActivate && params.myConda ? params.localConda : params.condaActivate ? "bioconda::sortmerna=4.2.0" : null)
if (params.oneContainer){ container "${params.TPcontainer}" } else {
container (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container ? "https://depot.galaxyproject.org/singularity/sortmerna:4.2.0--0" : "quay.io/biocontainers/sortmerna:4.2.0--0")
}
input:
tuple sample_id, file(reads) from reads_rna_ch
output:
tuple sample_id, file("*rRNA.R*.fq") into reads_rna_ass
tuple sample_id, file("${sample_id}_rRNA_reads.R1.fq"), file("${sample_id}_rRNA_reads.R2.fq"), file("${sample_id}_no_rRNA.R1.fq"), file("${sample_id}_no_rRNA.R2.fq") into save_rrna_reads
tuple sample_id, file("${sample_id}_remove_rRNA.log") into remove_rrna_sum
file("sortmerna.version.txt") into sortmerna_version
script:
if (!params.skipFilter) {
"""
sortmerna --ref ${params.rRNAdb} --reads ${reads[0]} --reads ${reads[1]} --threads ${task.cpus} --aligned rRNAreads --other nonrRNAreads --paired_in --out2 --fastx --workdir .
mv rRNAreads.log ${sample_id}_remove_rRNA.log
mv rRNAreads_fwd* ${sample_id}_rRNA_reads.R1.fq
mv rRNAreads_rev* ${sample_id}_rRNA_reads.R2.fq
mv nonrRNAreads_fwd* ${sample_id}_no_rRNA.R1.fq
mv nonrRNAreads_rev* ${sample_id}_no_rRNA.R2.fq
v=\$( sortmerna -version | grep "SortMeRNA version" | awk '{print \$3}' )
echo "SortMeRNA: \$v" >sortmerna.version.txt
"""
} else {
"""
sortmerna --ref ${params.rRNAdb} --reads ${reads[0]} --reads ${reads[1]} --threads ${task.cpus} --aligned rRNAreads --other nonrRNAreads --paired_in --out2 --fastx --workdir .
mv rRNAreads.log ${sample_id}_remove_rRNA.log
mv rRNAreads_fwd* ${sample_id}_rRNA_reads.R1.fq
mv rRNAreads_rev* ${sample_id}_rRNA_reads.R2.fq
mv nonrRNAreads_fwd* ${sample_id}_no_rRNA.R1.fq
mv nonrRNAreads_rev* ${sample_id}_no_rRNA.R2.fq
v=\$( sortmerna -version | grep "SortMeRNA version" | awk '{print \$3}' )
echo "SortMeRNA: \$v" >sortmerna.version.txt
"""
}
}
if (params.saveReads) {
process save_rrna_reads {
label 'med_cpus'
tag "${sample_id}"
publishDir "${params.outdir}/saveReads/rRNA", mode: "copy", overwrite: true, pattern: "*.gz"
conda (params.condaActivate && params.myConda ? params.localConda : params.condaActivate ? "conda-forge::pigz=2.3.4=hed695b0_1" : null)
if (params.oneContainer){ container "${params.TPcontainer}" } else {
container (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container ? "https://depot.galaxyproject.org/singularity/pigz:2.3.4" : "quay.io/biocontainers/pigz:2.3.4")
}
input:
tuple sample_id, file(r1), file(r2), file(r3), file (r4) from save_rrna_reads
output:
tuple sample_id, file("*.gz") into save_rrna_reads_out
script:
"""
cat $r1 >${sample_id}_rRNA_reads.R1.fq
pigz --best --force -p ${task.cpus} -r ${sample_id}_rRNA_reads.R1.fq
cat $r2 >${sample_id}_rRNA_reads.R2.fq
pigz --best --force -p ${task.cpus} -r ${sample_id}_rRNA_reads.R2.fq
cat $r3 >${sample_id}_no_rRNA.R1.fq
pigz --best --force -p ${task.cpus} -r ${sample_id}_no_rRNA.R1.fq
cat $r4 >${sample_id}_no_rRNA.R2.fq
pigz --best --force -p ${task.cpus} -r ${sample_id}_no_rRNA.R2.fq
"""
}
}
} else {
reads_rna_ch
.into{ reads_rna_ass; skip_rna_ch }
process skip_rrna_removal {
tag "${sample_id}"
input:
tuple sample_id, file(files) from skip_rna_ch
output:
tuple sample_id, file("rrna_removal.txt") into remove_rrna_sum
script:
"""
echo "rRNA removal step was skipped" >rrna_removal.txt
"""
}
}
if (!params.skipNormalization) {
process normalize_reads {
label 'med_mem'
tag "${sample_id}"
conda (params.condaActivate && params.myConda ? params.localConda : params.condaActivate ? "-c conda-forge -c bioconda trinity=2.9.1=h8b12597_1" : null)
if (params.oneContainer){ container "${params.TPcontainer}" } else {
container (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container ? "https://depot.galaxyproject.org/singularity/trinity:2.9.1--h8b12597_1" : "quay.io/biocontainers/trinity:2.9.1--h8b12597_1")
}
input:
tuple sample_id, file(reads) from reads_rna_ass
output:
tuple sample_id, file("left-${sample_id}.norm.fq"), file("right-${sample_id}.norm.fq") into ( norm_reads_soap, norm_reads_velvet, norm_reads_trinity, norm_reads_spades, norm_reads_transabyss, reads_rna_quast )
tuple sample_id, file("left-${sample_id}.norm.fq"), file("right-${sample_id}.norm.fq") into ( mapping_reads_trinity, mapping_reads_evi, mapping_symbiont )
tuple sample_id, file("left-${sample_id}.norm.fq"), file("right-${sample_id}.norm.fq") into save_norm_reads
tuple sample_id, file("${sample_id}_normStats.txt") into norm_report
script:
//def mem=(task.memory)
//def mem_MB=(task.memory.toMega())
if (!params.skipFilter) {
"""
echo ${sample_id}
echo -e "\\n-- Starting Normalization --\\n"
mem=\$( echo ${task.memory} | cut -f 1 -d " " )
insilico_read_normalization.pl --seqType fq -JM \${mem}G --max_cov ${params.normMaxCov} --min_cov ${params.normMinCov} --left ${reads[0]} --right ${reads[1]} --pairs_together --PARALLEL_STATS --CPU ${task.cpus}
echo -e "\\n-- DONE with Normalization --\\n"
cat .command.out | grep "stats_file" -A 3 | tail -n 3 >${sample_id}_normStats.txt
cp left.norm.fq left-"${sample_id}".norm.fq
cp right.norm.fq right-"${sample_id}".norm.fq
rm \$(readlink -e left.norm.fq) \$(readlink -e right.norm.fq ) left.norm.fq right.norm.fq
"""
} else if (params.skipFilter && !params.rRNAfilter) {
"""
echo ${sample_id}
zcat ${reads[0]} >left-${sample_id}.fq &
zcat ${reads[1]} >right-${sample_id}.fq
echo -e "\\n-- Starting Normalization --\\n"
mem=\$( echo ${task.memory} | cut -f 1 -d " " )
insilico_read_normalization.pl --seqType fq -JM \${mem}G --max_cov ${params.normMaxCov} --min_cov ${params.normMinCov} --left left-${sample_id}.fq --right right-${sample_id}.fq --pairs_together --PARALLEL_STATS --CPU ${task.cpus}
echo -e "\\n-- DONE with Normalization --\\n"
cat .command.out | grep "stats_file" -A 3 | tail -n 3 >${sample_id}_normStats.txt
cp left.norm.fq left-"${sample_id}".norm.fq
cp right.norm.fq right-"${sample_id}".norm.fq
rm \$(readlink -e left.norm.fq) \$(readlink -e right.norm.fq ) left.norm.fq right.norm.fq
"""
}
}
if (params.saveReads) {
process save_norm_reads {
label 'med_cpus'
tag "${sample_id}"
publishDir "${params.outdir}/saveReads/normalization", mode: "copy", overwrite: true, pattern: "*.gz"
conda (params.condaActivate && params.myConda ? params.localConda : params.condaActivate ? "conda-forge::pigz=2.3.4=hed695b0_1" : null)
if (params.oneContainer){ container "${params.TPcontainer}" } else {
container (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container ? "https://depot.galaxyproject.org/singularity/pigz:2.3.4" : "quay.io/biocontainers/pigz:2.3.4")
}
input:
tuple sample_id, file(r1), file(r2) from save_norm_reads
output:
tuple sample_id, file("*.gz") into save_norm_reads_out
script:
"""
cat $r1 >${sample_id}_norm.R1.fq
pigz --best --force -p ${task.cpus} -r ${sample_id}_norm.R1.fq
cat $r2 >${sample_id}_norm.R2.fq
pigz --best --force -p ${task.cpus} -r ${sample_id}_norm.R2.fq
"""
}
}
}
if (params.skipFilter && params.skipNormalization) {
process prepare_reads {
label 'low_cpus'
tag "${sample_id}"
input:
tuple sample_id, file(reads) from reads_rna_ass
output:
tuple sample_id, file("left-${sample_id}.fq"), file("right-${sample_id}.fq") into ( norm_reads_soap, norm_reads_velvet, norm_reads_trinity, norm_reads_spades, norm_reads_transabyss, reads_rna_quast )
tuple sample_id, file("left-${sample_id}.fq"), file("right-${sample_id}.fq") into ( mapping_reads_trinity, mapping_reads_evi, mapping_symbiont )
script:
if (hasExtension(params.reads, 'gz')) {
"""
echo ${sample_id}
zcat ${reads[0]} >left-${sample_id}.fq &
zcat ${reads[1]} >right-${sample_id}.fq
"""
} else {
"""
echo ${sample_id}
cat ${reads[0]} >left-${sample_id}.fq &
cat ${reads[1]} >right-${sample_id}.fq
"""
}
}
process skip_filter {
tag "${sample_id}"
input:
tuple sample_id, file(files) from skip_filter_ch
output:
tuple sample_id, file("filter_reads.txt") into fastp_csv
script:
"""
echo "Filter step was skipped" >filter_reads.txt
"""
}
process skip_normalization {
tag "${sample_id}"
input:
tuple sample_id, file(files) from skip_norm_ch
output:
tuple sample_id, file("norm_reads.txt") into norm_report
script:
"""
echo "Normalization step was skipped" >norm_reads.txt
"""
}
} else if (!params.skipFilter && params.skipNormalization) {
//reads_rna_ass
// .into{ norm_reads_soap; norm_reads_velvet; norm_reads_trinity; norm_reads_spades; norm_reads_transabyss; reads_rna_quast; mapping_reads_trinity; mapping_reads_evi; mapping_symbiont }
process skip_normalization_only {
tag "${sample_id}"
input:
tuple sample_id, file(reads) from reads_rna_ass
output:
tuple sample_id, file("norm_reads.txt") into norm_report
tuple sample_id, file("left-${sample_id}.fq"), file("right-${sample_id}.fq") into norm_reads_soap, norm_reads_velvet, norm_reads_trinity, norm_reads_spades, norm_reads_transabyss, reads_rna_quast, mapping_reads_trinity, mapping_reads_evi, mapping_symbiont
script:
"""
echo "Normalization step was skipped" >norm_reads.txt
echo ${sample_id}
cat ${reads[0]} >left-${sample_id}.fq &
cat ${reads[1]} >right-${sample_id}.fq
"""
}
} else if (params.skipFilter && !params.skipNormalization) {
process skip_filter_only {
tag "${sample_id}"
input:
tuple sample_id, file(files) from skip_filter_only_ch
output:
tuple sample_id, file("filter_reads.txt") into fastp_csv
script:
"""
echo "Filter step was skipped" >filter_reads.txt
"""
}
}
process trinity_assembly {
label 'med_mem'
tag "${sample_id}"
publishDir "${params.outdir}/assemblies", mode: "copy", overwrite: true, pattern: "*.fa"
publishDir "${workDir}/.versions", mode: "copy", overwrite: true, pattern: "*.version.txt"
conda (params.condaActivate && params.myConda ? params.localConda : params.condaActivate ? "-c conda-forge bioconda::trinity=2.9.1=h8b12597_1" : null)
if (params.oneContainer){ container "${params.TPcontainer}" } else {
container (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container ? "https://depot.galaxyproject.org/singularity/trinity:2.9.1--h8b12597_1" : "quay.io/biocontainers/trinity:2.9.1--h8b12597_1")
}
input:
tuple sample_id, file(left), file(right) from norm_reads_trinity
output:
tuple sample_id, file("${sample_id}.Trinity.fa") into ( assemblies_ch_trinity, busco4_ch_trinity, assemblies_ch_trinity_busco4, mapping_trinity )
file("trinity.version.txt") into trinity_version
script:
"""
mem=\$( echo ${task.memory} | cut -f 1 -d " " )
Trinity --max_memory \${mem}G --seqType fq --left ${left} --right ${right} --CPU ${task.cpus} --no_normalize_reads --full_cleanup --output trinity_out_dir
mv trinity_out_dir.Trinity.fasta ${sample_id}.Trinity.fa
v=\$( Trinity --version | grep "version" | head -n 1 | cut -f 2 -d "-" | tr -d "v" )
echo "Trinity: \$v" >trinity.version.txt
"""
}
process soap_assembly {
label 'med_mem'
tag "${sample_id}"
publishDir "${params.outdir}/assemblies", mode: "copy", overwrite: true, pattern: "*.fa"
publishDir "${workDir}/.versions", mode: "copy", overwrite: true, pattern: "*.version.txt"
conda (params.condaActivate && params.myConda ? params.localConda : params.condaActivate ? "-c conda-forge bioconda::soapdenovo-trans=1.04=ha92aebf_2" : null)
if (params.oneContainer){ container "${params.TPcontainer}" } else {
container (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container ? "https://depot.galaxyproject.org/singularity/soapdenovo-trans:1.04--ha92aebf_2" : "quay.io/biocontainers/soapdenovo-trans:1.04--ha92aebf_2")
}
input:
val k from "${params.k}"
tuple sample_id, file(left), file(right) from norm_reads_soap
output:
tuple sample_id, file("${sample_id}.SOAP.fa") into assemblies_ch_soap
tuple sample_id, file("${sample_id}.SOAP.k*") into assemblies_ch_soap_busco4
file("soap.version.txt") into soap_version
script:
"""
echo -e "\\n-- Generating SOAP config file --\\n"
echo "maxReadLen="${params.maxReadLen} >>config.txt
echo "[LIB]" >>config.txt
echo "rd_len_cutof="${params.rd_len_cutof} >>config.txt
#echo "avg_ins="${params.avg_ins} >>config.txt
echo "reverse_seq="${params.reverse_seq} >>config.txt
echo "asm_flags="${params.asm_flags} >>config.txt
echo "map_len="${params.map_len} >>config.txt
echo "q1="${left} >>config.txt
echo "q2="${right} >>config.txt
echo -e "\\n-- Starting SOAP assemblies --\\n"
for x in `echo $k | tr "," " "`;do
echo -e "\\n-- SOAP k\${x} --\\n"
SOAPdenovo-Trans-127mer all -s config.txt -K \${x} -o output\${x} -p ${task.cpus}
sed -i "s/>/>SOAP.k\${x}./g" output\${x}.scafSeq
done
echo -e "\\n-- Finished with the assemblies --\\n"
cat output*.scafSeq >${sample_id}.SOAP.fa
for x in `echo $k | tr "," " "`;do
cp output\${x}.scafSeq ${sample_id}.SOAP.k\${x}.fa
done
rm -rf output*
v=\$( SOAPdenovo-Trans-127mer --version | grep "version" | awk '{print \$2,\$3}' | cut -f 1 -d ":" | cut -f 2 -d " " )
echo "SOAP: \$v" >soap.version.txt
"""
}
process velvet_oases_assembly {
label 'med_mem'
tag "${sample_id}"
publishDir "${params.outdir}/assemblies", mode: "copy", overwrite: true, pattern: "*.fa"
publishDir "${workDir}/.versions", mode: "copy", overwrite: true, pattern: "*.version.txt"
conda (params.condaActivate && params.myConda ? params.localConda : params.condaActivate ? "-c conda-forge -c bioconda velvet=1.2.10 oases=0.2.09" : null)
if (params.oneContainer){ container "${params.TPcontainer}" } else {
container (workflow.containerEngine == 'singularity' && !params.singularity_pull_docker_container ? "https://depot.galaxyproject.org/singularity/mulled-v2-8ce10492777ba3fb1db6e6e13fa9b78ac116db2f:f54a9246f1216443f2e0f6de9ec5908ca882f710-0" : "quay.io/biocontainers/mulled-v2-8ce10492777ba3fb1db6e6e13fa9b78ac116db2f:f54a9246f1216443f2e0f6de9ec5908ca882f710-0")
}
input:
val k from "${params.k}"
tuple sample_id, file(left), file(right) from norm_reads_velvet
output:
tuple sample_id, file("${sample_id}.Velvet.fa") into assemblies_ch_velvet
tuple sample_id, file("${sample_id}.Velvet.k*") into assemblies_ch_velvet_busco4
file("velvet_oases.versions.txt") into velvet_version
script:
"""
echo -e "\\n-- Starting with Velveth --\\n"
for x in `echo $k | tr "," " "`;do
echo -e "\\n-- k\${x} --\\n"
velveth oases.\${x} \${x} -shortPaired -fastq -separate ${left} ${right}
done
echo -e "\\n-- Starting with Velvetg --\\n"
for x in `echo $k | tr "," " "`;do
echo -e "\\n-- vg \${x} --\\n"
velvetg oases.\${x} -read_trkg yes
done
echo -e "\\n-- Starting with Oases --\\n"
for x in `echo $k | tr "," " "`;do
echo -e "\\n-- oases \${x} --\\n"
oases oases.\${x}
done
echo -e "\\n-- Finished with Velvet/Oases assemblies --\\n"
for x in `echo $k | tr "," " "`;do
sed -i "s/>/>Velvet.k\${x}./g" oases.\${x}/contigs.fa
done
cat oases.*/contigs.fa >${sample_id}.Velvet.fa
for x in `echo $k | tr "," " "`;do
cp oases.\${x}/contigs.fa ${sample_id}.Velvet.k\${x}.fa
done
rm -rf oases.*
v=\$( velveth | grep "Version" | cut -f 2 -d " " )
echo "Velveth: \$v" >velvet_oases.versions.txt
v=\$( velvetg | grep "Version" | cut -f 2 -d " " )
echo "Velvetg: \$v" >>velvet_oases.versions.txt
v=\$( oases | grep "Version" | cut -f 2 -d " " )
echo "Oases: \$v" >>velvet_oases.versions.txt
"""
}
process rna_spades_assembly {
label 'med_mem'
tag "${sample_id}"
publishDir "${params.outdir}/assemblies", mode: "copy", overwrite: true, pattern: "*.fa"
publishDir "${workDir}/.versions", mode: "copy", overwrite: true, pattern: "*.version.txt"