-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathpipeface.nf
1354 lines (1201 loc) · 53.5 KB
/
pipeface.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
nextflow.enable.dsl=2
// create dummy NONE file for optional pipeface inputs
def filePath = "NONE"
new File(filePath).text = "Dummy file for optional pipeface inputs. Don't delete during a pipeline run unless you want a bad time.\n"
// set defaults for optional params (set default optional input files to dummy NONE file)
// secret sauce second outdir
params.outdir2 = ""
params.tandem_repeat = "NONE"
params.annotate_override = ""
params.in_data_format_override = ""
process scrape_settings {
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$filename" }, pattern: '*pipeface_settings.txt'
input:
tuple val(sample_id), val(family_id), val(extension), val(files), val(data_type), val(regions_of_interest), val(clair3_model)
val in_data
val in_data_format
val ref
val ref_index
val tandem_repeat
val snp_indel_caller
val sv_caller
val annotate
val calculate_depth
val outdir
val outdir2
output:
tuple val(sample_id), val(family_id), path('pipeface_settings.txt')
script:
// conditionally define reported SV caller
if( sv_caller == 'both' ) {
reported_sv_caller = 'cutesv,sniffles'
}
else if ( sv_caller == 'sniffles' ) {
reported_sv_caller = 'sniffles'
}
else if ( sv_caller == 'cutesv' ) {
reported_sv_caller = 'cutesv'
}
else if ( sv_caller == 'NONE' ) {
reported_sv_caller = 'NONE'
}
// conditionally define reported in data format
if ( in_data_format == 'ubam_fastq' ) {
reported_in_data_format = 'unaligned BAM and/or FASTQ'
}
else if ( in_data_format == 'aligned_bam' ) {
reported_in_data_format = 'aligned BAM'
}
else if ( in_data_format == 'snv_vcf' ) {
reported_in_data_format = 'SNP/indel VCF'
}
else if ( in_data_format == 'sv_vcf' ) {
reported_in_data_format = 'SV VCF'
}
if ( in_data_format == 'ubam_fastq' | in_data_format == 'aligned_bam' )
"""
echo "Sample ID: $sample_id" >> pipeface_settings.txt
echo "Family ID: $family_id" >> pipeface_settings.txt
echo "In data format: $reported_in_data_format" >> pipeface_settings.txt
echo "Input data file/files: $files" >> pipeface_settings.txt
echo "Data type: $data_type" >> pipeface_settings.txt
echo "Regions of interest file: $regions_of_interest" >> pipeface_settings.txt
echo "Clair3 model: $clair3_model" >> pipeface_settings.txt
echo "In data csv path: $in_data" >> pipeface_settings.txt
echo "Reference genome: $ref" >> pipeface_settings.txt
echo "Reference genome index: $ref_index" >> pipeface_settings.txt
echo "Tandem repeat file: $tandem_repeat" >> pipeface_settings.txt
echo "SNP/indel caller: $snp_indel_caller" >> pipeface_settings.txt
echo "SV caller: $reported_sv_caller" >> pipeface_settings.txt
echo "Annotate: $annotate" >> pipeface_settings.txt
echo "Calculate depth: $calculate_depth" >> pipeface_settings.txt
echo "Outdir: $outdir" >> pipeface_settings.txt
"""
else if( in_data_format == 'snv_vcf' | in_data_format == 'sv_vcf' )
"""
echo "Sample ID: $sample_id" >> pipeface_settings.txt
echo "Family ID: $family_id" >> pipeface_settings.txt
echo "In data format: $reported_in_data_format" >> pipeface_settings.txt
echo "Input data file/files: $files" >> pipeface_settings.txt
echo "In data csv path: $in_data" >> pipeface_settings.txt
echo "Annotate: $annotate" >> pipeface_settings.txt
echo "Outdir: $outdir" >> pipeface_settings.txt
"""
stub:
"""
touch pipeface_settings.txt
"""
}
process scrape_bam_header {
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$file_short.$filename" }
input:
tuple val(sample_id), val(family_id), val(extension), val(file), val(file_short)
val outdir
val outdir2
output:
tuple val(sample_id), val(family_id), val(file_short), path('header')
script:
if( extension == 'gz' )
"""
echo "none" > header
"""
else if ( extension == 'fastq' )
"""
echo "none" > header
"""
else if( extension == 'bam' )
"""
samtools head $file > header
"""
stub:
"""
touch header
"""
}
process merge_runs {
input:
tuple val(sample_id), val(family_id), val(extension), path(files)
output:
tuple val(sample_id), val(family_id), path('merged')
script:
if( extension == 'gz' )
"""
${
if (files instanceof List && files.size() > 1) {
"cat ${files} > merged"
} else {
"ln -s ${files} merged"
}
}
"""
else if ( extension == 'fastq' )
"""
${
if (files instanceof List && files.size() > 1) {
"cat ${files} | bgzip -@ ${task.cpus} > merged"
} else {
"ln -s ${files} merged"
}
}
"""
else if( extension == 'bam' )
"""
${
if (files instanceof List && files.size() > 1) {
"samtools merge -@ ${task.cpus} ${files} -o merged"
} else {
"ln -s ${files} merged"
}
}
"""
stub:
"""
touch merged
"""
}
process minimap2 {
input:
tuple val(sample_id), val(family_id), path(merged), val(extension), val(data_type)
val ref
val ref_index
output:
tuple val(sample_id), val(family_id), path('sorted.bam')
script:
// conditionally define preset
if( data_type == 'ont' ) {
preset = 'lr:hq'
}
else if( data_type == 'pacbio' ) {
preset = 'map-hifi'
}
if( extension == 'bam' )
"""
# run minimap
samtools fastq \
-@ ${task.cpus} \
-T '*' \
$merged | minimap2 \
-y \
-Y \
--secondary=no \
--MD \
-a \
-x $preset \
-t ${task.cpus} \
$ref - | samtools sort -@ ${task.cpus} -o sorted.bam -
# index bam
samtools index \
-@ ${task.cpus} \
sorted.bam
"""
else if( extension == 'gz' | extension == 'fastq' )
"""
# run minimap
minimap2 \
-y \
-Y \
--secondary=no \
--MD \
-a \
-x $preset \
-t ${task.cpus} \
$ref \
$merged | samtools sort -@ ${task.cpus} -o sorted.bam -
# index bam
samtools index \
-@ ${task.cpus} \
sorted.bam
"""
stub:
"""
touch sorted.bam
touch sorted.bam.bai
"""
}
process minimod {
def software = "minimod"
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$ref_name.$software.$filename" }, pattern: 'modfreqs.bed'
input:
tuple val(sample_id), val(family_id), path(bam), val(data_type)
val ref
val ref_index
val outdir
val outdir2
val ref_name
output:
tuple val(sample_id), val(family_id), path('modfreqs.bed'), optional: true
script:
if( data_type == 'ont' )
"""
# stage bam and bam index
# do this here instead of input tuple so I can handle processing an aligned bam as an input file without requiring a bam index for ubam input
bam_loc=\$(realpath ${bam})
ln -sf \${bam_loc} sorted.bam
ln -sf \${bam_loc}.bai .
ln -sf \${bam_loc}.bai sorted.bam.bai
# run minimod
minimod \
mod-freq \
-b \
$ref \
$bam \
-t ${task.cpus} \
-o modfreqs.bed
"""
else if( data_type == 'pacbio' )
"""
echo "Data type is pacbio, not running minimod on this data."
"""
stub:
"""
touch modfreqs.bed
"""
}
process mosdepth {
def depth_software = "mosdepth"
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$ref_name.$depth_software.$filename" }, pattern: 'depth.txt'
input:
tuple val(sample_id), val(family_id), path(bam), val(regions_of_interest)
val mosdepth_binary
val outdir
val outdir2
val ref_name
output:
tuple val(sample_id), val(family_id), path('depth.txt')
script:
// define a string to optionally pass regions of interest bed file
def regions_of_interest_optional = file(regions_of_interest).name != 'NONE' ? "-b $regions_of_interest" : ''
"""
# stage bam and bam index
# do this here instead of input tuple so I can handle processing an aligned bam as an input file without requiring a bam index for ubam input
bam_loc=\$(realpath ${bam})
ln -sf \${bam_loc} sorted.bam
ln -sf \${bam_loc}.bai .
ln -sf \${bam_loc}.bai sorted.bam.bai
# run mosdepth
$mosdepth_binary \
depth \
$bam \
$regions_of_interest_optional \
-t ${task.cpus}
# rename file
ln -s depth.mosdepth.summary.txt depth.txt
"""
stub:
"""
touch depth.txt
"""
}
process clair3 {
input:
tuple val(sample_id), val(family_id), path(bam), val(data_type), val(regions_of_interest), val(clair3_model)
val ref
val ref_index
output:
tuple val(sample_id), val(family_id), path('sorted.bam'), path('sorted.bam.bai'), path('snp_indel.vcf.gz'), path('snp_indel.vcf.gz.tbi')
script:
// define a string to optionally pass regions of interest bed file
def regions_of_interest_optional = file(regions_of_interest).name != 'NONE' ? "--bed_fn=$regions_of_interest" : ''
// conditionally define platform
if( data_type == 'ont' ) {
platform = 'ont'
}
else if( data_type == 'pacbio' ) {
platform = 'hifi'
}
"""
# stage bam and bam index
# do this here instead of input tuple so I can handle processing an aligned bam as an input file without requiring a bam index for ubam input
bam_loc=\$(realpath ${bam})
ln -sf \${bam_loc} sorted.bam
ln -sf \${bam_loc}.bai .
ln -sf \${bam_loc}.bai sorted.bam.bai
# run clair3
run_clair3.sh \
--bam_fn=$bam \
--ref_fn=$ref \
--output=./ \
--threads=${task.cpus} \
--platform=$platform \
--model_path=$clair3_model \
--sample_name=$sample_id \
--gvcf \
--include_all_ctgs \
$regions_of_interest_optional
# rename files
ln -s merge_output.vcf.gz snp_indel.vcf.gz
ln -s merge_output.vcf.gz.tbi snp_indel.vcf.gz.tbi
"""
stub:
"""
touch snp_indel.vcf.gz
touch snp_indel.vcf.gz.tbi
"""
}
process deepvariant_dry_run {
input:
tuple val(sample_id), val(family_id), path(bam), val(data_type)
val ref
val ref_index
output:
tuple val(sample_id), val(family_id), path('sorted.bam'), path('sorted.bam.bai'), env(make_examples_args), env(call_variants_args)
script:
// conditionally define model type
if( data_type == 'ont' ) {
model = 'ONT_R104'
}
else if ( data_type == 'pacbio' ) {
model = 'PACBIO'
}
"""
# stage bam and bam index
# do this here instead of input tuple so I can handle processing an aligned bam as an input file without requiring a bam index for ubam input
bam_loc=\$(realpath ${bam})
ln -sf \${bam_loc} sorted.bam
ln -sf \${bam_loc}.bai .
ln -sf \${bam_loc}.bai sorted.bam.bai
# do a dry-run of deepvariant
run_deepvariant \
--reads=$bam \
--ref=$ref \
--sample_name=$sample_id \
--output_vcf=snp_indel.raw.vcf.gz \
--model_type=$model \
--dry_run=true > commands.txt
# extract arguments for make_examples and call_variants stages
make_examples_args=\$(grep "/opt/deepvariant/bin/make_examples" commands.txt | awk '{split(\$0, arr, "--add_hp_channel"); print "--add_hp_channel" arr[2]}' | sed 's/--sample_name "[^"]*"//g')
call_variants_args=\$(grep "/opt/deepvariant/bin/call_variants" commands.txt | awk '{split(\$0, arr, "--checkpoint"); print "--checkpoint" arr[2]}')
"""
stub:
"""
make_examples_args=""
call_variants_args=""
touch sorted.bam
touch sorted.bam.bai
"""
}
process deepvariant_make_examples {
input:
tuple val(sample_id), val(family_id), path(bam), path(bam_index), val(make_examples_args), val(call_variants_args), val(regions_of_interest)
val ref
val ref_index
output:
tuple val(sample_id), val(family_id), path(bam), path(bam_index), val(call_variants_args), path('*.gz{,.example_info.json}')
script:
// define an optional string to pass regions of interest bed file
def regions_of_interest_optional = file(regions_of_interest).name != 'NONE' ? "--regions $regions_of_interest" : ''
"""
seq 0 ${task.cpus - 1} | parallel -q --halt 2 --line-buffer make_examples \\
--mode calling --ref "${ref}" --reads "${bam}" --sample_name "${sample_id}" ${regions_of_interest_optional} --examples "make_examples.tfrecord@${task.cpus}.gz" ${make_examples_args}
"""
stub:
"""
touch make_examples.tfrecord-00000-of-00104.gz
touch make_examples.tfrecord-00000-of-00104.gz.example_info.json
"""
}
process deepvariant_call_variants {
input:
tuple val(sample_id), val(family_id), path(bam), path(bam_index), val(call_variants_args), path(make_examples_out)
output:
tuple val(sample_id), val(family_id), path(bam), path(bam_index), val(call_variants_args), path('*.gz')
script:
def matcher = make_examples_out[0].baseName =~ /^(.+)-\d{5}-of-(\d{5})$/
def num_shards = matcher[0][2] as int
"""
call_variants --outfile "call_variants_output.tfrecord.gz" --examples "make_examples.tfrecord@${num_shards}.gz" ${call_variants_args}
"""
stub:
"""
touch call_variants_output-00000-of-00016.tfrecord.gz
"""
}
process deepvariant_post_processing {
input:
tuple val(sample_id), val(family_id), path(bam), path(bam_index), val(call_variants_args), path(call_variants_out)
val ref
val ref_index
output:
tuple val(sample_id), val(family_id), path(bam), path(bam_index), path('snp_indel.vcf.gz'), path('snp_indel.vcf.gz.tbi')
script:
"""
# postprocess_variants and vcf_stats_report stages in deepvariant
postprocess_variants --ref "${ref}" --infile "call_variants_output.tfrecord.gz" --outfile "snp_indel.raw.vcf.gz" --cpus "${task.cpus}" --sample_name "${sample_id}"
vcf_stats_report --input_vcf "snp_indel.raw.vcf.gz" --outfile_base "snp_indel.raw"
# filter out refcall variants
bcftools view -f 'PASS' snp_indel.raw.vcf.gz -o snp_indel.vcf.gz
# index vcf
tabix snp_indel.vcf.gz
"""
stub:
"""
touch snp_indel.vcf.gz
touch snp_indel.vcf.gz.tbi
"""
}
process whatshap_phase {
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$ref_name.$snp_indel_caller.$filename" }, pattern: 'snp_indel.phased.*'
input:
tuple val(sample_id), val(family_id), path(bam), path(bam_index), path(snp_indel_vcf), path(snp_indel_vcf_index)
val ref
val ref_index
val outdir
val outdir2
val ref_name
val snp_indel_caller
output:
tuple val(sample_id), val(family_id), path(bam), path(bam_index), path('snp_indel.phased.vcf.gz'), path('snp_indel.phased.vcf.gz.tbi')
tuple val(sample_id), val(family_id), path('snp_indel.phased.vcf.gz')
tuple val(sample_id), val(family_id), path('snp_indel.phased.vcf.gz'), path('snp_indel.phased.vcf.gz.tbi'), path('snp_indel.phased.read_list.txt'), path('snp_indel.phased.stats.gtf')
script:
"""
# run whatshap phase
whatshap phase \
--reference $ref \
--output snp_indel.phased.vcf.gz \
--output-read-list snp_indel.phased.read_list.txt \
--sample $sample_id \
--ignore-read-groups $snp_indel_vcf $bam
# index vcf
tabix snp_indel.phased.vcf.gz
# run whatshap stats
whatshap stats \
snp_indel.phased.vcf.gz \
--gtf snp_indel.phased.stats.gtf \
--sample $sample_id
"""
stub:
"""
touch snp_indel.phased.vcf.gz
touch snp_indel.phased.vcf.gz.tbi
touch snp_indel.phased.read_list.txt
touch snp_indel.phased.stats.gtf
"""
}
process whatshap_haplotag {
def mapper_phaser = "minimap2.whatshap"
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$ref_name.$mapper_phaser.$filename" }, pattern: 'sorted.haplotagged.*'
input:
tuple val(sample_id), val(family_id), path(bam), path(bam_index), path(snp_indel_vcf), path(snp_indel_vcf_index)
val ref
val ref_index
val outdir
val outdir2
val ref_name
output:
tuple val(sample_id), val(family_id), path('sorted.haplotagged.bam'), path('sorted.haplotagged.bam.bai')
tuple val(sample_id), val(family_id), path('sorted.haplotagged.tsv')
script:
"""
# run whatshap haplotag
whatshap haplotag \
--reference $ref \
--output sorted.haplotagged.bam \
--sample $sample_id \
--tag-supplementary \
--ignore-read-groups \
--output-threads ${task.cpus} \
--output-haplotag-list sorted.haplotagged.tsv \
$snp_indel_vcf $bam
# index bam
samtools index \
-@ ${task.cpus} \
sorted.haplotagged.bam
"""
stub:
"""
touch sorted.haplotagged.bam
touch sorted.haplotagged.bam.bai
touch sorted.haplotagged.tsv
"""
}
process vep_snv {
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$ref_name.$snp_indel_caller.$filename" }, pattern: 'snp_indel.phased.annotated.vcf.gz*'
input:
tuple val(sample_id), val(family_id), path(snp_indel_phased_vcf)
val ref
val ref_index
val vep_db
val revel_db
val gnomad_db
val clinvar_db
val cadd_snv_db
val cadd_indel_db
val spliceai_snv_db
val spliceai_indel_db
val alphamissense_db
val outdir
val outdir2
val ref_name
val snp_indel_caller
output:
tuple val(sample_id), val(family_id), path('snp_indel.phased.annotated.vcf.gz'), path('snp_indel.phased.annotated.vcf.gz.tbi')
script:
"""
# run vep
vep -i $snp_indel_phased_vcf \
-o snp_indel.phased.annotated.vcf.gz \
--format vcf \
--vcf \
--fasta $ref \
--dir $vep_db \
--assembly GRCh38 \
--species homo_sapiens \
--cache \
--offline \
--merged \
--sift b \
--polyphen b \
--symbol \
--hgvs \
--hgvsg \
--plugin REVEL,file=$revel_db \
--custom file=$gnomad_db,short_name=gnomAD,format=vcf,type=exact,fields=AF_joint%AF_exomes%AF_genomes%nhomalt_joint%nhomalt_exomes%nhomalt_genomes \
--custom file=$clinvar_db,short_name=ClinVar,format=vcf,type=exact,coords=0,fields=CLNSIG \
--plugin CADD,snv=$cadd_snv_db,indels=$cadd_indel_db \
--plugin SpliceAI,snv=$spliceai_snv_db,indel=$spliceai_indel_db \
--plugin AlphaMissense,file=$alphamissense_db \
--uploaded_allele \
--check_existing \
--filter_common \
--no_intergenic \
--pick \
--fork ${task.cpus} \
--no_stats \
--compress_output bgzip
# index vcf
tabix snp_indel.phased.annotated.vcf.gz
"""
stub:
"""
touch snp_indel.phased.annotated.vcf.gz
touch snp_indel.phased.annotated.vcf.gz.tbi
"""
}
process pbcpgtools {
def software = "pbcpgtools"
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$ref_name.$software.$filename" }, pattern: 'cpg_scores*'
input:
tuple val(sample_id), val(family_id), path(haplotagged_bam), path(haplotagged_bam_index), val(data_type)
val pbcpgtools_binary
val ref
val ref_index
val outdir
val outdir2
val ref_name
output:
tuple val(sample_id), val(family_id), path('cpg_scores_hap1.bw'), path('cpg_scores_hap1.bed'), path('cpg_scores_hap2.bw'), path('cpg_scores_hap2.bed'), path('cpg_scores_combined.bw'), path('cpg_scores_combined.bed'), optional: true
script:
if( data_type == 'pacbio' )
"""
# run pb-cpg-tools
$pbcpgtools_binary/bin/aligned_bam_to_cpg_scores \
--bam $haplotagged_bam \
--ref $ref \
--pileup-mode model \
--model $pbcpgtools_binary/models/pileup_calling_model.v1.tflite \
--modsites-mode denovo \
--hap-tag HP \
--threads ${task.cpus}
# rename files
ln -s aligned_bam_to_cpg_scores.hap1.bw cpg_scores_hap1.bw
ln -s aligned_bam_to_cpg_scores.hap1.bed cpg_scores_hap1.bed
ln -s aligned_bam_to_cpg_scores.hap2.bw cpg_scores_hap2.bw
ln -s aligned_bam_to_cpg_scores.hap2.bed cpg_scores_hap2.bed
ln -s aligned_bam_to_cpg_scores.combined.bw cpg_scores_combined.bw
ln -s aligned_bam_to_cpg_scores.combined.bed cpg_scores_combined.bed
"""
else if( data_type == 'ont' )
"""
echo "Data type is ONT, not running pb-CpG-tools on this data."
"""
stub:
"""
touch cpg_scores_hap1.bw
touch cpg_scores_hap1.bed
touch cpg_scores_hap2.bw
touch cpg_scores_hap2.bed
touch cpg_scores_combined.bw
touch cpg_scores_combined.bed
"""
}
process sniffles {
def sv_caller = "sniffles"
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$ref_name.$sv_caller.$filename" }, pattern: 'sv.phased.vcf.gz*'
input:
tuple val(sample_id), val(family_id), path(haplotagged_bam), path(haplotagged_bam_index)
val ref
val ref_index
val tandem_repeat
val outdir
val outdir2
val ref_name
output:
tuple val(sample_id), val(family_id), path('sv.phased.vcf.gz')
tuple val(sample_id), val(family_id), path('sv.phased.vcf.gz'), path('sv.phased.vcf.gz.tbi')
script:
// define a string to optionally pass tandem repeat bed file
def tandem_repeat_optional = file(tandem_repeat).name != 'NONE' ? "--tandem-repeats $tandem_repeat" : ''
"""
# run sniffles
sniffles \
--reference $ref \
--input $haplotagged_bam \
--threads ${task.cpus} \
--sample-id $sample_id \
--vcf sv.phased.vcf.gz \
--output-rnames \
--minsvlen 50 \
--phase $tandem_repeat_optional
"""
stub:
"""
touch sv.phased.vcf.gz
touch sv.phased.vcf.gz.tbi
"""
}
process cutesv {
def sv_caller = "cutesv"
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$ref_name.$sv_caller.$filename" }, pattern: 'sv.vcf.gz*'
input:
tuple val(sample_id), val(family_id), path(haplotagged_bam), path(haplotagged_bam_index), val(data_type)
val ref
val ref_index
val tandem_repeat
val outdir
val outdir2
val ref_name
output:
tuple val(sample_id), val(family_id), path('sv.vcf.gz')
tuple val(sample_id), val(family_id), path('sv.vcf.gz'), path('sv.vcf.gz.tbi')
script:
if( data_type == 'ont' ) {
settings = '--max_cluster_bias_INS 100 --diff_ratio_merging_INS 0.3 --max_cluster_bias_DEL 100 --diff_ratio_merging_DEL 0.3'
}
else if( data_type == 'pacbio' ) {
settings = '--max_cluster_bias_INS 1000 --diff_ratio_merging_INS 0.9 --max_cluster_bias_DEL 1000 --diff_ratio_merging_DEL 0.5'
}
"""
# run cuteSV
cuteSV \
$haplotagged_bam \
$ref \
sv.vcf \
./ \
--sample ${sample_id} \
-t ${task.cpus} \
--genotype \
--report_readid \
--min_size 50 \
$settings
# compress and index vcf
bgzip \
-@ ${task.cpus} \
sv.vcf
tabix sv.vcf.gz
"""
stub:
"""
touch sv.vcf.gz
touch sv.vcf.gz.tbi
"""
}
process vep_sniffles_sv {
def sv_caller = "sniffles"
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$ref_name.$sv_caller.$filename" }, pattern: 'sv.phased.annotated.vcf.gz*'
input:
tuple val(sample_id), val(family_id), path(sv_phased_vcf)
val ref
val ref_index
val vep_db
val gnomad_db
val gnomad_sv_db
val clinvar_db
val cadd_sv_db
val outdir
val outdir2
val ref_name
output:
tuple val(sample_id), val(family_id), path('sv.phased.annotated.vcf.gz'), path('sv.phased.annotated.vcf.gz.tbi')
script:
"""
# run vep
vep -i $sv_phased_vcf \
-o sv.phased.annotated.vcf.gz \
--format vcf \
--vcf \
--fasta $ref \
--dir $vep_db \
--assembly GRCh38 \
--species homo_sapiens \
--cache \
--offline \
--merged \
--sift b \
--polyphen b \
--symbol \
--hgvs \
--hgvsg \
--custom file=$gnomad_sv_db,short_name=gnomAD_sv,format=vcf,type=overlap,reciprocal=1,overlap_cutoff=80,same_type=1,num_records=50,fields=ALGORITHMS%BOTHSIDES_SUPPORT%CHR2%CPX_INTERVALS%CPX_TYPE%END%END2%EVIDENCE%LOW_CONFIDENCE_REPETITIVE_LARGE_DUP%MEMBERS%MULTIALLELIC%NCR%OUTLIER_SAMPLE_ENRICHED_LENIENT%PAR%PCRMINUS_NCR%PCRPLUS_NCR%PESR_GT_OVERDISPERSION%POS2%PREDICTED_BREAKEND_EXONIC%PREDICTED_COPY_GAIN%PREDICTED_DUP_PARTIAL%PREDICTED_INTERGENIC%PREDICTED_INTRAGENIC_EXON_DUP%PREDICTED_INTRONIC%PREDICTED_INV_SPAN%PREDICTED_LOF%PREDICTED_MSV_EXON_OVERLAP%PREDICTED_NEAREST_TSS%PREDICTED_NONCODING_BREAKPOINT%PREDICTED_NONCODING_SPAN%PREDICTED_PARTIAL_DISPERSED_DUP%PREDICTED_PARTIAL_EXON_DUP%PREDICTED_PROMOTER%PREDICTED_TSS_DUP%PREDICTED_UTR%RESOLVED_POSTHOC%SOURCE%SVLEN%SVTYPE%UNRESOLVED_TYPE%AN%AC%AF%N_BI_GENOS%N_HOMREF%N_HET%N_HOMALT%FREQ_HOMREF%FREQ_HET%FREQ_HOMALT%CN_NUMBER%CN_COUNT%CN_STATUS%CN_FREQ%CN_NONREF_COUNT%CN_NONREF_FREQ \
--custom file=$clinvar_db,short_name=ClinVar,format=vcf,type=overlap,reciprocal=1,overlap_cutoff=50,same_type=1,num_records=50,fields=CLNSIG \
--plugin CADD,sv=$cadd_sv_db \
--uploaded_allele \
--check_existing \
--filter_common \
--no_intergenic \
--pick \
--fork ${task.cpus} \
--no_stats \
--compress_output bgzip
# index vcf
tabix sv.phased.annotated.vcf.gz
"""
stub:
"""
touch sv.phased.annotated.vcf.gz
touch sv.phased.annotated.vcf.gz.tbi
"""
}
process vep_cutesv_sv {
def sv_caller = "cutesv"
publishDir "$outdir/$family_id/$outdir2/$sample_id", mode: 'copy', overwrite: true, saveAs: { filename -> "$sample_id.$ref_name.$sv_caller.$filename" }, pattern: 'sv.annotated.vcf.gz*'
input:
tuple val(sample_id), val(family_id), path(sv_vcf)
val ref
val ref_index
val vep_db
val gnomad_db
val gnomad_sv_db
val clinvar_db
val cadd_sv_db
val outdir
val outdir2
val ref_name
output:
tuple val(sample_id), val(family_id), path('sv.annotated.vcf.gz'), path('sv.annotated.vcf.gz.tbi')
script:
"""
# run vep
vep -i $sv_vcf \
-o sv.annotated.vcf.gz \
--format vcf \
--vcf \
--fasta $ref \
--dir $vep_db \
--assembly GRCh38 \
--species homo_sapiens \
--cache \
--offline \
--merged \
--sift b \
--polyphen b \
--symbol \
--hgvs \
--hgvsg \
--custom file=$gnomad_sv_db,short_name=gnomAD_sv,format=vcf,type=overlap,reciprocal=1,overlap_cutoff=80,same_type=1,num_records=50,fields=ALGORITHMS%BOTHSIDES_SUPPORT%CHR2%CPX_INTERVALS%CPX_TYPE%END%END2%EVIDENCE%LOW_CONFIDENCE_REPETITIVE_LARGE_DUP%MEMBERS%MULTIALLELIC%NCR%OUTLIER_SAMPLE_ENRICHED_LENIENT%PAR%PCRMINUS_NCR%PCRPLUS_NCR%PESR_GT_OVERDISPERSION%POS2%PREDICTED_BREAKEND_EXONIC%PREDICTED_COPY_GAIN%PREDICTED_DUP_PARTIAL%PREDICTED_INTERGENIC%PREDICTED_INTRAGENIC_EXON_DUP%PREDICTED_INTRONIC%PREDICTED_INV_SPAN%PREDICTED_LOF%PREDICTED_MSV_EXON_OVERLAP%PREDICTED_NEAREST_TSS%PREDICTED_NONCODING_BREAKPOINT%PREDICTED_NONCODING_SPAN%PREDICTED_PARTIAL_DISPERSED_DUP%PREDICTED_PARTIAL_EXON_DUP%PREDICTED_PROMOTER%PREDICTED_TSS_DUP%PREDICTED_UTR%RESOLVED_POSTHOC%SOURCE%SVLEN%SVTYPE%UNRESOLVED_TYPE%AN%AC%AF%N_BI_GENOS%N_HOMREF%N_HET%N_HOMALT%FREQ_HOMREF%FREQ_HET%FREQ_HOMALT%CN_NUMBER%CN_COUNT%CN_STATUS%CN_FREQ%CN_NONREF_COUNT%CN_NONREF_FREQ \
--custom file=$clinvar_db,short_name=ClinVar,format=vcf,type=overlap,reciprocal=1,overlap_cutoff=50,same_type=1,num_records=50,fields=CLNSIG \
--plugin CADD,sv=$cadd_sv_db \
--uploaded_allele \
--check_existing \
--filter_common \
--no_intergenic \
--pick \
--fork ${task.cpus} \
--no_stats \
--compress_output bgzip
# index vcf
tabix sv.annotated.vcf.gz
"""
stub:
"""
touch sv.annotated.vcf.gz
touch sv.annotated.vcf.gz.tbi
"""
}
workflow {
// grab parameters
in_data = "$params.in_data"
in_data_format = "$params.in_data_format"
in_data_format_override = "$params.in_data_format_override"
ref = "$params.ref"
ref_index = "$params.ref_index"
tandem_repeat = "$params.tandem_repeat"
snp_indel_caller = "$params.snp_indel_caller"
sv_caller = "$params.sv_caller"
annotate = "$params.annotate"
annotate_override = "$params.annotate_override"
calculate_depth = "$params.calculate_depth"
outdir = "$params.outdir"
outdir2 = "$params.outdir2"
mosdepth_binary = "$params.mosdepth_binary"
pbcpgtools_binary = "$params.pbcpgtools_binary"
vep_db = "$params.vep_db"
revel_db = "$params.revel_db"
gnomad_db = "$params.gnomad_db"
gnomad_sv_db = "$params.gnomad_sv_db"
clinvar_db = "$params.clinvar_db"
cadd_snv_db = "$params.cadd_snv_db"
cadd_indel_db = "$params.cadd_indel_db"
cadd_sv_db = "$params.cadd_sv_db"
spliceai_snv_db = "$params.spliceai_snv_db"
spliceai_indel_db = "$params.spliceai_indel_db"
alphamissense_db = "$params.alphamissense_db"
// check user provided parameters
if ( !in_data ) {
exit 1, "No in data csv file specified. Either include in parameter file or pass to --in_data on the command line."
}
if ( !file(in_data).exists() ) {
exit 1, "In data csv file path does not exist, '${in_data}' provided."
}
if ( !in_data_format ) {
exit 1, "No in data format selected. Either include in parameter file or pass to --in_data_format on the command line. Should be 'ubam_fastq', 'aligned_bam' or 'snv_vcf'."
}
if ( in_data_format != 'ubam_fastq' && in_data_format != 'aligned_bam' && in_data_format != 'snv_vcf' && in_data_format != 'sv_vcf' ) {
exit 1, "In data format should be 'ubam_fastq', 'aligned_bam', 'snv_vcf' or 'sv_vcf', '${in_data_format}' selected."
}
if ( in_data_format == 'snv_vcf' && tandem_repeat != 'NONE' ) {
exit 1, "In data format is SNP/indel VCF, but you haven't set the tandem repeat file to 'NONE'. Either set tandem_repeat to 'NONE' in parameter file or pass '--tandem_repeat NONE' on the command line"
}
if ( in_data_format == 'sv_vcf' && tandem_repeat != 'NONE' ) {
exit 1, "In data format is SV VCF, but you haven't set the tandem repeat file to 'NONE'. Either set tandem_repeat to 'NONE' in parameter file or pass '--tandem_repeat NONE' on the command line"