-
Notifications
You must be signed in to change notification settings - Fork 3
/
run.nf
2668 lines (2345 loc) · 78.9 KB
/
run.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
//Global Parameters
params.assembly = "an_assembly"
params.readin = "NO_FILE"
params.hicreadf = "NO_FILE_HIC_R1"
params.hicreadr = "NO_FILE_HIC_R2"
params.matreadf = "NO_FILE_MAT_R1"
params.matreadr = "NO_FILE_MAT_R2"
params.patreadf = "NO_FILE_PAT_R1"
params.patreadr = "NO_FILE_PAT_R2"
params.outfasta = "genome.out.fasta"
params.outdir = 'results'
params.threads = '21'
params.lite = false
//Runtype Parameters
params.scaffold = false
params.kmer = 'kmc'
params.polish = false
params.polishtype = 'simple'
params.hapscaffold = false
params.yahs = false
params.patch = false
//HiFIASM Parameters
params.l = 0
params.mode = 'default'
params.ploidy = '2'
//Busco Parameters
params.busco = false
params.buscooffline = false
params.buscodb = "/work/busco"
params.linreage = 'insecta_odb10'
params.buscoevalue = '0.001'
//Shhquis.jl Prameters
params.hclustlinkage = "average"
bam_ch = Channel.fromPath(params.readin)
right_hicfastq_check = Channel.fromPath(params.hicreadr)
left_hicfastq_check = Channel.fromPath(params.hicreadf)
//right_matfastq_check = Channel.fromPath(params.matreadf)
//left_matfastq_check = Channel.fromPath(params.matreadr)
//right_patfastq_check = Channel.fromPath(params.patreadf)
//left_patfastq_check = Channel.fromPath(params.patreadr)
bam_ch.into {
in_check_ch
in_Hifi_ch
}
process check_in_file {
label 'shortq'
container = 'mgibio/alignment_helper-cwl:2.2.1'
cpus = 1
input:
file in_file from in_check_ch.flatten()
output:
stdout check_in_file_output
shell:
'''
state () { printf "%b\n" "[$(date)]: $*" 2>&1; }
error () { printf "%b\n" "[$(date)]: $*" >&2; exit 1; }
warn () { printf "%b\n" "[$(date)]: $*" >&2; }
touch check_bam.flag.txt
state "checking file type"
file=!{in_file}
stat $file
if [[ $file == *.bam ]]; then
state " ...file type is bam file type"
samtools flagstat $file
elif [[ $file == *.fastq.gz || $file == *.fq.gz ]]; then
state " ...file type is fastq gz file type"
state "check if file can be opened, and it starts with @"
at_check=$(zcat $file | awk '{ print $1; exit }')
[[ $at_check =~ '@' ]] || error "$file doesn't start with an @";
state "check if file can be divided by four"
modulo_four_check=$(zcat $file | grep -v "^=.*" | wc -l)
[[ $(( $modulo_four_check % 4 )) -eq 0 ]] || warn "number of lines in $file not divisible by four, continuing anyway"
elif [[ $file == *.fastq || *.fq ]]; then
state " ...file type is fastq file type"
state "check if file can be opened, and it starts with @"
at_check=$( head -n 1 $file )
[[ $at_check =~ '@' ]] || error "$file doesn't start with an @";
state "check if file can be divided by four"
modulo_four_check=$(cat $file | grep -v "^=.*" | wc -l)
[[ $(( $modulo_four_check % 4 )) -eq 0 ]] || warn "number of lines in $file not divisible by four, continuing anyway"
else
error "trying to run otb with somthing that does not end with the correct file type"
fi
state "check file on $file passed"
sleep 120;
exit 0;
'''
}
process check_fastq {
label 'shortq'
cpus = 1
input:
file right_fastq from right_hicfastq_check
file left_fastq from left_hicfastq_check
output:
file 'out/right.fastq.gz' into right_fastq_hicstuff, right_fastq_hicstuff_polish, right_yahs, simple_right_yahs, merfin_right_yahs, dv_right_yahs
file 'out/left.fastq.gz' into left_fastq_hicstuff, left_fastq_hicstuff_polish, left_yahs, simple_left_yahs, merfin_left_yahs, dv_left_yahs
file 'out/*.fastq.gz' into fasta_in_ch
stdout check_fastq_output
when:
!params.lite
shell:
'''
state () { printf "%b\n" "[$(date)]: $*" 2>&1; }
error () { printf "%b\n" "[$(date)]: $*" >&2; exit 1; }
warn () { printf "%b\n" "[$(date)]: $*" >&2; }
state "use touch to create a flag, so that I can be found easily"
touch check_fastq.flag.txt
state "stat !{right_fastq}..."
stat !{right_fastq}
state "stat !{left_fastq}..."
stat !{left_fastq}
state "if !{right_fastq} ends in gz zcat, and if it does not, cat the first line, save."
[[ !{right_fastq} =~ ".gz" ]] && first=$(zcat !{right_fastq} | awk '{ print $1; exit }') || first=$( cat !{right_fastq} | awk '{ print $1; exit }')
state "if !{left_fastq} end in gz zcat, and if it does not, cat the first line, save"
[[ !{left_fastq} =~ ".gz" ]] && second=$(zcat !{left_fastq} | awk '{ print $1; exit }') || second=$( cat !{left_fastq} | awk '{ print $1; exit }')
state "if the first line of the fastqs doesn't start with an @, error out, otherwise continue"
[[ $first =~ '@' ]] || error "!{right_fastq} doesn't start with an @";
[[ $second =~ '@' ]] || errror "!{left_fastq} doesn't start with an @";
state "check to make sure that fastqs are divisable by 4"
[[ !{right_fastq} =~ ".gz" ]] && first=$(zcat !{right_fastq} | grep -v "^=.*" | wc -l) || first=$( cat !{right_fastq} | grep -v "^=.*" | wc -l)
[[ !{left_fastq} =~ ".gz" ]] && second=$(zcat !{left_fastq} | grep -v "^=.*" | wc -l) || second=$( cat !{left_fastq} | grep -v "^=.*" | wc -l )
[[ $(( $first % 4 )) -eq 0 ]] || warn "number of lines in !{right_fastq} not divisable by four, continuing anyway"
[[ $(( $second % 4 )) -eq 0 ]] || warn "number of lines in !{left_fastq} not divisable by four, continuing anyway"
state "make softlinks for both files"
mkdir out
if [[ !{right_fastq} =~ ".gz" ]]; then
cd out
ln -s ../!{right_fastq} right.fastq.gz
cd ..
else
gzip -c !{right_fastq} > out/right.fastq.gz
fi
if [[ !{left_fastq} =~ ".gz" ]]; then
cd out
ln -s ../!{left_fastq} left.fastq.gz
cd ..
else
gzip -c !{left_fastq} > out/left.fastq.gz
fi
state "successful completion"
sleep 120;
exit 0;
'''
}
process HiFiAdapterFilt {
label 'shortq'
container = 'dmolik/pbadapterfilt'
cpus = params.threads
input:
file in_file from in_Hifi_ch.flatten()
output:
file '*.filt.fastq' into hifiasm_filt_fastq_ch, filt_fastq_ch, minimap_dv_filt_ch, minimap_merfin_filt_ch, meryl_filt_ch
stdout pbadapterfilt_output
"""
touch pbadapterfilt.flag.txt
pbadapterfilt.sh ${in_file} -t ${task.cpus}
gzip -d *.filt.fastq.gz
echo "finished adapter filtering"
sleep 120;
exit 0;
"""
}
process HiFiASM {
label 'longq'
container = 'dmolik/hifiasm'
cpus = params.threads
input:
file fasta from hifiasm_filt_fastq_ch.collect()
output:
file '*.gfa' into gfa_ch
file '*.ec.fa' into fasta_ec_ch
stdout HiFiASM_output
script:
if( params.mode == 'phasing' && params.hicreadr != 'NO_FILE_HIC_R1' && params.hicreadr != 'NO_FILE_HIC_R2' )
"""
touch hifiasm.flag.txt
hifiasm -l${params.l} -o ${params.assembly} -t 16 --write-paf --write-ec --h1 ${params.hicreadf} --h2 ${params.hicreadr} ${fasta} 2>&1
echo "finished alignment"
sleep 120;
exit 0;
"""
else if( params.mode == 'default')
"""
touch hifiasm.flag.txt
hifiasm -l${params.l} -o ${params.assembly} -t 16 --write-paf --write-ec ${fasta} 2>&1
echo "finished alignment"
sleep 120;
exit 0;
"""
else if( params.mode == 'primary')
"""
touch hifiasm.flag.txt
hifiasm -l${parms.l} -o ${params.assembly} --primary -t 16 --write-paf --write-ec ${fasta} 2>&1
echo "finished alignment"
sleep 120;
exit 0;
"""
else if( params.mode == 'trio' && params.patreadf != 'NO_FILE_PAT_R1' && params.patreadr != 'NO_FILE_PAT_R2' && params.matreadf != 'NO_FILE_MAT_R1' && params.matreadr != 'NO_FILE_MAT_R2')
"""
touch hifiasm.flag.txt
yak count -b37 -t${task.cpus} -o pat.yak <(zcat ${params.patreadf}) <(zcat ${params.patreadr})
yak count -b37 -t${task.cpus} -o mat.yak <(zcat ${params.matreadf}) <(zcat ${params.matreadr})
hifiasm -l${parms.l} -o ${params.assembly} --primary -t ${task.cpus} --write-paf --write-ec -1 pat.yak -2 mat.yak${fasta} 2>&1
echo "finished alignment"
sleep 120;
exit 0;
"""
else
error "Invalid alignment mode: ${params.mode}"
}
process gfa2fasta {
label 'shortq'
publishDir "${params.outdir}/01_hifiasm", mode: 'rellink'
container = 'pvstodghill/any2fasta'
cpus 1
input:
file gfa from gfa_ch.flatten()
output:
file '*.p_ctg.gfa.fasta' optional true into gfa2fasta_fasta_res_ch
file '*[a-z].p_ctg.gfa.fasta' optional true into fasta_unoriented_ch, fasta_genome_ch, fasta_busco_ch, no_polish_yahs_align_genome_ch, fasta_fai_yahs_genome_ch
file '*hap[12].p_ctg.gfa.fasta' optional true into fasta_hap_ch, simple_fasta_hap_polish_ch, merfin_fasta_hap_polish_ch, dv_fasta_hap_polish_ch, yahs_fasta_hap_polish_ch, yahs_simple_fasta_hap_polish_ch, yahs_merfin_fasta_hap_polish_ch, yahs_dv_fasta_hap_polish_ch
stdout gfa2fasta_output
"""
touch any2fasta.flag.txt
any2fasta ${gfa} > ${gfa}.fasta
echo "finished gfa to fasta conversion"
sleep 120;
exit 0;
"""
}
process busco_gfa {
label 'longq'
publishDir "${params.outdir}/01_hifiasm/busco", mode: 'rellink'
container = 'ezlabgva/busco:v5.2.2_cv1'
cpus = params.threads
input:
file fasta from fasta_busco_ch.flatten()
output:
file '*'
stdout busco_gfa_output
when:
params.busco
script:
if( params.linreage == 'auto-lineage' && params.buscooffline == false)
"""
touch busco.flag.txt
busco -q --long -e ${params.buscoevalue} -i ${fasta} -o "${params.assembly}_${fasta}_busco" -m genome -c ${task.cpus} --auto-lineage
exit 0;
"""
else if( params.linreage == 'auto-lineage-prok' && params.buscooffline == false)
"""
touch busco.flag.txt
busco -q --long -e ${params.buscoevalue} -i ${fasta} -o "${params.assembly}_${fasta}_busco" -m genome -c ${task.cpus} --auto-lineage-prok
exit 0;
"""
else if( params.linreage == 'auto-lineage-euk'&& params.buscooffline == false)
"""
touch busco.flag.txt
busco -q --long -e ${params.buscoevalue} -i ${fasta} -o "${params.assembly}_${fasta}_busco" -m genome -c ${task.cpus} --auto-lineage-euk
exit 0;
"""
else if( params.buscooffline == false)
"""
touch busco.flag.txt
busco -q --long -e ${params.buscoevalue} -i ${fasta} -o "${params.assembly}_${fasta}_busco" -m genome -c ${task.cpus} -l ${params.linreage}
exit 0;
"""
else if( params.buscooffline == true && params.buscodb == 'work/busco')
"""
touch busco.flag.txt
busco -q --long -e ${params.buscoevalue} -i ${fasta} -o "${params.assembly}_${fasta}_busco" -m genome -c ${task.cpus} -l ${params.linreage} --offline --download_path "$baseDir/work/busco"
exit 0;
"""
else if( params.buscooffline == true && params.buscodb != 'work/busco')
"""
touch busco.flag.txt
busco -q --long -e ${params.buscoevalue} -i ${fasta} -o "${params.assembly}_${fasta}_busco" -m genome -c ${task.cpus} -l ${params.linreage} --offline --download_path "$params.buscodb"
exit 0;
"""
else
"""
touch busco.flag.txt
"""
}
process ragtag_dot_py {
label 'longq'
container = 'dmolik/ragtag'
cpus = params.threads
input:
file fasta from fasta_unoriented_ch
file fasta_ec from fasta_ec_ch
output:
file "${params.assembly}_ragtag_ec_patch/ragtag.patch.fasta" into ragtag_fasta_res_ch, ragtag_fasta_genome_ch, fasta_fai_genome_ch, fasta_sshquis_genome_ch
stdout ragtag_dot_py_output
when:
params.polish
script:
if ( params.patch )
"""
touch ragtag.flag.txt
ragtag.py patch -u --aligner minimap2 -t ${task.cpus} --mm2-params '-x map-hifi -t ${task.cpus} -I 64GB -2 -K 4G -w 21 -k 21' -o ./${params.assembly}_ragtag_ec_patch ${fasta} ${fasta_ec}
echo "finished patching"
sleep 120;
exit 0;
"""
else
"""
touch ratag.flag.txt
echo "ignoring ragtag patch"
mkdir ${params.assembly}_ragtag_ec_patch
cd ${params.assembly}_ragtag_ec_patch
ln -s ../${fasta} ragtag.patch.fasta
sleep 120;
exit 0;
"""
}
process faidx {
label 'shortq'
container = 'mgibio/alignment_helper-cwl:2.2.1'
cpus 1
input:
file genome from fasta_fai_genome_ch
output:
file "*.fai" into fai_ch
stdout faidx_output
when:
params.polish
"""
touch faidx.flag.txt
samtools faidx -o ${genome}.fai ${genome}
echo "finished indexing"
sleep 120;
exit 0;
"""
}
process yahs_faidx {
label 'shortq'
container = 'mgibio/alignment_helper-cwl:2.2.1'
cpus 1
input:
file genome from fasta_fai_yahs_genome_ch
output:
file "${params.assembly}.yahs.fasta.fai" into yahs_fai_ch
file "${params.assembly}.yahs.fasta" into yahs_genome_ch
when:
params.yahs && params.scaffold
"""
touch faidx.yahs.flag.txt
ln -s ${genome} "${params.assembly}.yahs.fasta"
samtools faidx -o "${params.assembly}.yahs.fasta.fai" "${params.assembly}.yahs.fasta"
echo "finished indexing"
sleep 120;
exit 0;
"""
}
process hicstuff {
label 'longq'
publishDir "${params.outdir}/02_hicstuff", mode: 'rellink'
container = 'koszullab/hicstuff'
cpus = params.threads
input:
file genome from fasta_genome_ch
file left from left_fastq_hicstuff
file right from right_fastq_hicstuff
output:
file 'hicstuff_out/abs_fragments_contacts_weighted.bg2' into abs_ch
file 'hicstuff_out/info_contigs.txt' into contigs_ch
file 'hicstuff_out/fragments_list.txt'
file 'hicstuff_out/plots/frags_hist.pdf'
stdout hicstuff_output
when:
params.scaffold
"""
touch hicstuff.flag.txt
hicstuff pipeline -t ${task.cpus} -a minimap2 --no-cleanup -e 10000000 --force --out hicstuff_out --duplicates --matfmt=bg2 --plot -g ${genome} ${left} ${right}
echo "finished fragment calculations"
sleep 120;
exit 0;
"""
}
/*process hicstuff_polish {
label 'longq'
publishDir "${params.outdir}/02_hicstuff", mode: 'rellink'
container = 'koszullab/hicstuff'
cpus = params.threads
input:
file genome from ragtag_fasta_genome_ch
file left from left_fastq_hicstuff_polish
file right from right_fastq_hicstuff_polish
output:
file 'hicstuff_out/abs_fragments_contacts_weighted.bg2' into abs_ch
file 'hicstuff_out/polish_fragments_list.txt'
file 'hicstuff_out/info_contigs.txt' into contigs_ch
file 'hicstuff_out/plots/polish_frags_hist.pdf'
stdout hicstuff_polish_output
when:
params.polish && params.scaffold
"""
touch hicstuff_for_polished.flag.txt
hicstuff pipeline -t ${task.cpus} -a minimap2 --no-cleanup -e 10000000 --force --out hicstuff_out --duplicates --matfmt=bg2 --plot -g ${genome} ${left} ${right}
mv hicstuff_out/fragments_list.txt hicstuff_out/polish_fragments_list.txt
mv hicstuff_out/plots/frags_hist.pdf hicstuff_out/plots/polish_frags_hist.pdf
echo "finished fragment calculations"
sleep 120;
exit 0;
"""
}*/
process Shhquis_dot_jl {
label 'mediumq'
publishDir "${params.outdir}/03_polish", mode: 'rellink'
container = 'dmolik/shhquis'
cpus params.threads
input:
file abs from abs_ch
file contig from contigs_ch
file genome from fasta_sshquis_genome_ch
file fai from fai_ch
output:
file "${params.outfasta}" into shhquis_fasta_res_ch, polish_haps_genome_ch, shhquis_simple_ch, shhquis_merfin_ch, shhquis_dv_fai_ch, shhquis_dv_ch, shhquis_bcftools_dv_ch, shhquis_bcftools_merfin_ch, shhquis_dv_minimap_ch, shquis_minimap_merfin_ch, shhquis_mpileup_ch
file "${params.outfasta}"
stdout Shhquis_dot_jl_output
when:
params.polish
"""
touch shhquis.flag.txt
shh.jl --reorient ${params.outfasta} --genome ${genome} --fai ${fai} --bg2 ${abs} --contig ${contig} --hclust-linkage ${params.hclustlinkage} --threads ${task.cpus}
echo "finished reorientation"
sleep 120;
exit 0;
"""
}
process K_mer_counting {
label 'mediumq'
container = 'dmolik/k-mer-counting-tools'
cpus = params.threads
input:
file filt_reads from filt_fastq_ch.collect()
output:
file '*.histo' into histo_ch
file 'version.txt' into jellyfish_ver_ch
stdout jellyfish_output
script:
if( params.kmer == 'jellyfish' )
"""
touch jellyfish.flag.txt
jellyfish count -C -m 21 -s 1000000000 -t ${task.cpus} -o reads.jf ${filt_reads}
jellyfish histo -t ${task.cpus} reads.jf > ${params.assembly}.histo
jellyfish cite > version.txt
sleep 120;
exit 0;
"""
else if( params.kmer == 'kmc' )
"""
mkdir tmp
ls ${filt_reads} > FILES.lst
kmc -v -k21 -t${task.cpus} -ci1 -cs10000 @FILES.lst reads tmp/
kmc_tools transform reads histogram ${params.assembly}.histo -cx10000
kmc | head -n 1 > version.txt
"""
else
error "Invalid k-mer tool: ${params.kmer}"
}
process genomescope2 {
label 'mediumq'
publishDir "${params.outdir}/00_ordination/genomescope", mode: 'rellink'
container = 'dmolik/genomescope2'
cpus = params.threads
input:
file histo from histo_ch
output:
file "${params.assembly}/*"
file "kcov.txt" into kcov_ch
file "${params.assembly}/lookup_table.txt" into lookup_table_ch
file 'version.txt' into genomescope_ver_ch
stdout genomescope2_output
"""
touch genomescope.flag.txt
xvfb-run genomescope.R -i ${histo} -o ${params.assembly} -k 21 -p ${params.ploidy} --fitted_hist
genomescope.R --version > version.txt
awk '/kmercov [0-9]/ { print \$2 }' ${params.assembly}/model.txt >> kcov.txt
echo "finished genomescope"
sleep 120;
exit 0;
"""
}
process simple_fcs_adaptor {
label 'shortq'
publishDir "${params.outdir}/03_polish", mode: 'rellink'
container = 'dmolik/fcs-adaptor'
cpus = 1
input:
file genome from shhquis_simple_ch
output:
file 'cleaned_sequences/*' into simple_fcs_adaptor_ch
file '*'
stdout simple_fcs_adaptor_output
when:
params.polishtype == "simple"
"""
touch dv_fcs_adaptor.flag.txt
/app/fcs/bin/av_screen_x -o . --euk ${genome}
echo "finished simple fcs adaptor"
sleep 120;
exit 0;
"""
}
process simple_polish {
label 'shortq'
container = 'mgibio/alignment_helper-cwl:2.2.1'
cpus = 1
input:
file genome from simple_fcs_adaptor_ch
output:
file "${params.assembly}.polished.genome.fasta" into simple_polished_genome_ch, simple_polished_genome_busco_ch, yahs_simple_genome_ch, yahs_simple_align_genome_ch
file "${params.assembly}.polished.genome.fasta.fai" into yahs_simple_fai_ch
when:
params.polishtype == "simple"
"""
touch simple_polish.flag.txt
ln -s ${genome} ${params.assembly}.polished.genome.fasta
samtools faidx -o ${params.assembly}.polished.genome.fasta.fai ${params.assembly}.polished.genome.fasta
echo "finished softlink"
sleep 120;
exit 0;
"""
}
process minimap_for_merfin {
label 'mediumq'
container = 'dmolik/ragtag'
cpus = params.threads
input:
file filt_reads from minimap_merfin_filt_ch
file genome from shquis_minimap_merfin_ch
output:
file "mapped.sam" into sam_for_merfin_ch
stdout minimap_dot_sh_output
when:
params.polishtype == "merfin"
"""
touch minimap.flag.sh
minimap2 -a ${genome} ${filt_reads} > mapped.sam
echo "finished minimap"
sleep 120;
exit 0;
"""
}
process samtools_mpileup_merfin {
label 'mediumq'
container = 'mgibio/alignment_helper-cwl:2.2.1'
cpus = params.threads
input:
file sam_file from sam_for_merfin_ch
file genome from shhquis_mpileup_ch
output:
file 'out.mpileup' into bcf_for_merfin_ch
stdout samtools_mpileup_output
when:
params.polishtype == "merfin"
shell:
'''
touch samtools.mpileup.flag.txt
samtools sort -@ !{task.cpus} -o aln.bam !{sam_file}
samtools index -@ !{task.cpus} aln.bam
samtools view -H aln.bam | grep '@SQ' | sed 's/^.*SN://g' | cut -f 1 | xargs -I {} -n 1 -P !{task.cpus} sh -c "samtools mpileup -BQ0 -d 100000 -uf !{genome} -r {} aln.bam > tmp.{}.mpileup"
cat tmp.*.mpileup > out.mpileup
echo "finished mpileup"
sleep 120;
exit 0;
'''
}
process bcftools_refmt {
label 'shortq'
container = 'mgibio/bcftools:1.9'
cpus = params.threads
input:
file mpileup from bcf_for_merfin_ch
output:
file "final.reshaped.vcf.gz" into vcf_for_merfin_ch
stdout bcftools_refmt_output
when:
params.polishtype == "merfin"
"""
touch bcftools.qual.flag.txt
echo '##INFO=<ID=DP,Number=1,Type=Integer,Description="Approximate read depth; some reads may have been filtered">' > merfin_header.vcf
echo '##FORMAT=<ID=GT,Number=1,Type=String,Description="Genotype">' >> merfin_header.vcf
echo '##FORMAT=<ID=DP,Number=1,Type=Integer,Description="Read Depth">' >> merfin_header.vcf
cat ${mpileup} | bcftools call --threads ${task.cpus} -mv > var.raw.vcf
bcftools filter --threads ${task.cpus} -s LowQual -e '%QUAL<20 || DP>100' var.raw.vcf > var.flt.vcf
grep -v "#" var.flt.vcf | sed 's/,/;/g' > var.temp.reshaped.vcf
bcftools view --threads ${task.cpus} -h var.flt.vcf > var.temp.reshaped.header.vcf
cat var.temp.reshaped.header.vcf var.temp.reshaped.vcf > var.temp.reshaped.combined.vcf
rm var.temp.reshaped.header.vcf var.temp.reshaped.vcf
bcftools annotate --threads ${task.cpus} -h merfin_header.vcf var.temp.reshaped.combined.vcf > var.temp.reshaped.vcf
bcftools view --threads ${task.cpus} -h var.temp.reshaped.vcf | sed 's/\tINFO/\tINFO\tFORMAT\tIND/g' > var.reshaped.vcf
rm var.temp.reshaped.vcf
bcftools view --threads ${task.cpus} -H var.temp.reshaped.combined.vcf | awk -F"\t" -v OFS="\t" '{gsub(/DP=/,".\tGT:DP\t1/1:",\$8);print \$0}' >> var.reshaped.vcf
bcftools view --threads ${task.cpus} var.reshaped.vcf -Oz > final.reshaped.vcf.gz
rm var.reshaped.vcf
rm var.temp.reshaped.combined.vcf
echo "finished bcftools reformat"
sleep 120;
exit 0;
"""
}
process merfin {
label 'longq'
publishDir "${params.outdir}/03_polish", mode: 'rellink'
container = 'dmolik/merfin'
cpus = params.threads
input:
file genome from shhquis_merfin_ch
file kcov_file from kcov_ch
file lookup_table from lookup_table_ch
file filt_reads from meryl_filt_ch
file vcf_file from vcf_for_merfin_ch
output:
file 'merfin.polish.vcf' into merfin_vcf_ch
stdout merfin_output
when:
params.polishtype == "merfin"
shell:
'''
echo "warning merfin is experimental"
touch merfin.flag.txt
meryl count k=21 !{filt_reads} output reads.meryl
meryl greater-than 1 reads.meryl output reads.gt1.meryl
merfin -polish -threads !{task.cpus} -sequence !{genome} -peak $( cat !{kcov_file} | sed 's/e.*//g' ) -prob !{lookup_table} -readmers reads.gt1.meryl -vcf !{vcf_file} -output merfin
echo "finished merfin"
sleep 120;
exit 0;
'''
}
process minimap_for_deep_variant {
label 'mediumq'
container = 'dmolik/ragtag'
cpus = params.threads
input:
file filt_reads from minimap_dv_filt_ch
file genome from shhquis_dv_minimap_ch
output:
file "mapped.sam" into sam_for_dv_ch
stdout minimap_dv_output
when:
params.polishtype == "dv"
"""
touch minimap.dv.flag.sh
minimap2 -t ${task.cpus} -a ${genome} ${filt_reads} > mapped.sam
echo "finished minimap"
sleep 120;
exit 0;
"""
}
process samtools_index_for_deep_variant {
label 'shortq'
container = 'mgibio/alignment_helper-cwl:2.2.1'
cpus = params.threads
input:
file sam from sam_for_dv_ch
file genome from shhquis_dv_fai_ch
output:
file 'mapped.sort.bam' into bam_dv_index_ch
file '*.bai' into bai_dv_index_ch
file '*.fai' into fai_dv_index_ch
when:
params.polishtype == "dv"
"""
touch samtools.index.flag.txt
samtools view -S -b ${sam} > mapped.bam
samtools sort -@ ${task.cpus} mapped.bam -o mapped.sort.bam
samtools index -@ ${task.cpus} mapped.sort.bam
samtools faidx ${genome}
echo "finished indexing"
sleep 120;
exit 0;
"""
}
process deep_variant {
label 'longq'
publishDir "${params.outdir}/03_polish", mode: 'rellink'
container = 'google/deepvariant'
cpus = params.threads
input:
file genome from shhquis_dv_ch
file genome_fai from fai_dv_index_ch
file bam_read from bam_dv_index_ch
file bai_read from bai_dv_index_ch
output:
file 'google_dv.vcf' into dv_vcf_ch
file '*'
stdout deep_variant_output
when:
params.polishtype == "dv"
"""
echo "warning deep variant is experimental"
touch deep_variant.flag.txt
/opt/deepvariant/bin/run_deepvariant --model_type=PACBIO --ref=${genome} --reads=${bam_read} --output_vcf=google_dv.vcf --output_gvcf=google_dv.gvcf --num_shards=${task.cpus}
echo "finished deep variant"
sleep 120;
exit 0;
"""
}
process dv_bcftools {
label 'mediumq'
publishDir "${params.outdir}/03_polish", mode: 'rellink'
container = 'mgibio/bcftools:1.9'
cpus = params.threads
input:
file genome from shhquis_bcftools_dv_ch
file vcf from dv_vcf_ch
output:
file "${params.assembly}.vcf_polished_assembly.fasta" into dv_fcs_adaptor_ch
file "${params.assembly}.vcf_polished_assembly.fasta"
stdout dv_bcftools_output
when:
params.polishtype == "dv"
"""
touch dv.bcftools.flag.txt
bcftools view --threads ${task.cpus} -Oz ${vcf} > ${vcf}.gz
bcftools index --threads ${task.cpus} ${vcf}.gz
bcftools consensus ${vcf}.gz -f ${genome} -H 1 > ${params.assembly}.vcf_polished_assembly.fasta
echo "finished bcftools from deep variant"
sleep 120;
exit 0;
"""
}
process dv_fcs_adaptor {
label 'shortq'
publishDir "${params.outdir}/03_polish", mode: 'rellink'
container = 'dmolik/fcs-adaptor'
cpus = 1
input:
file genome from dv_fcs_adaptor_ch
output:
file 'cleaned_sequences/*' into dv_vcf_polished_genome_ch, dv_vcf_res_ch, dv_vcf_polished_busco_genome_ch, yahs_dv_genome_ch, yahs_dv_align_genome_ch
file '*'
stdout dv_fcs_adaptor_output
when:
params.polishtype == "dv"
"""
touch dv_fcs_adaptor.flag.txt
/app/fcs/bin/av_screen_x -o . --euk ${genome}
echo "finished dv fcs adaptor"
sleep 120;
exit 0;
"""
}
process merfin_bcftools {
label 'mediumq'
publishDir "${params.outdir}/03_polish", mode: 'rellink'
container = 'mgibio/bcftools:1.9'
cpus = params.threads
input:
file genome from shhquis_bcftools_merfin_ch
file vcf from merfin_vcf_ch
output:
file "${params.assembly}.vcf_polished_assembly.fasta" into merfin_fcs_adaptor_ch
file "${params.assembly}.vcf_polished_assembly.fasta"
stdout merfin_bcftools_output
when:
params.polishtype == "merfin"
"""
touch merfin.bcftools.flag.txt
bcftools view --threads ${task.cpus} -Oz ${vcf} > ${vcf}.gz
bcftools index --threads ${task.cpus} ${vcf}.gz
bcftools consensus ${vcf}.gz -f ${genome} > ${params.assembly}.vcf_polished_assembly.fasta
echo "finished bcftools from merfin"
sleep 120;
exit 0;
"""
}
process merfin_fcs_adaptor {
label 'shortq'
publishDir "${params.outdir}/03_polish", mode: 'rellink'
container = 'dmolik/fcs-adaptor'
cpus = 1
input:
file genome from merfin_fcs_adaptor_ch
output:
file 'cleaned_sequences/*' into merfin_vcf_polished_genome_ch, merfin_vcf_res_ch, merfin_vcf_polished_busco_genome_ch, yahs_merfin_genome_ch, yahs_merfin_align_genome_ch
file '*'
stdout merfin_fcs_adaptor_output
when:
params.polishtype == "merfin"
"""
touch merfin_fcs_adaptor.flag.txt
/app/fcs/bin/av_screen_x -o . --euk ${genome}
echo "finished merfin fcs adaptor"
sleep 120;
exit 0;
"""
}
process bwa_for_yahs {
label 'mediumq'
container = 'staphb/bwa'
cpus = params.threads
input:
file left_reads from left_yahs
file right_reads from right_yahs
file genome from no_polish_yahs_align_genome_ch
output:
file "mapped.sam" into yahs_sam_ch
stdout bwa_for_yahs_output
when:
params.yahs
"""
touch bwa.yahs.flag.sh
bwa index ${genome}
bwa mem -5SP -t ${task.cpus} ${genome} ${left_reads} ${right_reads} > mapped.sam
echo "finished bwa"
sleep 120;
exit 0;
"""
}
process bwa_for_simple_yahs {
label 'mediumq'
container = 'staphb/bwa'
cpus = params.threads
input:
file left_reads from simple_left_yahs
file right_reads from simple_right_yahs
file genome from yahs_simple_align_genome_ch
output:
file "mapped.sam" into yahs_simple_sam_ch
stdout bwa_for_yahs_simple_output
when:
params.yahs
"""
touch minimap.yahs.simple.flag.sh
bwa index ${genome}
bwa mem -5SP -t ${task.cpus} ${genome} ${left_reads} ${right_reads} > mapped.sam
echo "finished bwa"
sleep 120;
exit 0;
"""
}
process bwa_for_merfin_yahs {
label 'mediumq'
container = 'staphb/bwa'
cpus = params.threads
input:
file left_reads from merfin_left_yahs
file right_reads from merfin_right_yahs
file genome from yahs_merfin_align_genome_ch
output:
file "mapped.sam" into yahs_merfin_sam_ch
stdout bwa_for_yahs_merfin_output
when:
params.yahs
"""
touch bwa.yahs.merfin.flag.sh
bwa index ${genome}
bwa mem -5SP -t ${task.cpus} ${genome} ${left_reads} ${right_reads} > mapped.sam
echo "finished bwa"
sleep 120;
exit 0;
"""
}
process bwa_for_dv_yahs {
label 'mediumq'
container = 'staphb/bwa'
cpus = params.threads
input:
file left_reads from dv_left_yahs
file right_reads from dv_right_yahs
file genome from yahs_dv_align_genome_ch
output:
file "mapped.sam" into yahs_dv_sam_ch
stdout bwa_for_yahs_dv_output
when:
params.yahs
"""
touch bwa.yahs.merfin.flag.sh
bwa index ${genome}
bwa mem -5SP -t ${task.cpus} ${genome} ${left_reads} ${right_reads} > mapped.sam
echo "finished bwa"
sleep 120;
exit 0;
"""
}
process bam_sort_for_yahs {
label 'shortq'
container = 'mgibio/alignment_helper-cwl:2.2.1'
cpus = params.threads
input:
file sam_file from yahs_sam_ch
output:
file 'aln.bam' into bam_for_yahs_ch
stdout bam_sort_for_yahs_output
when:
params.yahs
shell:
'''
touch bam.sort.yahs.flag.txt
samtools view -S -h -F 2316 !{sam_file} | samblaster | samtools sort -n -@ !{task.cpus} -o aln.bam
echo "finished sort"
sleep 120;
exit 0;
'''
}
process bam_sort_for_simple_yahs {
label 'shortq'
container = 'mgibio/alignment_helper-cwl:2.2.1'
cpus = params.threads
input:
file sam_file from yahs_simple_sam_ch