-
Notifications
You must be signed in to change notification settings - Fork 7
/
donut_falls.nf
executable file
·1982 lines (1614 loc) · 64.3 KB
/
donut_falls.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
nextflow.enable.dsl = 2
// read but ignored most things from
// https://carpentries-incubator.github.io/Pipeline_Training_with_Nextflow/07-Nextflow_Best_Practice/index.html
// ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
// Greetings!
// ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
println('')
println(' __ ___ ')
println('| ) _ _ _)_ )_ _ ) ) _ ')
println('|_/ (_) ) ) (_( (_ ( (_( ( ( ( ')
println(' _) ')
println('')
println('Currently using the Donut Falls workflow for use with nanopore sequencing')
println('Author: Erin Young')
println('email: eriny@utah.gov')
println("Version: ${workflow.manifest.version}")
println('')
// ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
// Setting default param values
// ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
params.config_file = false
if (params.config_file) {
def src = new File("${workflow.projectDir}/configs/donut_falls_config_template.config")
def dst = new File("${workflow.launchDir}/edit_me.config")
dst << src.text
println("A config file can be found at ${workflow.launchDir}/edit_me.config")
exit 0
}
params.sequencing_summary = ''
params.sample_sheet = ''
params.assembler = 'flye'
params.outdir = 'donut_falls'
params.test = ''
// ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
// Checking params
// ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
def paramCheck(keys) {
set_keys = [
"outdir",
"sample_sheet",
"sequencing_summary",
"assembler",
"test",
"config_file"]
for(key in keys){
if (key !in set_keys){
println("WARNING: ${key} isn't a supported param!")
println("Supported params: ${set_keys}")
}
}
}
paramCheck(params.keySet())
// ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
// Input files
// ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
if (params.sequencing_summary){
Channel
.fromPath("${params.sequencing_summary}", type: 'file', checkIfExists: true)
.view { "Summary File : $it" }
.set { ch_sequencing_summary }
} else {
ch_sequencing_summary = Channel.empty()
}
// using a sample sheet with the column header of 'sample,fastq,fastq_1,fastq_2'
// sample = meta.id
// fastq = nanopore fastq file
// fastq_1 = illumina fastq file
// fastq_2 = illumina fastq file
if (params.sample_sheet) {
Channel
.fromPath("${params.sample_sheet}", type: "file")
.splitCsv( header: true, sep: ',' )
.map { it ->
meta = [id:it.sample]
tuple( meta,
file("${it.fastq}", checkIfExists: true),
"${it.fastq_1}",
"${it.fastq_2}")
}
.set{ ch_input_files }
} else {
ch_input_files = Channel.empty()
}
// channel for illumina files (paired-end only)
ch_input_files
.filter { it[2] != it[3] }
.map { it -> tuple(it[0], [file(it[2], checkIfExists: true), file(it[3], checkIfExists: true)])}
.set { ch_illumina_input }
// channel for nanopore files
ch_input_files
.map { it -> tuple (it[0], file(it[1], checkIfExists: true))}
.set { ch_nanopore_input }
// ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
// Processes
// ##### ##### ##### ##### ##### ##### ##### ##### ##### #####
process bandage {
tag "${meta.id}"
label 'process_low'
publishDir "${params.outdir}/${meta.id}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/bandage:0.8.1'
time '10m'
input:
tuple val(meta), file(gfa)
output:
path "bandage/*", emit: files
tuple val(meta), file("bandage/*.png"), emit: png
path "versions.yml", emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${gfa.baseName}"
"""
mkdir -p bandage
Bandage image ${gfa} bandage/${prefix}.png ${args}
Bandage image ${gfa} bandage/${prefix}.svg ${args}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
bandage: \$(Bandage --version | awk '{print \$NF}')
END_VERSIONS
"""
}
process busco {
tag "${meta.id}"
label "process_medium"
publishDir "${params.outdir}/${meta.id}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/busco:5.8.0-prok-bacteria_odb10_2024-01-08'
time '45m'
input:
tuple val(meta), file(fasta)
output:
path("busco/*/*"), emit: everything
path("busco/*/short_summary*.txt"), optional: true, emit: summary
path "versions.yml" , emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: '--offline -l /busco_downloads/lineages/bacteria_odb10'
def prefix = task.ext.prefix ?: "${fasta.baseName}"
"""
busco ${args} \
-m genome \
-i ${fasta} \
-o busco/${prefix} \
--cpu ${task.cpus}
cat <<-END_VERSIONS > versions.yml
"${task.process}":
busco: \$( busco --version | awk '{print \$NF}' )
END_VERSIONS
"""
}
process bwa {
tag "${meta.id}"
label 'process_high'
// no publishDir because the sam files are too big
container 'staphb/bwa:0.7.18'
time '2h'
input:
tuple val(meta), file(fasta), file(fastq)
output:
tuple val(meta), file(fasta), file("bwa/*_{1,2}.sam"), emit: sam
path "versions.yml", emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${fasta.baseName}"
"""
mkdir -p bwa
bwa index ${fasta}
bwa mem -t ${task.cpus} -a ${fasta} ${fastq[0]} > bwa/${prefix}_1.sam
bwa mem -t ${task.cpus} -a ${fasta} ${fastq[1]} > bwa/${prefix}_2.sam
cat <<-END_VERSIONS > versions.yml
"${task.process}":
bwa: \$(bwa 2>&1 | grep -i version | awk '{print \$NF}')
END_VERSIONS
"""
}
process circulocov {
tag "${meta.id}"
label "process_medium"
publishDir "${params.outdir}/${meta.id}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/circulocov:0.1.20240104'
time '1h'
input:
tuple val(meta), file(fasta), file(nanopore), file(illumina)
output:
path "circulocov/*overall_summary.txt", emit: summary
tuple val(meta), file("circulocov/*/overall_summary.txt"), emit: results
path "circulocov/*/*", emit: everything
path "circulocov/*/fastq/*", emit: fastq
path "versions.yml", emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: '-a'
def prefix = task.ext.prefix ?: "${fasta.baseName}"
def reads = (illumina =~ /input/) ? "" : "--illumina ${illumina.join(' ')}"
"""
mkdir -p circulocov/${prefix}
circulocov ${args} \
--threads ${task.cpus} \
--genome ${fasta} \
--nanopore ${nanopore} \
${reads} \
--out circulocov/${prefix} \
--sample ${prefix}
cp circulocov/${prefix}/overall_summary.txt circulocov/${prefix}_overall_summary.txt
cat <<-END_VERSIONS > versions.yml
"${task.process}":
circulocov: \$(circulocov -v | awk '{print \$NF}')
END_VERSIONS
"""
}
process copy {
tag "${meta.id}"
label 'process_low'
publishDir "${params.outdir}/${meta.id}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/multiqc:1.25'
time '10m'
input:
tuple val(meta), file(fasta), file(circulocov), file(gfastats)
output:
path "consensus/*", emit: fastas
when:
task.ext.when == null || task.ext.when
shell:
"""
#!/usr/bin/env python3
import glob
import json
import csv
import os
def gfastats_to_dict(header_dict):
dict = {}
with open('gfastats_summary.csv', mode='r') as file:
reader = csv.DictReader(file)
for row in reader:
if row['sample'] == header_dict['name'] + '_' + header_dict['assembler']:
key = row['Header']
dict[key] = row
return dict
def circulocov_to_dict(header_dict):
dict = {}
with open('circulocov_summary.txt', mode='r', newline='') as file:
reader = csv.DictReader(file, delimiter='\\t')
for row in reader:
if row['sample'].replace('_reoriented','') == header_dict['name'] + '_' + header_dict['assembler'] :
key = row['contigs']
dict[key] = row
return dict
def copy_fasta(fasta, header_dict, gfa_dict, circulocov_dict):
with open(fasta, 'r') as file:
fasta_dict = {}
for line in file:
line = line.strip()
if line.startswith('>'):
contig = str(line.replace('>','').split()[0])
circular = gfa_dict[contig]['Is circular'].replace('Y','true').replace('N','false')
length = gfa_dict[contig]['Total segment length']
gc_per = gfa_dict[contig]['GC content %']
meandepth = circulocov_dict[contig]['nanopore_meandepth']
assembler = header_dict['assembler']
step = header_dict['step']
# creating the header
header = '>' + contig
header = header + ' circ=' + circular
header = header + ' len=' + length
header = header + ' gc=' + gc_per
header = header + ' cov=' + meandepth
header = header + ' asmb=' + assembler
if assembler != 'unicycler':
header = header + ' stp=' + step
header = header + '\\n'
# creating the dict
fasta_dict[contig] = {}
fasta_dict[contig]['seq'] = ''
fasta_dict[contig]['header'] = header
fasta_dict[contig]['length'] = int(length)
else:
fasta_dict[contig]['seq'] = fasta_dict[contig]['seq'] + line
sorted_dict = dict(sorted(fasta_dict.items(), key=lambda item: item[1]['length'], reverse = True))
with open(f"consensus/{header_dict['fasta']}", 'w') as outfile:
for contig in sorted_dict:
seq = '\\n'.join([fasta_dict[contig]['seq'][i:i+70] for i in range(0, len(fasta_dict[contig]['seq']), 70)])
outfile.write(fasta_dict[contig]['header'])
outfile.write(seq + '\\n')
def main():
os.mkdir('consensus')
header_dict = {}
fasta = glob.glob('*.fasta')[0]
header_dict['fasta'] = fasta
name = fasta.replace('.fasta', '')
assemblers = ['dragonflye', 'flye', 'hybracter', 'raven', 'unicycler']
steps = ['reoriented', 'polypolish', 'pypolca', 'medaka']
for step in steps:
if step in name:
header_dict['step'] = step
name = name.replace(f"_{step}",'')
break
if 'step' not in header_dict.keys():
header_dict['step'] = False
for assembler in assemblers:
if assembler in name:
header_dict['assembler'] = assembler
name = name.replace(f"_{assembler}",'')
break
header_dict['name'] = name
gfa_dict = gfastats_to_dict(header_dict)
circulocov_dict = circulocov_to_dict(header_dict)
copy_fasta(fasta, header_dict, gfa_dict, circulocov_dict)
if __name__ == '__main__':
main()
"""
}
process dnaapler {
tag "${meta.id}"
label "process_medium"
publishDir "${params.outdir}/${meta.id}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/dnaapler:0.8.1'
time '1h'
input:
tuple val(meta), file(fasta), file(ignore)
output:
tuple val(meta), file("dnaapler/*_reoriented.fasta"), emit: fasta
path "dnaapler/*", emit: files
path "versions.yml", emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${fasta.baseName}"
"""
dnaapler all ${args} \
--input ${fasta} \
--prefix ${prefix} \
--output dnaapler \
--threads ${task.cpus} \
--ignore ${ignore} || \
cp ${fasta} dnaapler/${prefix}_reoriented.fasta
cat <<-END_VERSIONS > versions.yml
"${task.process}":
dnaapler: \$(dnaapler --version | awk '{print \$NF}')
END_VERSIONS
"""
}
process fastp {
tag "${meta.id}"
label "process_low"
publishDir "${params.outdir}/${meta.id}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/fastp:0.23.4'
time '10m'
input:
tuple val(meta), file(reads)
output:
tuple val(meta), file("fastp/*_fastp*.fastq.gz"), emit: fastq
path "fastp/*", emit: everything
path "fastp/*_fastp*.json", emit: summary
path "versions.yml", emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: ''
def lrargs = task.ext.lrargs ?: '--qualified_quality_phred 12 --length_required 1000'
def prefix = task.ext.prefix ?: "${meta.id}"
if (reads.toList().size() > 1 ){
"""
mkdir -p fastp
fastp ${args} \
--in1 ${reads[0]} \
--in2 ${reads[1]} \
--out1 fastp/${prefix}_fastp_sr_R1.fastq.gz \
--out2 fastp/${prefix}_fastp_sr_R2.fastq.gz \
-h fastp/${prefix}_fastp_sr.html \
-j fastp/${prefix}_fastp_sr.json
passed_filter_reads=\$(grep passed_filter_reads fastp/${prefix}_fastp_sr.json | awk '{print \$NF}' | head -n 1 )
cat <<-END_VERSIONS > versions.yml
"${task.process}":
fastp: \$(fastp --version 2>&1 | awk '{print \$NF}' )
END_VERSIONS
"""
} else {
"""
mkdir -p fastp
fastp ${lrargs} \
--in1 ${reads[0]} \
--out1 fastp/${prefix}_fastp_lr.fastq.gz \
-h fastp/${prefix}_fastp_lr.html \
-j fastp/${prefix}_fastp_lr.json
passed_filter_reads=\$(grep passed_filter_reads fastp/${prefix}_fastp_sr.json | awk '{print \$NF}' | head -n 1 )
cat <<-END_VERSIONS > versions.yml
"${task.process}":
fastp: \$(fastp --version 2>&1 | awk '{print \$NF}')
END_VERSIONS
"""
}
}
process flye {
tag "${meta.id}"
label "process_high"
publishDir "${params.outdir}/${meta.id}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/flye:2.9.5'
time '10h'
input:
tuple val(meta), file(fastq)
output:
tuple val(meta), file("flye/*_flye.fasta"), emit: fasta, optional: true
tuple val(meta), file("flye/*_flye.gfa"), emit: gfa, optional: true
path "flye/*_assembly_info.tsv", emit: summary
path "flye/*", emit: everything
path "versions.yml", emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: ''
def read_type = task.ext.read_type ?: '--nano-hq'
def prefix = task.ext.prefix ?: "${meta.id}"
"""
mkdir -p flye
flye ${args} \
${read_type} ${fastq} \
--threads ${task.cpus} \
--out-dir flye
# renaming final files
if [ -f "flye/assembly.fasta" ] ; then cp flye/assembly.fasta flye/${prefix}_flye.fasta ; fi
if [ -f "flye/assembly_graph.gfa" ] ; then cp flye/assembly_graph.gfa flye/${prefix}_flye.gfa ; fi
# getting a summary file
head -n 1 flye/assembly_info.txt | awk '{print "sample\\t" \$0}' > flye/${prefix}_assembly_info.tsv
tail -n+2 flye/assembly_info.txt | awk -v sample=${prefix} '{print sample "\\t" \$0}' >> flye/${prefix}_assembly_info.tsv
cat <<-END_VERSIONS > versions.yml
"${task.process}":
flye: \$( flye --version | awk '{print \$NF}')
END_VERSIONS
"""
}
process gfastats {
tag "${meta.id}"
label "process_medium"
publishDir "${params.outdir}/${meta.id}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/gfastats:1.3.7'
time '10m'
input:
tuple val(meta), file(gfa)
output:
tuple val(meta), file(gfa), file("gfastats/*_gfastats_summary.csv"), emit: stats
path "gfastats/*_gfastats_summary.csv", emit: summary
path "gfastats/*", emit: everything
path "versions.yml", emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${gfa.baseName}"
"""
mkdir -p gfastats
gfastats \
${gfa} \
${args} \
--threads ${task.cpus} \
--tabular \
--seq-report \
> gfastats/${prefix}_gfastats.txt
head -n 1 gfastats/${prefix}_gfastats.txt | tr "\\t" "," | awk '{print "sample," \$0 }' > gfastats/${prefix}_gfastats_summary.csv
tail -n+2 gfastats/${prefix}_gfastats.txt | tr "\\t" "," | awk -v sample=${prefix} '{print sample "," \$0 }' >> gfastats/${prefix}_gfastats_summary.csv
cat <<-END_VERSIONS > versions.yml
"${task.process}":
gfastats: \$( gfastats -v | head -n 1 | awk '{print \$NF}')
END_VERSIONS
"""
}
process gfa_to_fasta {
tag "${meta.id}"
label "process_low"
// no publishDir
container 'staphb/multiqc:1.25'
time '10m'
input:
tuple val(meta), file(gfa), file(stats)
output:
tuple val(meta), file("*fasta"), file("noncircular.txt"), emit: fasta
when:
task.ext.when == null || task.ext.when
"""
#!/usr/bin/env python3
import csv
import glob
def convert_to_fasta(summary_dict, gfa_file):
outfile = '_'.join(gfa_file.split('.')[:-1]) + ".fasta"
with open(gfa_file, mode='r') as file:
for line in file:
parts = line.split()
if parts and parts[0] == "S":
header = parts[1]
seq = parts[2]
if header in summary_dict.keys():
new_header = ">" + header + " length=" + summary_dict[header]['Total segment length'] + " circular=" + summary_dict[header]["Is circular"].replace("N","false").replace("Y","true") + " gc_per=" + summary_dict[header]["GC content %"] + "\\n"
with open(outfile, mode='a') as output_file:
output_file.write(new_header)
output_file.write(seq + "\\n")
def read_summary_csv(gfastats_file):
summary_dict = {}
with open(gfastats_file, mode='r', newline='') as file:
reader = csv.DictReader(file)
for row in reader:
key = row['Header']
summary_dict[key] = row
with open("noncircular.txt", mode='a') as output_file:
if summary_dict[key]["Is circular"] == "N":
output_file.write(key + "\\n")
return summary_dict
gfastats_file = glob.glob("*_gfastats_summary.csv")
gfa_file = glob.glob("*.gfa")
summary_dict = read_summary_csv(gfastats_file[0])
convert_to_fasta(summary_dict, gfa_file[0])
"""
}
// mash results : Reference-ID, Query-ID, Mash-distance, P-value, and Matching-hashes
process mash {
tag "${meta.id}"
label "process_medium"
publishDir "${params.outdir}/${meta.id}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/mash:2.3'
time '30m'
input:
tuple val(meta), file(illumina), file(nanopore)
output:
tuple val(meta), env(dist), optional: true, emit: dist
path "mash/*", optional: true, emit: txt
path "versions.yml", emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: ''
def ont_args = task.ext.ont_args ?: '-m 2'
def ill_args = task.ext.ill_args ?: '-m 2'
def short_re = "${illumina.join(' ')}"
def prefix = task.ext.prefix ?: "${meta.id}"
"""
mkdir mash
cat ${short_re} | \
mash sketch ${ill_args} \
-o ${prefix}.illumina -
mash sketch ${ont_args} \
-o ${prefix}.nanopore ${nanopore}
mash dist ${args} \
-p ${task.cpus} \
${prefix}.illumina.msh \
${prefix}.nanopore.msh | \
awk -v prefix=${prefix} '{print prefix "\\t" \$0 }' \
> mash/${prefix}.mashdist.txt
dist=\$(head -n 1 mash/${prefix}.mashdist.txt | awk '{print \$4}')
cat <<-END_VERSIONS > versions.yml
"${task.process}":
mash: \$( mash --version )
END_VERSIONS
"""
}
// From https://github.com/nanoporetech/medaka
// > It is not recommended to specify a value of --threads greater than 2 for medaka consensus since the compute scaling efficiency is poor beyond this.
// > Note also that medaka consensus may been seen to use resources equivalent to <threads> + 4 as an additional 4 threads are used for reading and preparing input data.
process medaka {
tag "${meta.id}"
label "process_medium"
publishDir "${params.outdir}/${meta.id}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'ontresearch/medaka:v1.11.3'
time '30m'
input:
tuple val(meta), path(fasta), path(fastq)
output:
tuple val(meta), path("medaka/*_medaka.fasta"), emit: fasta
path "medaka/*", emit: everything
path "versions.yml", emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${fasta.baseName.replaceAll('_reoriented','')}"
"""
mkdir -p medaka
# someday...
# medaka tools resolve_model --auto_model consensus ${fastq}
medaka_consensus ${args} \
-i ${fastq} \
-d ${fasta} \
-o medaka \
-t 1
if [ -f "medaka/consensus.fasta" ]; then cp medaka/consensus.fasta medaka/${prefix}_medaka.fasta ; fi
cat <<-END_VERSIONS > versions.yml
"${task.process}":
medaka: \$( medaka --version | awk '{print \$NF}')
END_VERSIONS
"""
}
process multiqc {
tag "combining reports"
label "process_low"
publishDir "${params.outdir}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/multiqc:1.25'
time '10m'
input:
file(input)
output:
path "multiqc/multiqc_report.html", emit: report
path "multiqc/multiqc_data/*", emit: everything
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: ''
"""
if [ -f "pypolca_summary.tsv" ]
then
echo "# plot_type: 'table'" > pypolca_mqc.txt
echo "# section_name: 'pypolca'" >> pypolca_mqc.txt
echo "# description: 'Long read polishing'" >> pypolca_mqc.txt
echo "# pconfig:" >> pypolca_mqc.txt
echo "# namespace: 'Cust Data'" >> pypolca_mqc.txt
echo "# headers:" >> pypolca_mqc.txt
echo "# Substitution_Errors_Found:" >> pypolca_mqc.txt
echo "# title: 'Substitution Errors Found'" >> pypolca_mqc.txt
echo "# description: 'Substitution Errors Found'" >> pypolca_mqc.txt
echo "# Insertion/Deletion_Errors_Found:" >> pypolca_mqc.txt
echo "# title: 'Insertion/Deletion Errors Found'" >> pypolca_mqc.txt
echo "# description: 'Insertion/Deletion Errors Found'" >> pypolca_mqc.txt
echo "# Assembly_Size:" >> pypolca_mqc.txt
echo "# title: 'Assembly Size'" >> pypolca_mqc.txt
echo "# description: 'Assembly Size'" >> pypolca_mqc.txt
echo "# Consensus_Quality_Before_Polishing:" >> pypolca_mqc.txt
echo "# title: 'Consensus Quality Before Polishing'" >> pypolca_mqc.txt
echo "# description: 'Consensus Quality Before Polishing'" >> pypolca_mqc.txt
echo "# Consensus_QV_Before_Polishing:" >> pypolca_mqc.txt
echo "# title: 'Consensus QV Before Polishing'" >> pypolca_mqc.txt
echo "# description: 'Consensus QV Before Polishing'" >> pypolca_mqc.txt
cat pypolca_summary.tsv >> pypolca_mqc.txt
fi
if [ -f "gfastats_summary.csv" ]
then
echo "# plot_type: 'table'" > gfastats_mqc.csv
echo "# section_name: 'gfastats'" >> gfastats_mqc.csv
echo "# description: 'Metrics for GFA files'" >> gfastats_mqc.csv
echo "# pconfig:" >> gfastats_mqc.csv
echo "# namespace: 'Cust Data'" >> gfastats_mqc.csv
echo "# headers:" >> gfastats_mqc.csv
echo "# sample:" >> gfastats_mqc.csv
echo "# title: 'Sample and analysis'" >> gfastats_mqc.csv
echo "# description: 'Sample and analysis that generated contig'" >> gfastats_mqc.csv
echo "# Header:" >> gfastats_mqc.csv
echo "# title: 'Header'" >> gfastats_mqc.csv
echo "# description: 'Name of contig'" >> gfastats_mqc.csv
echo "# Total segment length:" >> gfastats_mqc.csv
echo "# title: 'Total segment length'" >> gfastats_mqc.csv
echo "# description: 'Total segment length'" >> gfastats_mqc.csv
echo "# A:" >> gfastats_mqc.csv
echo "# title: 'A'" >> gfastats_mqc.csv
echo "# description: 'Number of A'" >> gfastats_mqc.csv
echo "# C:" >> gfastats_mqc.csv
echo "# title: 'C'" >> gfastats_mqc.csv
echo "# description: 'Number of C'" >> gfastats_mqc.csv
echo "# G:" >> gfastats_mqc.csv
echo "# title: 'G'" >> gfastats_mqc.csv
echo "# description: 'Number of G'" >> gfastats_mqc.csv
echo "# T:" >> gfastats_mqc.csv
echo "# title: 'T'" >> gfastats_mqc.csv
echo "# description: 'Number of T'" >> gfastats_mqc.csv
echo "# GC content %:" >> gfastats_mqc.csv
echo "# title: 'GC content %'" >> gfastats_mqc.csv
echo "# description: 'GC content %'" >> gfastats_mqc.csv
echo "# # soft-masked bases:" >> gfastats_mqc.csv
echo "# title: '# soft-masked bases'" >> gfastats_mqc.csv
echo "# description: '# soft-masked bases'" >> gfastats_mqc.csv
echo "# Is circular:" >> gfastats_mqc.csv
echo "# title: 'Is circular'" >> gfastats_mqc.csv
echo "# description: 'Is circular'" >> gfastats_mqc.csv
cat gfastats_summary.csv | awk '{print NR ',' \$0}' >> gfastats_mqc.csv
fi
if [ -f "flye_summary.tsv" ]
then
echo "# plot_type: 'table'" > flye_mqc.csv
echo "# section_name: 'flye'" >> flye_mqc.csv
echo "# description: 'Assembly Info'" >> flye_mqc.csv
echo "# pconfig:" >> flye_mqc.csv
echo "# namespace: 'Cust Data'" >> flye_mqc.csv
echo "# headers:" >> flye_mqc.csv
echo "# sample:" >> flye_mqc.csv
echo "# title: 'Sample'" >> flye_mqc.csv
echo "# description: 'Sample that generated contig'" >> flye_mqc.csv
echo "# #seq_name:" >> flye_mqc.csv
echo "# title: '#seq_name'" >> flye_mqc.csv
echo "# description: 'Name of contig'" >> flye_mqc.csv
echo "# length:" >> flye_mqc.csv
echo "# title: 'length'" >> flye_mqc.csv
echo "# description: 'length'" >> flye_mqc.csv
echo "# cov.:" >> flye_mqc.csv
echo "# title: 'cov'" >> flye_mqc.csv
echo "# description: 'Coverage'" >> flye_mqc.csv
echo "# circ:" >> flye_mqc.csv
echo "# title: 'circ'" >> flye_mqc.csv
echo "# description: 'Whether contig is circular'" >> flye_mqc.csv
echo "# repeat:" >> flye_mqc.csv
echo "# title: 'repeat'" >> flye_mqc.csv
echo "# description: 'repeat'" >> flye_mqc.csv
echo "# mult.:" >> flye_mqc.csv
echo "# title: 'mult'" >> flye_mqc.csv
echo "# description: 'mult.'" >> flye_mqc.csv
echo "# alt_group:" >> flye_mqc.csv
echo "# title: 'alt_group'" >> flye_mqc.csv
echo "# description: 'alt_group'" >> flye_mqc.csv
echo "# graph_path:" >> flye_mqc.csv
echo "# title: 'graph_path'" >> flye_mqc.csv
echo "# description: 'graph_path'" >> flye_mqc.csv
cat flye_summary.tsv | awk '{print NR '\\t' \$0}' >> flye_mqc.csv
fi
circulocov_check=\$(ls * | grep overall_summary.txt | head -n 1)
if [ -n "\$circulocov_check" ]
then
illumina_check=\$(grep -h illumina *overall_summary.txt | head -n 1)
if [ -n "\$illumina_check" ]
then
circulocov_summary_header=\$illumina_check
else
circulocov_summary_header=\$(grep -h nanopore_numreads *overall_summary.txt | head -n 1)
fi
echo \$circulocov_summary_header | awk '{print \$1 "\\t" \$2 "\\t" \$3 "\\t" \$4 "\\t" \$5 "\\t" \$6 "\\t" \$7 "\\t" \$8 "\\t" \$9 "\\t" \$10 "\\t" \$11 "\\t" \$12}' > circulocov_summary.txt
cat *overall_summary.txt | grep -v nanopore_numreads | awk '{print \$1 "\\t" \$2 "\\t" \$3 "\\t" \$4 "\\t" \$5 "\\t" \$6 "\\t" \$7 "\\t" \$8 "\\t" \$9 "\\t" \$10 "\\t" \$11 "\\t" \$12}' >> circulocov_summary.txt
echo "# plot_type: 'table'" > circulocov_mqc.txt
echo "# section_name: 'CirculoCov'" >> circulocov_mqc.txt
echo "# description: 'Coverage estimates for circular sequences'" >> circulocov_mqc.txt
echo "# pconfig:" >> circulocov_mqc.txt
echo "# namespace: 'Cust Data'" >> circulocov_mqc.txt
echo "# headers:" >> circulocov_mqc.txt
echo "# sample:" >> circulocov_mqc.txt
echo "# title: 'Sample'" >> circulocov_mqc.txt
echo "# description: 'Sample that generated contig'" >> circulocov_mqc.txt
echo "# circ:" >> circulocov_mqc.txt
echo "# title: 'circ'" >> circulocov_mqc.txt
echo "# description: 'Whether contig was circular'" >> circulocov_mqc.txt
echo "# contigs:" >> circulocov_mqc.txt
echo "# title: 'contigs'" >> circulocov_mqc.txt
echo "# description: 'name of contig'" >> circulocov_mqc.txt
echo "# length:" >> circulocov_mqc.txt
echo "# title: 'length'" >> circulocov_mqc.txt
echo "# description: 'length of contig'" >> circulocov_mqc.txt
echo "# nanopore_numreads:" >> circulocov_mqc.txt
echo "# title: 'numreads'" >> circulocov_mqc.txt
echo "# description: 'number of nanopore reads mapping to contig'" >> circulocov_mqc.txt
echo "# nanopore_covbases:" >> circulocov_mqc.txt
echo "# title: 'covbases'" >> circulocov_mqc.txt
echo "# description: 'nanopore covbases of contig'" >> circulocov_mqc.txt
echo "# nanopore_coverage:" >> circulocov_mqc.txt
echo "# title: 'coverage'" >> circulocov_mqc.txt
echo "# description: 'nanopore coverage of contig'" >> circulocov_mqc.txt
echo "# nanopore_meandepth:" >> circulocov_mqc.txt
echo "# title: 'meandepth'" >> circulocov_mqc.txt
echo "# description: 'nanopore meandepth of contig'" >> circulocov_mqc.txt
cat circulocov_summary.txt | awk '{print NR '\\t' \$0}' >> circulocov_mqc.txt
fi
multiqc ${args} \
--outdir multiqc \
.
"""
}
process nanoplot_summary {
tag "${summary}"
label "process_low"
publishDir "${params.outdir}/summary", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/nanoplot:1.42.0'
time '30m'
input:
file(summary)
output:
path "nanoplot/*", emit: final_directory
path "versions.yml", emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: ''
"""
mkdir -p nanoplot
NanoPlot ${args} \
--summary ${summary} \
--threads ${task.cpus} \
--outdir nanoplot \
--tsv_stats
cat <<-END_VERSIONS > versions.yml
"${task.process}":
nanoplot: \$(NanoPlot --version | awk '{print \$NF}')
END_VERSIONS
"""
}
process nanoplot {
tag "${meta.id}"
label "process_low"
publishDir "${params.outdir}/${meta.id}", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/nanoplot:1.42.0'
time '10m'
input:
tuple val(meta), file(fastq)
output:
path "nanoplot/*", emit: everything
path "nanoplot/${meta.id}*_NanoStats.txt", emit: stats
path "nanoplot/${meta.id}*_NanoStats.csv", emit: summary
path "versions.yml", emit: versions
when:
task.ext.when == null || task.ext.when
shell:
def args = task.ext.args ?: ''
def prefix = task.ext.prefix ?: "${meta.id}"
def readtype = fastq.toList().size() > 1 ? '_illumina' : ''
"""
mkdir -p nanoplot
NanoPlot ${args} \
--fastq ${fastq.join(' ')} \
--threads ${task.cpus} \
--prefix ${prefix}${readtype}_ \
--tsv_stats \
--outdir nanoplot
echo "sample,\$( cut -f 1 nanoplot/${prefix}${readtype}_NanoStats.txt | tr '\\n' ',' )" > nanoplot/${prefix}${readtype}_NanoStats.csv
echo "${prefix}${readtype},\$(cut -f 2 nanoplot/${prefix}${readtype}_NanoStats.txt | tr '\\n' ',' )" >> nanoplot/${prefix}${readtype}_NanoStats.csv
cat <<-END_VERSIONS > versions.yml
"${task.process}":
nanoplot: \$(NanoPlot --version | awk '{print \$NF}')
END_VERSIONS
"""
}
process png {
tag "${meta.id}"
label "process_low"
publishDir "${params.outdir}/${meta.id}/bandage", mode: 'copy', saveAs: { filename -> filename.equals('versions.yml') ? null : filename }
container 'staphb/multiqc:1.25'
time '10m'