This repository has been archived by the owner on Jul 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy pathmain.nf
1810 lines (1512 loc) · 83.1 KB
/
main.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
/*
========================================================================================
samba
========================================================================================
samba Analysis Pipeline.
#### Homepage / Documentation
https://github.com/ifremer-bioinformatics/samba
----------------------------------------------------------------------------------------
*/
def helpMessage() {
// Add to this help message with new command line parameters
log.info SeBiMERHeader()
log.info"""
Usage:
The typical command for running the pipeline after filling the conf/custom.config file is as follows:
nextflow run main.nf -profile <docker,singularity,conda>,custom
Mandatory arguments:
--excel_sample_file [file] Path to XLS input file containing two sheets named "manifest" and "metadata".
or
--input_metadata [file] Path to input file with project samples metadata (csv format).
--input_manifest [file] Path to input file with samples reads files paths (csv format).
-profile [str] Configuration profile to use. Can use multiple (comma separated).
Available: conda, docker, singularity, test, custom.
Generic:
--singleEnd [bool] Set to true to specify that the inputs are single-end reads.
--longreads [bool] Set to true to specify that the inputs are long reads (Nanopore/Pacbio) (default = false for illumina short reads).
--compress_result [bool] Zip the final result directory (default = true)
Other options
--outdir [path] The output directory where the results will be saved.
-w/--work-dir The temporary directory where intermediate data will be saved.
--email [email] Set this parameter to your e-mail address to get a summary e-mail with details of the run sent to you when the workflow exits
--email_on_fail [email] Same as --email, except only send mail if the workflow is not successful
-name [str] Name for the pipeline run. If not specified, Nextflow will automatically generate a random mnemonic.
--projectName [str] Name of the project being analyzed.
Data integrity:
--data_integrity_enable [bool] Data integrity checking step. Set to false to deactivate this step. (default = true)
--primer_filter [str] Percentage of primers supposed to be found in raw reads (default : 70).
Raw reads cleaning:
--cutadapt_enable [bool] Primer removal process. Set to false to deactivate this step. (default = true)
--primerF [str] Forward primer (to be used in Cutadapt cleaning step).
--primerR [str] Reverse primer (to be used in Cutadapt cleaning step).
--errorRate [str] Cutadapt error rate allowed to match primers (default : 0.1).
--overlap [str] Cutadapt overlaping length between primer and read (default : 18 for test dataset, must be changed for user dataset).
ASVs inference:
--FtrimLeft [str] The number of nucleotides to remove from the start of each forward read (default : 0 = no trimming).
--RtrimLeft [str] The number of nucleotides to remove from the start of each reverse read (default : 0 = no trimming).
--FtruncLen [str] Truncate forward reads after FtruncLen bases. Reads shorter than this are discarded (default : 0 = no trimming).
--RtruncLen [str] Truncate reverse reads after RtruncLen bases. Reads shorter than this are discarded (default : 0 = no trimming).
--FmaxEE [str] Forward reads with higher than maxEE "expected errors" will be discarded (default = 2).
--RmaxEE [str] Reverse with higher than maxEE "expected errors" will be discarded (default = 2).
--minQ [str] Truncate reads at the first instance of a quality score less than or equal to minQ (default = 2).
--chimeras [str] Chimera detection method : default = "consensus". Set to "pooled" if the samples in the sequence table are all pooled together for bimera identification.
Merge ASVs tables:
--dada2merge [bool] Set to true to merge DADA2 ASVs tables.
--merge_tabledir [path] Path to the directory containing the ASVs tables to merge (this directory must contain only the ASVs tables to merge).
--merge_repseqsdir [path] Path to the directory containing the representative sequences to merge (this directory must constain only the representative sequences to merge).
Distribution based-clustering:
--dbotu3_enable [bool] Distribution based-clustering step. Set to false to deactivate this step. (default = true)
--gen_crit [str] dbotu3 Genetic criterion (default = 0.1).
--abund_crit [str] dbotu3 Abundance criterion (default = 10).
--pval_crit [str] dbotu3 P-value criterion (default = 0.0005).
Taxonomic assignation:
--extract_db [bool] Set to true to extract specific region from reference database (default = false)
--seqs_db [file] Path to reference database (required if extract_db = true).
--taxo_db [file] Path to taxonomic reference database (required if extract_db = true).
--database [file] Path to preformatted QIIME2 format database (required if extract_db = false).
--confidence [str] Confidence threshold for limiting taxonomic depth. Set to "disable" to disable confidence calculation, or 0 to calculate confidence but not apply it to limit the taxonomic depth of the assignments (default = 0.9).
Taxonomy filtering:
--filtering_tax_enable [bool] Set to true to filter asv table and sequences based on taxonomic assignation (default = false)
--tax_to_exclude [str] List of taxa you want to exclude (comma-separated list).
--tax_to_include [str] List of taxa you want to include (comma-separated list).
Decontamination:
--microDecon_enable [bool] Sample decontamination step. Set to true to activate this step. (default = false)
--control_list [str] Comma separated list of control samples (e.g : "sample1,sample4,sample7") (required if microDecon_enable = true).
--nb_controls [str] Number of control sample listed (required if microDecon_enable = true).
--nb_samples [str] Number of samples that are not control samples (required if microDecon_enable = true).
Predict functionnal abundance:
--picrust2_enable [bool] Set to true to enable functionnal prediction step. (default = false)
--picrust_var [str] According to your metadata file, list the column names corresponding to the variables to group samples for functional predictions (comma-separated list).
--method [str] HSP method of your choice. (default = 'mp' ) The most accurate prediction methode. Faster method: 'pic'.
--nsti [str] Max NSTI value accepted. (default = 2) NSTI cut-off of 2 should eliminate junk sequences.
Differential abundance testing:
--ancom_var [str] According to your metadata file, list the column names corresponding to the variables to group samples for ANCOM analysis (comma-separated list).
Samples removing:
--remove_sample [bool] Set to true to enable samples removing. (default = false)
--sample_to_remove [str] List of samples you to remove (comma-separated list).
Statistics:
--stats_alpha_enable [bool] Set to false to deactivate Alpha diversity statistics step. (default = true)
--stats_beta_enable [bool] Set to false to deactivate Beta diversity statistics steps. (default = true)
--stats_desc_comp_enable [bool] Set to false to deactivate Descriptive comparisons steps. (default = true)
--kingdom [str] Kingdom to be displayed in barplots.
--taxa_nb [str] Number of taxa to be displayed in barplots.
--alpha_div_group [str] According to your metadata file, list the column names corresponding to the variables to group samples for Alpha diversity (comma-separated list).
--beta_div_var [str] According to your metadata file, select the column name corresponding to the variable of interest for Beta diversity (comma-separated list).
--desc_comp_crit [str] According to your metadata file, select the column name corresponding to the variable of interest for Descriptive comparisons graphs (comma-separated list).
--hc_method [str] Hierarchical clustering method (default = 'ward.D2').
--stats_only [bool] Perform only statistical analysis (ASV table and newick tree required). Set to true to activate. (default = false)
--inasv_table [file] if stats_only is activated, set the path to your own ASV table in tsv format.
--innewick [file] if stats_only is activated, set the path to your own phylogenetic tree in newick format.
Final analysis report:
--report_enable [bool] Set to false to deactivate report creation. (default = true)
Long reads options:
--lr_type [str] Long reads technology. For pacbio, [map-pb] and for nanopore, [map-ont]
--lr_tax_fna [file] Path to reference database indexed with Minimap2 (required).
--lr_taxo_flat [file] Path to taxonomic reference file (required).
--lr_rank [int] Minimal rank level to keep a hit as assigned [5]. 1:Kingdom, 2:Phylum, 3:Class, 4:Order, 5:Family, 6:Genus, 7:Species
""".stripIndent()
}
// Show help message
if (params.help) {
helpMessage()
exit 0
}
/*
* SET UP CONFIGURATION VARIABLES
*/
import java.text.SimpleDateFormat
def d = new Date()
def dtFormat = "dd/MM/yyyy"
def date = d.format(dtFormat, TimeZone.getTimeZone('GMT+2'))
// Has the run name been specified by the user?
// this has the bonus effect of catching both -name and --name
custom_runName = params.name
if (!(workflow.runName ==~ /[a-z]+_[a-z]+/)) {
custom_runName = workflow.runName
}
//Copy config files to output directory for each run
paramsfile = file("$baseDir/conf/base.config", checkIfExists: true)
paramsfile.copyTo("$params.outdir/conf/base.config")
if (workflow.profile.contains('shortreadstest')) {
testparamsfile = file("$baseDir/conf/shortreadstest.config", checkIfExists: true)
testparamsfile.copyTo("$params.outdir/conf/shortreadstest.config")
}
if (workflow.profile.contains('longreadstest')) {
testparamsfile = file("$baseDir/conf/longreadstest.config", checkIfExists: true)
testparamsfile.copyTo("$params.outdir/conf/longreadstest.config")
}
if (workflow.profile.contains('custom')) {
customparamsfile = file("$baseDir/conf/custom.config", checkIfExists: true)
customparamsfile.copyTo("$params.outdir/conf/custom.config")
}
// If XLS is used as input file
if (!params.excel_sample_file.isEmpty()) {
excel_sample_file_ch = Channel.fromPath(params.excel_sample_file, checkIfExists:true)
}
//If only running the stats processes of the pipeline
if (params.stats_only) {
if (!params.inasv_table || params.inasv_table.isEmpty()) {
log.error "Parameter --inasv_table cannot be null or empty. Set the path to the ASV count table"
exit 1
} else {
inasv_table_ch = Channel.fromPath(params.inasv_table, checkIfExists:true)
.set { tsv_only }
}
if (!params.innewick || params.innewick.isEmpty()) {
log.error "Parameter --innewick cannot be null or empty. Set the path to the newick tree"
exit 1
} else {
newick_ch = Channel.fromPath(params.innewick, checkIfExists:true)
.set { newick_only }
}
//Force to false other processes options
params.dada2merge = false
params.data_integrity_enable = false
params.cutadapt_enable = false
params.dbotu3_enable = false
params.filtering_tax_enable = false
params.microDecon_enable = false
params.picrust2_enable = false
} else {
params.inasv_table = ""
params.innewick = ""
inasv_table_ch = Channel.empty()
newick_ch = Channel.empty()
}
//If pipeline runs for merging dada2 data
if (params.dada2merge) {
if (!params.merge_tabledir || params.merge_tabledir.isEmpty()) {
log.error "Parameter --merge_tabledir cannot be null or empty. Set the path to the folder with ASV tables to merge"
exit 1
} else {
dada2merge_tabledir_ch = Channel.fromPath(params.merge_tabledir, checkIfExists:true)
}
if (!params.merge_repseqsdir || params.merge_repseqsdir.isEmpty()) {
log.error "Parameter --merge_repseqsdir cannot be null or empty. Set the path to the folder with ASV sequences to merge"
exit 1
} else {
dada2merge_repseqsdir_ch = Channel.fromPath(params.merge_repseqsdir, checkIfExists:true)
}
//Force to false other processes options
params.data_integrity_enable = false
params.cutadapt_enable = false
params.dbotu3_enable = false
params.filtering_tax_enable = false
params.microDecon_enable = false
params.picrust2_enable = false
params.stats_only = false
} else {
params.merge_tabledir = ""
params.merge_repseqsdir = ""
dada2merge_tabledir_ch = Channel.empty()
dada2merge_repseqsdir_ch = Channel.empty()
}
//If taxonomy step require to extract primer regions
if (!params.longreads && !params.stats_only) {
if (params.extract_db) {
if (!params.seqs_db || params.seqs_db.isEmpty()) {
log.error "Parameter --seqs_db cannot be null or empty. Set the path to the reference sequences"
exit 1
}
if (!params.taxo_db || params.taxo_db.isEmpty()) {
log.error "Parameter --taxo_db cannot be null or empty. Set the path to the reference taxonomy"
exit 1
}
} else {
if (!params.database || params.database.isEmpty()) {
log.error "Parameter --database cannot be null or empty. Set the path to the reference database"
}
}
}
if (params.microDecon_enable && !params.control_list) {
log.error "ERROR : A comma separated list of control samples (--control_list) must be set."
exit 1
}
if (params.longreads) {
//Force to false other processes options
params.data_integrity_enable = false
params.cutadapt_enable = false
params.qiime2 = false
params.dada2merge = false
params.dbotu3_enable = false
params.filtering_tax_enable = false
params.microDecon_enable = false
params.ancom_enable = false
params.asv = false
params.picrust2_enable = false
// Initialized variables not used in long reads analysis
params.primerF = ""
params.primerR = ""
params.errorRate = ""
params.overlap = ""
params.FtrimLeft = ""
params.RtrimLeft = ""
params.FtruncLen = ""
params.RtruncLen = ""
params.FmaxEE = ""
params.RmaxEE = ""
params.minQ = ""
params.chimeras = ""
params.database = ""
params.seqs_db = ""
params.taxo_db = ""
params.tax_to_exclude = ""
params.nb_controls = ""
params.nb_samples = ""
params.remove_sample = false
params.sample_to_remove = ""
params.ancom_var = ""
} else {
// Initialized variables not used in short reads analysis
params.lr_rank = ""
params.lr_type = ""
params.lr_tax_fna = ""
params.lr_taxo_flat = ""
}
if (!params.microDecon_enable) {
params.nb_controls = "0"
params.nb_samples = ""
params.control_list = "none"
}
if (!params.stats_alpha_enable) {
params.alpha_div_group = ""
params.kingdom = ""
params.taxa_nb = ""
}
if (!params.stats_beta_enable) {
params.beta_div_var = ""
params.hc_method = ""
}
if (!params.stats_desc_comp_enable) {
params.desc_comp_crit = ""
params.desc_comp_tax_level = ""
}
if (!params.filtering_tax_enable) {
params.tax_to_exclude = ""
}
if (!params.remove_sample) {
params.sample_to_remove = ""
}
if (!params.extract_db) {
params.seqs_db = ""
params.taxo_db = ""
}
if (!params.picrust2_enable) {
params.picrust_var = ""
params.method = ""
params.nsti = ""
}
/*
* PIPELINE INFO
*/
// Header log info
log.info SeBiMERHeader()
def summary = [:]
if (workflow.revision) summary['Pipeline Release'] = workflow.revision
summary['Run Name'] = custom_runName ?: workflow.runName
summary['Project Name'] = params.projectName
if (!params.excel_sample_file.isEmpty()) {
summary['Sample File'] = params.excel_sample_file
} else {
summary['Manifest File'] = params.input_manifest
summary['Metadata File'] = params.input_metadata
}
summary['Data Type'] = params.singleEnd ? 'Single-End' : 'Paired-End'
if (workflow.containerEngine) summary['Container'] = "$workflow.containerEngine"
summary['Output dir'] = params.outdir
summary['Launch dir'] = workflow.launchDir
summary['Working dir'] = workflow.workDir
summary['Script dir'] = workflow.projectDir
summary['User'] = workflow.userName
summary['Config Profile'] = workflow.profile
if (params.stats_only) summary['Stats only'] = "Pipeline running only statistics processes"
if (params.data_integrity_enable) summary['Data integrity'] = "Data integrity checking process enabled"
if (params.cutadapt_enable) summary['Primer removal'] = "Primer removal process enabled"
if (params.dbotu3_enable) summary['Clustering'] = "Distribution based-clustering process enabled"
if (params.filtering_tax_enable) summary['Tax filtering'] = "Filtering ASV table and sequences based on taxonomic assignation"
if (params.microDecon_enable) summary['Decontamination'] = "Sample decontamination process enabled"
if (params.dada2merge) summary['Dada2 merge'] = "Dada2 merge process enabled"
if (params.picrust2_enable) summary['Prediction'] = "Functionnal prediction process enabled"
if (params.ancom_enable) summary['Ancom'] = "Differential abundance ANCOM analysis process enabled"
if (params.stats_alpha_enable) summary['Alpha div'] = "Alpha diversity indexes process enabled"
if (params.stats_beta_enable) summary['Beta div'] = "Beta diversity statistics processes enabled"
if (params.stats_desc_comp_enable) summary["Desc comp"] = "Descriptive comparisons statistics process enabled"
if (params.longreads) summary["Long reads"] = "Going to run long reads processes"
if (params.email || params.email_on_fail) {
summary['E-mail Address'] = params.email
summary['E-mail on failure'] = params.email_on_fail
}
log.info summary.collect { k,v -> "${k.padRight(18)}: $v" }.join("\n")
log.info "-\033[2m--------------------------------------------------\033[0m-"
// Check the hostnames against configured profiles
checkHostname()
Channel.from(summary.collect{ [it.key, it.value] })
.map { k,v -> "<dt>$k</dt><dd><samp>${v ?: '<span style=\"color:#999999;\">N/A</a>'}</samp></dd>" }
.reduce { a, b -> return [a, b].join("\n ") }
.map { x -> """
id: 'samba-summary'
description: " - this information is collected when the pipeline is started."
section_name: 'samba Workflow Summary'
section_href: 'https://github.com/ifremer-bioinformatics/samba'
plot_type: 'html'
data: |
<dl class=\"dl-horizontal\">
$x
</dl>
""".stripIndent() }
.set { ch_workflow_summary }
// Check the hostnames against configured profiles
checkHostname()
/*
* STEP 0 - Get test data if running in test profile
*/
if (workflow.profile.contains('test')) {
process get_test_data {
label 'internet_access'
output :
file 'data_is_ready' into ready_excel2tsv, ready_integrity, ready_import, ready_lr
file 'manifest' into testmanifest
file 'metadata' into testmetadata
when :
!params.stats_only && !params.dada2merge
script :
def datatype = params.longreads ? "longreads" : "shortreads"
"""
get_test_data.sh ${baseDir} 'data_is_ready' ${datatype} 'manifest' 'metadata' &> get_test_data.log 2>&1
"""
}
if (!params.stats_only || !params.dada2merge) {
if (params.longreads) {
testmetadata.set { metadata4stats }
} else {
testmanifest.into { manifest ; manifest4integrity }
testmetadata.into { metadata4dada2 ; metadata4dbotu3 ; metadata_filtering_tax ; metadata4stats ; metadata4integrity ; metadata4picrust2 ; metadata4ancom }
}
}
} else {
data_ready = Channel.value("none")
data_ready.into { ready_excel2tsv ; ready_integrity ; ready_import ; ready_lr}
if (params.excel_sample_file.isEmpty()) {
if (!params.stats_only || !params.dada2merge) {
// Check if input metadata file exits
if (!params.input_metadata || params.input_metadata.isEmpty()) {
log.error "Parameter --input_metadata cannot be null or empty. Set the path to the Metadata file."
exit 1
} else {
Channel.fromPath(params.input_metadata, checkIfExists:true)
.into { metadata4dada2 ; metadata4dbotu3 ; metadata_filtering_tax ; metadata4stats ; metadata4integrity ; metadata4picrust2 ; metadata4ancom }
}
if (!params.input_manifest || params.input_manifest.isEmpty()) {
log.error "Parameter --input_manifest cannot be null or empty. Set the path to the Manifest file."
exit 1
} else {
Channel.fromPath(params.input_manifest, checkIfExists:true)
.into { manifest ; manifest4integrity }
}
} else {
Channel.empty().into { manifest ; manifest4integrity }
}
}
}
/*
* STEP 1 - Checking data integrity
*/
if (!params.longreads) {
if (!params.excel_sample_file.isEmpty()) {
/* Format Excel file to tsv */
process excel2tsv {
label 'biopython_env'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: 'q2_manifest.sort.tsv'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: 'q2_metadata.sort.tsv'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: 'excel2tsv.log'
input :
file xls from excel_sample_file_ch
file ready from ready_excel2tsv
output :
file "q2_metadata.sort.tsv" into metadata_xls
file "q2_manifest.sort.tsv" into manifest_xls
file "excel2tsv.log"
when :
!params.stats_only && !params.dada2merge
script :
def datatype = params.singleEnd ? "single" : "paired"
"""
excel2tsv.py -x ${xls} -s ${datatype} &> excel2tsv.log 2>&1
"""
}
}
integrity_manifest = params.excel_sample_file.isEmpty() ? manifest4integrity : manifest_xls
integrity_metadata = params.excel_sample_file.isEmpty() ? metadata4integrity : metadata_xls
if (params.data_integrity_enable) {
/* Check data integrity */
process data_integrity {
label 'biopython_env'
publishDir "${params.outdir}/${params.data_integrity_dirname}", mode: 'copy', pattern: 'data_integrity.txt'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: 'data_integrity.txt'
publishDir "${params.outdir}/${params.data_integrity_dirname}", mode: 'copy', pattern: '*.sort'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: '*.sort'
input :
file manifest from integrity_manifest
file metadata from integrity_metadata
file ready from ready_integrity
output :
file 'data_integrity.txt'
file "q2_metadata.sort.tsv" into metadata_sort
file "q2_manifest.sort.tsv" into manifest_sort
when :
params.data_integrity_enable && !params.stats_only && !params.dada2merge
script :
def datatype = params.singleEnd ? "single" : "paired"
"""
data_integrity.py -e ${metadata} -a ${manifest} -p ${params.primer_filter} -s ${datatype} -t ${task.cpus} -c ${params.control_list} &> data_integrity.log 2>&1
"""
}
metadata_sort.into { metadata4dada2 ; metadata4dbotu3 ; metadata_filtering_tax ; metadata4stats ; metadata4picrust2 ; metadata4ancom }
manifest_sort.set { manifest }
} else {
metadata_xls.into { metadata4dada2 ; metadata4dbotu3 ; metadata_filtering_tax ; metadata4stats ; metadata4picrust2 ; metadata4ancom }
manifest_xls.set { manifest }
}
/*
* STEP 2 - Import metabarcoding data into QIIME2 object
*/
process q2_import {
label 'qiime2_env1cpu'
publishDir "${params.outdir}/${params.import_dirname}", mode: 'copy', pattern: 'data.qz*'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: '*_output'
publishDir "${params.outdir}/${params.report_dirname}/version", mode: 'copy', pattern: 'v_*.txt'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern : 'completecmd', saveAs : { complete_cmd_import -> "cmd/${task.process}_complete.sh" }
input :
file q2_manifest from manifest
file ready from ready_import
output :
file 'data.qza' into imported_data
file 'data.qzv' into imported_visu
file 'import_output' into imported_output
file 'completecmd' into complete_cmd_import
file 'v_qiime2.txt' into qiime2_version
when :
!params.stats_only && !params.dada2merge
script :
"""
q2_import.sh ${params.singleEnd} ${q2_manifest} data.qza data.qzv import_output completecmd &> q2_import.log 2>&1
qiime --version|grep 'q2cli'|cut -d' ' -f3 > v_qiime2.txt
"""
}
/*
* STEP 3 - Trim metabarcode data with cutadapt
*/
if (params.cutadapt_enable) {
process q2_cutadapt {
label 'qiime2_env'
publishDir "${params.outdir}/${params.trimmed_dirname}", mode: 'copy', pattern: 'data*.qz*'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: '*_output'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern : 'completecmd', saveAs : { complete_cmd_cutadapt -> "cmd/${task.process}_complete.sh" }
input :
file imported_data from imported_data
output :
file 'data_trimmed.qza' into trimmed_data
file 'data_trimmed.qzv' into trimmed_visu
file 'trimmed_output' into trimmed_output
file 'completecmd' into complete_cmd_cutadapt
when :
params.cutadapt_enable && !params.stats_only && !params.dada2merge
script :
"""
q2_cutadapt.sh ${params.singleEnd} ${task.cpus} ${imported_data} ${params.primerF} ${params.primerR} ${params.errorRate} ${params.overlap} data_trimmed.qza data_trimmed.qzv trimmed_output completecmd &> q2_cutadapt.log 2>&1
"""
}
}
dada2_input = params.cutadapt_enable ? trimmed_data : imported_data
/*
* STEP 4 - Dada2 ASVs inference
*/
process q2_dada2 {
label 'qiime2_env'
publishDir "${params.outdir}/${params.dada2_dirname}", mode: 'copy', pattern: '*.qz*'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: '*_output'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern : 'completecmd', saveAs : { complete_cmd_dada2 -> "cmd/${task.process}_complete.sh" }
input :
file dada2_input from dada2_input
file metadata from metadata4dada2
output :
file 'rep_seqs.qza' into dada2_seqs_dbotu3, dada2_seqs_taxo, dada2_seqs_filtering_tax, dada2_seqs_decontam, dada2_seqs_phylo, dada2_seqs_picrust2, dada2_seqs_ancom
file 'rep_seqs.qzv' into visu_repseps
file 'table.qza' into dada2_table_dbotu3, dada2_table_filtering_tax, dada2_table_picrust2, dada2_table_ancom
file 'table.qzv' into visu_table
file 'stats.qza' into stats_table
file 'stats.qzv' into visu_stats
file 'dada2_output' into dada2_output
file 'completecmd' into complete_cmd_dada2
when :
!params.stats_only && !params.dada2merge
script :
"""
q2_dada2.sh ${params.singleEnd} ${dada2_input} ${metadata} rep_seqs.qza rep_seqs.qzv table.qza table.qzv stats.qza stats.qzv dada2_output ${params.FtrimLeft} ${params.RtrimLeft} ${params.FtruncLen} ${params.RtruncLen} ${params.FmaxEE} ${params.RmaxEE} ${params.minQ} ${params.chimeras} ${task.cpus} completecmd &> q2_dada2.log 2>&1
"""
}
/*
* STEP 5 - Distribution based-clustering with dbotu3
*/
if (params.dbotu3_enable) {
/* Run dbotu3 */
process q2_dbotu3 {
label 'qiime2_env'
publishDir "${params.outdir}/${params.dbotu3_dirname}", mode: 'copy', pattern: '*.qz*'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: '*_output'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern : 'completecmd', saveAs : { complete_cmd_dbotu3 -> "cmd/${task.process}_complete.sh" }
input :
file table from dada2_table_dbotu3
file seqs from dada2_seqs_dbotu3
file metadata from metadata4dbotu3
output :
file 'dbotu3_details.txt' into dbotu3_details
file 'dbotu3_seqs.qza' into dbotu3_seqs_decontam, dbotu3_seqs_taxo, dbotu3_seqs_filtering_tax, dbotu3_seqs_phylo, dbotu3_seqs_picrust2, dbotu3_seqs_ancom
file 'dbotu3_seqs.qzv' into dbotu3_seqs_visu
file 'dbotu3_table.qza' into dbotu3_table, dbotu3_table_filtering_tax, dbotu3_table_picrust2, dbotu3_table_ancom
file 'dbotu3_table.qzv' into dbotu3_table_visu
file 'dbotu3_output' into dbotu3_output
file 'completecmd' into complete_cmd_dbotu3
when :
!params.stats_only && !params.dada2merge && params.dbotu3_enable
script :
"""
q2_dbotu3.sh ${table} ${seqs} ${metadata} dbotu3_details.txt dbotu3_seqs.qza dbotu3_seqs.qzv dbotu3_table.qza dbotu3_table.qzv dbotu3_output ${params.gen_crit} ${params.abund_crit} ${params.pval_crit} completecmd &> q2_dbotu3.log 2>&1
"""
}
}
/*
* STEP 6 - Use Dada2 merge to merge ASVs tables and sequences
*/
if (params.dada2merge) {
Channel.fromPath(params.input_metadata, checkIfExists:true)
.set { metadata_merge_ch }
process q2_dada2_merge {
label 'qiime2_env'
publishDir "${params.outdir}/${params.dada2_dirname}/merged", mode: 'copy', pattern: '*.qza'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: 'dada2_output'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern : 'completecmd', saveAs : { complete_cmd_dada2merge -> "cmd/${task.process}_complete.sh" }
input :
path table_dir from dada2merge_tabledir_ch
path seq_dir from dada2merge_repseqsdir_ch
path metadata_merge from metadata_merge_ch
output :
file 'merged_table.qza' into merge_table_picrust2, merge_table_ancom
file 'merged_seq.qza' into merge_seqs_taxo, merge_seqs_phylo, merge_seqs_picrust2, merge_seqs_ancom
file 'dada2_output' into dada2merge_output
file 'completecmd' into complete_cmd_dada2merge
when :
params.dada2merge
script :
"""
q2_merge.sh ${table_dir} ${seq_dir} merged_table.qza merged_seq.qza ${metadata_merge} merged_table.qzv dada2_output merged_seq.qzv completecmd &> q2_merge.log 2>&1
"""
}
}
outputA = params.dada2merge ? dada2merge_output : dada2_output
output_ch = params.dbotu3_enable ? dbotu3_output : outputA
output_ch.into { taxonomy_output ; decontam_output }
seqs_taxoA = params.dada2merge ? merge_seqs_taxo : dada2_seqs_taxo
seqs_taxo = params.dbotu3_enable ? dbotu3_seqs_taxo : seqs_taxoA
/*
* STEP 7 - Run taxonomy assignment
*/
process q2_taxonomy {
label 'qiime2_highRAM'
publishDir "${params.outdir}/${params.taxo_dirname}", mode: 'copy', pattern: '*.qz*'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: 'taxo_output'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: 'ASV_taxonomy.tsv'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: 'ASV_table*'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern : 'completecmd', saveAs : { complete_cmd_taxo -> "cmd/${task.process}_complete.sh" }
input :
file repseqs_taxo from seqs_taxo
file summary_output from taxonomy_output
output :
file 'taxonomy.qza' into data_taxonomy_filtering_tax, data_taxonomy_ancom
file 'taxonomy.qzv' into visu_taxonomy
file 'ASV_taxonomy.tsv' into taxonomy_tsv, taxonomy_tsv_filtering_tax
file 'taxo_output' into taxo_output
file 'ASV_table_with_taxonomy.biom' into biom
file 'ASV_table_with_taxonomy.tsv' into biom_tsv, biom_tsv_decontam
file 'taxonomic_database.qza' optional true into trained_database
file 'seqs_db_amplicons.qza' optional true into seqs_db_filtered
file 'completecmd' into complete_cmd_taxo
when :
!params.stats_only
script :
"""
q2_taxo.sh ${task.cpus} ${params.extract_db} ${params.primerF} ${params.primerR} ${params.confidence} ${repseqs_taxo} taxonomy.qza taxonomy.qzv taxo_output ASV_taxonomy.tsv ${summary_output} ASV_table_with_taxonomy.biom ASV_table_with_taxonomy.tsv taxonomic_database.qza seqs_db_amplicons.qza completecmd tmpdir ${params.database} ${params.seqs_db} ${params.taxo_db} &> q2_taxo.log 2>&1
"""
}
asv_table = params.dbotu3_enable ? dbotu3_table_filtering_tax : dada2_table_filtering_tax
asv_seq = params.dbotu3_enable ? dbotu3_seqs_filtering_tax : dada2_seqs_filtering_tax
/*
* STEP 8 - Filtering ASVs based on taxonomy assignment
*/
if (params.filtering_tax_enable) {
process q2_filtering_tax {
label 'qiime2_env'
publishDir "${params.outdir}/${params.tax_filtering_dirname}", mode: 'copy', pattern: '*.qz*'
publishDir "${params.outdir}/${params.report_dirname}/tax_filtering", mode: 'copy', pattern: 'tax_filtered_table_with_tax.*'
publishDir "${params.outdir}/${params.report_dirname}/tax_filtering", mode: 'copy', pattern: 'tax_filtered_output'
publishDir "${params.outdir}/${params.report_dirname}/version", mode: 'copy', pattern: 'v_*.txt'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern : 'completecmd', saveAs : { complete_cmd_filtering_tax -> "cmd/${task.process}_complete.sh" }
input :
file asv_table from asv_table
file asv_tax from data_taxonomy_filtering_tax
file asv_seq from asv_seq
file asv_tax_tsv from taxonomy_tsv_filtering_tax
file metadata from metadata_filtering_tax
output :
file 'tax_filtered_table.qza' into tax_filtered_table, tax_filtered_table_picrust2, tax_filtered_table_ancom
file 'tax_filtered_seq.qza' into tax_filtered_seq, tax_filtered_seq_picrust2
file 'tax_filtered_table.qzv' into tax_filtered_table_visu
file 'tax_filtered_output' into tax_filtered_output
file 'tax_filtered_seq.qzv' into tax_filtered_seq_visu
file 'tax_filtered_table_with_tax.biom' into tax_filtered_table_biom
file 'tax_filtered_table_with_tax.tsv' into tax_filtered_table_tsv, tax_filtered_table_tsv_stats
file 'completecmd' into complete_cmd_filtering_tax
when :
!params.stats_only
script :
"""
q2_filtering_tax.sh ${asv_table} ${asv_tax} ${params.tax_to_exclude} ${params.tax_to_include} tax_filtered_table.qza ${asv_seq} tax_filtered_seq.qza tax_filtered_table.qzv ${metadata} tax_filtered_output tax_filtered_seq.qzv ${asv_tax_tsv} tax_filtered_table_with_tax.biom tax_filtered_table_with_tax.tsv completecmd &> q2_filtering_tax.log 2>&1
"""
}
}
microDecon_table = params.filtering_tax_enable ? tax_filtered_table_tsv : biom_tsv_decontam
/*
* STEP 9 - Decontaminate samples with MicroDecon
*/
if (params.microDecon_enable) {
process microDecon_step1 {
label 'microdecon_env'
publishDir "${params.outdir}/${params.microDecon_dirname}", mode: 'copy', pattern: 'decontaminated_ASV_table.tsv'
publishDir "${params.outdir}/${params.microDecon_dirname}", mode: 'copy', pattern: 'abundance_removed.txt'
publishDir "${params.outdir}/${params.microDecon_dirname}", mode: 'copy', pattern: 'ASV_removed.txt'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern: 'decontaminated_ASV_table.tsv'
publishDir "${params.outdir}/${params.report_dirname}/microDecon", mode: 'copy', pattern: 'decontaminated_ASV_table.tsv'
publishDir "${params.outdir}/${params.report_dirname}/microDecon", mode: 'copy', pattern: 'abundance_removed.txt'
publishDir "${params.outdir}/${params.report_dirname}/microDecon", mode: 'copy', pattern: 'ASV_removed.txt'
publishDir "${params.outdir}/${params.report_dirname}/version", mode: 'copy', pattern: 'v_*.txt'
publishDir "${params.outdir}/${params.report_dirname}", mode: 'copy', pattern : 'completecmd', saveAs : { complete_cmd_microDecon -> "cmd/${task.process}_complete.sh" }
input :
file microDecon_table from microDecon_table
output :
file 'decontaminated_ASV_table.tsv' into decontam_table, decontam_table_step2, decontam_table_step3
file 'abundance_removed.txt' into abund_removed
file 'ASV_removed.txt' into ASV_removed
file 'completecmd' into complete_cmd_microDecon
file 'v_microdecon.txt' into microdecon_version
when :
!params.stats_only && !params.dada2merge && params.microDecon_enable
shell :
"""
sed '1d' ${microDecon_table} > microDecon_table
sed -i 's/#OTU ID/ASV_ID/g' microDecon_table
sed -i "s/'//g" microDecon_table
microDecon.R microDecon_table ${params.control_list} ${params.nb_controls} ${params.nb_samples} decontaminated_ASV_table.tsv abundance_removed.txt ASV_removed.txt &> microDecon.log 2>&1
cp ${baseDir}/bin/microDecon.R completecmd &>> microDecon.log 2>&1
Rscript -e "write(x=as.character(packageVersion('microDecon')), file='v_microdecon.txt')"
"""
}
process microDecon_step2 {
label 'qiime2_env'
publishDir "${params.outdir}/${params.microDecon_dirname}", mode: 'copy', pattern: 'decontaminated_ASV_table.qza'
publishDir "${params.outdir}/${params.report_dirname}/microDecon", mode: 'copy', pattern: 'decontaminated_ASV_table.qza'
input :
file table4microDecon from decontam_table_step2
output :
file 'decontaminated_ASV_table.qza' into decontam_table_qza, decontam_table_picrust2, decontam_table_ancom
when :
!params.stats_only && !params.dada2merge && params.microDecon_enable
shell :
"""
biom convert -i ${table4microDecon} -o decontaminated_ASV_table.biom --to-hdf5 --table-type="OTU table" --process-obs-metadata taxonomy
qiime tools import --input-path decontaminated_ASV_table.biom --type 'FeatureTable[Frequency]' --input-format BIOMV210Format --output-path decontaminated_ASV_table.qza
"""
}
/* Extract non-contaminated ASV ID */
process microDecon_step3 {
label 'seqtk_env'
publishDir "${params.outdir}/${params.microDecon_dirname}", mode: 'copy', pattern: 'decontaminated_ASV_ID.txt'
publishDir "${params.outdir}/${params.microDecon_dirname}", mode: 'copy', pattern: 'decontaminated_ASV.fasta'
publishDir "${params.outdir}/${params.report_dirname}/microDecon", mode: 'copy', pattern: 'decontaminated_ASV.fasta'
input :
file decontam_table from decontam_table_step3
file dada2_output from decontam_output
output :
file 'decontaminated_ASV_ID.txt' into decontam_ASV_ID
file 'decontaminated_ASV.fasta' into decontam_ASV_fasta
when :
!params.stats_only && !params.dada2merge && params.microDecon_enable
shell :
"""
cut -d \$'\t' -f1 ${decontam_table} | sed '1d' > decontaminated_ASV_ID.txt
seqtk subseq ${dada2_output}/sequences.fasta decontaminated_ASV_ID.txt > decontaminated_ASV.fasta
"""
}
/* Reformat decontaminated sequence to QIIME2 format */
process microDecon_step4 {
label 'qiime2_env'
publishDir "${params.outdir}/${params.phylogeny_dirname}", mode: 'copy', pattern: '*.qza'
input :
file ASV_fasta from decontam_ASV_fasta
output :
file 'decontam_seqs.qza' into decontam_seqs_qza, decontam_seqs_phylo, decontam_seqs_picrust2, decontam_seqs_ancom
when :
!params.stats_only && !params.dada2merge && params.microDecon_enable
shell :
"""
qiime tools import --input-path ${ASV_fasta} --output-path decontam_seqs.qza --type 'FeatureData[Sequence]'
"""
}
}
} else {
if (workflow.profile.contains('test')) {
longreadsmanifest = testmanifest.splitCsv(header: true, sep:'\t')
.map { row -> tuple( row."sample-id", file(row."absolute-filepath")) }
longreadstofasta = testmanifest.splitCsv(header: true, sep:'\t')
.map { row -> file(row."absolute-filepath") }
} else {
Channel.fromPath(params.input_manifest, checkIfExists:true).into { manifest_lr ; manifest_lr2fasta }
longreadsmanifest = manifest_lr.splitCsv(header: true, sep:'\t')
.map { row -> tuple( row."sample-id", file(row."absolute-filepath")) }
longreadstofasta = manifest_lr2fasta.splitCsv(header: true, sep:'\t')
.map { row -> file(row."absolute-filepath") }
}
/* _______________________________________________________________ */
/* Long reads part */
/* _______________________________________________________________ */
process lr_mapping {
label 'lr_mapping_env'
publishDir "${params.outdir}/${params.lr_mapping_dirname}", mode: 'copy', pattern: '*.bam'
publishDir "${params.outdir}/${params.report_dirname}/version", mode: 'copy', pattern: 'v_*.txt'
input:
set sample, file(fastq) from longreadsmanifest
file ready from ready_lr
output:
file "*.bam" into lr_mapped
file 'lr_mapping.ok' into process_lr_mapping_report
file 'lr_samtools-sort.log' into process_lr_sort_report
file 'v_minimap2.txt' into v_minimap2_version
shell:
"""
minimap2 -t ${task.cpus} -K 25M -ax ${params.lr_type} -L ${params.lr_tax_fna} ${fastq} | samtools view -h -F0xe00 | samtools sort -o ${sample}.bam -O bam - &> lr_minimap2.log 2>&1
touch lr_mapping.ok
samtools index ${sample}.bam &> lr_samtools-sort.log 2>&1
touch lr_samtools-sort.ok
minimap2 --version > v_minimap2.txt
"""
}
process lr_getfasta {
label 'seqtk_env'
input :
file(fastq) from longreadstofasta
output :
file 'lr_sequences.fasta' into lr_sequences
shell :
"""
seqtk seq -a ${fastq} > 'lr_sequences.fasta'
"""
}
lr_sequences.collectFile(name : 'lr_sequences.fasta', newLine : false, storeDir : "${params.outdir}/${params.lr_mapping_dirname}")
.subscribe { println "Fasta sequences are saved to file : $it" }
process lr_get_taxonomy {
label 'biopython_env'
publishDir "${params.outdir}/${params.lr_taxonomy_dirname}", mode: 'copy', pattern: '*.tsv'
input:
file '*' from lr_mapped.collect()
output:
file 'samples.tsv' into lr_biom_tsv
file 'lr_count_table.ok' into process_lr_taxonomy_report
shell:
"""
lr_count_table_minimap2.py -b "." -t "${params.lr_taxo_flat}" -r ${params.lr_rank} -o samples.tsv &> lr_count_table.log 2>&1
touch lr_count_table.ok
"""
}
}
if (!params.longreads) {
seqs_phyloA = params.dada2merge ? merge_seqs_phylo : dada2_seqs_phylo
seqs_phyloB = params.dbotu3_enable ? dbotu3_seqs_phylo : seqs_phyloA