-
Notifications
You must be signed in to change notification settings - Fork 18
/
RunStructuralVariantPipeline_Delly.pl
executable file
·1905 lines (1760 loc) · 63.2 KB
/
RunStructuralVariantPipeline_Delly.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/perl -w
##########StructuralVaraintFinder.pl########
#Author: Ronak Shah
#Date: 07/01/2013
#LastModified: 08/22/2013
#Version: 1.0
#Description: Get In the data and run the mapping and structural variant finding
#process.
#############
###Log:
##07/01/2013
#v1.0
use strict;
use Getopt::Long;
use IO::File;
use List::Util qw(max sum);
use Tie::IxHash;
use Vcf;
use File::Basename;
use FindBin qw($Bin);
use lib "$Bin/lib";
use Schedule;
use Cluster;
my (
$sampleFile,
$stdNormal,
$titleFile,
$fof,
$poolName,
$projectName,
$process,
$datadir,
$outdir,
$mvFiles,
$bwa,
$baitIntervalFile,
$targetIntervalFile,
$targetIntervalBedFile,
$refFile_hg19,
$refFile_b37,
$refFile,
$TMPDIR,
$PICARD,
$JAVA,
$samtools,
$fastqSource,
$GATK,
$PYTHON,
$PYTHONPATH,
$prog,
$RefGeneFile,
$queue,
$PERL,
$DELLY,
$BCFTOOLS,
$QSUB,
$standardNormalList,
$MAPQ,
$BASEQ,
$barcodeFile,
$adaptorFile,
$TrimGalore,
$nprocessors,
$ZCAT,
$GZIP,
$FilterSV,
$AnnotateSV,
$OverallSupportingReads,
$OverallSupportingReadsHotspot,
$SampleTumorSupportingReads,
$SampleTumorSupportingReadsHotspot,
$SampleNormalSupportingReads,
$SampleNormalSupportingReadsHotspot,
$OverallSupportingSplitReads,
$OverallSupportingSplitReadsHotspot,
$LengthOfSV,
$OverallMapq,
$OverallMapqHotspot,
$SampleTumorGenotypeQualityFilter,
$SampleTumorGenotypeQualityFilterHotspot,
$SampleNormalGenotypeQualityFilter,
$SampleNormalGenotypeQualityFilterHotspot,
$DistanceBtwTumorNormalCTX,
$dRANGER,
$MCR,
$pair_file,
$bam_list,
$genome,
$scheduler,
$priority_project,
$priority_group
);
my $SINGULARITY = '';
my $singularityParams = '';
my $singularityBind = '';
my $singularityenv_prepend_path = "";
my $binPath = $Bin;
my $variant_config_file = $binPath . "/variants_pipeline_config.txt"; #default variant config file
my $sv_config_file = $binPath . "/strvar/template_dmp_sv.conf"; #default sv config file
#--This variable holds the current time
my $now = time;
if (@ARGV < 1 or !GetOptions (
'pre=s' => \$poolName,
'variant_config=s' => \$variant_config_file,
'sv_config=s' => \$sv_config_file,
'outputDirectory=s' => \$outdir,
'pair=s' => \$pair_file,
'bam_list=s' => \$bam_list,
'genome=s' => \$genome,
'scheduler=s' => \$scheduler,
'priority_project=s' => \$priority_project,
'priority_group=s' => \$priority_group
))
{
Usage();
}
#Check for Pool Name
if(!$poolName)
{
die "Please specify the project name by -pre\n";
}
if(!$genome || ($genome ne "hg19" && $genome ne "b37" && $genome ne "hybrid" && $genome ne "human_hybrid"))
{
die "Please specify the genome build by using -genome. Valid values are 'hg19', 'b37', 'hybrid', 'human_hybrid'\n";
}
$genome = $genome eq 'human_hybrid' ? 'hybrid' : $genome;
if ($variant_config_file) {
print "The variant configration file in use is $variant_config_file.\n";
}
else {
print "Please speciy varaint configuration file by -variant_config\n";
Usage();
exit;
}
if ($sv_config_file) {
print "The sv configration file in use is $sv_config_file.\n";
}
else {
print "Please speciy sv configuration file by -sv_config\n";
Usage();
exit;
}
if ($outdir) {
print "Results will be written in $outdir\n";
`/bin/mkdir -p $outdir`;
die "[ERROR]: Fail to create outdir: $outdir\n" if(!-d $outdir);
}
else {
print "Please enter the directory where to write the data while/after being processed.See Usage\n";
Usage();
exit;
}
my %NormalTumorPair = ();
if($pair_file)
{
ReadNormalTumorPair();
}
else
{
die "Please specify the pairing file by using -pair PAIR_FILE\n";
}
my %SampleBamHash = ();
my %BamSampleHash = ();
if($bam_list)
{
ReadBamList();
}
else
{
die "Please specify the bam list file by using -bam_list BAM_LIST_FILE\n";
}
# This is variable is the path to the bin folder
my $genomeDataPath = $binPath . "/data/" . $genome . "/";
my $HG19MAT = $genomeDataPath . "RefSeq_hg19.mat";
my $ExcludeRegions = $genomeDataPath . "human.hg19.excl.tsv";
my $HotspotFile = $genomeDataPath . "v3clin_hg19_structuralvariants_geneInterval.txt";
my $CancerCensusFile = $genomeDataPath . "cancer_gene_census.tsv";
my $DGvFile = $genomeDataPath . "DGv_Annotation.tsv";
my $RepeatRegionFile = $genomeDataPath . "repeatRegion.tsv";
#Load Variant Pipeline Main Configuration File
&verifyConfig($variant_config_file);
#Get SV Configration File details
my ($Version) = &GetConfiguration( $sv_config_file, $outdir );
my $PrintConfigFile = "RunConfigration_StrVar.txt";
open( VERSION, ">", "$outdir/$PrintConfigFile" ) || die "Cannot open $outdir/$PrintConfigFile, Reason:$!\n";
#Prin Version of tools and Files used
print VERSION "Tools|Files\tVersion\n";
while ( my ( $tools_files, $version ) = each(%$Version) ) {
print VERSION "$tools_files\t$version\n";
}
close(VERSION);
#use default value to override config file
$TMPDIR = $outdir . "/tmp/";
`/bin/mkdir -p $TMPDIR`;
die "[ERROR]: Fail to create TMPDIR: $TMPDIR\n" if(!-d $TMPDIR);
# if ( !$mvFiles ) {
# print "Folders will be created and Files will be moved.\n";
# $mvFiles = 1;
# }
# else {
# if ( $mvFiles == 1 ) {
# print "Folders will be created and Files will be moved.\n";
# }
# if ( $mvFiles == 2 ) {
# print "Folders will not be created and Files will not be moved.\n";
# }
# }
# if ( !$stdNormal ) {
# $stdNormal = "NULL";
# }
# else {
# print "Starndard Normal is given: $stdNormal\n";
# }
# if ( !$fastqSource ) {
# print "Assume fastq files came from GCL.\n";
# $fastqSource = "GCL";
# }
# else {
# if ( $fastqSource ne "GCL" && $fastqSource ne "DMP" ) {
# print "Please indicate fastqSource. See Usage\n";
# Usage();
# exit;
# }
# }
# if ($barcodeFile) {
# print "The barcode file in use is $barcodeFile.\n";
# }
# else {
# print "Please enter the barcode file.See Usage\n";
# Usage();
# exit;
# }
# if ($adaptorFile) {
# print "The barcode file in use is $adaptorFile.\n";
# }
# else {
# print "Please enter the adaptor file.See Usage\n";
# Usage();
# exit;
# }
if ( !$TMPDIR ) {
print "Path to temporary directory is not given. See Usage\n";
Usage();
exit;
}
else {
print "TMPDIR=$TMPDIR\n";
}
# if ( !$baitIntervalFile ) {
# print "Bait Interval file is not given. See Usage.\n";
# Usage();
# exit;
# }
# else {
# print "BAIT_INTERVAL=$baitIntervalFile\n";
# }
# if ( !$targetIntervalFile ) {
# print "Target Interval file is not given. See Usage\n";
# Usage();
# exit;
# }
# else {
# print "Target_INTERVAL=$targetIntervalFile\n";
# }
if ( !$refFile ) {
print "Reference Sequence file is not given. See Usage\n";
Usage();
exit;
}
else {
print "Reference_Sequence=$refFile\n";
}
if ( !$HotspotFile ) {
print "Hotspot location BED4 file is not given. See Usage\n";
Usage();
exit;
}
else {
print "HotspotFile=$HotspotFile\n";
}
#if ( !$JAVA ) {
# print "Path to java executables is not given. See Usage\n";
# Usage();
# exit;
#}
#else {
# print "JAVA=$JAVA\n";
#}
#Check if path to FilterSV script is given
if ( !$FilterSV ) {
$FilterSV = $binPath . "/strvar/FilterSV.pl";
print
"FilterSV.pl script path is not given, default location will be used.\n";
}
else {
print "Filter SV script location: $FilterSV.\n";
}
#Check if path to FilterSV script is given
if ( !$AnnotateSV ) {
$AnnotateSV = $binPath . "/strvar/AnnotateSVs.py";
print
"AnnotateSVs.py script path is not given, default location will be used.\n";
}
else {
print "Annotate SV script location: $AnnotateSV.\n";
}
if ( !$DELLY ) {
print "Path to Delly is not given. See Usage\n";
Usage();
exit;
}
else {
print "Delly=$DELLY\n";
}
#overallSupportingReadsPE
if ( !$OverallSupportingReads ) {
print "OverallSupportingReads not given default will be used.\n";
$OverallSupportingReads = 5;
print "OverallSupportingReads:$OverallSupportingReads\n";
}
else {
print "OverallSupportingReadsPE:$OverallSupportingReads.\n";
}
#sampleTumorSupportingReadsPE
if ( !$SampleTumorSupportingReads ) {
print "SampleTumorSupportingReadsPE not given default will be used.\n";
$SampleTumorSupportingReads = 2;
print "SampleTumorSupportingReadsPE:$SampleTumorSupportingReads\n";
}
else {
print "SampleTumorSupportingReadsPE:$SampleTumorSupportingReads.\n";
}
#sampleTumorSupportingReadsPE_Hotspot
if ( !$SampleTumorSupportingReadsHotspot ) {
print "SampleTumorSupportingReadsHotspot not given default will be used.\n";
$SampleTumorSupportingReadsHotspot = 1;
print
"SampleTumorSupportingReadsHotspot:$SampleTumorSupportingReadsHotspot\n";
}
else {
print
"SampleTumorSupportingReadsHotspot:$SampleTumorSupportingReadsHotspot.\n";
}
#sampleNormalSupportingReadsPE
if ( !$SampleNormalSupportingReads ) {
print "SampleNormalSupportingReadsPE not given default will be used.\n";
$SampleNormalSupportingReads = 2;
print "SampleNormalSupportingReadsPE:$SampleNormalSupportingReads\n";
}
else {
print "SampleNormalSupportingReadsPE:$SampleNormalSupportingReads.\n";
}
#sampleNormalSupportingReadsPE_Hotspot
if ( !$SampleNormalSupportingReadsHotspot ) {
print
"SampleNormalSupportingReadsHotspot not given default will be used.\n";
$SampleNormalSupportingReadsHotspot = 3;
print
"SampleNormalSupportingReadsHotspot:$SampleNormalSupportingReadsHotspot\n";
}
else {
print
"SampleNormalSupportingReadsHotspot:$SampleNormalSupportingReadsHotspot.\n";
}
#overallSupportingReadsSR
if ( !$OverallSupportingSplitReads ) {
print "OverallSupportingSplitReads not given default will be used.\n";
$OverallSupportingSplitReads = 0;
print "OverallSupportingReadsSR:$OverallSupportingSplitReads\n";
}
else {
print "OverallSupportingReadsSR:$OverallSupportingSplitReads.\n";
}
#overallSupportingReadsPE_Hotspot
if ( !$OverallSupportingReadsHotspot ) {
print "OverallSupportingReadsHotspot not given default will be used.\n";
$OverallSupportingReadsHotspot = 3;
print "OverallSupportingReadsPE_Hotspot:$OverallSupportingReadsHotspot\n";
}
else {
print "OverallSupportingReadsPE_Hotspot:$OverallSupportingReadsHotspot.\n";
}
#overallSupportingReadsSR_Hotspot
if ( !$OverallSupportingSplitReadsHotspot ) {
print
"OverallSupportingSplitReadsHotspot not given default will be used.\n";
$OverallSupportingSplitReadsHotspot = 0;
print
"OverallSupportingSplitReadsHotspott:$OverallSupportingSplitReadsHotspot\n";
}
else {
print
"OverallSupportingSplitReadsHotspot:$OverallSupportingSplitReadsHotspot.\n";
}
#lengthOfSV
if ( !$LengthOfSV ) {
print "LengthOfSV not given default will be used.\n";
$LengthOfSV = 300;
print "LengthOfSV:$LengthOfSV\n";
}
else {
print "LengthOfSV:$LengthOfSV.\n";
}
#overallMAPQ
if ( !$OverallMapq ) {
print "OverallMapq not given default will be used.\n";
$OverallMapq = 10;
print "OverallMapq:$OverallMapq\n";
}
else {
print "OverallMapq:$OverallMapq.\n";
}
#overallMAPQ_Hotspot
if ( !$OverallMapqHotspot ) {
print "OverallMapqHotspot not given default will be used.\n";
$OverallMapqHotspot = 5;
print "OverallMapqHotspot:$OverallMapqHotspot\n";
}
else {
print "OverallMapqHotspot:$OverallMapqHotspot.\n";
}
#sampleTumorGenotypeQualityFilter
if ( !$SampleTumorGenotypeQualityFilter ) {
print "SampleTumorGenotypeQualityFilter not given default will be used.\n";
$SampleTumorGenotypeQualityFilter = 15;
print
"SampleTumorGenotypeQualityFilter = $SampleTumorGenotypeQualityFilter\n";
}
else {
print
"SampleTumorGenotypeQualityFilter = $SampleTumorGenotypeQualityFilter\n";
}
#sampleTumorGenotypeQualityFilterHotspot
if ( !$SampleTumorGenotypeQualityFilterHotspot ) {
print
"SampleTumorGenotypeQualityFilterHotspot not given default will be used.\n";
$SampleTumorGenotypeQualityFilterHotspot = 5;
print
"SampleTumorGenotypeQualityFilterHotspot = $SampleTumorGenotypeQualityFilterHotspot\n";
}
else {
print
"SampleTumorGenotypeQualityFilterHotspot = $SampleTumorGenotypeQualityFilterHotspot\n";
}
#sampleNormalGenotypeQualityFilter
if ( !$SampleNormalGenotypeQualityFilter ) {
print "SampleNormalGenotypeQualityFilter not given default will be used.\n";
$SampleNormalGenotypeQualityFilter = 15;
print
"SampleNormalGenotypeQualityFilter = $SampleNormalGenotypeQualityFilter\n";
}
else {
print
"SampleNormalGenotypeQualityFilter = $SampleNormalGenotypeQualityFilter\n";
}
#sampleGenotypeQualityFilterHotspot
if ( !$SampleNormalGenotypeQualityFilterHotspot ) {
print
"SampleNormalGenotypeQualityFilterHotspot not given default will be used.\n";
$SampleNormalGenotypeQualityFilterHotspot = 20;
print
"SampleNormalGenotypeQualityFilterHotspot = $SampleNormalGenotypeQualityFilterHotspot\n";
}
else {
print
"SampleNormalGenotypeQualityFilterHotspot = $SampleNormalGenotypeQualityFilterHotspot\n";
}
#DistanceBtwTumorNormalCTX
if ( !$DistanceBtwTumorNormalCTX ) {
print "DistanceBtwTumorNormalCTX not given default will be used.\n";
$DistanceBtwTumorNormalCTX = 5;
print "DistanceBtwTumorNormalCTX = $DistanceBtwTumorNormalCTX\n";
}
else {
print "SDistanceBtwTumorNormalCTX = $DistanceBtwTumorNormalCTX\n";
}
&MakeCSH($outdir);
my @allProcess = split( ",", $process );
my $allProcessList = join( ",", @allProcess );
my $numberOfProcess = scalar(@allProcess);
my $processCount = 0;
my $parseFilenames;
while ( $processCount < $numberOfProcess ) {
my $runProcess = shift(@allProcess);
($parseFilenames) = &Select( $runProcess, $parseFilenames );
$processCount++;
}
sleep(30);
CleanUpFiles($outdir);
#--Calculate total runtime (current time minus start time)
$now = time - $now;
#--Print runtime
printf(
"\n\nTotal running time: %02d:%02d:%02d\n\n",
int( $now / 3600 ),
int( ( $now % 3600 ) / 60 ),
int( $now % 60 )
);
print "\n!!!!Done, Thanks for using the script!!!\n";
exit;
#####################################
#####################################
#Run only single process at a time.
sub Select {
my ( $process, $parseFilenames ) = @_;
my $SVoutput;
if ( $process == 1 ) {
#$parseFilenames = &MergeDataFromDirectory();
}
elsif ( $process == 2 ) {
#$parseFilenames = &DoMapping($parseFilenames);
}
elsif ( $process == 3 ) {
#$parseFilenames = &CalcHsMetrics($parseFilenames);
}
elsif ( $process == 4 ) {
$parseFilenames = &CallStructuralVariants($parseFilenames);
}
elsif ( $process == 5 ) {
$parseFilenames = &FilterStructuralVariants($parseFilenames);
}
elsif ( $process == 6 ) {
( $parseFilenames, $SVoutput ) =
&AnnotateStructuralVariants($parseFilenames);
}
elsif (( $process eq "all" )
or ( $process eq "ALL" )
or ( $process eq "All" ) )
{
#$parseFilenames = &MergeDataFromDirectory();
#$parseFilenames = &DoMapping($parseFilenames);
#$parseFilenames = &CalcHsMetrics($parseFilenames);
$parseFilenames = &CallStructuralVariants($parseFilenames);
$parseFilenames = &FilterStructuralVariants($parseFilenames);
$parseFilenames = &AnnotateStructuralVariants($parseFilenames);
}
else {
print
"Select:The process number entered ($process) does not exist, See Usage.\n";
exit(1);
}
return ($parseFilenames);
}
#####################################
#####################################
#How to use the script.
sub Usage {
print "Unknow option: @_\n" if (@_);
print "\nUsage : StructuralVariantFinder.pl [options]
[--config|c S Path to configration file(required;Template:/home/shahr2/Scripts/All/StrVarConfig_(script_version)_(bait_version.txt)]
[--dataDirectory|d S Path where all the files to be processed are located (required)]
[--outputDirectory|o S Path where all the output files will be written (required)]
Inside Config File:
>Locations:
barcodeFile S tab-delimited barcode file describing name of the barcode(Required)
adaptorFile S tab-delimited adaptor file describing sequence of the adaptor for corresponding barcode(Required)
BWA S Path to bwa mem program. (Required)
PICARD S Path to picard tools (Required)
DELLY S Path to delly executables (Required)
SAMTOOLS S Path to samtools source folder.(Required)
BaitInterval S Path to baits interval file.(Required)
TargetInterval S Path to targets interval file. (Required)
Reference S Path to genome reference file. (Required)
TMPDIR S Path to temporary directory. (Required)
JAVA S Path to java executables. (Required)
ExcludeRegions S Path to bed file indicating regions to exclude(Required)
>Parmeters
SampleFile S csv file describing details about the sample (required and submit with full path)
TitleFile S tab-delimited title file for the samples (required and submit with full path)
stdNormal S file to be used as standard normal #full path of bam file, *.bai file to be located in same folder)
ListOfStandardNormals S Name of the normal files with there path (fof:Paired files;one per line;one after another) (Required)
projectName S Name of the project(required,e.g:Colons).
poolName S Name of the pool(required,e.g:Colon5P1).]
Process S 1 => MergingFastq 2 => Run Mapping. 3 => Run HsMetrics. 4 => Call Structural Variants. 5 => Filter Structural Varaints 6 => Annotate Structural Variants\"1,2,3,4,5,6\" for all or in valid combination.]
Datadir S Path where all the files to be processed are located. (required)
Outdir S Path where all the output files will be written. (required)
moveFiles I 2 => Skip Making Folders & Moving Files. 1 => Make Folders and Move Files. (default:1,optional)
NumberOfProcessors I Number of processors to use for analysis (default:1,optional)
FOF S Name of the files with there path. (fof:Paired files;one per line;one after another) (optional)
>Versions
This would contain the versions for all things used in the pipeline.
>Parmeters
This would contain the parameters for the Pipleine
\n";
print "For any question please contact Ronak Shah (shahr2\@mskcc.org)\n";
print "!~!~! Comments, flames and suggestion are welcome !~!~!\n";
exit;
}
###################################################
###################################################
#--GET VARIANT CONFIGRATION DETAIL
sub verifyConfig{
my ($paths) = @_;
open(CONFIG, "$paths") || die "Can't open config file $paths $!";
while(<CONFIG>){
chomp;
my @conf = split(/\s+/, $_);
if($conf[0] =~ /singularity/i){
if(!-e "$conf[1]/singularity"){
die "CAN'T FIND singularity IN $conf[1] $!";
}
$SINGULARITY = $conf[1];
}
elsif($conf[0] =~ /DELLY/i){
if(!-e "$conf[1]/delly"){
die "CAN'T FIND delly IN $conf[1] $!";
}
$DELLY = "$conf[1]/delly";
}
elsif($conf[0] =~ /BCFTOOLS/i){
if(!-e "$conf[1]/bcftools"){
die "CAN'T FIND bcftools IN $conf[1] $!";
}
$BCFTOOLS = "$conf[1]/bcftools";
}
elsif($conf[0] =~ /^PERL/i){
if(!-e "$conf[1]/perl"){
die "CAN'T FIND perl IN $conf[1] $!";
}
$PERL = "$conf[1]/perl";
}
elsif($conf[0] =~ /^HG19_FASTA/i && $genome eq "hg19"){
if(!-e "$conf[1]"){
die "CAN'T FIND hg19 fasta at $conf[1] $!";
}
$refFile = $conf[1];
}
elsif($conf[0] =~ /^B37_FASTA/i && $genome eq "b37"){
if(!-e "$conf[1]"){
die "CAN'T FIND b37 fasta at $conf[1] $!";
}
$refFile = $conf[1];
}
elsif($conf[0] =~ /^B37_MM10_HYBRID_FASTA/i && $genome eq "hybrid"){
if(!-e "$conf[1]"){
die "CAN'T FIND hybrid fasta at $conf[1] $!";
}
$refFile = $conf[1];
}
elsif($conf[0] =~ /^PYTHON/i){
if(!-e "$conf[1]/python"){
die "CAN'T FIND python IN $conf[1] $!";
}
$PYTHON = "$conf[1]/python";
}
elsif($conf[0] =~ /^dRANGER/i){
if(!-e "$conf[1]/AnnotateSVs/run_AnnotateSVs_v2.sh"){
die "CAN'T FIND dRANGER IN $conf[1] $!";
}
$dRANGER= "$conf[1]/AnnotateSVs/run_AnnotateSVs_v2.sh";
}
elsif($conf[0] =~ /^MCR/i){
if(!-d "$conf[1]"){
die "CAN'T FIND MCR at $conf[1] $!";
}
$MCR= $conf[1];
}
}
my %sinParams = (singularity_exec => "$SINGULARITY/singularity", singularity_image => "$Bin/variants_pipeline_singularity_prod.simg");
$singularityParams = Schedule::singularityParams(%sinParams);
$singularityBind = Schedule::singularityBind($scheduler);
$ENV{'SINGULARITYENV_PREPEND_PATH'} = $singularityenv_prepend_path;
$ENV{'SINGULARITY_BINDPATH'} = $singularityBind;
$ENV{'OMP_NUM_THREADS'} = '2';
close CONFIG;
}
###################################################
###################################################
#--GET SV CONFIGRATION DETAIL
sub GetConfiguration {
my ($sv_config_file) = @_;
my @data = ();
tie( my %config, 'Tie::IxHash' );
tie( my %location, 'Tie::IxHash' );
tie( my %version, 'Tie::IxHash' );
tie( my %parameters, 'Tie::IxHash' );
print "Reading the configuration file\n";
# change the default Input Record Separator.
$/ = ">";
open( CONFIG, "$sv_config_file" ) or die "Cannot open $sv_config_file. Error: $!\n";
my $junk = <CONFIG>;
while (<CONFIG>) {
next if ( $_ =~ /^#/ );
chomp($_);
my ( $defLine, @configLines ) = split /\n/, $_;
if ( $defLine =~ /Locations/ ) {
foreach my $config (@configLines) {
next if ( $config =~ /^#/ );
@data = split( "=", $config, 2 );
$data[0] =~ s/\s//g;
$data[1] =~ s/\s//g;
$location{ $data[0] } = $data[1];
}
}
if ( $defLine =~ /Parameters/ ) {
foreach my $config (@configLines) {
next if ( $config =~ /^#/ );
@data = split( "=", $config, 2 );
$data[0] =~ s/\s//g;
$data[1] =~ s/\s//g;
$parameters{ $data[0] } = $data[1];
}
}
if ( $defLine =~ /Versions/ ) {
foreach my $config (@configLines) {
next if ( $config =~ /^#/ );
@data = split( "=", $config, 2 );
$data[0] =~ s/\s//g;
$data[1] =~ s/\s//g;
$version{ $data[0] } = $data[1];
}
}
}
close(CONFIG);
print "Completed reading the configuration file\n";
# Change back the Input Record Separator to default.
$/ = "\n";
###Set Variables
eval {
#$TMPDIR = $location{"TMPDIR"};
#$PERL = $location{"PERL"};
#$JAVA = $location{"JAVA"};
#$GATK = $location{"GATK"};
#$refFile = $location{"Reference"};
#$PICARD = $location{"PICARD"};
#$baitIntervalFile = $location{"BaitInterval"};
#$targetIntervalFile = $location{"TargetInterval"};
#$bwa = $location{"BWA"};
#$PYTHON = $location{"PYTHON"};
#$PYTHONPATH = $location{"PYTHONPATH"};
#$samtools = $location{"SAMTOOLS"};
#$DELLY = $location{"DELLY"};
#$barcodeFile = $location{"barcodeFile"};
#$RepeatRegionFile = $location{"RepeatRegionAnnotation"};
#$DGvFile = $location{"DGvAnnotations"};
#$CancerCensusFile = $location{"CosmicCensus"};
#$RepeatRegionFile = $location{"RepeatRegionAnnotation"};
#$RefGeneFile = $location{"RefGeneFile"};
#$barcodeFile = $location{"BarcodeKey"};
#$adaptorFile = $location{"AdaptorKey"};
#$QSUB = $location{"QSUB"};
#$TrimGalore = $location{"TrimGalore"};
#$ZCAT = $location{"ZCAT"};
#$GZIP = $location{"GZIP"};
#$FilterSV = $location{"FilterSV"};
#$AnnotateSV = $location{"AnnotateSV"};
#$HotspotFile = $location{"HotspotFile"};
#$dRANGER = $location{"dRANGER"};
#$MCR = $location{"MCR"};
$queue = $parameters{"SGE_QUEUE"};
#$fastqSource = $parameters{"fastqSource"};
#$sampleFile = $parameters{"SampleFile"};
#$titleFile = $parameters{"TitleFile"};
#$standardNormalList = $parameters{"ListOfStandardNoramlsForGenotyping"};
#$outdir = $parameters{"Outdir"};
#$datadir = $parameters{"Datadir"};
#$stdNormal = $parameters{"stdNormal"};
#$fof = $parameters{"FOF"};
$MAPQ = $parameters{"MAPQ"};
$BASEQ = $parameters{"BASEQ"};
#$poolName = $parameters{"poolName"};
#$projectName = $parameters{"projectName"};
$mvFiles = $parameters{"moveFiles"};
$process = $parameters{"Process"};
$prog = $parameters{"Program"};
$nprocessors = $parameters{"NumberOfProcessors"};
$OverallSupportingReads = $parameters{"OverallSupportingReads"};
$OverallSupportingReadsHotspot = $parameters{"OverallSupportingReadsHotspot"};
$SampleTumorSupportingReads = $parameters{"SampleTumorSupportingReads"};
$SampleTumorSupportingReadsHotspot = $parameters{"SampleTumorSupportingReadsHotspot"};
$SampleNormalSupportingReads = $parameters{"SampleNormalSupportingReads"};
$SampleNormalSupportingReadsHotspot = $parameters{"SampleNormalSupportingReadsHotspot"};
$OverallSupportingSplitReads = $parameters{"OverallSupportingSplitReads"};
$OverallSupportingSplitReadsHotspot = $parameters{"OverallSupportingSplitReadsHotspot"};
$LengthOfSV = $parameters{"LengthOfSV"};
$OverallMapq = $parameters{"OverallMapq"};
$OverallMapqHotspot = $parameters{"OverallMapqHotspot"};
$SampleTumorGenotypeQualityFilter = $parameters{"SampleTumorGenotypeQualityFilter"};
$SampleTumorGenotypeQualityFilterHotspot = $parameters{"SampleTumorGenotypeQualityFilterHotspot"};
$SampleNormalGenotypeQualityFilter = $parameters{"SampleNormalGenotypeQualityFilter"};
$SampleNormalGenotypeQualityFilterHotspot = $parameters{"SampleNormalGenotypeQualityFilterHotspot"};
};
if ($@) {
print "Did not find a variable in configuration file.Error: $@\n";
exit(1);
}
return ( \%version );
}
###################################################
###################################################
#--Make Notification file
sub MakeCSH {
my ($outdir) = @_;
my $filename = $outdir . "/Notify.csh";
if ( !-e $filename ) {
my $ntmp = new IO::File(">$filename");
print $ntmp "#!/bin/csh\n";
print $ntmp "#Notification File\n";
print $ntmp "echo", " This is Done", "\n";
$ntmp->close();
`chmod +x $filename`;
}
else {
print "$filename exists and wont be created.\n";
}
return;
}
###################################################
###################################################
#--Waiting for the process to finish
sub WaitToFinish {
my ( $outdir, @waitfilenames ) = @_;
print "Waiting for the Process to finish...\n";
foreach my $wfile (@waitfilenames) {
next if ( $wfile eq "NULL" );
wait while ( !-e "$outdir/$wfile" );
#print "$outdir/$wfile\n";
while ( -e "$outdir/$wfile" ) {
#print "$outdir/$wfile\n";
open( FH, "<", "$outdir/$wfile" );
while (<FH>) {
if ( $_ =~ /This is Done/ig ) {
#print "\nFinished: $wfile\n";
last;
}
else {
wait;
}
}
last;
}
close(FH);
}
foreach my $wfile (@waitfilenames) {
next if ( $wfile eq "NULL" );
`rm $outdir/$wfile`;
}
return;
}
# #####################################
# #####################################
# #This will help to call:
# #Somatic SVs: Delly
sub CallStructuralVariants {
my @names = keys(%BamSampleHash);
my @FilterData = ();
my @notifyNames = ();
tie( my %NormalPerFile, 'Tie::IxHash' );
my $now = time;
my $NormalUsed = $poolName . "_NormalUsedInSVcalling.txt";
my @fileNames = ();
my ( $waitFileNames, $svOutdir );
#Call Somatic SVs
print "Started running Somatics Variant jobs on SGE at " . localtime() . "\n";
my $count = 0;
foreach my $file (@names) {
my $fileSampleId = $BamSampleHash{$file};
my $fileClass;
my $normalSampleId = "";
if(exists($NormalTumorPair{$fileSampleId}) )
{
$fileClass = "Tumor";
$normalSampleId = $NormalTumorPair{$fileSampleId};
}
else
{
$fileClass = "Normal"
}
next if ( $fileClass =~ m/Normal/i );
my $normal = $SampleBamHash{$normalSampleId};
print "Final2:Tumor->$file\nNormal->$normal\n\n";
$NormalPerFile{$fileSampleId} = $normalSampleId;
( $waitFileNames, $svOutdir ) = &RunDelly( $normal, $file, $normalSampleId, $fileSampleId, $outdir, $count );
foreach my $waitName (@$waitFileNames) {
push( @notifyNames, $waitName );
}
push( @FilterData, "$svOutdir,$normalSampleId,$fileSampleId" );
$count++;
}
&WaitToFinish( $outdir, @notifyNames );
open( NFH, ">", "$outdir/$NormalUsed" ) || die "Cannot open NormalUsedinSVFile:$outdir/$NormalUsed;$!\n";
while ( my ( $key, $value ) = each(%NormalPerFile) ) {
print NFH "$key\t$value\n";
}
close(NFH);
$now = time - $now;
print "Finished running Germline and Somatic Variant jobs on SGE at " . localtime() . "\n";
printf(
"Total running time: %02d:%02d:%02d\n\n",
int( $now / 3600 ),
int( ( $now % 3600 ) / 60 ),
int( $now % 60 )
);
return ( \@names, \@FilterData );
}
#######################################
#######################################
#Run Delly
sub RunDelly {
my ( $normal, $tumor, $nId, $tId, $outdir, $count ) = @_;
my @waitFilenames = ();
my $date = `date "+%Y%m%d"`;
my $dellyOutdir = $outdir . "/StrVarAnalysis";
my $sampleTumorOutput = $dellyOutdir . "/" . $tId;
my ( $tFlag, $nFlag );
#Make Ouput dir
if ( !( -d "$dellyOutdir" ) ) {
`mkdir $dellyOutdir`;
}
else {
if ( $count == 0 ) {
warn "$dellyOutdir exists !!\n";
}
}
#for making link to files
my $NormalBai = $normal;
$NormalBai =~ s/\.bam/\.bai/;
my ($TumorBai) = $tumor;
$TumorBai =~ s/\.bam/\.bai/;
my $lnNormal = pop @{ [ split( "/", $normal ) ] };
chomp($lnNormal);
my ($lnNormalBai) = $lnNormal . ".bai";
my $lnTumor = pop @{ [ split( "/", $tumor ) ] };