-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.nf
543 lines (402 loc) · 15.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
// Files need to be duplex called and split into "sampleID.duplex.fastq.gz" and "sampleID.simplex.fastq.gz"
def helpMessage() {
log.info"""
# Nanopore Q20+ genome assembly and polishing
A pipeline for assembly and polishing of fungal genomes from Oxford Nanopore Q20+ reads from Kit14 using Flye and Medaka.
## Examples
nextflow run jwdebler/nanopore_kit14_assembly -resume -latest -profile docker,nimbus --reads "reads/"
## Parameters
--reads <glob>
Required
A folder containing two files per sample.
The basename of the file is used as the sample ID and must contain
`duplex` and `simplex`.
Example of file names: `Sample1.duplex.fastq.gz`, `Sample1.simplex.fastq.gz`.
(Default: a folder called `reads/`)
--genomeSize <glob>
not required
Size of genome, for example "42m" (Default: 42m)
--medakaModel <glob>
not required
Which basecaller model was used?
r1041_e82_400bps_sup_v5.0.0 (kit114, sup, 5 kHz)
r1041_e82_400bps_sup_v4.1.0 (kit114, sup, 4 kHz)
(Default: r1041_e82_400bps_sup_v4.3.0)
--outdir <path>
The directory to store the results in.
(Default: `assembly`)
--minlen
Min read length to keep for assembly
(Default: 1000)
--quality
Min read q-score to keep for read filtering
(Default: 8)
## Exit codes
- 0: All ok.
- 1: Incomplete parameter inputs.
"""
}
//by default script looks for reads in the current directory
params.reads=""
params.size="42m"
params.medakaModel="r1041_e82_400bps_sup_v5.0.0"
params.minlen="1000"
params.quality="8"
if (params.help) {
helpMessage()
exit 0
}
if ( params.reads ) {
nanoporeReads = Channel
.fromFilePairs(params.reads + "*{sim,du}plex.fastq.gz")
.map { sampleID, reads -> [sampleID.tokenize('.')[0], reads] }
.map { sampleID -> [sampleID[0]] + sampleID[1] }
.tap { ReadsDuplexForChopper }
.tap { ReadsSimplexForChopper }
.tap { ReadsDuplexForQC }
.tap { ReadsSimplexForQC }
.view()
} else {
nanoporeReads = Channel
.fromFilePairs("*{sim,du}plex.fastq.gz")
.map { sampleID, reads -> [sampleID.tokenize('.')[0], reads] }
.map { sampleID -> [sampleID[0]] + sampleID[1] }
.tap { ReadsDuplexForChopper }
.tap { ReadsSimplexForChopper }
.tap { ReadsDuplexForQC }
.tap { ReadsSimplexForQC }
.view()
}
process version_medaka {
label "medaka"
output:
path 'versions.txt' into medaka_version
"""
echo medaka: >> versions.txt
medaka --version >> versions.txt
echo --------------- >> versions.txt
"""
}
process version_seqkit {
label "seqkit"
output:
path 'versions.txt' into seqkit_version
"""
echo seqkit: >> versions.txt
seqkit version >> versions.txt
echo --------------- >> versions.txt
"""
}
process version_flye{
label "flye"
output:
path 'versions.txt' into flye_version
"""
echo flye: >> versions.txt
flye --version >> versions.txt
echo --------------- >> versions.txt
"""
}
process version_nextdenovo {
label "nextdenovo"
output:
path 'versions.txt' into nextdenovo_version
"""
echo nextdenovo: >> versions.txt
nextDenovo --version >> versions.txt
echo --------------- >> versions.txt
"""
}
process version_chopper {
label "chopper"
output:
path 'versions.txt' into chopper_version
"""
echo chopper: >> versions.txt
chopper --version >> versions.txt
echo --------------- >> versions.txt
"""
}
process versions {
input:
path "medaka.txt" from medaka_version
path "seqkit.txt" from seqkit_version
path "flye.txt" from flye_version
path "nextdenovo.txt" from nextdenovo_version
path "chopper.txt" from chopper_version
publishDir "${params.outdir}/", mode: 'copy', pattern: 'versions.txt'
output:
path "versions.txt"
script:
"""
cat medaka.txt seqkit.txt flye.txt nextdenovo.txt chopper.txt> versions.txt
"""
}
// filtering reads
// checks for duplicate read IDs and removes DCS reads
process QC_chopper_Duplex {
label "chopper"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/02-processed-reads", pattern: '*.fastq.gz'
input:
tuple sampleID, 'duplex.fastq.gz', 'simplex.fastq.gz' from ReadsDuplexForChopper
output:
tuple sampleID, "${sampleID}.duplex.chopper.200bp.q${params.quality}.fastq.gz" into FilteredDuplex200
tuple sampleID, "${sampleID}.duplex.chopper.${params.minlen}bp.q${params.quality}.fastq.gz" into FilteredDuplex1000
"""
wget https://raw.githubusercontent.com/JWDebler/nanopore_kit14_assembly/main/data/DCS.fasta
minimap2 -d dcs.mmi DCS.fasta
seqkit rmdup -n duplex.fastq.gz | minimap2 -t "${task.cpus}" -ax lr:hq dcs.mmi - | samtools view -O fastq -@ "${task.cpus}" - | chopper -t ${task.cpus} -q ${params.quality} -l 200 | pigz -9 > ${sampleID}.duplex.chopper.200bp.q${params.quality}.fastq.gz
chopper -i ${sampleID}.duplex.chopper.200bp.q${params.quality}.fastq.gz -t ${task.cpus} -l ${params.minlen} | pigz -9 > ${sampleID}.duplex.chopper.${params.minlen}bp.q${params.quality}.fastq.gz
"""
}
process QC_chopper_Simplex {
label "chopper"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/02-processed-reads", pattern: '*.fastq.gz'
input:
tuple sampleID, 'duplex.fastq.gz', 'simplex.fastq.gz' from ReadsSimplexForChopper
output:
tuple sampleID, "${sampleID}.simplex.chopper.200bp.q${params.quality}.fastq.gz" into FilteredSimplex200
tuple sampleID, "${sampleID}.simplex.chopper.${params.minlen}bp.q${params.quality}.fastq.gz" into FilteredSimplex1000
"""
wget https://raw.githubusercontent.com/JWDebler/nanopore_kit14_assembly/main/data/DCS.fasta
minimap2 -d dcs.mmi DCS.fasta
seqkit rmdup -n simplex.fastq.gz | minimap2 -t "${task.cpus}" -ax lr:hq dcs.mmi - | samtools view -O fastq -@ "${task.cpus}" - | chopper -t ${task.cpus} -q ${params.quality} -l 200 | pigz -9 > ${sampleID}.simplex.chopper.200bp.q${params.quality}.fastq.gz
chopper -i ${sampleID}.simplex.chopper.200bp.q${params.quality}.fastq.gz -t ${task.cpus} -l ${params.minlen} | pigz -9 > ${sampleID}.simplex.chopper.${params.minlen}bp.q${params.quality}.fastq.gz
"""
}
// read QC
process QC_nanoplot_Raw_Duplex {
label "nanoplot"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/01-QC", pattern: '*.html'
input:
tuple sampleID, "${sampleID}.duplex.fastq.gz", "${sampleID}.simplex.fastq.gz" from ReadsDuplexForQC
output:
path "*.html"
"""
NanoPlot \
--fastq ${sampleID}.duplex.fastq.gz \
-o output && \
cp output/NanoPlot-report.html ${sampleID}.nanoplot.duplex.html
"""
}
process QC_nanoplot_Raw_Simplex {
label "nanoplot"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/01-QC", pattern: '*.html'
input:
tuple sampleID, "${sampleID}.duplex.fastq.gz", "${sampleID}.simplex.fastq.gz" from ReadsSimplexForQC
output:
path "*.html"
"""
NanoPlot \
--fastq ${sampleID}.simplex.fastq.gz \
-o output && \
cp output/NanoPlot-report.html ${sampleID}.nanoplot.simplex.html
"""
}
process QC_nanoplot_Chopper_Duplex {
label "nanoplot"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/01-QC", pattern: '*.html'
input:
tuple sampleID, "${sampleID}.duplex.fastq.gz" from FilteredDuplex1000
output:
path "*.html"
tuple sampleID, "${sampleID}.duplex.fastq.gz" into FilterdForAssemblyDuplex
"""
NanoPlot \
--fastq ${sampleID}.duplex.fastq.gz \
-o output && \
cp output/NanoPlot-report.html ${sampleID}.nanoplot.chopper.duplex.html
"""
}
process QC_nanoplot_Chopper_Simplex {
label "nanoplot"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/01-QC", pattern: '*.html'
input:
tuple sampleID, "${sampleID}.simplex.fastq.gz" from FilteredSimplex1000
output:
path "*.html"
tuple sampleID, "${sampleID}.simplex.fastq.gz" into FilterdForAssemblySimplex
"""
NanoPlot \
--fastq ${sampleID}.simplex.fastq.gz \
-o output && \
cp output/NanoPlot-report.html ${sampleID}.nanoplot.chopper.simplex.html
"""
}
FilterdForAssemblyDuplex.join(FilterdForAssemblySimplex)
.tap { FilteredForFlye }
//.tap { FilteredForNextdenovo }
process mergeFilteredReads {
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/02-processed-reads", pattern: '*mergedSimplexDuplex.fastq.gz'
input:
tuple sampleID, "duplex.fastq.gz", "simplex.fastq.gz" from FilteredDuplex200.join(FilteredSimplex200)
output:
tuple sampleID, "${sampleID}.mergedSimplexDuplex.fastq.gz" into MergedFilteredForMedakaFlye
tuple sampleID, "${sampleID}.mergedSimplexDuplex.fastq.gz" into MergedFilteredForMedakaNextdenovo
"""
cat duplex.fastq.gz simplex.fastq.gz > ${sampleID}.mergedSimplexDuplex.fastq.gz
"""
}
// flye assembly
process Assembly_flye {
label "flye"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/03-assembly", pattern: '*_flye.*'
input:
tuple sampleID, "${sampleID}.duplex.chopper.fastq.gz", "${sampleID}.simplex.chopper.fastq.gz" from FilteredForFlye
output:
tuple sampleID, "${sampleID}_flye.fasta" into MedakaFlye
tuple sampleID, "${sampleID}.duplex.chopper.fastq.gz", "${sampleID}.simplex.chopper.fastq.gz" into FilteredForNextdenovo
file "${sampleID}_flye.assembly_info.txt"
"""
flye \
--nano-hq ${sampleID}.duplex.chopper.fastq.gz ${sampleID}.simplex.chopper.fastq.gz \
--read-error 0.03 \
--genome-size ${params.size} \
--asm-coverage 50 \
--threads ${task.cpus} \
--out-dir ${sampleID}.flye
cp ${sampleID}.flye/assembly.fasta ${sampleID}_flye.fasta
cp ${sampleID}.flye/assembly_info.txt ${sampleID}_flye.assembly_info.txt
"""
}
process Assembly_nextdenovo {
label "nextdenovo"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/03-assembly", pattern: '*_nextdenovo.fasta'
publishDir "${params.outdir}/${sampleID}/02-processed-reads", pattern: '*corredted.fasta'
input:
tuple sampleID, "duplex.fastq.gz", "simplex.fastq.gz" from FilteredForNextdenovo
output:
tuple sampleID, "${sampleID}_nextdenovo.fasta", "simplex.fastq.gz" into MedakaNextdenovo
tuple sampleID, "${sampleID}.nextdenovo.corredted.fasta"
"""
ls duplex.fastq.gz simplex.fastq.gz > ${sampleID}.fofn
echo '''
[General]
job_type = local
job_prefix = ${sampleID}.nextdenovo
task = all
rewrite = yes
deltmp = yes
parallel_jobs = 5
input_type = raw
read_type = ont # clr, ont, hifi
input_fofn = ${sampleID}.fofn
workdir = ${sampleID}.nextdenovo
[correct_option]
read_cutoff = 1k
genome_size = ${params.size} # estimated genome size
sort_options = -m 4g -t 12
minimap2_options_raw = -t 12
pa_correction = 5
correction_options = -p 10
[assemble_option]
minimap2_options_cns = -t 12
nextgraph_options = -a 1
''' > ${sampleID}.config
nextDenovo ${sampleID}.config
cp ${sampleID}.nextdenovo/03.ctg_graph/nd.asm.fasta ${sampleID}_nextdenovo.fasta
cat ${sampleID}.nextdenovo/02.cns_align/01.seed_cns.sh.work/seed_cns*/cns.fasta > ${sampleID}.nextdenovo.corredted.fasta
"""
}
process Polishing_medaka_flye {
label "medaka"
tag {sampleID}
input:
tuple sampleID, "flye.fasta", "mergedReads.fastq.gz" from MedakaFlye.join(MergedFilteredForMedakaFlye)
output:
tuple sampleID, "${sampleID}_flye_medaka.fasta" into SeqkitFlye
"""
medaka_consensus \
-i mergedReads.fastq.gz \
-d flye.fasta \
-o ${sampleID}_medaka_output \
-m ${params.medakaModel} \
-t ${task.cpus}
cp ${sampleID}_medaka_output/consensus.fasta ${sampleID}_flye_medaka.fasta
"""
}
process Polishing_medaka_nextdenovo {
label "medaka"
tag {sampleID}
input:
tuple sampleID, "nextdenovo.fasta", "simplex.fastq.gz", "mergedReads.fastq.gz" from MedakaNextdenovo.join(MergedFilteredForMedakaNextdenovo)
output:
tuple sampleID, "${sampleID}_nextenovo_medaka.fasta" into SeqkitNextdenovo
tuple sampleID, "simplex.fastq.gz" into Correction_dechat
"""
medaka_consensus \
-i mergedReads.fastq.gz \
-d nextdenovo.fasta \
-o ${sampleID}_medaka_output \
-m ${params.medakaModel} \
-t ${task.cpus}
cp ${sampleID}_medaka_output/consensus.fasta ${sampleID}_nextenovo_medaka.fasta
"""
}
process Cleanup_seqkitFlye {
label "seqkit"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/04-medaka-polished", pattern: '*.fasta'
input:
tuple sampleID, "${sampleID}_flye_medaka.unsorted.fasta" from SeqkitFlye
output:
tuple sampleID, "${sampleID}_flye_medaka.fasta" into FlyeForRagtag
"""
seqkit sort -lr ${sampleID}_flye_medaka.unsorted.fasta > ${sampleID}_flye_medaka.sorted.fasta
seqkit replace -p '.+' -r '${sampleID}_ctg_{nr}' --nr-width 2 ${sampleID}_flye_medaka.sorted.fasta > ${sampleID}_flye_medaka.fasta
"""
}
process Cleanup_seqkitNextdenovo {
label "seqkit"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/04-medaka-polished", pattern: '*.fasta'
input:
tuple sampleID, "${sampleID}_nextdenovo_medaka.unsorted.fasta" from SeqkitNextdenovo
output:
tuple sampleID, "${sampleID}_nextdenovo_medaka.fasta" into NextDenovoForRagtag
"""
seqkit sort -lr ${sampleID}_nextdenovo_medaka.unsorted.fasta > ${sampleID}_nextdenovo_medaka.sorted.fasta
seqkit replace -p '.+' -r '${sampleID}_ctg_{nr}' --nr-width 2 ${sampleID}_nextdenovo_medaka.sorted.fasta > ${sampleID}_nextdenovo_medaka.fasta
"""
}
// compare assemblies with RagTag and order according to Nextdenovo
process Cleanup_ragtag {
label "ragtag"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/05-ragtag"
input:
tuple sampleID, "nextdenovo.fasta", "flye.fasta" from NextDenovoForRagtag.join(FlyeForRagtag)
output:
path "ragtag.*"
"""
ragtag.py scaffold nextdenovo.fasta flye.fasta
cp ragtag_output/* .
"""
}
process Correction_dechat {
label "dechat"
tag {sampleID}
publishDir "${params.outdir}/${sampleID}/02-processed-reads", pattern: '*.fasta.gz'
input:
tuple sampleID, "${sampleID}.simplex.fastq.gz" from Correction_dechat
output:
tuple sampleID, "${sampleID}.corrected.dechat.fasta.gz"
script:
"""
dechat \
-t ${task.cpus} \
-o ${sampleID} \
-i ${sampleID}.simplex.fastq.gz
pigz -9 ${sampleID}.ec.fa
mv ${sampleID}.ec.fa.gz ${sampleID}.corrected.dechat.fasta.gz
"""
}