forked from jdemeul/nanowgs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
executable file
·844 lines (603 loc) · 29.5 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
#!/usr/bin/env nextflow
/*
====================================
N A N O W G S
====================================
nanowgs Analysis Pipeline.
https://github.com/AlexanRNA/nanowgs
------------------------------------
*/
nextflow.enable.dsl=2
log.info """\
LIST OF PARAMETERS
================================
GENERAL
Results-folder : $params.outdir
Sample ID: : $params.sampleid
================================
INPUT & REFERENCES
Input-files : $params.ont_base_dir
Reference genome : $params.genomeref
================================
"""
// Command line shortcuts, quick entry point:
include { basecall_reads as basecall } from './modules/guppy'
include { filter_reads as filter } from './modules/fastp'
include { parallel_gzip as pigz; parallel_gzip_assembly; parallel_gzip_gfa } from './modules/pigz'
include { minimap_alignment as minimap } from './modules/minimap2'
include { sam_to_sorted_bam as samtobam; bam_to_sorted_bam as bamtobam1; bam_to_sorted_bam as bamtobam2; get_haplotype_readids; index_bam_longpohase ; ubam2fastq ; sam_to_sorted_bam_qscore } from './modules/samtools'
include { sniffles_sv_calling as sniffles } from './modules/sniffles'
include { svim_sv_calling as svim } from './modules/svim'
include { cutesv_sv_calling as cutesv } from './modules/cutesv'
include { dysgu_sv_calling as dysgu } from './modules/dysgu'
include { svim_sv_filtering as filtersvim; sniffles_sv_filtering as filtersniffles; variant_filtering as filter_snp_indel } from './modules/bcftools'
include { vcf_concat; vcf_concat_sv_snv as merge_sv_snv } from './modules/bcftools'
include { longphase_phase; longphase_tag; longphase_zip_index} from './modules/longphase'
include { seqtk } from './modules/seqtk'
include { survivor_sv_consensus as survivor } from './modules/survivor'
include { medaka_snv_calling as medaka_snv } from './modules/medaka'
include { deepvariant_snv_calling_slurm as deepvariant } from './modules/deepvariant'
// include { deepvariant_snv_calling_gpu_parallel as deepvariant_par } from './modules/deepvariant'
include { run_shasta_assembly as shasta } from './modules/shasta'
include { racon_assembly_polishing as racon } from './modules/racon'
include { medaka_assembly_polishing as medaka_polish } from './modules/medaka'
include { medaka_assembly_polish_align; medaka_assembly_polish_stitch; medaka_assembly_polish_consensus } from './modules/medaka'
include { hapdup; hapdup_with_haptagged_bam as hapduptagged; haptagtransfer } from './modules/hapdup'
include { flye_polishing as flye_hap1; flye_polishing as flye_hap2 } from './modules/flye'
include { dipdiff } from './modules/dipdiff'
include { dipdiff as dipdiff_reference } from './modules/dipdiff'
include { create_personal_genome as crossstitch; prepare_svs_stitch } from './modules/crossstitch'
include { run_quast as quast_hap1; run_quast as quast_hap2; run_quast as quast_hap1_ref; run_quast as quast_hap2_ref } from './modules/quast'
include { run_mummer as mummer_hap1; run_mummer as mummer_hap2; run_mummer as mummer_hap1_ref; run_mummer as mummer_hap2_ref } from './modules/mummer'
include { run_pycoqc } from './modules/pycoqc'
include { clair3_variant_calling } from './modules/clair3'
include { fast5_2pod5 } from './modules/pod5'
include { basecall_dorado } from './modules/dorado'
include { cramino } from './modules/cramino'
include { kyber } from './modules/kyber'
include { mosdepth; mosdepth_plot} from './modules/mosdepth'
include { extract_SV_lengths; plot_SV_lengths } from './modules/r-visualisation'
include { modkit_stats; modkit_adjustmods_5mC; modkit_adjustmods_5hC; modkit_adjustmods_m6A; modkit_pileup; modkit_pileup as modkit_pileup2; remove_a; overlap as overlap1; overlap as overlap2; visualise_intersect; visualise_intersect as visualise_intersect2 } from './modules/modkit'
/*
* Dorado basecalling
* Allows to basecall directly from fast5 or pod5
* The output is a bam file
*/
workflow dorado_call {
// use the below line only if skip is still present
// ont_basedir = Channel.fromPath( "${params.ont_base_dir + '/*{fast5_pass,fast5_fail}'}" , checkIfExists: true, type: 'dir' ).collect()
// use parameter fast5 to check if the data are in fast5 or pod5
if ( params.fast5 ){
// convert fast5 to pod5
ont_basedir = Channel.fromPath( params.ont_base_dir, checkIfExists: true )
fast5_2pod5(ont_basedir)
basecall_dorado( fast5_2pod5.out.reads_pod5 )
} else {
// if pod5 format, go directly to basecalling
ont_basedir = Channel.fromPath( params.ont_base_dir, checkIfExists: true )
basecall_dorado( ont_basedir )
}
}
/**
* Slurm pipeline using dorado output
*
*/
workflow slurm_dorado {
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
genomerefidx = Channel.fromPath( params.genomerefindex, checkIfExists: true )
//alignment
// todo decouple ubam to fastq from the rest, so I can feed fastq to shasta
// ubam_to_bam(Channel.fromPath( params.ubam , checkIfExists: true ), genomeref)
// index_bam(ubam_to_bam.out.mapped_bam)
// ubam to fastq
ubam2fastq( Channel.fromPath( params.ubam , checkIfExists: true ))
// mapping and sam to bam
minimap_align_bamout_qscore( genomeref, ubam2fastq.out.fastq.collect() )
// cramino and kyber for quick QC
kyber ( minimap_align_bamout_qscore.out.bam )
cramino ( minimap_align_bamout_qscore.out.bam )
mosdepth (minimap_align_bamout_qscore.out.bam, minimap_align_bamout_qscore.out.idx )
mosdepth_plot ( mosdepth.out.coverage_txt )
//TODO test
// modified bases QC
if ( params.mod_bases != "") {
modkit_stats ( minimap_align_bamout_qscore.out.bam )
modkit_adjustmods_5hC ( minimap_align_bamout_qscore.out.bam )
modkit_adjustmods_5mC ( modkit_adjustmods_5hC.out.out_bam )
modkit_adjustmods_m6A ( minimap_align_bamout_qscore.out.bam )
// sort andd index modbams
bamtobam1 ( modkit_adjustmods_5mC.out.out_bam, genomeref )
bamtobam2 ( modkit_adjustmods_m6A.out.out_bam, genomeref )
// check if input files exist
beds = Channel.fromPath( [params.tss_bed, params.ctcf_bed], checkIfExists: true ).flatten()
beds.view()
modkit_pileup ( bamtobam1.out.sorted_bam, bamtobam1.out.bam_index )
modkit_pileup2 ( bamtobam2.out.sorted_bam, bamtobam2.out.bam_index )
// remove "a" rows from modkit pileup
remove_a ( modkit_pileup2.out.out_bed )
// bedtools intersect
overlap1 ( modkit_pileup.out.out_bed, beds )
overlap2 ( remove_a.out.out_bed, beds )
// visualise intersect
visualise_intersect ( overlap1.out.intersect_beds )
visualise_intersect2 ( overlap2.out.intersect_beds )
}
// variant calling from alignment
clair3_variant_calling(minimap_align_bamout_qscore.out.bam, minimap_align_bamout_qscore.out.idx, genomeref, genomerefidx)
filter_snp_indel( clair3_variant_calling.out.snp_indel )
sniffles( minimap_align_bamout_qscore.out.bam, minimap_align_bamout_qscore.out.idx, genomeref )
filtersniffles( sniffles.out.sv_calls )
// SV size visualisation
extract_SV_lengths( filtersniffles.out.variants_pass )
plot_SV_lengths( extract_SV_lengths.out.dels, extract_SV_lengths.out.ins)
// longphase
// phasing
longphase_phase( genomeref, filter_snp_indel.out.variants_pass, filtersniffles.out.variants_pass, minimap_align_bamout_qscore.out.bam, minimap_align_bamout_qscore.out.idx )
longphase_zip_index(longphase_phase.out.snv_indel_phased, longphase_phase.out.sv_phased)
longphase_tag( longphase_phase.out.snv_indel_phased, longphase_phase.out.sv_phased, minimap_align_bamout_qscore.out.bam, minimap_align_bamout_qscore.out.idx , genomeref)
index_bam_longpohase(longphase_tag.out.haplotagged_bam)
// crossstitch
// crossstitch( longphase_phase.out.snv_indel_phased, longphase_phase.out.sv_phased, minimap_align_bamout_qscore.out.bam, genomeref, params.karyotype )
// TODO
// add annotation dfam R script
// de novo assembly
// TODO test both trimmed and untrimmed + below code
filter( ubam2fastq.out.fastq.collect() )
shasta( filter.out.fastq_trimmed )
parallel_gzip_assembly ( shasta.out.assembly )
parallel_gzip_gfa ( shasta.out.assembly_gfa )
// hapdup
// use reference-based haplotype tags to assure assembly-based haplotypes match reference-based ones
// TODO test if it works with zipped fasta assembly
// haptagtransfer( longphase_tag.out.haplotagged_bam, parallel_gzip_assembly.out.assembly )
// hapduptagged( haptagtransfer.out.retagged_bam, haptagtransfer.out.retagged_bamindex, parallel_gzip_assembly.out.assembly )
}
/*
* Building slurm pipeline with guppy basecalling included
*
*/
workflow slurm_guppy {
// guppy basecalling
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
genomerefidx = Channel.fromPath( params.genomerefindex, checkIfExists: true )
basecall( Channel.fromPath( params.ont_base_dir ), genomeref )
// filtering and trimming
filter( basecall.out.fastqs.collect() )
pigz( filter.out.fastq_trimmed )
// alignment
minimap_align_bamout( genomeref, pigz.out.fastqgz )
// variant calling from alignment
deepvariant( minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, genomeref )
filter_snp_indel( deepvariant.out.indel_snv_vcf )
clair3_variant_calling(minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, genomeref, genomerefidx)
sniffles( minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, genomeref )
filtersniffles( sniffles.out.sv_calls )
// shasta assembly
shasta( pigz.out.fastqgz )
// QC
run_pycoqc ( basecall.out.seq_summary, minimap_align_bamout.out.bam, minimap_align_bamout.out.idx )
// phasing
longphase_phase( genomeref, filter_snp_indel.out.variants_pass, filtersniffles.out.variants_pass, minimap_align_bamout.out.bam, minimap_align_bamout.out.idx )
longphase_tag( longphase_phase.out.snv_indel_phased, longphase_phase.out.sv_phased, minimap_align_bamout.out.bam, minimap_align_bamout.out.idx , genomeref)
crossstitch( longphase_phase.out.snv_indel_phased, filtersniffles.out.variants_pass, minimap_align_bamout.out.bam, genomeref, params.karyotype )
// use reference-based haplotype tags to assure assembly-based haplotypes match reference-based ones
haptagtransfer( longphase_tag.out.haplotagged_bam, shasta.out.assembly )
hapduptagged( haptagtransfer.out.retagged_bam, haptagtransfer.out.retagged_bamindex, shasta.out.assembly )
}
/*
* Fastq to SV/SNP call
*
*/
workflow fastq_process {
// genome
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
genomerefidx = Channel.fromPath( params.genomerefindex, checkIfExists: true )
// filtering and trimming
filter( Channel.fromPath( params.fastq + "*.fastq.gz" ).collect() )
pigz( filter.out.fastq_trimmed )
// alignment
minimap_align_bamout( genomeref, pigz.out.fastqgz )
// cramino and kyber for quick QC
kyber ( minimap_align_bamout.out.bam )
cramino ( minimap_align_bamout.out.bam )
mosdepth (minimap_align_bamout.out.bam, minimap_align_bamout.out.idx )
mosdepth_plot ( mosdepth.out.coverage_txt )
clair3_variant_calling(minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, genomeref, genomerefidx)
filter_snp_indel( clair3_variant_calling.out.snp_indel )
sniffles( minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, genomeref )
filtersniffles( sniffles.out.sv_calls )
// SV size visualisation
extract_SV_lengths( filtersniffles.out.variants_pass )
plot_SV_lengths( extract_SV_lengths.out.dels, extract_SV_lengths.out.ins)
// longphase
// phasing
longphase_phase( genomeref, filter_snp_indel.out.variants_pass, filtersniffles.out.variants_pass, minimap_align_bamout.out.bam, minimap_align_bamout.out.idx )
longphase_tag( longphase_phase.out.snv_indel_phased, longphase_phase.out.sv_phased, minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, genomeref )
// crossstitch
crossstitch( longphase_phase.out.snv_indel_phased, longphase_phase.out.sv_phased, minimap_align_bamout.out.bam, genomeref, params.karyotype )
// de novo assembly
shasta( filter.out.fastq_trimmed )
parallel_gzip_assembly ( shasta.out.assembly )
parallel_gzip_gfa ( shasta.out.assembly_gfa )
}
/*
* SNP calling, longphase, crossstitch
*
*/
workflow bam_to_crossstitch {
// genome
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
genomerefidx = Channel.fromPath( params.genomerefindex, checkIfExists: true )
inputbam = Channel.fromPath( params.bam , checkIfExists: true )
inputbamidx = Channel.fromPath( params.bamidx , checkIfExists: true )
clair3_variant_calling(inputbam, inputbamidx, genomeref, genomerefidx)
filter_snp_indel( clair3_variant_calling.out.snp_indel )
sniffles( inputbam, inputbamidx, genomeref )
filtersniffles( sniffles.out.sv_calls )
// SV size visualisation
extract_SV_lengths( filtersniffles.out.variants_pass )
plot_SV_lengths( extract_SV_lengths.out.dels, extract_SV_lengths.out.ins)
// longphase
// phasing
longphase_phase( genomeref, filter_snp_indel.out.variants_pass, filtersniffles.out.variants_pass, inputbam, inputbamidx )
longphase_tag( longphase_phase.out.snv_indel_phased, longphase_phase.out.sv_phased, inputbam, inputbamidx, genomeref )
// crossstitch
crossstitch( longphase_phase.out.snv_indel_phased, longphase_phase.out.sv_phased, inputbam, genomeref, params.karyotype )
}
/*
* longphase, crossstitch from INDEL and SV calls
*
*/
workflow calls_to_crossstitch {
// genome
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
genomerefidx = Channel.fromPath( params.genomerefindex, checkIfExists: true )
inputclair3 = Channel.fromPath( params.clair_file , checkIfExists: true )
inputsniffles = Channel.fromPath( params.sniffles_file , checkIfExists: true )
inputbam = Channel.fromPath( params.bam , checkIfExists: true )
inputbamidx = Channel.fromPath( params.bamidx , checkIfExists: true )
filter_snp_indel( inputclair3 )
// longphase
// phasing
longphase_phase( genomeref, filter_snp_indel.out.variants_pass, inputsniffles, inputbam, inputbamidx )
longphase_tag( longphase_phase.out.snv_indel_phased, longphase_phase.out.sv_phased, inputbam, inputbamidx, genomeref )
// crossstitch
crossstitch( longphase_phase.out.snv_indel_phased, longphase_phase.out.sv_phased, inputbam, genomeref, params.karyotype )
}
/*
* longphase, crossstitch from INDEL and SV calls
*
*/
workflow crossstitch_cli {
// genome
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
genomerefidx = Channel.fromPath( params.genomerefindex, checkIfExists: true )
inputclair3 = Channel.fromPath( params.clair_file , checkIfExists: true )
inputsniffles = Channel.fromPath( params.sniffles_file , checkIfExists: true )
inputbam = Channel.fromPath( params.bam , checkIfExists: true )
inputbamidx = Channel.fromPath( params.bamidx , checkIfExists: true )
// crossstitch
crossstitch( inputclair3, inputsniffles, inputbam, genomeref, params.karyotype )
}
/*
* Guppy basecalling
*/
workflow guppy_basecalling_cli {
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
// genomeindex = Channel.fromPath( params.genomeref + "/indexes/minimap2-ont/genome.mmi" )
basecall( Channel.fromPath( params.ont_base_dir ), genomeref )
}
/*
* Sam to sorted bam conversion and indexing – CLI shortcut
*/
workflow sam_to_sorted_bam_cli {
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
sam = Channel.fromPath( params.mapped_sam, checkIfExists: true )
samtobam( sam, genomeref )
}
/*
* Call structural variation and generate consensus
*/
workflow call_svs {
take:
genomeref
bam
bam_index
// step
main:
cutesv( bam, bam_index, genomeref )
sniffles( bam, bam_index, genomeref )
svim( bam, bam_index, genomeref )
filtersvim( svim.out.sv_calls )
dysgu( bam, bam_index, genomeref )
allsvs = cutesv.out.sv_calls
.mix( sniffles.out.sv_calls, filtersvim.out.sv_calls_q10 )
.collect()
survivor( allsvs )
emit:
cutesv = cutesv.out.sv_calls
sniffles = sniffles.out.sv_calls
svim = filtersvim.out.sv_calls_q10
consensus = survivor.out.sv_consensus
}
/*
* Call structural variation and generate consensus
*/
workflow call_svs_cli {
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
// genomeindex = Channel.fromPath( params.genomeref + "/indexes/minimap2-ont/genome.mmi" )
bam = Channel.fromPath( params.aligned_bam )
bam_index = Channel.fromPath( params.aligned_bam + ".bai" )
call_svs( genomeref, bam, bam_index, "cli" )
}
/*
* Call small variants using ONT Medaka
*/
workflow medaka_variant_calling_cli {
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
// genomeindex = Channel.fromPath( params.genomeref + "/indexes/minimap2-ont/genome.mmi" )
aligned_reads = Channel.fromPath( params.aligned_bam )
aligned_reads_idx = Channel.fromPath( params.aligned_bam + ".bai" )
medaka_snv( aligned_reads, aligned_reads_idx, genomeref )
}
/*
* Call small variants using PEPPER-Margin-DeepVariant – CLI shortcut
*/
workflow pepper_deepvariant_calling_cli {
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
// genomeindex = Channel.fromPath( params.genomeref + "/indexes/minimap2-ont/genome.mmi" )
bam = Channel.fromPath( params.aligned_bam )
bam_index = Channel.fromPath( params.aligned_bam + ".bai" )
deepvariant( bam, bam_index, genomeref )
}
// /*
// * Run a de novo genome assembly using Shasta – CLI shortcut
// */
// workflow shasta_assembly_cli {
// fastq = Channel.fromPath( params.processed_reads )
// config = Channel.fromPath( params.shasta_config )
// shasta( fastq, config )
// }
workflow assembly_polishing {
take:
assembly
fastq
main:
minimap( assembly, fastq )
racon( fastq, minimap.out.mapped_sam, assembly )
// medaka_polish( fastq, racon.out.consensus )
medaka_polish_parallel( fastq, racon.out.consensus )
emit:
polished_assembly = medaka_polish_parallel.out.consensus
}
workflow deepvariant_parallel {
take:
bam
bam_index
genomeref
main:
contigs = genomeref.splitFasta( record: [id: true, seqString: false ]).map { it.id }
deepvariant_par( bam, bam_index, genomeref, contigs )
vcf_concat( deepvariant_par.out.indel_snv_vcf.collect() )
emit:
indel_snv_vcf = vcf_concat.out.merged_vcf
}
workflow medaka_polish_parallel {
take:
fastqs
draft
main:
medaka_assembly_polish_align( fastqs, draft )
// draft.splitFasta( record: [id: true, seqString: false ]).view { it.id }
contigs = draft.splitFasta( record: [id: true, seqString: false ]).map { it.id }.randomSample( 100000, 234 ).buffer( size: 50, remainder: true )
medaka_assembly_polish_consensus( medaka_assembly_polish_align.out.calls_to_draft,
medaka_assembly_polish_align.out.calls_to_draft_index,
contigs )
medaka_assembly_polish_stitch( medaka_assembly_polish_consensus.out.probs.collect(), draft )
emit:
consensus = medaka_assembly_polish_stitch.out.consensus
}
workflow medaka_polish_parallel_cli {
fastqs = Channel.fromPath( params.processed_reads )
draft = Channel.fromPath( params.genomeref )
medaka_assembly_polish_parallel( fastqs, draft )
}
/*
* Process reads/squiggles from an ONT run
*/
workflow process_reads {
take:
genomeref
ont_base
main:
if ( params.rebasecall ) {
// if ( !file( params.genomeref + "/indexes/minimap2-ont/genome.mmi" ).exists() ) {
// create_minimap_index( genomeref )
// genomeindex = create_minimap_index.out.mmi
// } else {
// genomeindex = Channel.fromPath( params.genomeref + "/indexes/minimap2-ont/genome.mmi" )
// }
basecall( Channel.fromPath( params.ont_base_dir ), genomeref )
filter( basecall.out.fastqs.collect() )
} else if ( params.basecall_dir ) {
filter( Channel.fromPath( params.basecall_dir + "**.fastq.gz" ).collect() )
} else {
filter( Channel.fromPath( params.ont_base_dir + "**.fastq.gz" ).collect() )
}
pigz( filter.out.fastq_trimmed )
emit:
fastq_trimmed = filter.out.fastq_trimmed
}
/*
* Process reads/squiggles from an ONT run – CLI shortcut
*/
workflow process_reads_cli {
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
ont_base = Channel.fromPath( params.ont_base_dir )
process_reads( genomeref, ont_base )
}
/*
* Align reads to a reference genome using minimap2 and turn into sorted bam – CLI shortcut
*/
workflow minimap_alignment_cli {
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
fastqs = Channel.fromPath( params.processed_reads )
minimap( genomeref, fastqs )
}
workflow minimap_align_bamout {
take:
genomeref
fastq
main:
minimap( genomeref, fastq )
samtobam( minimap.out.mapped_sam, genomeref )
emit:
bam = samtobam.out.sorted_bam
idx = samtobam.out.bam_index
}
workflow minimap_align_bamout_qscore {
take:
genomeref
fastq
main:
minimap( genomeref, fastq )
sam_to_sorted_bam_qscore( minimap.out.mapped_sam, genomeref )
emit:
bam = sam_to_sorted_bam_qscore.out.sorted_bam
idx = sam_to_sorted_bam_qscore.out.bam_index
}
workflow lra_alignment_sv_calling {
take:
fastqs
genomeref
main:
// genome indexing
if ( !file( params.genomeref + "/indexes/lra-ont/genome.fa.gli" ).exists() || !file( params.genomeref + "/indexes/lra-ont/genome.fa.mmi" ).exists() ) {
create_lra_index( genomeref )
genomeindex_gli = create_lra_index.out.gli
genomeindex_mmi = create_lra_index.out.mmi
} else {
genomeindex_gli = Channel.fromPath( params.genomeref + "/indexes/lra-ont/genome.fa.gli" )
genomeindex_mmi = Channel.fromPath( params.genomeref + "/indexes/lra-ont/genome.fa.mmi" )
}
// alignment and conversion into indexed sorted bam
lra_alignment( genomeref, fastqs, genomeindex_gli, genomeindex_mmi )
samtobam( lra_alignment.out.mapped_sam, genomeref )
// SV calling using cuteSV
cutesv( samtobam.out.sorted_bam, samtobam.out.bam_index, genomeref )
}
workflow assembly_based_variant_calling {
take:
fastq
// genomeref
main:
// 1. Assembly-based pipeline
shasta( fastq )
// assembly_polishing( shasta.out.assembly, fastq)
// minimap_align_bamout( assembly_polishing.out.polished_assembly, fastq )
// minimap( assembly_polishing.out.polished_assembly, fastq )
// samtobam( minimap.out.mapped_sam, assembly_polishing.out.polished_assembly )
// call_svs( assembly_polishing.out.polished_assembly, minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, "assembly" )
// deepvariant( minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, assembly_polishing.out.polished_assembly, "assembly" )
// call_svs( assembly_polishing.out.polished_assembly, samtobam.out.sorted_bam, samtobam.out.bam_index )
// deepvariant( samtobam.out.sorted_bam, samtobam.out.bam_index, assembly_polishing.out.polished_assembly )
emit:
polished_assembly = shasta.out.assembly
// svs = call_svs.out.consensus
// snvs = deepvariant.out.indel_snv_vcf
// snvs_idx = deepvariant.out.indel_snv_vcf_index
}
workflow reference_based_variant_calling {
take:
fastq
genomeref
main:
// minimap( genomeref, fastq )
// samtobam( minimap.out.mapped_sam, genomeref )
minimap_align_bamout( genomeref, fastq )
// note that on the current VSC system (P100 and V100 nodes) GPU nodes
// lack sufficient memory to run PEPPER-DeepVariant genome-wide
// the current if statement reflects that and splits up the genome by chromosome to run as separate jobs
// if ( params.deepvariant_with_gpu ) {
// deepvar = deepvariant_parallel( minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, genomeref )
// } else {
deepvariant( minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, genomeref )
// }
call_svs( genomeref, deepvariant.out.haplotagged_bam, deepvariant.out.haplotagged_bam_idx )
emit:
svs = call_svs.out.consensus
snvs = deepvariant.out.indel_snv_vcf
snvs_idx = deepvariant.out.indel_snv_vcf_index
haplotagged_bam = deepvariant.out.haplotagged_bam
haplotagged_bam_idx = deepvariant.out.haplotagged_bam_idx
}
workflow haploid_to_diploid_assembly {
take:
fastq
reference
haploid_assembly
main:
minimap_align_bamout( haploid_assembly, fastq )
hapdup( minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, haploid_assembly )
// dipdiff( haploid_assembly, hapdup.out.hap1, hapdup.out.hap2 )
dipdiff_reference( reference, hapdup.out.hap1, hapdup.out.hap2 )
}
workflow wgs_analysis_fastq {
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
ont_base = Channel.fromPath( params.ont_base_dir, checkIfExists: true )
// process reads
process_reads( genomeref, ont_base )
// 2. Reference alignment-based pipeline
minimap_align_bamout( genomeref, process_reads.out.fastq_trimmed )
deepvariant( minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, genomeref )
filter_snp_indel( deepvariant.out.indel_snv_vcf )
sniffles( minimap_align_bamout.out.bam, minimap_align_bamout.out.idx, genomeref )
filtersniffles( sniffles.out.sv_calls )
longphase_phase( genomeref, filter_snp_indel.out.variants_pass, filtersniffles.out.variants_pass, minimap_align_bamout.out.bam, minimap_align_bamout.out.idx )
longphase_tag( longphase_phase.out.snv_indel_phased, longphase_phase.out.sv_phased, minimap_align_bamout.out.bam, minimap_align_bamout.out.idx , genomeref)
// seqtk( longphase_tag.out.hap1ids, longphase_tag.out.hap2ids, process_reads.out.fastq_trimmed )
// prepare_svs_stitch( longphase_phase.out.sv_phased, genomeref )
// crossstitch( longphase_phase.out.snv_indel_phased, prepare_svs_stitch.out.fixed_svs, genomeref, params.karyotype )
crossstitch( longphase_phase.out.snv_indel_phased, filtersniffles.out.variants_pass, minimap_align_bamout.out.bam, genomeref, params.karyotype )
// de novo assembly using shasta
shasta( process_reads.out.fastq_trimmed )
// use reference-based haplotype tags to assure assembly-based haplotypes match reference-based ones
haptagtransfer( longphase_tag.out.haplotagged_bam, shasta.out.assembly )
hapduptagged( haptagtransfer.out.retagged_bam, haptagtransfer.out.retagged_bamindex, shasta.out.assembly )
// quast_hap1( genomeref, hapduptagged.out.hap1, "hap1" )
// quast_hap1_ref( genomeref, crossstitch.out.hap1, "hap1" )
// quast_hap2( genomeref, hapduptagged.out.hap2, "hap2" )
// quast_hap2_ref( genomeref, crossstitch.out.hap2, "hap2" )
// mummer_hap1( genomeref, hapduptagged.out.hap1, "hap1" )
// mummer_hap2( genomeref, hapduptagged.out.hap2, "hap2" )
// mummer_hap1_ref( genomeref, crossstitch.out.hap1, "hap1" )
// mummer_hap2_ref( genomeref, crossstitch.out.hap2, "hap2" )
// snv_indel = reference_based_variant_calling.out.snvs
// get_haplotype_readids( reference_based_variant_calling.out.haplotagged_bam )
}
workflow {
genomeref = Channel.fromPath( params.genomeref, checkIfExists: true )
ont_base = Channel.fromPath( params.ont_base_dir, checkIfExists: true )
// basecalls = Channel.fromPath( params.basecall_dir )
// reads = Channel.fromPath( params.processed_reads, checkIfExists: true )
// genomeindex = Channel.fromPath( params.genomeref + "/indexes/minimap2-ont/genome.mmi" )
// process reads
process_reads( genomeref, ont_base )
// assembly based variant calling
assembly_based_variant_calling( process_reads.out.fastq_trimmed )
// 2. Reference alignment-based pipeline
reference_based_variant_calling( process_reads.out.fastq_trimmed, genomeref )
// snv_indel = reference_based_variant_calling.out.snvs
haploid_to_diploid_assembly( process_reads.out.fastq_trimmed, genomeref, assembly_based_variant_calling.out.polished_assembly )
// lra_alignment_sv_calling( process_reads.out.fastq_trimmed, genomeref )
// minimap_alignment_snv_calling( process_reads.out.fastq_trimmed, genomeref )
get_haplotype_readids( reference_based_variant_calling.out.haplotagged_bam )
}
// -m ${Math.floor( $task.memory / $task.cpus ) }
// ch_reference_fasta.view()
// ch_reference_index.view()
workflow.onComplete {
println "Pipeline completed at: ${workflow.complete}"
println "Time to complete workflow execution: ${workflow.duration}"
println "Execution status: ${workflow.success ? 'Succesful' : 'Failed' }"
}