-
Notifications
You must be signed in to change notification settings - Fork 5
/
main.nf
406 lines (340 loc) · 15.8 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
#!/usr/bin/env nextflow
nextflow.enable.dsl = 2
params.fq = "*.fastq"
params.outdir = "results"
params.noSpeciesPolishing = false
params.lowAbundanceThreshold = 0.02
params.isDemultiplexed = false
params.porechop_extra_end_trim = 0
params.noNanoplot = false
params.nanofilt_quality = 10
params.nanofilt_length = 1000
params.nanofilt_maxlength = 1700
params.nanofilt_headcrop = 0
params.nanofilt_tailcrop = 0
params.yacrd_c = 4
params.yacrd_n = 0.4
params.removeChimeras = false
params.megan_lcaAlgorithm = "naive"
params.megan_lcaCoveragePercent = 100
params.megan_topPercent = 10
params.megan_topPercentPolish = 5
params.megan_minPercentReadCover = 70
params.minimap2_k = 15
params.minimap2_f = 1000
params.minimap2_x = "map-ont"
params.minimap2_KM = 200
params.help = false
params.silvaFasta = "./silvadb/Exports/SILVA_138.1_SSURef_NR99_tax_silva.fasta.gz"
params.silvaTaxNcbiSp = "./silvadb/Exports/taxonomy/ncbi/tax_ncbi-species_ssu_ref_nr99_138.1.txt.gz"
params.silvaTaxmap = "./silvadb/Exports/taxonomy/ncbi/taxmap_slv_ssu_ref_nr_138.1.txt.gz"
params.silvaFastaURL = "https://www.arb-silva.de/fileadmin/silva_databases/current/Exports/SILVA_138.1_SSURef_NR99_tax_silva.fasta.gz"
params.silvaTaxNcbiSpURL = "https://www.arb-silva.de/fileadmin/silva_databases/current/Exports/taxonomy/ncbi/tax_ncbi-species_ssu_ref_nr99_138.1.txt.gz"
params.silvaTaxmapURL = "https://www.arb-silva.de/fileadmin/silva_databases/current/Exports/taxonomy/taxmap_slv_ssu_ref_nr_138.1.txt.gz"
params.fullSilva = false
sayHi()
// Show help message
if (params.help) {
helpMessage()
exit 0
}
// Validation of parameters
def parameters_expected = [
'help',
'fq',
'outdir',
'noSpeciesPolishing','no-species-polishing',
'lowAbundanceThreshold','low-abundance-threshold',
'isDemultiplexed', 'is-demultiplexed', // This is because https://github.com/nextflow-io/nextflow/issues/2061
'porechop_extra_end_trim',
'noNanoplot', 'no-nanoplot',
'nanofilt_quality',
'nanofilt_length',
'nanofilt_maxlength',
'nanofilt_headcrop',
'nanofilt_tailcrop',
'yacrd_c',
'yacrd_n',
'removeChimeras', 'remove-chimeras',
'megan_lcaAlgorithm', 'megan_lca-algorithm',
'megan_lcaCoveragePercent', 'megan_lca-coverage-percent',
'megan_topPercent', 'megan_top-percent',
'megan_topPercentPolish', 'megan_top-percent-polish',
'megan_minPercentReadCover', 'megan_min-percent-read-cover',
'minimap2_k',
'minimap2_f',
'minimap2_x',
'minimap2_KM',
'silvaFasta', 'silva-fasta',
'silvaTaxNcbiSp', 'silva-tax-ncbi-sp',
'silvaTaxmap', 'silva-taxmap',
'silvaFastaURL', 'silva-fasta-URL',
'silvaTaxNcbiSpURL', 'silva-tax-ncbi-sp-URL',
'silvaTaxmapURL', 'silva-taxmap-URL',
'fullSilva', 'full-silva'
] as Set
def parameter_diff = params.keySet() - parameters_expected
if (parameter_diff.size() != 0){
exit 1, "[Pipeline error] Parameter(s) $parameter_diff is/are not valid in the pipeline!\n"
}
helloParameters()
if (! params.fq ){
println("You must provide at least 1 fastq file using --fq flag.")
System.exit(1)
}
if (!["naive", "weighted", "longReads"].contains(params.megan_lcaAlgorithm)){
println("lcaAlgorithm not valid, must be one of 'naive', 'weighted', or 'longReads'")
System.exit(1)
}
Channel
.fromPath(params.fq, checkIfExists: true)
.ifEmpty { exit 1, "Non fastq files found: ${params.fq}" }
.set{ fqs_ch }
// include modules
include {GetVersions} from './modules/processes'
include {Fastq2Fasta} from './modules/processes'
include {MakeDB} from './modules/processes'
include {Minimap2} from './modules/processes'
include {MeganLca} from './modules/processes'
include {GetReadInfo} from './modules/processes'
include {ComputeAbundances} from './modules/processes'
include {Polish} from './workflows/PolishMinimap'
// include sub-workflows
include {SetSilva} from './workflows/Silva'
include {Demultiplex} from './workflows/Demultiplex'
include {QFilt} from './workflows/QFiltWorkflow'
include {QCheck} from './workflows/QCheckWorkflow'
workflow {
GetVersions()
// Download, if not available, and generate synonyms
SetSilva()
SetSilva.out.fasta
.set{ silva_fasta_ch }
SetSilva.out.synonyms
.set{ silva_synonyms_ch }
// Demultiplex if not already
if (! params.isDemultiplexed ){
Demultiplex( fqs_ch )
Demultiplex.out
.flatten()
.map { file -> tuple(file.baseName, file) }
.set{ barcode_ch }
} else {
fqs_ch
.flatten()
.map { file -> tuple(file.baseName, file) }
.set{ barcode_ch }
}
// Quality control sub-workflow
QFilt( barcode_ch )
QFilt.out.set{ filtered_scrubbed_ch }
if (! params.noNanoplot ) {
QCheck( barcode_ch, filtered_scrubbed_ch )
}
Fastq2Fasta( filtered_scrubbed_ch )
Fastq2Fasta.out.set{ fasta_ch }
MakeDB( silva_fasta_ch )
Minimap2( fasta_ch, MakeDB.out )
MeganLca( Minimap2.out, silva_synonyms_ch )
MeganLca.out
.collectFile(storeDir: "$params.outdir/Rma"){
val, file ->
["${val}.rma", file]
}
GetReadInfo( MeganLca.out )
GetReadInfo.out
.set{ base_read_assingments_ch }
// Publish read taxonomy assignments
base_read_assingments_ch
.collectFile(storeDir: "$params.outdir/Read_Assignments") {
val, file ->
[ "${val}.read_info" , file ]
}
// Compute taxa counts and classification
base_read_assingments_ch
.map{val, file -> file}
.collect()
.set{ all_read_assignments }
ComputeAbundances(
all_read_assignments,
silva_synonyms_ch,
!params.noSpeciesPolishing
)
// Publish taxa counts and classification
ComputeAbundances.out.counts
.collectFile(storeDir: "$params.outdir/")
ComputeAbundances.out.taxcla
.collectFile(storeDir: "$params.outdir/")
// Polish sub-Workflow
if (!params.noSpeciesPolishing){
Polish(
fasta_ch,
silva_fasta_ch,
silva_synonyms_ch,
base_read_assingments_ch,
ComputeAbundances.out.silva_ids,
ComputeAbundances.out.read_ids
)
// Publish polished taxa counts and classification
Polish.out.counts
.collectFile(storeDir: "$params.outdir/"){
file -> [ "COUNTS_polished.tsv" , file ]
}
Polish.out.taxcla
.collectFile(storeDir: "$params.outdir/"){
file -> [ "TAXCLA_polished.tsv" , file ]
}
}
}
def sayHi(){
log.info """ ____ __ ____ ____ ____ __ __ ____
( _ \\ / \\( _ \\( __)( __)( )( ) ( __)
) __/( O )) / ) _) ) _) )( / (_/\\ ) _)
(__) \\__/(__\\_)(____)(__) (__)\\____/(____)
---------------------------------------------
... A full-length 16S profiling Pipeline ....
---------------------------------------------"""
}
def helpMessage() {
log.info """
Usage:
A typical command for running the pipeline would be as follows:
nextflow run microgenlab/porefile --fq "data/*.fastq"
Input fastq file(s):
--fq Path to input data (must be surrounded with quotes), e.g.: "./path/to/fastqs/*.fastq".
Other:
--silvaFasta Path to SILVA_*_SSURef_NR99_tax_silva.fasta.gz file. You can provide it
either compressed (.gz) or not. If not provided, the workflow automatically
adds a download step (you must have internet connection).
--silvaFastaURL URL to SILVA_*_SSURef_NR99_tax_silva.fasta.gz file. It will be used if you
don't provide the --silvaFasta parameter (above). Default is:
'https://www.arb-silva.de/fileadmin/silva_databases/current/Exports/SILVA_138.1_SSURef_NR99_tax_silva.fasta.gz'.
--silvaTaxNcbiSp Path to tax_ncbi-species_ssu_ref_nr99_*.txt.gz file. You can provide it
either compressed (.gz) or not. If not provided, the workflow automatically
adds a download step.
--silvaTaxNcbiSpURL URL to tax_ncbi-species_ssu_ref_nr99_*.txt.gz file. It will be used if you
don't provide the --silvaFasta parameter (above). Default is:
'https://www.arb-silva.de/fileadmin/silva_databases/current/Exports/taxonomy/ncbi/tax_ncbi-species_ssu_ref_nr99_138.1.txt.gz'.
--silvaTaxmap Path to taxmap_slv_ssu_ref_nr_*.txt.gz file. You can provide it
either compressed (.gz) or not. If not provided, the workflow automatically
adds a download step.
--silvaTaxmapURL URL to taxmap_slv_ssu_ref_nr_*.txt.gz file. It will be used if you
don't provide the --silvaFasta parameter (above). Default is:
'https://www.arb-silva.de/fileadmin/silva_databases/current/Exports/taxonomy/taxmap_slv_ssu_ref_nr_138.1.txt.gz'.
--fullSilva By default, porefile reduces SILVA to prokatyote SSU (16S). Use this flag
to deactivate the reducing step and use the full SILVA database.
--outdir Name of the results directory. Default: "results".
Process specific parameters:
Porechop parameters:
--porechop_extra_end_trim The '--extra_end_trim' parameter of Porechop. Default: 0.
NanoFilt parameters:
--nanofilt_quality The '--quality' parameter of NanoFilt. Default: 8.
--nanofilt_length The '--length' parameter of NanoFilt (minimum length). Default: 1000.
--nanofilt_maxlength The '--maxlength' parameter of NanoFilt. Default: 1700.
--nanofilt_headcrop The '--headcrop' parameter of NanoFilt. Default: 0.
--nanofilt_tailcrop The '--tailcrop' parameter of NanoFilt. Default: 0.
Yacrd parameters:
--yacrd_c The '-c' parameter of Yacrd (minimum coverage). Default: 4 .
--yacrd_n The '-n' parameter of Yacrd (minimum coverage of read). Default: 0.4 .
Minimap2 parameters:
--minimap2_k The '-k' parameter of minimap2. Default: 15.
--minimap2_x The '-x' parameter of minimap2. Default: 'map-ont'. Possible values: 'map-ont',
'asm5', 'asm10', 'asm20', 'map-pb', or 'map-hifi'.
--minimap2_f The '-f' parameter of minimap2. Default: 1000. Only applied in the Automap module.
--minimap2_KM The '-K' parameter of minimap2, in Megabases. Default: 200.
Megan6 parameters:
--megan_lcaAlgorithm The '--lcaAlgorithm' parameter of sam2rma tool (Megan6). Default: 'naive'.
Possible values are: 'naive', 'weighted', or 'longReads'.
--megan_topPercent The '--topPercent' parameter of sam2rma tool (Megan6). Default: 10.
--megan_topPercentPolish The '--topPercent' parameter of sam2rma tool (Megan6) applied when polishing step
is activated. Default: 5.
--megan_minPercentReadCover The '--minPercentReadCover' parameter of sam2rma and blast2rma tools (Megan6).
Default: 70.
--megan_lcaCoveragePercent The '--lcaCoveragePercent' parameter of sam2rma and blast2rma tools (Megan6).
Default: 100.
Other control options:
--isDemultiplexed Set this flag to avoid Demultiplex sub-workflow. If set, each fastq file is
processed as a different barcode.
--removeChimeras Set this flag to activate the chimera-removing step with Yacrd.
--noNanoplot Set this flag to avoid QCheck sub-workflow.
--noSpeciesPolishing Avoid the polishing sub-workflow.
--lowAbundanceThreshold The threshold of total abundance (from 0 to 1) to be considered as "low", and
which the pipeline will try to re assign (default: 0.02).
Container options (note single dash usage!):
-profile docker Use docker as container engine (default).
-profile singularity Use singularity as container engine.
-profile podman Use podman as container engine.
Help:
--help Print this help and exit.
Authors:
Cecilia Salazar ([email protected])
Ignacio Ferrés ([email protected])
Matías Giménez ([email protected])
Gregorio Iraola ([email protected])
Microbial Genomics Laboratory
Institut Pasteur de Montevideo (Uruguay)
""".stripIndent()
}
def helloParameters(){
log.info """ Nextflow-version: $nextflow.version
Porefile-version: $workflow.manifest.version
Porefile-commit: $workflow.commitId
Porefile-branch: $workflow.revision
Profile: $workflow.profile
Work directory: $workflow.workDir
Container: $workflow.container
Input directory: $params.fq
Output directory: $params.outdir
Command: $workflow.commandLine
⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻""".stripIndent()
log.info """ Minimap2 related parameters:
--minimap2_k: $params.minimap2_k
--minimap2_f: $params.minimap2_f
--minimap2_x: $params.minimap2_x
--minimap2_KM: $params.minimap2_KM
⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻""".stripIndent()
log.info """ SILVAdb related parameters: """
if (file(params.silvaFasta).exists()){
log.info """ --silvaFasta: $params.silvaFasta"""
}else{
log.info """ SILVAdb fasta file not provided. Download URL:
--silvaFastaURL $params.silvaFastaURL""".stripIndent()
}
if (file(params.silvaTaxNcbiSp).exists()){
log.info """ --silvaTaxNcbiSp: $params.silvaTaxNcbiSp"""
}else{
log.info """SILVAdb tax_ncbi-species file not provided. Download URL:
--silvaTaxNcbiSpURL $params.silvaTaxNcbiSpURL""".stripIndent()
}
if (file(params.silvaTaxmap).exists()){
log.info """ --silvaTaxmap: $params.silvaTaxmap"""
}else{
log.info """SILVAdb taxmap file not provided. Download URL:
--silvaTaxmapURL $params.silvaTaxmapURL""".stripIndent()
}
if (params.fullSilva){
log.info """ Full SILVAdb selected:""".stripIndent()
}else{
log.info """ Reduce SILVAdb selected:""".stripIndent()
}
log.info """ --fullSilva: $params.fullSilva
⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻""".stripIndent()
log.info """ Other process parameters:
Data is already demultiplexed?
--isDemultiplexed: $params.isDemultiplexed
Porechop
--porechop_extra_end_trim: $params.porechop_extra_end_trim
NanoFilt
--nanofilt_quality: $params.nanofilt_quality
--nanofilt_length: $params.nanofilt_length
--nanofilt_maxlength: $params.nanofilt_maxlength
--nanofilt_headcrop: $params.nanofilt_headcrop
--nanofilt_tailcrop: $params.nanofilt_tailcrop
Yacrd
--removeChimeras: $params.removeChimeras
--yacrd_c: $params.yacrd_c
--yacrd_n: $params.yacrd_n
NanoPlot
--noNanoplot: $params.noNanoplot
⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻⎻""".stripIndent()
}