-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.nf
executable file
·1353 lines (1135 loc) · 33.7 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
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
/* Minor Allele Simulation + Detection Pipeline
* Usage: nextflow run /path/to/main.nf
*
* Author: Mohammed Khalfan < mkhalfan@nyu.edu >
* NYU Center for Genetics and System Biology 2020
*/
// Setting some defaults here,
// can be overridden in config or via command line
params.out = "${params.outdir}/out"
params.tmpdir = "${params.outdir}/gatk_temp"
println "ref: $params.ref"
println "outdir: $params.out"
// Stage some files we will need
ref = file(params.ref)
error_model_fq_read1 = file(params.error_model_fq_read1)
error_model_fq_read2 = file(params.error_model_fq_read2)
mut_model_vcf = file(params.mut_model_vcf)
readsim_model_bam = file(params.readsim_model_bam)
// Prepare the fastq read pairs for input.
// Use the size parameter to not auto-group, and instead
// use the mapping through getBaseName() and subtract
// two regexs to get the ID.
// This enables support for CGSB sequence data file naming format
Channel
.fromFilePairs( params.reads, size: -1)
{ file -> file.getBaseName() - ~/((_read[12])|(_n0[12])|(_R[12]))/ - ~/.f*q/ }
.set { read_pairs_ch }
Channel
.fromFilePairs( params.bams, size: 1)
{ file -> file.getBaseName() - ~/.bam/ }
.set { bams_in_ch }
process buildIndex{
input:
path genome from params.ref
output:
path '*' into index_ch
script:
"""
bwa index $genome
samtools faidx $genome
java -jar \$PICARD_JAR CreateSequenceDictionary R=${genome} O=${genome.baseName}.dict
"""
}
process genMutModel{
output:
file('MutModel.p') into mut_model_ch
when:
params.do_sim_reads
script:
"""
python2 /apps/neat-genreads/2.0/utilities/genMutModel.py \
-r $ref \
-m $mut_model_vcf \
-o MutModel.p \
--no-whitelist
"""
}
process seqErrorModel{
output:
file('SeqErrorModel.p') into seq_err_model_ch
file('SeqErrorModel.p') into seq_err_model_ch_2
when:
params.do_sim_reads
script:
"""
python2 /apps/neat-genreads/2.0/utilities/genSeqErrorModel.py \
-i $error_model_fq_read1 \
-o SeqErrorModel.p \
-i2 $error_model_fq_read2
"""
}
process gcModel{
output:
file('gc_model.p') into gc_model_ch, gc_model_ch_2, gc_model_ch_3
when:
params.do_sim_reads
script:
"""
bedtools genomecov -d -ibam $readsim_model_bam > ${readsim_model_bam}.genomecov
python2 /apps/neat-genreads/2.0/utilities/computeGC.py -r $ref -i ${readsim_model_bam}.genomecov -o gc_model.p
"""
}
process fraglenModel{
output:
file('fraglen.p') into fraglen_model_ch
when:
params.do_sim_reads
script:
"""
samtools view $readsim_model_bam | python2 /apps/neat-genreads/2.0/utilities/computeFraglen.py
"""
}
process simulate_golden_snps{
publishDir "${params.out}/vcfsim_1", mode:'copy'
input:
file(mut_model) from mut_model_ch
file(seq_err_model) from seq_err_model_ch
file(gc_model) from gc_model_ch
output:
set val(pair_id),
file("${pair_id}_golden.vcf") into vcfsim_1_out_ch
file("${pair_id}_golden.vcf") into vcfsim_1_out_ch_2
file('*') into vcfsim_1_out
when:
params.do_sim_reads
script:
pair_id = params.fcid
"""
python2 /apps/neat-genreads/2.0/genReads.py \
-r $ref \
-p 100 \
-R 151 \
-o $pair_id \
-e $seq_err_model \
--gc-model $gc_model \
-m $mut_model \
-M $params.mut_rate \
--vcf \
--no-fastq \
-c $params.readsim_cov
"""
}
process simulate_pcr_snps{
publishDir "${params.out}/vcfsim_2", mode:'copy'
input:
set val(pair_id),
file(golden_vcf) from vcfsim_1_out_ch
file(gc_model) from gc_model_ch_3
each m_rate from params.m_rates
output:
set val(pair_id),
file("*.vcf") into vcfsim_2_out_ch
script:
name = m_rate[0]
m = m_rate[1]
pair_id = pair_id + "_${name}"
"""
python2 /apps/neat-genreads/2.0/genReads.py \
-r $ref \
-p 100 \
-R 151 \
-o $pair_id \
-v $golden_vcf \
--vcf \
--no-fastq \
-c $params.readsim_cov \
-M $m
"""
}
process set_vcf_afs{
publishDir "${params.out}/set_vcf_afs", mode:'copy'
input:
file (golden_vcf) from vcfsim_1_out_ch_2
set val(pair_id), file(vcf) from vcfsim_2_out_ch
each af from params.readsim_allele_fracs
output:
set val(pair_id),
file("${pair_id}.vcf") \
into set_vcf_afs_ch
set val(pair_id),
file("${pair_id}_golden.vcf") \
into golden_vcf_ch_out, golden_vcf_comp_ch, \
golden_vcf_bcftools_stats_ch
file("${pair_id}_golden.vcf") \
into analyze_af_report_vcf
script:
pair_id = pair_id + "_AF_${af}"
"""
prepare_neat_vcf.py $vcf $golden_vcf $ref $af $pair_id $params.seed
"""
}
process reorder_model_bam{
output:
file("reordered_model_bam.bam") into reorder_model_bam_ch
when:
params.do_sim_reads
script:
"""
java -jar \$PICARD_JAR ReorderSam \
INPUT=$readsim_model_bam \
OUTPUT=reordered_model_bam.bam \
REFERENCE=$ref
"""
}
process simulate_reads{
publishDir "${params.out}/readsim_2", mode:'copy'
input:
set val(pair_id),
file(vcf) from set_vcf_afs_ch
file(seq_err_model) from seq_err_model_ch_2
file(fraglen_model) from fraglen_model_ch
file(gc_model) from gc_model_ch_2
file(model_bam) from reorder_model_bam_ch
output:
set val(pair_id),
file("${pair_id}_read1.fq"),
file("${pair_id}_read2.fq") \
into readsim_out_ch
file("*") into readsim_out
script:
"""
# Simulate reads inserting snps from the output
# of the above step directly into the reads
python2 /apps/neat-genreads/2.0/genReads.py \
-r $ref \
-p 100 \
-R 151 \
-o ${pair_id} \
-e $seq_err_model \
-v ${vcf} \
--vcf \
--pe-model $fraglen_model \
--gc-model $gc_model \
-c $params.readsim_cov \
-M 0
# Simulate reads inserting snps from the output
# of the above step directly into the reads
# using ReSeq
#reseq illuminaPE \
# -r $ref \
# -b $model_bam \
# -V ${pair_id}.vcf \
# -1 ${pair_id}_read1.fq \
# -2 ${pair_id}_read2.fq \
# -c $params.readsim_cov \
# --noBias
"""
}
process downsample_readsim_fq{
publishDir "${params.out}/downsampled_fastqs", mode:'copy'
input:
set pair_id,
file(read1),
file(read2),
file(vcf) \
from readsim_out_ch
.join(golden_vcf_ch_out)
each seed_frac_pair from params.readsim_downsample_fracs
output:
set val(pair_id),
file("${pair_id}_read[12].fq") \
into readsim_downsampled_ch
//file("${pair_id}_golden.vcf") into downsample_bzip_tabix_vcf_ch
//file("${pair_id}_golden.vcf") into golden_vcf_comp_ch
//set val(pair_id),
// file("${pair_id}_golden.vcf") \
// into golden_vcf_comp_ch
//set val(mx_id),
// file("${mx_id}_golden.vcf") \
// into golden_vcf_comp_ch_mx
script:
seed = seed_frac_pair[0]
frac = seed_frac_pair[1]
pair_id = pair_id + "_frac_" + frac
//clean_id = pair_id.replaceFirst(/_m[12]_/, '_')
mx_id = pair_id.replaceFirst(/_m[12]_/, '_mx_')
downsampled_dp = params.readsim_cov * frac
if (frac < 1.0)
"""
seqtk sample -s${seed} ${read1} $frac > ${pair_id}_read1.fq
seqtk sample -s${seed} ${read2} $frac > ${pair_id}_read2.fq
#modify_neat_dp.py $vcf $downsampled_dp > ${pair_id}_golden.vcf
#cp ${pair_id}_golden.vcf ${mx_id}_golden.vcf
"""
else
"""
cp ${read1} ${pair_id}_read1.fq
cp ${read2} ${pair_id}_read2.fq
#modify_neat_dp.py $vcf $downsampled_dp > ${pair_id}_golden.vcf
#cp ${pair_id}_golden.vcf ${mx_id}_golden.vcf
"""
}
process trim {
publishDir "${params.out}/trimmed", mode:'copy'
input:
set pair_id,
file(reads) from read_pairs_ch
.mix(readsim_downsampled_ch)
output:
set val(pair_id),
file("${pair_id}_trimmed_1.fq.gz"),
file("${pair_id}_trimmed_2.fq.gz") \
into trimmed_ch_bwa, trimmed_ch_star
script:
trim_adapters = ''
if (params.adapters != '') {
trim_adapters = "ILLUMINACLIP:${params.adapters}:2:30:10:8:true"
}
"""
java -jar \$TRIMMOMATIC_JAR \
PE \
-phred33 \
-threads ${task.cpus} \
${reads[0]} \
${reads[1]} \
${pair_id}_trimmed_1.fq.gz \
${pair_id}.unpair_trimmed_1.fq.gz \
${pair_id}_trimmed_2.fq.gz \
${pair_id}.unpair_trimmed_2.fq.gz \
${trim_adapters} \
LEADING:20 TRAILING:20 SLIDINGWINDOW:4:20 MINLEN:20
"""
}
process star{
container 'docker://gencorefacility/star:2.7.6a'
publishDir "${params.out}/star", mode:'copy'
input:
set pair_id,
file(read_1),
file(read_2) from trimmed_ch_star
output:
set val(pair_id),
file("${pair_id}_star.Aligned.out.sam") \
into star_aligned_reads_ch
when:
params.aligner_star
script:
pair_id = pair_id + "_STAR"
"""
zcat $read_1 | paste - - - - | sort -k1,1 -t " " | tr "\t" "\n" > ${pair_id}_trimmed_1.sorted.fq
zcat $read_2 | paste - - - - | sort -k1,1 -t " " | tr "\t" "\n" > ${pair_id}_trimmed_2.sorted.fq
STAR \
--runThreadN ${task.cpus} \
--genomeDir ${params.star_ref} \
--outFilterScoreMinOverLread 0.3 \
--outFilterMatchNminOverLread 0.3 \
--readFilesIn ${pair_id}_trimmed_1.sorted.fq ${pair_id}_trimmed_2.sorted.fq \
--outReadsUnmapped Fastx \
--outFileNamePrefix ${pair_id}_star.
"""
}
process addReadGroups {
//publishDir "${params.out}/star_readgroups_added", mode:'copy'
input:
set val(sample_id),
file(sam) from star_aligned_reads_ch
.mix(bams_in_ch)
output:
set val(sample_id),
file("${sample_id}_star.Aligned.out.RG.Sorted.bam") \
into rg_added_ch
script:
"""
gatk AddOrReplaceReadGroups \
-I ${sam} \
-O ${sample_id}_star.Aligned.out.RG.Sorted.bam \
--SORT_ORDER coordinate \
-RGID ${sample_id} \
-RGLB ${sample_id} \
-RGPL ${params.pl} \
-RGPU ${params.fcid} \
-RGSM ${sample_id}
"""
}
process bwa {
publishDir "${params.out}/aligned_reads", mode:'copy'
input:
file genome from ref
file index from index_ch
set pair_id,
file(read_1),
file(read_2) from trimmed_ch_bwa
output:
set val(pair_id),
file("${pair_id}_aligned_reads.bam") \
into aligned_reads_ch
when:
params.aligner_bwa || (!params.aligner_star and !params.aligner_bbmap)
script:
pair_id = pair_id + "_BWA"
readGroup = "@RG\\tID:${pair_id}\\tLB:${pair_id}\\tPL:${params.pl}\\tPM:${params.pm}\\tSM:${pair_id}"
"""
bwa mem \
-K 100000000 \
-v 3 -t ${task.cpus} \
-Y \
-R \"${readGroup}\" \
$genome \
$read_1 \
$read_2 \
> ${pair_id}_aligned_reads.sam
java -jar \$PICARD_JAR SortSam \
I=${pair_id}_aligned_reads.sam \
O=${pair_id}_aligned_reads.bam \
SORT_ORDER=coordinate \
CREATE_INDEX=true
"""
}
process check_for_mapped_reads{
input:
set val(sample_id),
file(bam) from aligned_reads_ch
.mix(rg_added_ch)
output:
file ("${sample_id}.txt") optional true into no_mapped_reads_ch
set val(sample_id),
file("${bam.baseName}_mapped.bam") optional true into mapped_reads_ch
script:
"""
x=(\$(samtools view -F 4 $bam | wc -l))
if [ \$x -lt 2 ]
then
echo $sample_id " FAILED mapped reads check"
echo $sample_id > ${sample_id}.txt
else
mv $bam ${bam.baseName}_mapped.bam
fi
"""
}
process markDuplicatesSpark {
publishDir "${params.out}/sorted", mode:'copy'
input:
set val(sample_id),
file(bam) from mapped_reads_ch
output:
set val(sample_id),
file("${sample_id}_sorted_dedup.bam") \
into sorted_dedup_bam_ch, sorted_dedup_ch_for_metrics, \
downsample_bam_ch, pilon_ch, bcftools_ch, mutect2_ch, \
tims_pipeline_ch, varscan_ch, ivar_ch, cliquesnv_ch
set val(sample_id),
file("${sample_id}_sorted_dedup.bam"),
file("${sample_id}_sorted_dedup.bam.bai") \
into bw_ch, freebayes_ch, lofreq_ch, qualimap_ch
set val(sample_id),
file("${sample_id}_dedup_metrics.txt") into dedup_qc_ch
val(sample_id) into pair_id_ch
set val(sample_id), file(bam) into genomecov_ch
script:
"""
gatk \
MarkDuplicatesSpark \
-I ${bam} \
-M ${sample_id}_dedup_metrics.txt \
-O ${sample_id}_sorted_dedup.bam
"""
}
process genomecov{
input:
set val(sample_id),
file(bam) from genomecov_ch
output:
file("${sample_id}.tsv") into cov_plot_ch
script:
"""
bedtools genomecov -d -ibam $bam > ${sample_id}.tsv
sed -i "s/^/${sample_id}\t/" ${sample_id}.tsv
"""
}
process cov_plot{
publishDir "${params.out}/reports", mode:'copy'
input:
file(tsv) from cov_plot_ch.collect()
output:
file("*") into cov_plot_out_ch
script:
"""
cat *.tsv > cov_data.tsv
sed -i '1i name\tsegment\tntpos\ttotalcount' cov_data.tsv
cov_plots.R ${params.fcid}-${workflow.runName}
mv cov_data.tsv ${params.fcid}_${workflow.runName}_cov_data.tsv
"""
}
process getMetrics {
publishDir "${params.out}/metrics", mode:'copy'
input:
path index from index_ch
set val(sample_id),
file(sorted_dedup_reads) from sorted_dedup_ch_for_metrics
output:
set val(sample_id),
file("${sample_id}_alignment_metrics.txt"),
file("${sample_id}_insert_metrics.txt"),
file("${sample_id}_insert_size_histogram.pdf"),
file("${sample_id}_depth_out.txt") \
into metrics_output, metrics_multiqc_ch
script:
"""
java -jar \$PICARD_JAR \
CollectAlignmentSummaryMetrics \
R=${ref} \
I=${sorted_dedup_reads} \
O=${sample_id}_alignment_metrics.txt
java -jar \$PICARD_JAR \
CollectInsertSizeMetrics \
INPUT=${sorted_dedup_reads} \
OUTPUT=${sample_id}_insert_metrics.txt \
HISTOGRAM_FILE=${sample_id}_insert_size_histogram.pdf
samtools depth -a ${sorted_dedup_reads} > ${sample_id}_depth_out.txt
"""
}
process timo{
publishDir "${params.out}/timo", mode:'copy'
input:
set val(sample_id),
file(preprocessed_bam) from tims_pipeline_ch
each timo_config from params.timo_configs
output:
file("${sample_id}_timo_${name}.vcf") \
into tims_bzip_tabix_vcf_ch, timo_reps
set val(sample_id),
file("${sample_id}_timo_${name}.vcf") \
into tims_vcf_ch, tims_bcftools_stats_ch
set val("${sample_id}"),
val("${sample_id}_timo_${name}") \
into timo_rep_ids
file("${sample_id}_timo_${name}_no-binom-check.vcf") \
into tims_bzip_tabix_vcf_ch_2, timo_reps_2
set val(sample_id),
file("${sample_id}_timo_${name}_no-binom-check.vcf") \
into tims_vcf_ch_2, tims_bcftools_stats_ch_2
set val("${sample_id}"),
val("${sample_id}_timo_${name}_no-binom-check") \
into timo_rep_ids_2
file ("${sample_id}_*") into tims_out_ch
script:
name = timo_config[0]
samtools_params = timo_config[1]
timo_params = timo_config[2]
"""
samtools view -b $samtools_params -o filtered.bam $preprocessed_bam
samtools index filtered.bam
timo.v2.py $timo_params --infile filtered.bam --ref $ref
## parse_tims_output.py will look for all files created by
## timo.v2.py in the working directory and convert
## them into a single VCF file
parse_tims_output.py $ref ${sample_id}
mv ${sample_id}.vcf ${sample_id}_timo_${name}.vcf
parse_tims_output.py $ref ${sample_id} true
mv ${sample_id}.vcf ${sample_id}_timo_${name}_no-binom-check.vcf
mkdir ${sample_id}_${name}
mv FILES/fullvarlist/*.csv ${sample_id}_${name}/.
"""
}
process test_pileup{
//publishDir "${params.out}/failed", mode:'copy', pattern: '*.txt'
input:
set val(sample_id),
file(bam) from varscan_ch
output:
file ("${sample_id}.txt") optional true into failed_ch
set val(sample_id),
file("${bam.baseName}_passed.bam") optional true into pileup_passed_ch
script:
"""
x=(\$(samtools mpileup -f $ref $bam | wc -l))
if [ \$x -eq 0 ]
then
echo $sample_id " FAILED pileup check"
echo $sample_id > ${sample_id}.txt
else
mv $bam ${bam.baseName}_passed.bam
fi
"""
}
process varscan {
publishDir "${params.out}/varscan", mode:'copy'
input:
set val(sample_id),
file(preprocessed_bam) from pileup_passed_ch
each vs_config from params.vs_configs
output:
file("${sample_id}_varscan_${name}.vcf") \
into varscan_bzip_tabix_vcf_ch, vs_reps
set val(sample_id),
file("${sample_id}_varscan_${name}.vcf") \
into varscan_vcf_ch, varscan_bcftools_stats_ch
//file("${sample_id}_varscan_${name}.vcf") into vs_reps
set val("${sample_id}"),
val("${sample_id}_varscan_${name}") into vs_rep_ids
script:
name = vs_config[0]
samtools_params = vs_config[1]
vs_params = vs_config[2]
"""
samtools mpileup $samtools_params -f $ref --max-depth 0 $preprocessed_bam |\
java -jar \$VARSCAN_JAR mpileup2snp $vs_params \
--output-vcf 1 > ${sample_id}_varscan_${name}.vcf
"""
}
process ivar{
publishDir "${params.out}/ivar", mode:'copy'
input:
set val(sample_id),
file(preprocessed_bam) from ivar_ch
each ivar_config from params.ivar_configs
output:
file("${sample_id}_ivar_${name}.vcf") \
into ivar_bzip_tabix_vcf_ch, ivar_reps
set val(sample_id),
file("${sample_id}_ivar_${name}.vcf") \
into ivar_vcf_ch, ivar_bcftools_stats_ch
//file("${sample_id}_ivar_${name}.vcf") into ivar_reps
set val("${sample_id}"),
val("${sample_id}_ivar_${name}") into ivar_rep_ids
script:
name = ivar_config[0]
ivar_params = ivar_config[1]
"""
samtools mpileup -aa -A -d 0 -B -Q 0 ${preprocessed_bam} |\
ivar variants $ivar_params \
-p ${sample_id}_ivar_${name} \
-r $ref
ivar_to_vcf.py ${sample_id}_ivar_${name}.tsv
"""
}
process lofreq{
publishDir "${params.out}/lofreq", mode:'copy'
input:
set val(sample_id),
file(preprocessed_bam),
file(preprocessed_bam_index) from lofreq_ch
each lofreq_config from params.lofreq_configs
output:
file("${sample_id}_lofreq_${name}.vcf") \
into lofreq_bzip_tabix_vcf_ch, lofreq_reps
set val(sample_id),
file("${sample_id}_lofreq_${name}.vcf") \
into lofreq_vcf_ch, lofreq_bcftools_stats_ch
file '*' into lofreq_out_ch
//file("${sample_id}_lofreq_${name}.vcf") into lofreq_reps
set val("${sample_id}"),
val("${sample_id}_lofreq_${name}") into lofreq_rep_ids
script:
name = lofreq_config[0]
lofreq_params = lofreq_config[1]
"""
lofreq call-parallel $lofreq_params \
--pp-threads ${task.cpus} \
-f $ref \
-o ${sample_id}_lofreq_${name}.vcf \
$preprocessed_bam
"""
}
process cliquesnv{
publishDir "${params.out}/cliquesnv", mode:'copy'
input:
set val(sample_id),
file(preprocessed_bam) from cliquesnv_ch
output:
file("${sample_id}_cliquesnv.vcf") into cliquesnv_bzip_tabix_vcf_ch
set val(sample_id),
file("${sample_id}_cliquesnv.vcf") \
into cliquesnv_vcf_ch
file '*' into cliquesnv_out_ch
when:
false
script:
"""
java -Xmx58G -jar \$CLIQUESNV_JAR \
-m snv-illumina-vc \
-in $preprocessed_bam \
-outDir vcf_out/ \
-t 1 \
-tf 0.005
mv vcf_out/${preprocessed_bam.baseName}.vcf ${sample_id}_cliquesnv.vcf
# CliqueSNV names contig as 'ref' for some reason, rename it to 'SARS-CoV2'
# here for downstream analysis (ex: bcftools isec). Todo: Make this param
sed -i 's/ref/SARS-CoV2/g' ${sample_id}_cliquesnv.vcf
"""
}
process freebayes{
publishDir "${params.out}/freebayes", mode:'copy'
input:
set val(sample_id),
file(preprocessed_bam),
file(preprocessed_bam_index) from freebayes_ch
each freebayes_config from params.freebayes_configs
output:
file("${sample_id}_freebayes_${name}.vcf") \
into freebayes_bzip_tabix_vcf_ch, freebayes_reps
set val(sample_id),
file("${sample_id}_freebayes_${name}.vcf") \
into freebayes_vcf_ch, freebayes_bcftools_stats_ch
file '*' into freebayes_out_ch
//file("${sample_id}_freebayes_${name}.vcf") into freebayes_reps
set val("${sample_id}"),
val("${sample_id}_freebayes_${name}") into freebayes_rep_ids
script:
name = freebayes_config[0]
fb_params = freebayes_config[1]
"""
freebayes $fb_params -f $ref $preprocessed_bam > ${sample_id}_freebayes_${name}.vcf
"""
}
process mutect2{
publishDir "${params.out}/mutect2", mode:'copy'
input:
file genome from ref
file index from index_ch
set val(sample_id),
file(preprocessed_bam) from mutect2_ch
each m2_config from params.m2_configs
output:
set val(sample_id),
file("${sample_id}_mutect2_${name}_filtered.vcf") \
into m2_vcf_ch, m2_bcftools_stats_ch
set val(sample_id),
file("${sample_id}_mutect2_${name}_unfiltered.vcf") \
into m2_unfiltered_vcf_ch, m2_unfiltered_bcftools_stats_ch
file("${sample_id}_mutect2_${name}_unfiltered.vcf") into mutect2_bzip_tabix_vcf_ch
file '*' into mutect2_out_ch
file("${sample_id}_mutect2_${name}_filtered.vcf") into m2_reps
set val("${sample_id}"),
val("${sample_id}_mutect2_${name}_filtered") into m2_rep_ids
file("${sample_id}_mutect2_${name}_unfiltered.vcf") into m2_unfiltered_reps
set val("${sample_id}"),
val("${sample_id}_mutect2_${name}_unfiltered") into m2_unfiltered_rep_ids
script:
name = m2_config[0]
m2_params = m2_config[1]
"""
gatk Mutect2 \
-R $genome \
$m2_params \
--max-reads-per-alignment-start 0 \
-I $preprocessed_bam \
-O ${sample_id}_mutect2_${name}_unfiltered.vcf
gatk FilterMutectCalls \
-R $genome \
-V ${sample_id}_mutect2_${name}_unfiltered.vcf \
-O tmp.vcf
gatk SelectVariants \
-R $genome \
-V tmp.vcf \
--exclude-filtered \
-O ${sample_id}_mutect2_${name}_filtered.vcf
"""
}
process pilon{
publishDir "${params.out}/pilon", mode:'copy'
input:
set val(sample_id),
file(preprocessed_bam) from pilon_ch
output:
file("${sample_id}_pilon.vcf") into pilon_bzip_tabix_vcf_ch
file '*' into pilon_out_ch
when:
false
script:
"""
java -Xmx16G -jar \$PILON_JAR \
--genome $ref \
--bam $preprocessed_bam \
--fix bases \
--changes \
--vcf \
--threads ${task.cpus} \
--mindepth 10 \
--output ${sample_id}_pilon_g
gatk SelectVariants \
-V ${sample_id}_pilon_g.vcf \
-O ${sample_id}_pilon.vcf \
--exclude-non-variants \
--exclude-filtered
"""
}
process bcftools{
publishDir "${params.out}/bcftools", mode:'copy'
input:
set val(sample_id),
file(preprocessed_bam) from bcftools_ch
output:
file("${sample_id}_bcftools.vcf") into bcftools_bzip_tabix_vcf_ch
when:
false
script:
"""
bcftools mpileup \
--redo-BAQ \
--adjust-MQ 50 \
--gap-frac 0.05 \
--max-depth 10000 \
--max-idepth 200000 \
--fasta-ref $ref \
$preprocessed_bam | bcftools call \
--ploidy 1 \
--keep-alts \
--multiallelic-caller \
--variants-only \
--output ${sample_id}_bcftools.vcf
"""
}
process haplotypeCaller {
publishDir "${params.out}/haplotypecaller", mode:'copy'
input:
file genome from ref
file index from index_ch
set val(sample_id),
file(preprocessed_bam) from sorted_dedup_bam_ch
each hc_config from params.hc_configs
output:
set val(sample_id),
file("${sample_id}_hc_${name}.vcf") \
into raw_snps_ch, raw_snps_qc_ch, hc_vcf_ch, \
hc_bcftools_stats_ch
file("${sample_id}_hc_${name}.vcf") into hc_reps
set val("${sample_id}"),
val("${sample_id}_hc_${name}") into hc_rep_ids
script:
name = hc_config[0]
hc_params = hc_config[1]
"""
gatk HaplotypeCaller $hc_params \
--max-reads-per-alignment-start 0 \
-R $genome \
-I $preprocessed_bam \
-O ${sample_id}_raw_variants.vcf
gatk SelectVariants \
-R $genome \
-V ${sample_id}_raw_variants.vcf \
-select-type SNP \
-O ${sample_id}_hc_${name}.vcf
"""
}
process filterSnps {
publishDir "${params.out}/filtered_snps", mode:'copy'
input:
set val(sample_id),
file(raw_snps) from raw_snps_ch
output:
set val(sample_id),
file("${sample_id}_filtered_snps.vcf") \
into filtered_snps_qc_ch
// we're not filtering haplotypecaller snps
when:
false
script:
"""
gatk VariantFiltration \
-R $ref \
-V $raw_snps \
-O ${sample_id}_filtered_snps.vcf \
-filter-name "QD_filter" -filter "QD < 2.0" \
-filter-name "FS_filter" -filter "FS > 60.0" \
-filter-name "MQ_filter" -filter "MQ < 40.0" \
-filter-name "SOR_filter" -filter "SOR > 4.0" \
-filter-name "ReadPosRankSum_filter" -filter "ReadPosRankSum < -8.0"
# This script generates the _consensus_snps.vcf
# and _eaf.vcf (empirical AF) files
filter_variants.py ${sample_id}
"""
}
process snpEff {
publishDir "${params.out}/snpeff", mode:'copy'