-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathsomatic.nf
3369 lines (2815 loc) · 137 KB
/
somatic.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
// Myeloma Genome Pipeline 1000
// Comprehensive pipeline for analysis of matched T/N Multiple Myeloma WGS data
// https://github.com/pblaney/mgp1000
// This module of the pipeline is used for somatic variant analysis of matched tumor/normal WGS samples.
import java.text.SimpleDateFormat;
def workflowTimestamp = "${workflow.start.format('MM-dd-yyyy HH:mm')}"
def helpMessage() {
log.info"""
.------------------------.
| .-..-. .--. .---. |
| : `' :: .--': .; : |
| : .. :: : _ : _.' |
| : :; :: :; :: : |
| :_;:_;`.__.':_; |
| ,-. .--. .--. .--. |
| .' :: ,. :: ,. :: ,. : |
| : :: :: :: :: :: :: : |
| : :: :; :: :; :: :; : |
| :_;`.__.'`.__.'`.__.' |
.________________________.
░█▀▀░█▀█░█▄█░█▀█░▀█▀░▀█▀░█▀▀
░▀▀█░█░█░█░█░█▀█░░█░░░█░░█░░
░▀▀▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀▀
Usage:
nextflow run somatic.nf --run_id STR --sample_sheet FILE -profile somatic [-bg] [-resume]
[--input_dir PATH] [--output_dir PATH] [--email STR] [--mutect_ref_vcf_concatenated STR]
[--battenberg_ref_cached STR] [--annotsv_ref_cached STR] [--vep_ref_cached STR] [--help]
Mandatory Arguments:
--run_id STR Unique identifier for pipeline run
--sample_sheet FILE CSV file containing the list of samples where the
first column designates the file name of the normal
sample, the second column for the file name of the
matched tumor sample
-profile STR Configuration profile to use, must use somatic
Optional Arguments:
-bg FLAG Runs the pipeline processes in the background, this
option should be included if deploying pipeline with
real data set so processes will not be cut if user
disconnects from deployment environment
-resume FLAG Successfully completed tasks are cached so that if
the pipeline stops prematurely the previously
completed tasks are skipped while maintaining their
output
--input_dir PATH Directory that holds BAMs and associated index files,
this should be given as an absolute path
[Default: input/preprocessedBams/]
--output_dir PATH Directory that will hold all output files this should
be given as an absolute path
[Default: output/]
--email STR Email address to send workflow completion/stoppage
notification
--mutect_ref_vcf_concatenated STR Indicates whether or not the gnomAD allele frequency
reference VCF used for MuTect2 processes has been
concatenated, this will be done in a process of the
pipeline if it has not, this does not need to be done
for every separate run after the first
[Default: no | Available: yes, no]
--battenberg_ref_cached STR Indicates whether or not the reference files used for
Battenberg have been downloaded/cached locally, this
will be done in a process of the pipeline if it has
not, this does not need to be done for every separate
run after the first
[Default: no | Available: yes, no]
--cpus INT Globally set the number of cpus to be allocated
--memory STR Globally set the amount of memory to be allocated,
written as '##.GB' or '##.MB'
--queue_size INT Set max number of tasks the pipeline will launch
[Default: 100]
--executor STR Set the job executor for the run
[Default: slurm | Available: local, slurm, lsf]
--help FLAG Prints this message
Toolbox Arguments:
--battenberg STR Indicates whether or not to use this tool
[Default: on | Available: off, on]
--battenberg_min_depth STR Manually set the minimum read depth in the normal
sample for SNP filtering in BAF calculations,
default is for 30x coverage
[Default: 10]
--battenberg_preset_rho_psi STR Wish to manually set the rho/psi for this run?
If TRUE, must set both rho and psi
[Default: FALSE | Available: FALSE, TRUE]
--battenberg_preset_rho INT Manually set the value of rho (purity)
[Default: NA]
--battenberg_preset_psi INT Manually set the value of psi (ploidy)
[Default: NA]
--facets STR Indicates whether or not to use this tool
[Default: on | Available: off, on]
--facets_min_depth INT Manually set the minimum read depth in the normal
sample for SNP filtering in BAF calculations,
default is for 30x coverage
[Default: 20]
--manta STR Indicates whether or not to use this tool
[Default: on | Available: off, on]
--svaba STR Indicates whether or not to use this tool
[Default: on | Available: off, on]
--delly STR Indicates whether or not to use this tool
[Default: on | Available: off, on]
--delly_strict STR Enforce stricter thresholds for calling SVs with DELLY
to overcome libraries with extraordinary number of
interchromosomal reads
[Default: off | Available: off, on]
--igcaller STR Indicates whether or not to use this tool
[Default: on | Available: off, on]
--varscan STR Indicates whether or not to use this tool
[Default: on | Available: off, on]
--mutect STR Indicates whether or not to use this tool
[Default: on | Available: off, on]
--strelka STR Indicates whether or not to use this tool
[Default: on | Available: off, on]
--conpair STR Indicates whether or not to use this tool
[Default: on | Available: off, on]
--conpair_min_cov INT Manually set the minimum coverage
[Default: 10]
--fragcounter STR Indicates whether or not to use this tool
[Default: on | Available: off, on]
--telomerecat STR Indicates whether or not to use this tool
[Default: off | Available: off, on]
--telomerehunter STR Indicates whether or not to use this tool
[Default: off | Available: off, on]
--caveman STR Indicates whether or not to use this tool
EXPERIMENTAL! Requires many process directories
and only calls in WES targets
[Default: off | Available: off, on]
""".stripIndent()
}
// #################################################### \\
// ~~~~~~~~~~~~~ PARAMETER CONFIGURATION ~~~~~~~~~~~~~~ \\
// Declare the defaults for all pipeline parameters
params.input_dir = "${workflow.projectDir}/input/preprocessedBams"
params.output_dir = "${workflow.projectDir}/output"
params.run_id = null
params.sample_sheet = null
params.email = null
params.seq_protocol = "WGS"
params.mutect_ref_vcf_concatenated = "no"
params.battenberg_ref_cached = "no"
params.telomerecat = "off"
params.telomerehunter = "off"
params.conpair = "on"
params.varscan = "on"
params.mutect = "on"
params.strelka = "on"
params.caveman = "off"
params.caveman_min_depth = 8
params.caveman_min_single_end_depth = 10
params.caveman_mut_prior = 0.000006
params.caveman_snp_prior = 0.0001
params.caveman_mut_prob_cutoff = 0.8
params.caveman_snp_prob_cutoff = 0.95
params.fragcounter = "on"
params.battenberg = "on"
params.facets = "on"
params.manta = "on"
params.svaba = "on"
params.svaba_mate_lookup_min = 3
params.delly = "on"
params.delly_strict = "off"
params.igcaller = "on"
params.conpair_min_cov = 10
params.battenberg_min_depth = 10
params.battenberg_preset_rho_psi = "FALSE"
params.battenberg_preset_rho = "NA"
params.battenberg_preset_psi = "NA"
params.facets_min_depth = 20
params.cpus = null
params.memory = null
params.queue_size = 100
params.executor = 'slurm'
params.help = null
// Print help message if requested
if( params.help ) exit 0, helpMessage()
// Print preemptive error message if user-defined input/output directories does not exist
if( !file(params.input_dir).exists() ) exit 1, "The user-specified input directory does not exist in filesystem."
// Print preemptive error messages if required parameters are not set
if( params.run_id == null ) exit 1, "The run command issued does not have the '--run_id' parameter set. Please set the '--run_id' parameter to a unique identifier for the run."
if( params.sample_sheet == null ) exit 1, "The run command issued does not have the '--sample_sheet' parameter set. Please set the '--sample_sheet' parameter to the path of the normal/tumor pair sample sheet CSV."
// Print preemptive error message if Strelka is set while Manta is not
if( params.strelka == "on" && params.manta == "off" ) exit 1, "Strelka requires output from Manta to run so both must be turned on"
// Set channels for reference files
Channel
.value( file('references/hg38/Homo_sapiens_assembly38.fasta') )
.set{ ref_genome_fasta_file }
Channel
.value( file('references/hg38/Homo_sapiens_assembly38.fasta.fai') )
.set{ ref_genome_fasta_index_file }
Channel
.value( file('references/hg38/Homo_sapiens_assembly38.dict') )
.set{ ref_genome_fasta_dict_file }
if( params.seq_protocol == "WGS" ) {
Channel
.value( file('references/hg38/wgs_calling_regions.hg38.bed') )
.set{ target_regions_bed }
} else if( params.seq_protocol == "WES" ) {
Channel
.value( file('references/hg38/wxs_exons_gencode_v39_autosome_sex_chroms.hg38.bed') )
.set{ target_regions_bed }
} else {
exit 1, "This run command cannot be executed. The '--seq_protocol' must be set to either 'WGS' for whole-genome or 'WES' for whole-exome."
}
Channel
.value( file('references/hg38/wgs_calling_regions_blacklist.0based.hg38.bed') )
.set{ wgs_bed_blacklist_0based }
Channel
.fromList( ['chr1', 'chr2', 'chr3', 'chr4', 'chr5', 'chr6',
'chr7', 'chr8', 'chr9', 'chr10', 'chr11', 'chr12',
'chr13', 'chr14', 'chr15', 'chr16', 'chr17', 'chr18',
'chr19', 'chr20', 'chr21', 'chr22', 'chrX', 'chrY',] )
.into{ chromosome_list_forVarscanSamtoolsMpileup;
chromosome_list_forMutectCalling;
chromosome_list_forMutectPileup;
chromosome_list_forCavemanSplit }
Channel
.value( file('references/hg38/sex_identification_loci.chrY.hg38.txt') )
.set{ sex_identification_loci }
Channel
.value( file('references/hg38/cytoband_autosome_sex_chroms.hg38.bed') )
.set{ cytoband_bed }
Channel
.value( file('references/hg38/1000g_pon.hg38.vcf.gz') )
.set{ panel_of_normals_1000G }
Channel
.value( file('references/hg38/1000g_pon.hg38.vcf.gz.tbi') )
.set{ panel_of_normals_1000G_index }
Channel
.value( file('references/hg38/af-only-gnomad.chr1-9.hg38.vcf.gz') )
.set{ gnomad_ref_vcf_chromosomes1_9 }
Channel
.value( file('references/hg38/af-only-gnomad.chr1-9.hg38.vcf.gz.tbi') )
.set{ gnomad_ref_vcf_chromosomes1_9_index }
Channel
.value( file('references/hg38/af-only-gnomad.chr10-22.hg38.vcf.gz') )
.set{ gnomad_ref_vcf_chromosomes10_22 }
Channel
.value( file('references/hg38/af-only-gnomad.chr10-22.hg38.vcf.gz.tbi') )
.set{ gnomad_ref_vcf_chromosomes10_22_index }
Channel
.value( file('references/hg38/af-only-gnomad.chrXYM-alts.hg38.vcf.gz') )
.set{ gnomad_ref_vcf_chromosomesXYM_alts }
Channel
.value( file('references/hg38/af-only-gnomad.chrXYM-alts.hg38.vcf.gz.tbi') )
.set{ gnomad_ref_vcf_chromosomesXYM_alts_index }
if( params.mutect == "on" && params.mutect_ref_vcf_concatenated == "yes" ) {
Channel
.fromPath( 'references/hg38/af-only-gnomad.hg38.vcf.gz', checkIfExists: true )
.ifEmpty{ error "The run command issued has the '--mutect_ref_vcf_concatenated' parameter set to 'yes', however the file does not exist. Please set the '--mutect_ref_vcf_concatenated' parameter to 'no' and resubmit the run command. For more information, check the README or issue the command 'nextflow run somatic.nf --help'"}
.set{ mutect_gnomad_ref_vcf_preBuilt }
Channel
.fromPath( 'references/hg38/af-only-gnomad.hg38.vcf.gz.tbi', checkIfExists: true )
.ifEmpty{ error "The '--mutect_ref_vcf_concatenated' parameter set to 'yes', however the index file does not exist for the reference VCF. Please set the '--mutect_ref_vcf_concatenated' parameter to 'no' and resubmit the run command. Alternatively, use Tabix to index the reference VCF."}
.set{ mutect_gnomad_ref_vcf_index_preBuilt }
}
Channel
.value( file('references/hg38/small_exac_common_3.hg38.vcf.gz') )
.set{ exac_common_sites_ref_vcf }
Channel
.value( file('references/hg38/small_exac_common_3.hg38.vcf.gz.tbi') )
.set{ exac_common_sites_ref_vcf_index }
if( params.battenberg_ref_cached == "yes" ) {
Channel
.fromPath( 'references/hg38/battenberg_reference/', checkIfExists: true )
.ifEmpty{ error "The run command issued has the '--battenberg_ref_cached' parameter set to 'yes', however the directory does not exist. Please set the '--battenberg_ref_cached' parameter to 'no' and resubmit the run command. For more information, check the README or issue the command 'nextflow run somatic.nf --help'"}
.set{ battenberg_ref_dir_preDownloaded }
}
Channel
.value( file('references/hg38') )
.set{ gc_mappability_dir }
Channel
.value( file('references/hg38/Hapmap_3.3.hg38.vcf.gz') )
.set{ hapmap_ref_snps_vcf }
Channel
.value( file('references/hg38/Hapmap_3.3.hg38.vcf.gz.tbi') )
.set{ hapmap_ref_snps_vcf_index }
Channel
.value( file('references/hg38/common_all_20180418.vcf.gz') )
.set{ common_dbsnp_ref_vcf }
Channel
.value( file('references/hg38/common_all_20180418.vcf.gz.tbi') )
.set{ common_dbsnp_ref_vcf_index }
Channel
.fromPath( ['references/hg38/Homo_sapiens_assembly38.fasta', 'references/hg38/Homo_sapiens_assembly38.fasta.fai',
'references/hg38/Homo_sapiens_assembly38.fasta.64.alt', 'references/hg38/Homo_sapiens_assembly38.fasta.64.amb',
'references/hg38/Homo_sapiens_assembly38.fasta.64.ann', 'references/hg38/Homo_sapiens_assembly38.fasta.64.bwt',
'references/hg38/Homo_sapiens_assembly38.fasta.64.pac', 'references/hg38/Homo_sapiens_assembly38.fasta.64.sa'] )
.set{ bwa_ref_genome_files }
Channel
.value( file('references/hg38/Homo_sapiens_assembly38.dbsnp138.vcf.gz') )
.set{ dbsnp_known_indel_ref_vcf }
Channel
.value( file('references/hg38/Homo_sapiens_assembly38.dbsnp138.vcf.gz.tbi') )
.set{ dbsnp_known_indel_ref_vcf_index }
Channel
.value( file('references/hg38/wgs_calling_regions_blacklist.1based.hg38.bed') )
.set{ wgs_bed_blacklist_1based }
Channel
.value( file('references/hg38/caveman_blacklist.hg38.bed') )
.set{ caveman_blacklist_0based }
Channel
.value( file('references/hg38/unmatchedNormal.bed.gz') )
.set{ unmatched_normal_bed }
Channel
.value( file('references/hg38/unmatchedNormal.bed.gz.tbi') )
.set{ unmatched_normal_bed_index }
Channel
.value( file('references/hg38/centromeric_repeats.hg38.bed.gz') )
.set{ centromeric_repeats_bed }
Channel
.value( file('references/hg38/centromeric_repeats.hg38.bed.gz.tbi') )
.set{ centromeric_repeats_bed_index }
Channel
.value( file('references/hg38/simple_repeats.hg38.bed.gz') )
.set{ simple_repeats_bed }
Channel
.value( file('references/hg38/simple_repeats.hg38.bed.gz.tbi') )
.set{ simple_repeats_bed_index }
Channel
.value( file('references/hg38/dbsnp138.hg38.bed.gz') )
.set{ dbsnp_bed }
Channel
.value( file('references/hg38/dbsnp138.hg38.bed.gz.tbi') )
.set{ dbsnp_bed_index }
Channel
.value( file('references/hg38/Homo_sapiens.GRCh38.108.gtf.gz') )
.set{ ensembl_gtf_file }
// #################################################### \\
// ~~~~~~~~~~~~~~~~ PIPELINE PROCESSES ~~~~~~~~~~~~~~~~ \\
log.info ''
log.info '################################################'
log.info ''
log.info " .------------------------. "
log.info " | .-..-. .--. .---. | "
log.info " | : `' :: .--': .; : | "
log.info " | : .. :: : _ : _.' | "
log.info " | : :; :: :; :: : | "
log.info " | :_;:_;`.__.':_; | "
log.info " | ,-. .--. .--. .--. | "
log.info " | .' :: ,. :: ,. :: ,. : | "
log.info " | : :: :: :: :: :: :: : | "
log.info " | : :: :; :: :; :: :; : | "
log.info " | :_;`.__.'`.__.'`.__.' | "
log.info " .________________________. "
log.info ''
log.info " ░█▀▀░█▀█░█▄█░█▀█░▀█▀░▀█▀░█▀▀ "
log.info " ░▀▀█░█░█░█░█░█▀█░░█░░░█░░█░░ "
log.info " ░▀▀▀░▀▀▀░▀░▀░▀░▀░░▀░░▀▀▀░▀▀▀ "
log.info ''
log.info "~~~ Launch Time ~~~"
log.info ''
log.info " ${workflowTimestamp}"
log.info ''
log.info "~~~ Input Directory ~~~"
log.info ''
log.info " ${params.input_dir}"
log.info ''
log.info "~~~ Output Directory ~~~"
log.info ''
log.info " ${params.output_dir}"
log.info ''
log.info "~~~ Run Report File ~~~"
log.info ''
log.info " nextflow_report.${params.run_id}.html"
log.info ''
log.info "~~~ Sequencing Protocol ~~~"
log.info ''
log.info " ${params.seq_protocol}"
log.info ''
log.info '################################################'
log.info ''
// Read user provided sample sheet to set the Tumor/Normal sample pairs
Channel
.fromPath( params.sample_sheet )
.splitCsv( header:true )
.map{ row -> tumor_bam = "${row.tumor}"
tumor_bam_index = "${row.tumor}".replaceFirst(/\.bam$/, "")
normal_bam = "${row.normal}"
normal_bam_index = "${row.normal}".replaceFirst(/\.bam$/, "")
return[ file("${params.input_dir}/${tumor_bam}"),
file("${params.input_dir}/${tumor_bam_index}*.bai"),
file("${params.input_dir}/${normal_bam}"),
file("${params.input_dir}/${normal_bam_index}*.bai") ] }
.into{ tumor_normal_pair_forAlleleCount;
tumor_normal_pair_forTelomerecat;
tumor_normal_pair_forTelomereHunter;
tumor_normal_pair_forConpairPileup;
tumor_normal_pair_forVarscanSamtoolsMpileup;
tumor_normal_pair_forMutectCalling;
tumor_normal_pair_forMutectPileup;
tumor_normal_pair_forManta;
tumor_normal_pair_forSvaba;
tumor_normal_pair_forDelly;
tumor_normal_pair_forIgCaller }
// alleleCount ~ determine the sex of each sample to use in downstream analyses
process identifySampleSex_allelecount {
publishDir "${params.output_dir}/somatic/sexOfSamples", mode: 'copy', pattern: '*.{txt}'
tag "${tumor_normal_sample_id}"
input:
tuple path(tumor_bam), path(tumor_bam_index), path(normal_bam), path(normal_bam_index) from tumor_normal_pair_forAlleleCount
path ref_genome_fasta_index from ref_genome_fasta_index_file
path sex_loci from sex_identification_loci
output:
tuple val(tumor_normal_sample_id), path(tumor_bam), path(tumor_bam_index), path(normal_bam), path(normal_bam_index) into bams_forVarscanBamReadcount
tuple val(tumor_normal_sample_id), path(tumor_bam), path(tumor_bam_index) into tumor_bams_forFragCounter
tuple val(tumor_normal_sample_id), path(normal_bam), path(normal_bam_index) into normal_bams_forFragCounter
tuple val(tumor_normal_sample_id), path(tumor_bam), path(tumor_bam_index), path(normal_bam), path(normal_bam_index) into bams_forFragCounterPileup
tuple val(tumor_normal_sample_id), path(tumor_bam), path(tumor_bam_index), path(normal_bam), path(normal_bam_index), path(sample_sex) into bams_and_sex_of_sample_forBattenberg
tuple val(tumor_normal_sample_id), path(tumor_bam), path(tumor_bam_index), path(normal_bam), path(normal_bam_index) into bams_forFacetsPileup
tuple val(tumor_normal_sample_id), path(tumor_bam), path(tumor_bam_index), path(normal_bam), path(normal_bam_index) into bams_forCaveman
script:
tumor_id = "${tumor_bam.baseName}".replaceFirst(/\..*$/, "")
normal_id = "${normal_bam.baseName}".replaceFirst(/\..*$/, "")
tumor_normal_sample_id = "${tumor_id}_vs_${normal_id}"
sex_loci_allele_counts = "${tumor_normal_sample_id}.sexloci.txt"
sample_sex = "${tumor_normal_sample_id}.sexident.txt"
"""
alleleCounter \
--loci-file "${sex_loci}" \
--hts-file "${normal_bam}" \
--ref-file "${ref_genome_fasta_index}" \
--output-file "${sex_loci_allele_counts}"
sample_sex_determinator.sh "${sex_loci_allele_counts}" > "${sample_sex}"
"""
}
// ~~~~~~~~~~~~~~~ Battenberg ~~~~~~~~~~~~~~ \\
// START
// Battenberg ~ download the reference files needed to run Battenberg
process downloadBattenbergReferences_battenberg {
publishDir "references/hg38", mode: 'copy'
beforeScript 'mkdir -p workdirTmp/'
afterScript 'rm -f workdirTmp/*'
output:
path battenberg_references into battenberg_ref_dir_fromProcess
when:
params.battenberg == "on" && params.battenberg_ref_cached == "no"
script:
battenberg_references = "battenberg_reference/"
"""
export TMPDIR="workdirTmp/"
mkdir -p ${battenberg_references}
cd ${battenberg_references}/
battenberg_reference_downloader.sh
"""
}
// Depending on whether the reference files used for Battenberg was pre-downloaded, set the input
// channel for the Battenberg process
if( params.battenberg_ref_cached == "yes" ) {
battenberg_ref_dir = battenberg_ref_dir_preDownloaded
}
else {
battenberg_ref_dir = battenberg_ref_dir_fromProcess
}
// Battenberg ~ whole genome sequencing subclonal copy number caller
process cnvCalling_battenberg {
publishDir "${params.output_dir}/somatic/battenberg", mode: 'copy'
tag "${tumor_normal_sample_id}"
beforeScript 'mkdir -p workdirTmp/'
afterScript 'rm -rf workdirTmp/*'
input:
tuple val(tumor_normal_sample_id), path(tumor_bam), path(tumor_bam_index), path(normal_bam), path(normal_bam_index), path(sample_sex), path(battenberg_references) from bams_and_sex_of_sample_forBattenberg.combine(battenberg_ref_dir)
output:
tuple val(tumor_normal_sample_id), path(battenberg_fit_cnv_profile_csv), path(battenberg_fit_segmented_logr) into fit_cnv_data
path battenberg_fit_purity_ploidy
path battenberg_fit_cnv_profile_png
path "${output_dir}/*_fit_cnv.csv"
path "${output_dir}/*_subclones.txt"
path "${output_dir}/*_rho_and_psi.txt"
path "${output_dir}/*_purity_ploidy.txt"
path "${output_dir}/*.tumour.png"
path "${output_dir}/*.germline.png"
path "${output_dir}/*_distance.png"
path "${output_dir}/*_coverage.png"
path "${output_dir}/*_alleleratio.png"
path "${output_dir}/*_BattenbergProfile_subclones.png"
path "${output_dir}/*_BattenbergProfile_average.png"
path "${output_dir}/*chr*_heterozygousData.png"
path "${output_dir}/*_nonroundedprofile.png"
path "${output_dir}/*_segment_chr*.png"
path "${output_dir}/*_GCwindowCorrelations_*Correction.txt"
path "${output_dir}/*_refit_suggestion.txt"
path "${output_dir}/*_segment_masking_details.txt"
path "${output_dir}/*_subclones_alternatives.txt"
path "${output_dir}/*_subclones_chr*.png"
path "${output_dir}/*_totalcn_chrom_plot.png"
path "${output_dir}/*_copynumberprofile.png"
when:
params.battenberg == "on"
script:
tumor_id = "${tumor_bam.baseName}".replaceFirst(/\..*$/, "")
normal_id = "${normal_bam.baseName}".replaceFirst(/\..*$/, "")
output_dir = "${tumor_normal_sample_id}_results"
battenberg_fit_cnv_profile_csv = "${tumor_normal_sample_id}.battenberg.fit.cnv.csv.gz"
battenberg_fit_segmented_logr = "${tumor_normal_sample_id}.logRsegmented.txt.gz"
battenberg_fit_purity_ploidy = "${tumor_normal_sample_id}.battenberg.fit.purity.ploidy.txt"
battenberg_fit_cnv_profile_png = "${tumor_normal_sample_id}.battenberg.fit.cnv.png"
"""
#export TMPDIR="workdirTmp/"
cp /opt/downloads/beagle.08Feb22.fa4.jar battenberg_reference/beagle5/
sex=\$(cut -d ' ' -f 1 "${sample_sex}")
battenberg_executor.sh \
"${tumor_id}" \
"${normal_id}" \
"${tumor_bam}" \
"${normal_bam}" \
"\${sex}" \
"${output_dir}" \
"${task.cpus}" \
"${params.battenberg_min_depth}" \
${params.battenberg_preset_rho_psi} \
${params.battenberg_preset_rho} \
${params.battenberg_preset_psi} \
"${tumor_id}_fit_cnv.csv"
gzip -c "${output_dir}/${tumor_id}.logRsegmented.txt" > "${battenberg_fit_segmented_logr}"
echo "purity\tploidy" > "${battenberg_fit_purity_ploidy}"
grep 'FRAC_GENOME' "${output_dir}/${tumor_id}_rho_and_psi.txt" | awk 'BEGIN {OFS="\t"} {print \$2,\$4}' >> "${battenberg_fit_purity_ploidy}"
cp "${output_dir}/${tumor_id}_second_nonroundedprofile.png" "${battenberg_fit_cnv_profile_png}"
gzip -c "${output_dir}/${tumor_id}_fit_cnv.csv" > "${battenberg_fit_cnv_profile_csv}"
"""
}
// devgru ~ Extract fit copy number data from Battenberg for final output
process fitCnvProfileExtract_devgru {
publishDir "${params.output_dir}/somatic/battenberg", mode: 'copy'
tag "${tumor_normal_sample_id}"
beforeScript 'mkdir -p workdirTmp/'
afterScript 'rm -f workdirTmp/*'
input:
tuple val(tumor_normal_sample_id), path(battenberg_fit_cnv_profile_csv), path(battenberg_fit_segmented_logr) from fit_cnv_data
output:
tuple val(tumor_normal_sample_id), path(final_battenberg_cnv_profile) into final_battenberg_cnv_profile_forConsensusPrep
when:
params.battenberg == "on"
script:
final_battenberg_cnv_profile = "${tumor_normal_sample_id}.battenberg.fit.cnv.bed"
"""
export TMPDIR="workdirTmp/"
Rscript --vanilla ${workflow.projectDir}/bin/battenberg_segment_chainer.R \
"${tumor_normal_sample_id}" \
"${battenberg_fit_cnv_profile_csv}" \
"${battenberg_fit_segmented_logr}" \
${task.cpus} \
"${final_battenberg_cnv_profile}"
"""
}
// Battenberg Consensus CNV Prep ~ extract and prepare CNV output for consensus
process consensusCnvPrep_battenberg {
tag "${tumor_normal_sample_id}"
beforeScript 'mkdir -p workdirTmp/'
afterScript 'rm -f workdirTmp/*'
input:
tuple val(tumor_normal_sample_id), path(final_battenberg_cnv_profile) from final_battenberg_cnv_profile_forConsensusPrep
output:
tuple val(tumor_normal_sample_id), path(battenberg_somatic_cnv_bed), path(battenberg_somatic_alleles_bed) into final_battenberg_cnv_profile_forConsensus
tuple val(tumor_normal_sample_id), path(battenberg_somatic_cnv_bed) into tumor_cnv_profile_forCaveman
when:
params.battenberg == "on"
script:
battenberg_somatic_cnv_bed = "${tumor_normal_sample_id}.battenberg.somatic.cnv.bed"
battenberg_somatic_alleles_bed = "${tumor_normal_sample_id}.battenberg.somatic.alleles.bed"
"""
export TMPDIR="workdirTmp/"
battenberg_cnv_profile_postprocesser.sh \
"${final_battenberg_cnv_profile}" \
"${battenberg_somatic_cnv_bed}" \
"${battenberg_somatic_alleles_bed}"
"""
}
// END
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\
// ~~~~~~~~~~~~~~~~~ FACETS ~~~~~~~~~~~~~~~~ \\
// START
// FACETS ~ generate SNP read count pileups for CNV calling
process snpPileup_facets {
publishDir "${params.output_dir}/somatic/facets", mode: 'copy'
tag "${tumor_normal_sample_id}"
input:
tuple val(tumor_normal_sample_id), path(tumor_bam), path(tumor_bam_index), path(normal_bam), path(normal_bam_index) from bams_forFacetsPileup
path common_dbsnp_vcf from common_dbsnp_ref_vcf
path common_dbsnp_vcf_index from common_dbsnp_ref_vcf_index
output:
tuple val(tumor_normal_sample_id), path(facets_snp_pileup) into snp_pileup_forFacets
when:
params.facets == "on"
script:
tumor_id = "${tumor_bam.baseName}".replaceFirst(/\..*$/, "")
normal_id = "${normal_bam.baseName}".replaceFirst(/\..*$/, "")
tumor_normal_sample_id = "${tumor_id}_vs_${normal_id}"
facets_snp_pileup = "${tumor_normal_sample_id}.facets.snp_pileup.csv.gz"
"""
snp-pileup \
--gzip \
--min-map-quality 15 \
--min-base-quality 20 \
--pseudo-snps 100 \
--min-read-counts ${params.facets_min_depth} \
"${common_dbsnp_vcf}" \
"${facets_snp_pileup}" \
"${normal_bam}" \
"${tumor_bam}"
"""
}
// FACETS ~ fraction and copy number estimate from tumor/normal sequencing
process cnvCalling_facets {
publishDir "${params.output_dir}/somatic/facets", mode: 'copy'
tag "${tumor_normal_sample_id}"
beforeScript 'mkdir -p workdirTmp/'
afterScript 'rm -f workdirTmp/*'
input:
tuple val(tumor_normal_sample_id), path(facets_snp_pileup) from snp_pileup_forFacets
output:
tuple val(tumor_normal_sample_id), path(facets_cnv_profile) into facets_cnv_profile_forConsensusPrep
path facets_purity_ploidy
path facets_run_log
path facets_cnv_pdf
path facets_spider_qc_pdf
when:
params.facets == "on"
script:
facets_run_log = "${tumor_normal_sample_id}.facets.log.txt"
facets_purity_ploidy = "${tumor_normal_sample_id}.facets.purity.ploidy.txt"
facets_cnv_profile = "${tumor_normal_sample_id}.facets.cnv.txt"
facets_cnv_pdf = "${tumor_normal_sample_id}.facets.cnv.pdf"
facets_spider_qc_pdf = "${tumor_normal_sample_id}.facets.spider.pdf"
if ( params.seq_protocol == "WGS" )
"""
export TMPDIR="workdirTmp/"
Rscript --vanilla ${workflow.projectDir}/bin/run_iarc_facets.R \
"${facets_snp_pileup}" \
hg38 \
1000 \
35 \
150 \
300 \
${params.facets_min_depth}
mv "${tumor_normal_sample_id}.facets.snp_pileup.R_sessionInfo.txt" "${facets_run_log}"
mv "${tumor_normal_sample_id}.facets.snp_pileup.def_cval"*"_stats.txt" "${facets_purity_ploidy}"
mv "${tumor_normal_sample_id}.facets.snp_pileup.def_cval"*"_CNV.txt" "${facets_cnv_profile}"
mv "${tumor_normal_sample_id}.facets.snp_pileup.def_cval"*"_CNV.pdf" "${facets_cnv_pdf}"
mv "${tumor_normal_sample_id}.facets.snp_pileup.def_cval"*"_CNV_spider.pdf" "${facets_spider_qc_pdf}"
"""
else if ( params.seq_protocol == "WES" )
"""
export TMPDIR="workdirTmp/"
Rscript --vanilla ${workflow.projectDir}/bin/run_iarc_facets.R \
"${facets_snp_pileup}" \
hg38 \
250 \
25 \
75 \
150 \
${params.facets_min_depth}
mv "${tumor_normal_sample_id}.facets.snp_pileup.R_sessionInfo.txt" "${facets_run_log}"
mv "${tumor_normal_sample_id}.facets.snp_pileup.def_cval"*"_stats.txt" "${facets_purity_ploidy}"
mv "${tumor_normal_sample_id}.facets.snp_pileup.def_cval"*"_CNV.txt" "${facets_cnv_profile}"
mv "${tumor_normal_sample_id}.facets.snp_pileup.def_cval"*"_CNV.pdf" "${facets_cnv_pdf}"
mv "${tumor_normal_sample_id}.facets.snp_pileup.def_cval"*"_CNV_spider.pdf" "${facets_spider_qc_pdf}"
"""
}
// FACETS ~ fraction and copy number estimate from tumor/normal sequencing
process consensusCnvPrep_facets {
tag "${tumor_normal_sample_id}"
beforeScript 'mkdir -p workdirTmp/'
afterScript 'rm -f workdirTmp/*'
input:
tuple val(tumor_normal_sample_id), path(facets_cnv_profile) from facets_cnv_profile_forConsensusPrep
output:
tuple val(tumor_normal_sample_id), path(facets_somatic_cnv_bed), path(facets_somatic_alleles_bed) into final_facets_cnv_profile_forConsensus
when:
params.facets == "on"
script:
facets_somatic_cnv_bed = "${tumor_normal_sample_id}.facets.somatic.cnv.bed"
facets_somatic_alleles_bed = "${tumor_normal_sample_id}.facets.somatic.alleles.bed"
"""
export TMPDIR="workdirTmp/"
facets_cnv_profile_postprocesser.sh \
"${facets_cnv_profile}" \
"${tumor_normal_sample_id}" \
"${facets_somatic_cnv_bed}" \
"${facets_somatic_alleles_bed}"
"""
}
// END
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\
// ~~~~~~~~~~~~~~~~~ Manta ~~~~~~~~~~~~~~~~~ \\
// START
// Manta ~ call structural variants and indels from mapped paired-end sequencing reads of matched tumor/normal sample pairs
process svAndIndelCalling_manta {
publishDir "${params.output_dir}/somatic/manta", mode: 'copy', pattern: '*.{vcf.gz,tbi}'
tag "${tumor_normal_sample_id}"
input:
tuple path(tumor_bam), path(tumor_bam_index), path(normal_bam), path(normal_bam_index) from tumor_normal_pair_forManta
path ref_genome_fasta from ref_genome_fasta_file
path ref_genome_fasta_index from ref_genome_fasta_index_file
path ref_genome_fasta_dict from ref_genome_fasta_dict_file
path target_bed from target_regions_bed
output:
tuple val(tumor_normal_sample_id), path(tumor_bam), path(tumor_bam_index), path(normal_bam), path(normal_bam_index), path(candidate_indel_vcf), path(candidate_indel_vcf_index) into bams_and_candidate_indel_vcf_forStrelka
tuple val(tumor_normal_sample_id), val(tumor_id), val(normal_id), path(manta_somatic_sv_vcf), path(manta_somatic_sv_vcf_index) into manta_sv_vcf_forPostprocessing
tuple val(tumor_normal_sample_id), path(tumor_bam), path(tumor_bam_index) into manta_tumor_bam_forDuphold
tuple path(unfiltered_sv_vcf), path(unfiltered_sv_vcf_index)
tuple path(germline_sv_vcf), path(germline_sv_vcf_index)
tuple val(tumor_normal_sample_id), path(germline_sv_vcf), path(germline_sv_vcf_index) into germline_indel_vcf_forCaveman
when:
params.manta == "on"
script:
tumor_id = "${tumor_bam.baseName}".replaceFirst(/\..*$/, "")
normal_id = "${normal_bam.baseName}".replaceFirst(/\..*$/, "")
tumor_normal_sample_id = "${tumor_id}_vs_${normal_id}"
zipped_bed= "${target_bed}.gz"
unfiltered_sv_vcf = "${tumor_normal_sample_id}.manta.somatic.sv.unfiltered.vcf.gz"
manta_somatic_config = "${tumor_normal_sample_id}.manta.somatic.config.ini"
unfiltered_sv_vcf_index = "${unfiltered_sv_vcf}.tbi"
germline_sv_vcf = "${tumor_normal_sample_id}.manta.germline.sv.vcf.gz"
germline_sv_vcf_index = "${germline_sv_vcf}.tbi"
candidate_indel_vcf = "${tumor_normal_sample_id}.manta.somatic.indels.unfiltered.vcf.gz"
candidate_indel_vcf_index = "${candidate_indel_vcf}.tbi"
manta_somatic_sv_vcf = "${tumor_normal_sample_id}.manta.somatic.sv.unprocessed.vcf.gz"
manta_somatic_sv_vcf_index = "${manta_somatic_sv_vcf}.tbi"
manta_call_parameters = params.seq_protocol == "WES" ? "--exome" : ""
if ( params.seq_protocol == "WGS" )
"""
bgzip < "${target_bed}" > "${zipped_bed}"
tabix "${zipped_bed}"
touch "${manta_somatic_config}"
cat \${MANTA_DIR}/bin/configManta.py.ini \
| sed 's|enableRemoteReadRetrievalForInsertionsInCancerCallingModes = 0|enableRemoteReadRetrievalForInsertionsInCancerCallingModes = 1|' \
| sed 's|minPassSomaticScore = 30|minPassSomaticScore = 35|' \
| sed 's|minCandidateSpanningCount = 3|minCandidateSpanningCount = 4|' >> "${manta_somatic_config}"
python \${MANTA_DIR}/bin/configManta.py \
--tumorBam "${tumor_bam}" \
--normalBam "${normal_bam}" \
--referenceFasta "${ref_genome_fasta}" \
--callRegions "${zipped_bed}" \
--config "${manta_somatic_config}" \
--runDir manta
python manta/runWorkflow.py \
--mode local \
--jobs "${task.cpus}" \
--memGb "${task.memory.toGiga()}"
mv manta/results/variants/candidateSV.vcf.gz "${unfiltered_sv_vcf}"
mv manta/results/variants/candidateSV.vcf.gz.tbi "${unfiltered_sv_vcf_index}"
mv manta/results/variants/candidateSmallIndels.vcf.gz "${candidate_indel_vcf}"
mv manta/results/variants/candidateSmallIndels.vcf.gz.tbi "${candidate_indel_vcf_index}"
zcat manta/results/variants/diploidSV.vcf.gz \
| grep -E "^#|PASS" \
| bgzip > "${germline_sv_vcf}"
tabix "${germline_sv_vcf}"
zcat manta/results/variants/somaticSV.vcf.gz \
| grep -E "^#|PASS" > somaticSV.passonly.vcf
\${MANTA_DIR}/libexec/convertInversion.py \
\${MANTA_DIR}/libexec/samtools \
"${ref_genome_fasta}" \
somaticSV.passonly.vcf \
| bgzip > "${manta_somatic_sv_vcf}"
tabix "${manta_somatic_sv_vcf}"
"""
else if ( params.seq_protocol == "WES" )
"""
bgzip < "${target_bed}" > "${zipped_bed}"
tabix "${zipped_bed}"
touch "${manta_somatic_config}"
cat \${MANTA_DIR}/bin/configManta.py.ini \
| sed 's|enableRemoteReadRetrievalForInsertionsInCancerCallingModes = 0|enableRemoteReadRetrievalForInsertionsInCancerCallingModes = 1|' \
| sed 's|minPassSomaticScore = 30|minPassSomaticScore = 35|' \
| sed 's|minCandidateSpanningCount = 3|minCandidateSpanningCount = 4|' >> "${manta_somatic_config}"
python \${MANTA_DIR}/bin/configManta.py \
--tumorBam "${tumor_bam}" \
--normalBam "${normal_bam}" \
--referenceFasta "${ref_genome_fasta}" \
--callRegions "${zipped_bed}" \
--config "${manta_somatic_config}" \
--runDir manta \
--exome
python manta/runWorkflow.py \
--mode local \
--jobs "${task.cpus}" \
--memGb "${task.memory.toGiga()}"
mv manta/results/variants/candidateSV.vcf.gz "${unfiltered_sv_vcf}"
mv manta/results/variants/candidateSV.vcf.gz.tbi "${unfiltered_sv_vcf_index}"
mv manta/results/variants/candidateSmallIndels.vcf.gz "${candidate_indel_vcf}"
mv manta/results/variants/candidateSmallIndels.vcf.gz.tbi "${candidate_indel_vcf_index}"
zcat manta/results/variants/diploidSV.vcf.gz \
| grep -E "^#|PASS" \
| bgzip > "${germline_sv_vcf}"
tabix "${germline_sv_vcf}"
zcat manta/results/variants/somaticSV.vcf.gz \
| grep -E "^#|PASS" > somaticSV.passonly.vcf
\${MANTA_DIR}/libexec/convertInversion.py \
\${MANTA_DIR}/libexec/samtools \
"${ref_genome_fasta}" \
somaticSV.passonly.vcf \
| bgzip > "${manta_somatic_sv_vcf}"
tabix "${manta_somatic_sv_vcf}"
"""
}
// BCFtools filter / view ~ filter out additional false positives based on alternative variant reads in normal sample
process filterAndPostprocessMantaVcf_bcftools {
tag "${tumor_normal_sample_id}"
input:
tuple val(tumor_normal_sample_id), val(tumor_id), val(normal_id), path(manta_somatic_sv_vcf), path(manta_somatic_sv_vcf_index) from manta_sv_vcf_forPostprocessing
output:
tuple val(tumor_normal_sample_id), path(final_manta_somatic_sv_vcf) into manta_sv_vcf_forDuphold
when:
params.manta == "on"
script:
final_manta_somatic_sv_vcf = "${tumor_normal_sample_id}.manta.somatic.sv.vcf"
"""
touch name.txt
echo "${normal_id}" >> name.txt
bcftools filter \
--output-type v \
--exclude 'FORMAT/SR[@name.txt:1]>2 || FORMAT/PR[@name.txt:1]>2' \
--output "${final_manta_somatic_sv_vcf}" \
"${manta_somatic_sv_vcf}"
"""
}
// duphold ~ efficiently annotate SV calls with sequence depth information to reduce false positive deletion and duplication calls
process falsePostiveSvFilteringManta_duphold {
publishDir "${params.output_dir}/somatic/manta", mode: 'copy', pattern: '*.{vcf.gz}'
tag "${tumor_normal_sample_id}"
input:
tuple val(tumor_normal_sample_id), path(tumor_bam), path(tumor_bam_index), path(final_manta_somatic_sv_vcf) from manta_tumor_bam_forDuphold.join(manta_sv_vcf_forDuphold)
path ref_genome_fasta from ref_genome_fasta_file
path ref_genome_fasta_index from ref_genome_fasta_index_file
path ref_genome_fasta_dict from ref_genome_fasta_dict_file
output:
tuple val(tumor_normal_sample_id), path(manta_filtered_final_sv_vcf) into manta_filtered_final_sv_vcf_forConsensus
when:
params.manta == "on"
script:
manta_filtered_final_sv_vcf = "${tumor_normal_sample_id}.manta.somatic.sv.final.vcf.gz"
"""
duphold \
--vcf "${final_manta_somatic_sv_vcf}" \
--bam "${tumor_bam}" \
--fasta "${ref_genome_fasta}" \
--threads ${task.cpus} \
--output "${tumor_normal_sample_id}.manta.somatic.sv.fpmarked.vcf"
# Filter using recommended thresholds for DEL/DUP
bcftools filter --output-type u --exclude 'INFO/SVTYPE="DEL" && FORMAT/DHFFC>0.7' "${tumor_normal_sample_id}.manta.somatic.sv.fpmarked.vcf" \
| bcftools filter --output-type z --exclude 'INFO/SVTYPE="DUP" && FORMAT/DHBFC<1.3' --output "${manta_filtered_final_sv_vcf}"
"""
}
// END
// ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \\