-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDTrace.pl
More file actions
executable file
·1846 lines (1603 loc) · 85 KB
/
DTrace.pl
File metadata and controls
executable file
·1846 lines (1603 loc) · 85 KB
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
use Getopt::Long;
use Data::Dumper;
use strict;
use File::Glob ':glob';
use File::Basename;
use FindBin qw($RealBin);
use Parallel::ForkManager;
use Statistics::Basic qw(:all);
use lib "$RealBin/lib";
use bwaMapping;
use snvCalling;
use cnaCalling;
use seqStats;
my %options;
my %runlevel;
my %runTask;
$options{'noexecute'} = 0;
$options{'quiet'} = 0;
$options{'runlevels'} = undef;
$options{'runTask'} = undef;
$options{'readlen'} = 0;
$options{'mapper'} = "bwa";
$options{'sampleName'} = 'SRP';
$options{'samplePairNames'} = "SRP";
$options{'gender'} = "female";
$options{'FASTQ1'} = 'SRP';
$options{'FASTQ2'} = 'SRP';
$options{'fastqFiles1'} = 'SRP';
$options{'fastqFiles2'} = 'SRP';
$options{'platform'} = "ILLUMINA";
$options{'skipTask'} = 'SRP';
$options{'bams'} = 'SRP';
$options{'bamID'} = 1;
$options{'mutectCall'} = 'SRP';
$options{'lanepath'} = 'SRP';
$options{'threads'} = 1;
$options{'splitChr'} = undef;
$options{'help'} = undef;
$options{'qcOFF'} = undef;
$options{'keepBedCount'}= undef;
$options{'root'} = "$RealBin/../PIPELINE";
$options{'readpool'} = 'SRP';
$options{'gf'} = "png"; #the format used in html report
$options{'bzip'} = undef; #to allow bzip copressed fastq files
$options{'Rbinary'} = 'R';
$options{'seqType'} = 'WXS,paired-end'; #experimental types
$options{'tmpDir'} = '';
$options{'bin'} = "$RealBin/";
$options{'configure'} = "SRP";
$options{'skipPileup'} = "yes";
$options{'samSens'} = 0.005;
$options{'snvPattern'} = "SRP"; #for grepping samtools vcf files (and other)
$options{'indelPattern'} = "SRP"; #for grepping samtools vcf files (and other)
$options{'lorenzScaleFactor'} = 1.0;
$options{'chrPrefInBam'} = "SRP";
$options{'somaticInfo'} = "SRP";
$options{'germline'} = "SRP";
$options{'samCallmaxDepth'} = 400;
$options{'indel'} = "SRP";
$options{'recheck'} = "SRP";
$options{'recheckBams'} = 'SRP';
$options{'plpTitan'} = 2.0;
$options{'plpeTitan'} = "TRUE";
$options{'ncTitan'} = 0.5;
$options{'ncmTitan'} = "map";
$options{'symmetric'} = "TRUE";
$options{'transtate'} = 1e12;
$options{'tranclone'} = 1e9;
$options{'maxMem'} = '4g';
$options{'javaTmp'} = '/local/scratch';
$options{'nwigString'} = 'SRP';
$options{'homoThred'} = 0.85;
$options{'ndepthThred'} = 8;
$options{'mergeNonsegdup'} = 1;
$options{'mergeRare'} = 1;
$options{'qualTitan'} = 50;
$options{'vafTitan'} = 0.15;
$options{'rareVariants'} = undef;
$options{'germlineLOH'} = ''; #this file contains ID for both tumors and normals
$options{'maxInsLine'} = 0;
$options{'ignoreRG'} = 0;
$options{'CfiftyOff'} = 0;
$options{'chrProcess'} = 'SRP';
$options{'chrProcessRegion'} = 'SRP';
$options{'noStrandBias'} = 'no';
$options{'customCalling'} = 'SRP';
$options{'cmeme'} = 5.5;
$options{'cmedian'} = 2;
if (@ARGV == 0) {
helpm();
} else {
printf STDERR "\n# $0 %s\n",join(" ",@ARGV);
}
GetOptions(
"sampleName=s" => \$options{'sampleName'},
"samplePairNames=s" => \$options{'samplePairNames'},
"gender=s" => \$options{'gender'},
"FASTQ1=s" => \$options{'FASTQ1'},
"FASTQ2=s" => \$options{'FASTQ2'},
"fastqFiles1=s"=> \$options{'fastqFiles1'},
"fastqFiles2=s"=> \$options{'fastqFiles2'},
"platform=s" => \$options{'platform'},
"bams=s" => \$options{'bams'}, #already mapped -> halfway enter the pipe
"bamID=s" => \$options{'bamID'},
"chrPrefInBam=s" => \$options{'chrPrefInBam'},
"mutectCall=s" => \$options{'mutectCall'}, #already called -> halfway enter the pipe
"qcOFF" => \$options{'qcOFF'},
"keepBedCount" => \$options{'keepBedCount'},
"runID=s" => \$options{'runID'},
"runlevel=s" => \$options{'runlevels'},
"runTask=s" => \$options{'runTask'},
"skipTask=s" => \$options{'skipTask'},
"seqType=s" => \$options{'seqType'},
"noexecute" => \$options{'noexecute'},
"quiet" => \$options{'quiet'},
"maxMem=s" => \$options{'maxMem'},
"javaTmp=s" => \$options{'javaTmp'},
"splitChr" => \$options{'splitChr'},
"readlen=i" => \$options{'readlen'},
"mapper=s" => \$options{'mapper'},
"threads=i" => \$options{'threads'},
"gf=s" => \$options{'gf'},
"root=s" => \$options{'root'},
"readpool=s" => \$options{'readpool'},
"bzip" => \$options{'bzip'},
"Rbinary=s" => \$options{'Rbinary'},
"help|h" => \$options{'help'},
"configure=s" => \$options{'configure'},
"somaticInfo=s"=> \$options{'somaticInfo'},
"germline=s" => \$options{'germline'},
"samCallmaxDepth=i" => \$options{'samCallmaxDepth'},
"indel=s" => \$options{'indel'},
"lorenzScaleFactor=f" => \$options{'lorenzScaleFactor'},
"recheck=s" => \$options{'recheck'},
"recheckBams=s" => \$options{'recheckBams'},
"tmpDir=s" => \$options{'tmpDir'},
"qualTitan=i" => \$options{'qualTitan'},
"vafTitan=f" => \$options{'vafTitan'},
"rareVariants" => \$options{'rareVariants'},
"plpTitan=f" => \$options{'plpTitan'},
"plpeTitan=s" => \$options{'plpeTitan'},
"ncTitan=f" => \$options{'ncTitan'},
"ncmTitan=s" => \$options{'ncmTitan'},
"symmetric=s" => \$options{'symmetric'},
"transtate=f" => \$options{'transtate'},
"tranclone=f" => \$options{'tranclone'},
"nwigString=s" => \$options{'nwigString'},
"homoThred=f" => \$options{'homoThred'},
"ndepthThred=i" => \$options{'ndepthThred'},
"mergeNonsegdup=i" => \$options{'mergeNonsegdup'},
"mergeRare=i" => \$options{'mergeRare'},
"germlineLOH=s"=> \$options{'germlineLOH'},
"maxInsLine=i" => \$options{'maxInsLine'},
"ignoreRG=i" => \$options{'ignoreRG'},
"CfiftyOff=i" => \$options{'CfiftyOff'},
"chrProcess=s" => \$options{'chrProcess'},
"skipPileup=s" => \$options{'skipPileup'},
"samSens=f" => \$options{'samSens'},
"snvPattern=s" => \$options{'snvPattern'},
"indelPattern=s" => \$options{'indelPattern'},
"noStrandBias=s" => \$options{'noStrandBias'}, #treatment of strandbias
"customCalling=s" => \$options{'customCalling'}, #customized calling file
"cmeme=f" => \$options{'cmeme'}, #cmeancmedian
"cmedian=f" => \$options{'cmedian'} #cmedian
);
#print help
helpm() if ($options{'help'});
### Read configuration and set all paths----------------------------------
my %confs;
open IN, "$options{'configure'}";
while ( <IN> ) {
chomp;
next if /^#/;
my @cols = split /\t/;
$confs{$cols[0]} = $cols[1];
}
close IN;
#translate environment variable
foreach my $confele (keys %confs){
while ($confs{$confele} =~ /\$([A-Za-z0-9]+)/g) {
my $eleName = $1;
my $eleTranslate;
if (exists ($confs{$eleName})) {
$eleTranslate = $confs{$eleName};
$confs{$confele} =~ s/\$$eleName/$eleTranslate/;
} else {
die("can't translate eleName: $eleName\n");
}
}
}
print STDERR Dumper (\%confs);
#-------------------------------------------------------------------------
### Frequently used names-------------------------------------------------
my @chrs = split(/\,/, $confs{'chrs'});
#-------------------------------------------------------------------------
#decompression option-----------------------------------------------------
$options{'decompress'} = "gzip -d -c";
$options{'compress'} = "gzip";
$options{'zipSuffix'} = "gz";
if ( $options{'bzip'} ) {
$options{'decompress'} = "bzip2 -d -c";
$options{'compress'} = "bzip2";
$options{'zipSuffix'} = "bz2";
}
#-------------------------------------------------------------------------
### Already specified full path fastq files-------------------------------
if ($options{'fastqFiles1'} ne 'SRP'){
$options{'fastqFiles1'} =~ s/\,/ /g;
}
if ($options{'fastqFiles1'} ne 'SRP'){
$options{'fastqFiles2'} =~ s/\,/ /g;
}
#-------------------------------------------------------------------------
### Runlevel/Task check up------------------------------------------------
if ($options{'runlevels'}) { #true runlevels
foreach my $r (split /\,/,$options{'runlevels'}) {
my $from=1;
my $to=20;
if ($r=~/^(\d+)/) {
$from=$1;
}
if ($r=~/\-(\d+)$/) {
$to=$1;
} elsif ($r!~/\-/) {
$to=$from;
}
for (my $i=$from;$i<=$to;$i++) {
$runlevel{$i}=1;
}
}
}
if ($options{'runTask'}) {
foreach my $task (split(/\,/, $options{'runTask'})) {
$runTask{$task} = '';
}
}
if (! $options{'runlevels'} and ! $options{'runTask'}) {
print STDERR "no runlevel or runTask has been set, exit.\n";
helpm();
}
#-------------------------------------------------------------------------
if ($options{'root'} eq "$RealBin/../PIPELINE") {
if (-e "$RealBin/../PIPELINE") {
print STDERR "no root dir given, analysis will be run under $options{'root'}.\n";
}
else {
print STDERR "no root dir given, $options{'root'} does not exist, please do -h or --help to check how to set root dir.\n";
helpm();
}
} else {
$options{'readpool'} = $options{'root'} if $options{'readpool'} eq 'SRP';
}
#store somatic information------------------------------------------------
my %somatic;
my %germline; #may have multiple tumors
if (-s "$options{'somaticInfo'}") {
open IN, "$options{'somaticInfo'}";
while ( <IN> ) {
chomp;
s/[\s\n]$//;
my @columns = split /\t/;
my $tumor = $columns[0];
my $normal = $columns[1];
$somatic{$tumor} = $normal;
push(@{$germline{$normal}}, $tumor) if $normal ne 'undef';
}
close IN;
#print STDERR Dumper (\%somatic);
#print STDERR Dumper (\%germline);
}
#-------------------------------------------------------------------------
#-----get the chr that need to be processed-------------------------------
if ($options{'chrProcess'} ne 'SRP') {
open IN, "$confs{'chromosomeSize'}";
while ( <IN> ) {
chomp;
my ($chr, $size) = split /\t/;
if ( $chr !~ /^chr/ ) {
$chr = 'chr'.$chr;
}
my $chrWithchr = $options{'chrProcess'};
if ( $chrWithchr !~ /^chr/ ) {
$chrWithchr = 'chr'.$chrWithchr;
}
if ($chr eq $chrWithchr) {
$options{'chrProcessRegion'} = $options{'chrProcess'}.':1-'.$size;
}
}
close IN;
}
print STDERR "chr region that need to be taken care is $options{'chrProcess'}\n";
#-------------------------------------------------------------------------
###
###preparation the lane and read path enviroment
###
if ($options{'lanepath'} eq 'SRP' and $options{'sampleName'} ne 'SRP') {
printtime();
$options{'lanepath'} = "$options{'root'}/$options{'sampleName'}"; #define lane path
print STDERR "####### lane name is set to $options{'sampleName'} #######\n\n";
unless (-e "$options{'lanepath'}") {
my $cmd = "mkdir -p $options{'lanepath'}";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
}
if ($options{'bams'} ne 'SRP') { #bam -> halfway enter pipe
unless (-e "$options{'lanepath'}/02_MAPPING") {
my $cmd = "mkdir -p $options{'lanepath'}/02_MAPPING";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
my $linkBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.br\.rmDup\.md\.bam";
if ( exists($runTask{'remap'}) ) { #need to do remapping
$linkBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.premap\.bam";
}
if ( exists($runTask{'indelRealignment'}) ) {
$linkBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.bam";
}
if ( exists($runTask{'BaseRecalibration'}) ) {
$linkBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.bam";
}
if ( exists($runTask{'MarkDuplicates'}) ) {
$linkBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.br\.bam";
}
if ( exists($runTask{'recalMD'}) ) {
$linkBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.br\.rmDup\.bam";
}
unless (-s "$linkBam") {
my $cmd = "ln -s $options{'bams'} $linkBam";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
unless (-s "$linkBam\.bai" or !-s "$options{'bams'}\.bai") { #if bam bai available and not linked
my $cmd = "ln -s $options{'bams'}\.bai $linkBam\.bai";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$linkBam" and !-s "$linkBam\.bai" and ! exists($runTask{'remap'}) ) { # not indexed before, fix
my $cmd = bwaMapping->bamIndex($confs{'samtoolsBin'}, $options{'threads'}, $linkBam); # index it
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
goto REALSTEPS;
}
if ($options{'mutectCall'} ne 'SRP') { #mutectCall -> halfway enter pipe
unless (-e "$options{'lanepath'}/04_SNV") {
my $cmd = "mkdir -p $options{'lanepath'}/04_SNV";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
my $linkMutect = "$options{'lanepath'}/04_SNV/$options{'sampleName'}\.mutect";
if ($options{'mutectCall'} =~ /\.gz$/) { #gzipped
$linkMutect .= '.gz';
}
unless (-s "$linkMutect") {
my $cmd = "ln -s $options{'mutectCall'} $linkMutect";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
goto REALSTEPS;
}
if ($options{'readpool'} ne 'SRP' and $options{'FASTQ1'} ne 'SRP' and $options{'fastqFiles1'} eq 'SRP') {
printtime();
print STDERR "####### preparing directories #######\n\n";
unless (-e "$options{'lanepath'}/01_READS/") {
my $cmd = "mkdir -p $options{'lanepath'}/01_READS/";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
my @fastqFile1 = split(/\,/, $options{'FASTQ1'});
$options{'fastqFiles1'} =~ s/^SRP//;
foreach my $fastqFile1 (@fastqFile1) {
if ($fastqFile1 !~ /\.[bg]z2?$/){
die "\[error\]: $fastqFile1 must be gzip or bzipped!\n";
}
$fastqFile1 = $options{'readpool'}.'/'.$fastqFile1;
$options{'fastqFiles1'} .= $fastqFile1." ";
}
$options{'fastqFiles1'} =~ s/\s$//;
if ($options{'FASTQ2'} ne 'SRP') {
my @fastqFile2 = split(/\,/, $options{'FASTQ2'});
$options{'fastqFiles2'} =~ s/^SRP//;
foreach my $fastqFile2 (@fastqFile2) {
$fastqFile2 = $options{'readpool'}.'/'.$fastqFile2;
$options{'fastqFiles2'} .= $fastqFile2." ";
}
$options{'fastqFiles2'} =~ s/\s$//;
}
print STDERR "lanefile1:\t$options{'fastqFiles1'}\n";
print STDERR "lanefile2:\t$options{'fastqFiles2'}\n"; #if paired end
}
if ($options{'fastqFiles1'} ne 'SRP') {
printtime();
print STDERR "####### preparing directories #######\n\n";
unless (-e "$options{'lanepath'}/01_READS/") {
my $cmd = "mkdir -p $options{'lanepath'}/01_READS/";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
foreach my $fastqFile1 (split(" ", $options{'fastqFiles1'})) {
my $cmd = "ln -b -s $fastqFile1 $options{'lanepath'}/01_READS/";
my $fastqFile1Basename = basename($fastqFile1);
RunCommand($cmd,$options{'noexecute'},$options{'quiet'}) unless (-s "$options{'lanepath'}/01_READS/$fastqFile1Basename");
}
}
if ($options{'fastqFiles2'} ne 'SRP' and $options{'fastqFiles2'} ne 'interleaved') {
foreach my $fastqFile2 (split(" ", $options{'fastqFiles2'})){
my $cmd = "ln -b -s $fastqFile2 $options{'lanepath'}/01_READS/";
my $fastqFile2Basename = basename($fastqFile2);
RunCommand($cmd,$options{'noexecute'},$options{'quiet'}) unless (-s "$options{'lanepath'}/01_READS/$fastqFile2Basename");
}
}
REALSTEPS:
############################ determine read length if not provided ###################################
if ( $options{'readlen'} == 0 and $options{'sampleName'} ne 'SRP') { #read length not set
if ($options{'fastqFiles1'} ne 'SRP') {
my @fastqFiles1Temp = split(/\s/, $options{'fastqFiles1'});
if ( -s "$fastqFiles1Temp[0]" ) {
my $first_second_line = `$options{'decompress'} "$fastqFiles1Temp[0]" | head -2 | grep -v "^@"`;
$options{'readlen'} = length($first_second_line) - 1;
}
}
if ( $options{'readlen'} == 0 ) { #still zero, check bams
my @bamTmp = bsd_glob("$options{'lanepath'}/02_MAPPING/*.bam");
foreach my $bamTmp (@bamTmp){
if (-s "$bamTmp"){
my $samSix = `samtools view $bamTmp \| awk \-F\"\t\" \'\{print \$6\}\' \| awk \'\$1 \!\~ \/\[IDNHS\\\*\]\/\' \| head \-1000 \| tr \"\\n\" \"\,\"`;
chomp($samSix);
my @matchLen;
foreach my $matchLen (split(/\,/, $samSix)){
$matchLen =~ /^(\d+)M$/;
$matchLen = $1;
push(@matchLen, $matchLen);
}
$options{'readlen'} = median(\@matchLen); #set length to the median of the first 1000 reads with complete matching
}
if ($options{'readlen'} > 0){
last;
}
} #loop each bams to find existing bam
} #check bam
print STDERR "read length is not set, will take the original read length ($options{'readlen'} bp)\n";
}
#######################################################################################################
###
###runlevel1: QC
###
my $runlevels = 1;
if (exists($runlevel{$runlevels}) or exists($runTask{'QC'})) {
printtime();
print STDERR "####### runlevel $runlevels now #######\n\n";
my $qc_out1 = "$options{'lanepath'}/01_READS/mate1.qc"; ######
my $qc_out2;
if ($options{'fastqFiles2'} ne 'SRP' and $options{'fastqFiles2'} ne 'interleaved') {
$qc_out2 = "$options{'lanepath'}/01_READS/mate2.qc";
}
unless ((-e "$qc_out1")) {
my $cmd = "$options{'decompress'} $options{'fastqFiles1'} | $options{'bin'}/fastx_quality_stats -Q33 -o $qc_out1";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'}) unless ($options{'qcOFF'});
}
unless (($options{'fastqFiles2'} eq 'SRP' or $options{'fastqFiles2'} eq 'interleaved') or ($qc_out2 ne '' and -e "$qc_out2")) {
my $cmd = "$options{'decompress'} $options{'fastqFiles2'} | $options{'bin'}/fastx_quality_stats -Q33 -o $qc_out2";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'}) unless ($options{'qcOFF'});
}
printtime();
print STDERR "####### runlevel $runlevels done #######\n\n";
}
###
###runlevel2: do the mapping and generate the statistics
###
$runlevels = 2;
if (exists($runlevel{$runlevels}) or exists($runTask{'mapping'}) or exists($runTask{'indelRealignment'}) or exists($runTask{'BaseRecalibration'}) or exists($runTask{'MarkDuplicates'}) or exists($runTask{'recalMD'})) {
my $premapBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.premap\.bam";
my $rawBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.bam";
my $sortedBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.bam";
#my $irBam = ($options{'chrProcess'} eq 'SRP')? "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.bam" : "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.$options{'chrProcess'}\.bam";
my $irBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.bam";
my $brBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.br\.bam";
my $rmDupBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.br\.rmDup\.bam";
my $finalBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.br\.rmDup\.md\.bam";
printtime();
print STDERR "####### runlevel $runlevels now #######\n\n";
unless (-e "$options{'lanepath'}/02_MAPPING") {
my $cmd = "mkdir -p $options{'lanepath'}/02_MAPPING";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
my @allBams = bsd_glob("$options{'lanepath'}/02_MAPPING/$options{'sampleName'}*\.bam");
if ($#allBams == -1 or exists($runTask{'mapping'}) or exists($runTask{'remap'})) {
my $ReadGroup = '@RG'."\tID:".$options{'bamID'}."\tSM\:".$options{'sampleName'}."\tPL\:".$options{'platform'};
my $cmd;
if (exists($runTask{'remap'}) and -e "$premapBam") {
$cmd = bwaMapping->bwaRemapping($confs{'bwaBin'}, $confs{'samtoolsBin'}, $ReadGroup, $options{'threads'}, $confs{'BWAINDEX'}, $rawBam, $premapBam);
} elsif ($options{'fastqFiles2'} eq 'interleaved') { #need smart paring
$cmd = bwaMapping->bwaSmartMapping($confs{'bwaBin'}, $confs{'samtoolsBin'}, $ReadGroup, $options{'threads'}, $confs{'BWAINDEX'}, $rawBam, $options{'fastqFiles1'});
} elsif ($options{'fastqFiles2'} eq 'SRP') { #single end
$cmd = bwaMapping->bwaSingleMapping($confs{'bwaBin'}, $confs{'samtoolsBin'}, $ReadGroup, $options{'threads'}, $confs{'BWAINDEX'}, $rawBam, $options{'fastqFiles1'});
} else { #paired-end
$cmd = bwaMapping->bwaPairMapping($confs{'bwaBin'}, $confs{'samtoolsBin'}, $ReadGroup, $options{'threads'}, $confs{'BWAINDEX'}, $rawBam, $options{'fastqFiles1'}, $options{'fastqFiles2'});
}
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if ( $options{'seqType'} =~ /xenograft/) { #need to filter out mouse reads
my $xenoStats = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.xenoStats";
my $noMouseBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.noMouse\.bam";
my $cmd = seqStats->xenoStats("$options{'bin'}/Rseq_bam_stats", $rawBam, $noMouseBam, $options{'readlen'}, $xenoStats);
unless (-e "$xenoStats") {
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$noMouseBam" and -s "$rawBam") {
(my $originalBam = $rawBam) =~ s/\.bam/\.original\.bam/;
$cmd = "mv $rawBam $originalBam -f";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = "mv $noMouseBam $rawBam -f";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
}
if ($options{'seqType'} =~ /WGS/ and $options{'seqType'} !~ /ignore/) {
print STDERR "stop for disk space checking\n";
exit 0;
}
unless (-s "$finalBam" and !(exists($runTask{'indelRealignment'}) or exists($runTask{'MarkDuplicates'}) or exists($runTask{'recalMD'}) or exists($runTask{'BaseRecalibration'})) ) { #processing bam
if (-s "$rawBam" and !(-s "$sortedBam")) { #must sort
my $cmd = bwaMapping->bamSort($confs{'samtoolsBin'}, $options{'threads'}, $rawBam."\.tmp", $sortedBam, $rawBam);
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = bwaMapping->bamIndex($confs{'samtoolsBin'}, $options{'threads'}, $sortedBam); #index it
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$rawBam" and -s "$sortedBam") {
my $cmd = "rm $rawBam -f";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if ((-s "$sortedBam" and !(-s "$irBam")) or exists($runTask{'indelRealignment'})) { #indel realignment
if ($options{'skipTask'} !~ /indelRealignment/) {
my $indelTargetList = $sortedBam."\.target_intervals.list";
my $CHR = 'ALL';
#if ( $options{'chrProcess'} ne 'SRP' ) {
# $CHR = $options{'chrProcess'};
# $indelTargetList = $sortedBam."\.$CHR\.target_intervals.list";
#}
if ($options{'splitChr'}) { #if split chr, folk it up, not for hpc clusters, only for workstations, need to be merged later
my $chrBatches = partitionArray(\@chrs, $options{'threads'});
foreach my $chrBatch (@{$chrBatches}) {
my $manager = Parallel::ForkManager->new($options{'threads'});
my $processedChroms = "chromosome ";
foreach my $chrom (@{$chrBatch}) {
$manager->start and next;
$CHR = $chrom;
$indelTargetList =~ s/\.target_intervals.list/\.$CHR\.target_intervals.list/;
$irBam =~ s/\.bam/\.$CHR\.bam/;
my $cmd;
unless (-s "$indelTargetList") {
$cmd = bwaMapping->indelRealignment1($confs{'gatkBin'}, $sortedBam, $confs{'GFASTA'}, $confs{'KNOWNINDEL1'}, $confs{'KNOWNINDEL2'}, $CHR, $indelTargetList, $options{'threads'}, $options{'maxMem'}, $options{'javaTmp'}, $confs{'java'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
$cmd = bwaMapping->indelRealignment2($confs{'gatkBin'}, $sortedBam, $confs{'GFASTA'}, $indelTargetList, $confs{'KNOWNINDEL1'}, $confs{'KNOWNINDEL2'}, $CHR, $irBam, $options{'threads'}, $options{'maxMem'}, $options{'javaTmp'}, $confs{'java'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = bwaMapping->bamIndex($confs{'samtoolsBin'}, $options{'threads'}, $irBam); #index it
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$manager->finish;
$processedChroms .= $chrom.',';
}
$manager->wait_all_children;
print STDERR "$processedChroms have been processed!\n";
}
} else {
my $cmd;
unless (-s "$indelTargetList") {
$cmd = bwaMapping->indelRealignment1($confs{'gatkBin'}, $sortedBam, $confs{'GFASTA'}, $confs{'KNOWNINDEL1'}, $confs{'KNOWNINDEL2'}, $CHR, $indelTargetList, $options{'threads'}, $options{'maxMem'}, $options{'javaTmp'}, $confs{'java'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
if ($options{'skipTask'} =~ /irStep2/) {
print STDERR "indel realign list produced. stop now\n";
exit 0;
}
}
$cmd = bwaMapping->indelRealignment2($confs{'gatkBin'}, $sortedBam, $confs{'GFASTA'}, $indelTargetList, $confs{'KNOWNINDEL1'}, $confs{'KNOWNINDEL2'}, $CHR, $irBam, $options{'threads'}, $options{'maxMem'}, $options{'javaTmp'}, $confs{'java'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = bwaMapping->bamIndex($confs{'samtoolsBin'}, $options{'threads'}, $irBam); #index it
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
} else {
my $cmd = "mv $sortedBam $irBam";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = bwaMapping->bamIndex($confs{'samtoolsBin'}, $options{'threads'}, $irBam); #index it
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
}
#if ($options{'chrProcess'} ne 'SRP') { #for each chromosome
# print STDERR "stop for merging irBams\n";
# exit 0;
#}
if (-s "$sortedBam" and -s "$irBam") {
my $cmd = "rm $sortedBam $sortedBam\.bai -f";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$irBam") { #remove redundant bai
(my $redBai = $irBam.'.bai') =~ s/\.bam\.bai/\.bai/;
if (-s "$redBai") {
my $cmd = "rm $redBai -f";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
}
if ((-s "$irBam" and !(-s "$brBam")) or exists($runTask{'BaseRecalibration'})) { #base recalibration
my $cmd;
if ($options{'skipTask'} !~ /BaseRecalibration/) { #if skipped
my $brTable = $irBam.".baseRecal.table";
unless (-s "$brTable") {
$cmd = bwaMapping->BaseRecalibration($confs{'gatkBin'}, $irBam, $confs{'GFASTA'}, $confs{'muTectDBSNP'}, $confs{'KNOWNINDEL1'}, $confs{'KNOWNINDEL2'}, $brTable, $options{'threads'}, $options{'maxMem'}, $options{'javaTmp'}, $confs{'java'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
$cmd = bwaMapping->BaseRecalibrationPrint($confs{'gatkBin'}, $irBam, $confs{'GFASTA'}, $brTable, $brBam, $options{'threads'}, $options{'maxMem'}, $options{'javaTmp'}, $confs{'java'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
} else {
$cmd = "mv $irBam $brBam";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
$cmd = bwaMapping->bamIndex($confs{'samtoolsBin'}, $options{'threads'}, $brBam); #index it
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$brBam" and (-s "$irBam" or -s "$irBam\.bai")) {
my $cmd = "rm $irBam $irBam\.bai -f";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$brBam") { #remove redundant bai
(my $redBai = $brBam.'.bai') =~ s/\.bam\.bai/\.bai/;
if (-s "$redBai") {
my $cmd = "rm $redBai -f";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
}
if ( exists($runTask{'BaseRecalibrationOnly'}) ) {
exit 0;
}
if ((-s "$brBam" and !(-s "$rmDupBam")) or exists($runTask{'MarkDuplicates'})) { #rmDup
my $rmDupMetric = $brBam.".rmDupMetric";
my $cmd = bwaMapping->MarkDuplicates($confs{'MarkDuplicatesBin'}, $brBam, $rmDupBam, $rmDupMetric, $options{'maxMem'}, $options{'javaTmp'}, $confs{'java'});
if ($options{'skipTask'} =~ /MarkDuplicates/) {
$cmd = "mv $brBam $rmDupBam";
}
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$brBam" and -s "$rmDupBam") {
my $cmd = "rm $brBam $brBam\.bai -f";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if ((-s "$rmDupBam" and !(-s "$finalBam")) or exists($runTask{'recalMD'})) {
if ($options{'skipTask'} !~ /recalMD/) {
my $cmd = bwaMapping->recalMD($confs{'samtoolsBin'}, $rmDupBam, $confs{'GFASTA'}, $finalBam, $options{'threads'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = bwaMapping->bamIndex($confs{'samtoolsBin'}, $options{'threads'}, $finalBam); #index it
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
} else {
my $cmd = "mv $rmDupBam $finalBam";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = bwaMapping->bamIndex($confs{'samtoolsBin'}, $options{'threads'}, $finalBam); #index it
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
}
if (-s "$rmDupBam" and -s "$finalBam") {
my $cmd = "rm $rmDupBam $rmDupBam\.bai -f";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
}
if (-s "$finalBam" and !-s "$finalBam\.bai") {
my $cmd = bwaMapping->bamIndex($confs{'samtoolsBin'}, $options{'threads'}, $finalBam); #index it
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
printtime();
print STDERR "####### runlevel $runlevels done #######\n\n";
}
###
###runlevel3: STATS
###
$runlevels = 3;
if (exists $runlevel{$runlevels}) {
unless (-e "$options{'lanepath'}/03_STATS") {
my $cmd = "mkdir -p $options{'lanepath'}/03_STATS";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
#basic read counting stats:
my $mappingStats = "$options{'lanepath'}/03_STATS/$options{'sampleName'}\.mapping.stats";
my $finalBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.br\.rmDup\.md\.bam";
my $statBam = ($options{'recheckBams'} eq "SRP")? $finalBam : $options{'recheckBams'};
if ( ! -e "$finalBam" ) {
$finalBam = $statBam;
}
unless (-s "$mappingStats") {
#my $cmd = seqStats->mappingStats("$options{'bin'}/Rseq_bam_stats", $statBam, $options{'readlen'}, $mappingStats);
my $cmd = seqStats->mappingStats($confs{'samtoolsBin'}, $statBam, $options{'readlen'}, $mappingStats);
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
#loren curve
my $bedCover = "$options{'lanepath'}/03_STATS/$options{'sampleName'}\.bedcoverNoDup";
my $lorenzCover = "$options{'lanepath'}/03_STATS/$options{'sampleName'}\.lorenzNoDup";
unless (-s "$lorenzCover") {
unless (-s "$bedCover") {
my $cmd = seqStats->grepStarts("$options{'bin'}/grep_starts", $confs{'targetRegion'}, $statBam, $bedCover, $options{'chrPrefInBam'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
my $cmd = seqStats->getLorenz("$options{'bin'}/lorenzCurveNGS.pl", $bedCover, $lorenzCover, $options{'lorenzScaleFactor'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$bedCover" and -s "$lorenzCover") {
my $cmd = "rm $bedCover -f";
#RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
#for titanCNA
my $bedCount = "$options{'lanepath'}/03_STATS/$options{'sampleName'}\.w1k.count";
my $wigOut = "$options{'lanepath'}/03_STATS/$options{'sampleName'}\.wig";
unless (-s "$wigOut") {
unless (-s "$bedCount") {
my $cmd = seqStats->grepStarts("$options{'bin'}/grep_starts", $confs{'w1kBed'}, $finalBam, $bedCount, $options{'chrPrefInBam'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
my $cmd = seqStats->bed2wig("$options{'bin'}/bed2wig.pl", $bedCount, $wigOut);
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$bedCount" and -s "$wigOut") {
my $cmd = "rm $bedCount -f";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'}) unless ($options{'keepBedCount'});
}
#for insert size
if ($options{'seqType'} =~ /paired/) { #do the insert size only if it is paired-end
unless (-s "$options{'lanepath'}/03_STATS/$options{'sampleName'}\.ins\.gz") {
unless (-s "$options{'lanepath'}/03_STATS/$options{'sampleName'}\.ins") {
my $insertBam = $finalBam;
if ( $finalBam !~ /\.bam$/ ) { #likely a file of file names
$insertBam = `head -1 $finalBam`;
$insertBam =~ s/[\s\n]//;
}
my $cmd = seqStats->insertSize($confs{'samtoolsBin'}, $insertBam, "$options{'lanepath'}/03_STATS/$options{'sampleName'}\.ins", $options{'maxInsLine'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$options{'lanepath'}/03_STATS/$options{'sampleName'}\.ins") {
my $cmd = "gzip $options{'lanepath'}/03_STATS/$options{'sampleName'}\.ins";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
}
unless (-s "$options{'lanepath'}/03_STATS/$options{'sampleName'}\.insertSize\.pdf") {
my $cmd = seqStats->plotInsertSize($confs{'RscriptBin'}, "$options{'bin'}/insertSize.R", "$options{'lanepath'}/03_STATS/", $options{'sampleName'},
"$options{'lanepath'}/03_STATS/$options{'sampleName'}\.ins\.gz", "$options{'lanepath'}/03_STATS/$options{'sampleName'}\.insertSize\.pdf");
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
} #insert size
printtime();
print STDERR "####### runlevel $runlevels now #######\n\n";
printtime();
print STDERR "####### runlevel $runlevels done #######\n\n";
}
###
###runlevel4: SNV calling
###
$runlevels = 4;
if (exists($runlevel{$runlevels}) or exists($runTask{'recheck'}) or exists($runTask{'annovar'}) or exists($runTask{'mergeCustomCallingChr'})) {
unless (-e "$options{'lanepath'}/04_SNV") {
my $cmd = "mkdir -p $options{'lanepath'}/04_SNV";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
printtime();
print STDERR "####### runlevel $runlevels now #######\n\n";
#my $finalBam = ($options{'splitChr'})?"$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.$chrs[0]\.rmDup\.bam":"$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.rmDup\.bam";
my $finalBam = "$options{'lanepath'}/02_MAPPING/$options{'sampleName'}\.sorted\.ir\.br\.rmDup\.md\.bam";
my $normalBam;
if (!exists($runlevel{$runlevels}) and exists($runTask{'recheck'})) {
goto RECHECK;
}
if (!exists($runlevel{$runlevels}) and exists($runTask{'annovar'})) {
goto ANNOVAR;
}
if (!exists($runlevel{$runlevels}) and exists($runTask{'mergeCustomCallingChr'})) {
goto MERGECUSTOM;
}
if ($options{'somaticInfo'} eq "SRP"){
print STDERR "ERROR: somaticInfo is not provided! Must set for somatic calling!\n";
exit 22;
} elsif ( !exists( $somatic{$options{'sampleName'}} ) ) {
print STDERR "ERROR: $options{'sampleName'} is not in the somatic hash table!\n";
} else { #get normal bam
my $normalSampleName = $somatic{$options{'sampleName'}};
if ($options{'samplePairNames'} eq 'redefine') {
$options{'samplePairNames'} = $options{'sampleName'}.','.$normalSampleName; #redefine sample pair name, default SRP not redefine
print STDERR "samplePairNames: $options{'samplePairNames'}\n";
}
$normalBam = "$options{'root'}/$normalSampleName/02_MAPPING/$normalSampleName\.sorted\.ir\.br\.rmDup\.md\.bam";
unless (-s "$normalBam") {
print STDERR "ERROR (warning): $normalBam is not found, please run mapping and processing for $normalSampleName!!\n";
exit 22;
}
}
if ($options{'germline'} =~ /samtoolsOnly/) {
goto GERMLINE;
}
if ($options{'indel'} =~ /strelkaOnly/) {
goto INDEL;
}
my $muTectOut = ($options{'chrProcess'} eq 'SRP')? "$options{'lanepath'}/04_SNV/$options{'sampleName'}\.mutect" : "$options{'lanepath'}/04_SNV/$options{'sampleName'}\.$options{'chrProcess'}\.mutect";
my $vcfOutTmp = $muTectOut.'.vcf';
my $vcfOut = $muTectOut.'.genome.vcf';
my $vcfOutSorted = $muTectOut.'.genome.sorted.vcf';
my $vcfMultiAnno = $vcfOutSorted."\.$confs{'species'}_multianno.txt";
my $vcfMultiAnnoVCF = $vcfOutSorted."\.$confs{'species'}_multianno.vcf";
my $vcfMultiAnnoMod = $vcfOutSorted."\.$confs{'species'}_multianno.mod.vcf";
if (exists($runTask{'mergeMutectChr'})) {
goto MERGE;
}
unless ((-s "$muTectOut" or -s "$muTectOut\.gz") or !exists( $somatic{$options{'sampleName'}} ) ) {
my $cmd = snvCalling->muTectCalling($confs{'muTectBin'}, $finalBam, $normalBam, $confs{'GFASTA'}, $confs{'muTectCOSMIC'}, $confs{'muTectDBSNP'}, $muTectOut, $vcfOutTmp, $options{'chrProcessRegion'}, $options{'maxMem'}, $options{'javaTmp'}, $confs{'java'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
#annoVar annotate---------------------------------------------------------------------
if ((-s "$muTectOut" or -s "$muTectOut\.gz") and !-s "$vcfMultiAnnoMod" and exists( $somatic{$options{'sampleName'}} ) ) {
my $cmd = snvCalling->muTect2vcf("$options{'bin'}/mutect2vcf.pl", $muTectOut, $vcfOut, $options{'samplePairNames'}); #convert mutect 2 vcf
if (-s "$muTectOut\.gz") {
$cmd = snvCalling->muTect2vcf("$options{'bin'}/mutect2vcf.pl", $muTectOut.".gz", $vcfOut, $options{'samplePairNames'});
}
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = snvCalling->vcfSort($confs{'vcfSortBin'}, $vcfOut, $vcfOutSorted); #sort vcf
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = snvCalling->runAnnovar("$confs{'ANNOVARDIR'}/table_annovar.pl", $vcfOutSorted, $confs{'ANNOVARDB'}, $confs{'species'}); #table annovar
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = snvCalling->convertVCFannovar("$options{'bin'}/convert_annovar_vcf.pl", $vcfMultiAnno, $vcfMultiAnnoVCF);
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
#rm temporary files
if (-s "$vcfMultiAnnoMod" and -s "$vcfOutTmp") {
my $cmd = "rm -rf $vcfOutTmp $vcfOutTmp\.idx";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$vcfMultiAnnoMod" and -s "$vcfOut") {
my $cmd = "rm -rf $vcfOut";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$vcfMultiAnnoMod" and -s "$vcfOutSorted\.avinput") {
my $cmd = "rm -rf $vcfOutSorted\.avinput";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$vcfMultiAnnoMod" and -s "$vcfOutSorted\.invalid_input") {
my $cmd = "rm -rf $vcfOutSorted\.invalid_input";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$vcfMultiAnnoMod" and -s "$vcfOutSorted\.refGene.invalid_input") {
my $cmd = "rm -rf $vcfOutSorted\.refGene.invalid_input";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
if (-s "$vcfMultiAnnoMod" and -s "$vcfMultiAnno") {
my $cmd = "rm -rf $vcfMultiAnno $vcfMultiAnnoVCF";
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
#------------------------------------------------------------------------------------
GERMLINE:
if ($options{'germline'} =~ /samtools/) {
my $vcfOut = ($options{'chrProcess'} eq 'SRP')? "$options{'lanepath'}/04_SNV/$options{'sampleName'}\.samtools.genome.vcf" : "$options{'lanepath'}/04_SNV/$options{'sampleName'}\.$options{'chrProcess'}\.samtools.genome.vcf";
(my $vcfOutSorted = $vcfOut) =~ s/\.vcf$/.sorted.vcf/;
my $vcfMultiAnno = $vcfOutSorted."\.$confs{'species'}_multianno.txt";
my $vcfMultiAnnoVCF = $vcfOutSorted."\.$confs{'species'}_multianno.vcf";
my $vcfMultiAnnoMod = $vcfOutSorted."\.$confs{'species'}_multianno.mod.vcf";
my $vcfMultiAnnoModsnv = $vcfOutSorted."\.$confs{'species'}_multianno.mod.vcf.snv";
my $vcfMultiAnnoModindel = $vcfOutSorted."\.$confs{'species'}_multianno.mod.vcf.indel";
if (exists($runTask{'mergeSamtoolsChr'})) {
goto MERGESAMTOOLS;
}
unless (-s "$vcfOut" or -s "$vcfOutSorted" or -s "$vcfMultiAnnoMod" or -s "$vcfMultiAnnoModsnv") {
my $cmd = snvCalling->samtoolsCalling($confs{'samtoolsBin'}, $confs{'bcftoolsBin'}, $finalBam, $normalBam, $confs{'GFASTA'}, $vcfOut, $options{'samCallmaxDepth'}, $options{'ignoreRG'}, $options{'chrProcessRegion'}, $options{'samSens'}, $options{'CfiftyOff'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
#annoVar annotate---------------------------------------------------------------------
if ((-s "$vcfOut" or -s "$vcfMultiAnnoMod") and !-s "$vcfMultiAnnoModsnv") {
unless (-s "$vcfMultiAnnoMod") {
my $cmd = snvCalling->vcfSort($confs{'vcfSortBin'}, $vcfOut, $vcfOutSorted); #sort vcf
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = snvCalling->runAnnovar("$confs{'ANNOVARDIR'}/table_annovar.pl", $vcfOutSorted, $confs{'ANNOVARDB'}, $confs{'species'}); #table annovar
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = snvCalling->convertVCFannovar("$options{'bin'}/convert_annovar_vcf.pl", $vcfMultiAnno, $vcfMultiAnnoVCF);
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
}
my $cmd = snvCalling->grepSNVvcf($vcfMultiAnnoMod, $vcfMultiAnnoModsnv, $options{'snvPattern'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});
$cmd = snvCalling->grepINDELvcf($vcfMultiAnnoMod, $vcfMultiAnnoModindel, $options{'indelPattern'});
RunCommand($cmd,$options{'noexecute'},$options{'quiet'});