-
Notifications
You must be signed in to change notification settings - Fork 18
/
process_alignments_human.pl
executable file
·2001 lines (1763 loc) · 126 KB
/
process_alignments_human.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
use strict;
use Getopt::Long qw(GetOptions);
use FindBin qw($Bin);
use lib "$Bin/lib";
use Schedule;
use Cluster;
use File::Basename;
use POSIX qw(strftime);
my $cur_date = strftime "%Y%m%d", localtime;
my ($patient, $email, $impact, $wes, $svnRev, $pair, $group, $bamgroup, $config, $nosnps, $targets, $ug, $scheduler, $priority_project, $priority_group, $abra, $indelrealigner, $noindelrealign, $help, $step1, $allSomatic, $scalpel, $somaticsniper, $strelka, $varscan, $virmid, $lancet, $vardict, $pindel, $abra_target, $rna, $mutect2, $manta, $nofacets);
my $pre = 'TEMP';
my $output = "results";
my $species = 'b37';
my $uID = `/usr/bin/id -u -n`;
chomp $uID;
my $rsync = "/juno/res/bic/$uID";
my $tempdir = "/scratch/$uID";
GetOptions ('email=s' => \$email,
'pre=s' => \$pre,
'pair=s' => \$pair,
'patient=s' => \$patient,
'group=s' => \$group,
'config=s' => \$config,
'targets=s' => \$targets,
'species=s' => \$species,
'nosnps' => \$nosnps,
'ug|unifiedgenotyper' => \$ug,
'abra' => \$abra,
'impact' => \$impact,
'wes' => \$wes,
'indelrealigner' => \$indelrealigner,
'step1' => \$step1,
'bamgroup=s' => \$bamgroup,
'scheduler=s' => \$scheduler,
'svnRev=s' => \$svnRev,
'priority_project=s' => \$priority_project,
'priority_group=s' => \$priority_group,
'help' => \$help,
'rsync=s' => \$rsync,
'allsomatic|allSomatic|all_somatic' => \$allSomatic,
'scalpel' => \$scalpel,
'somaticsniper' => \$somaticsniper,
'strelka' => \$strelka,
'varscan' => \$varscan,
'virmid' => \$virmid,
'lancet' => \$lancet,
'vardict' => \$vardict,
'pindel' => \$pindel,
'tempdir=s' => \$tempdir,
'output|out|o=s' => \$output,
'abratarget|abra_target=s' => \$abra_target,
'rna=s' => \$rna,
'mutect2' => \$mutect2,
'manta' => \$manta,
'noindelrealign|noir' => \$noindelrealign,
'nofacets' => \$nofacets) or exit(1);
if(!$group || !$config || !$scheduler || !$targets || !$bamgroup || $help){
print <<HELP;
USAGE: process_alignments_human.pl -group GROUP -bampgroup BAMBROUP -config CONFIG -scheduler SCHEDULER -targets TARGETS
* GROUP: file listing grouping of samples for realign/recal steps (REQUIRED)
* BAMGROUP: files listing bams to be processed together; every bam for each group on 1 line, comma-separated (required)
* SPECIES: b37, human_hybrid|xenograft (b37_mm10)
* TARGETS: name of targets assay; will search for targets/baits ilists and targets padded file in $Bin/targets/TARGETS unless given full path to targets directory (REQUIRED)
* CONFIG: file listing paths to programs needed for pipeline; full path to config file needed (REQUIRED)
* SCHEDULER: currently support for SGE, LUNA, and JUNO (REQUIRED)
* PAIR: file listing tumor/normal pairing of samples for mutect/maf conversion; if not specified, considered unpaired
* PRE: output prefix (default: TEMP)
* OUTPUT: output results directory (default: results)
* RSYNC: path to rsync data for archive (default: /juno/res/bic/USER_ID)
* PRIORITY_PROJECT: sge notion of priority assigned to projects (default: ngs)
* PRIORITY_GROUP: lsf notion of priority assigned to groups (default: Pipeline)
* -nosnps: if no snps to be called; e.g. when only indelrealigned/recalibrated bams needed
* -abra: run abra to realign indels (default)
* -indelrealigner: run GATK indelrealigner (abra runs as default)
* -noindelrealign: skip indel realignment
* -nofacets: skip facets
* -step1: forece the pipeline to start from the first step in pipeline
* haplotypecaller is default; -ug || -unifiedgenotyper to also make unifiedgenotyper variant calls
* TEMPDIR: temp directory (default: /scratch/$uID)
* ALLSOMATIC: run all somatic callers; mutect/haplotypecaller always run; otherwise -scalpel, -somaticsniper, -strelka, -varscan, -virmid, -lancet, -vardict, -pindel, -mutect2, -manta to run them individually
HELP
exit;
}
if(!-d "$rsync"){
die "Can't rsync to $rsync. Please pick a differnt location using the rsync parameter $!";
}
my $curDir = `pwd`;
chomp $curDir;
if($output !~ /^\//){
$output = "$curDir/$output";
}
if($pre =~ /^\d+/){
$pre = "s_$pre";
}
if($wes && $impact){
die "Cannot run as both a wes and an impact. Please select -wes OR -impact";
}elsif(!$wes && !$impact){
die "Must specify to run the project as either -wes or -impact";
}
if($abra && $indelrealigner){
die "Cannot run both abra and gatk indelrealigner $!";
}
if(($abra || $indelrealigner) && $noindelrealign)
{
die "Cannot skip indel realignment when -abra or -indelrealigner is specified $!";
}
if(!$abra && !$indelrealigner && !$noindelrealign){
$abra = 1;
}
if($allSomatic){
$scalpel = 1;
$somaticsniper = 1;
$strelka = 1;
$varscan = 1;
$virmid = 1;
$lancet = 1;
$vardict = 1;
$pindel = 1;
$mutect2 = 1;
$manta = 1;
}
my $ABRA = '';
my $BCFTOOLS= '';
my $BEDTOOLS = '';
my $GATK = '';
my $GATK4 = '';
my $HTSTOOLS = '';
my $FACETS_SUITE = '';
my $LANCET = '';
my $MANTA = '';
my $MUTECT = '';
my $PICARD = '';
my $PINDEL = '';
my $SAMTOOLS = '';
my $SCALPEL = '';
my $SOMATIC_SNIPER = '';
my $STRELKA = '';
my $TABIX = '';
my $VARDICT_JAVA = '';
my $VARDICT_PERL = '';
my $VARSCAN = '';
my $VEP = '';
my $VIRMID = '';
my $JAVA = '';
my $JAVA7_MUTECT = '';
my $PYTHON = '';
my $PERL = '';
my $R_FACETS = '';
my $SINGULARITY = '';
my $singularityParams = '';
my $singularityBind = '';
my $singularityenv_prepend_path = "";
my $B37_FASTA = '';
my $B37_FAI = '';
my $B37_MM10_HYBRID_FASTA = '';
my $B37_MM10_HYBRID_FAI = '';
my $B37_BWA_INDEX = '';
my $B37_MM10_HYBRID_BWA_INDEX = '';
my $HG19_FASTA = '';
my $HG19_FAI = '';
my $HG19_MM10_HYBRID_FASTA = '';
my $HG19_MM10_HYBRID_FAI = '';
my $HG19_BWA_INDEX = '';
my $HG19_MM10_HYBRID_BWA_INDEX = '';
open(CONFIG, "$config") or die "CAN'T OPEN CONFIG FILE $config $!";
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] =~ /abra/i){
if(!-e "$conf[1]/abra.jar"){
die "CAN'T FIND GenomeAnalysisTK.jar IN $conf[1] $!";
}
$ABRA = $conf[1];
}
elsif($conf[0] =~ /bcftools/i){
if(!-e "$conf[1]/bcftools"){
die "CAN'T FIND bcftools IN $conf[1] $!";
}
$BCFTOOLS = $conf[1];
}
elsif($conf[0] =~ /bedtools/i){
if(!-e "$conf[1]/bedtools"){
die "CAN'T FIND bedtools IN $conf[1] $!";
}
$BEDTOOLS = $conf[1];
}
elsif($conf[0] =~ /facets_suite/i){
if(!-e "$conf[1]/snp-pileup-wrapper.R" || !-e "$conf[1]/run-facets-wrapper.R" || !-e "$conf[1]/annotate-maf-wrapper.R"){
die "CAN'T FIND facets_suite IN $conf[1] $!";
}
$FACETS_SUITE = $conf[1];
}
elsif($conf[0] =~ /^gatk$/i){
if(!-e "$conf[1]/GenomeAnalysisTK.jar"){
die "CAN'T FIND GenomeAnalysisTK.jar IN $conf[1] $!";
}
$GATK = $conf[1];
}
elsif($conf[0] =~ /^gatk4$/i){
if(!-e "$conf[1]/gatk"){
# die "CAN'T gatk IN $conf[1] $!";
}
$GATK4 = $conf[1];
}
elsif($conf[0] =~ /htstools/i){
if(!-e "$conf[1]/snp-pileup"){
die "CAN'T FIND htstools IN $conf[1] $!";
}
$HTSTOOLS = $conf[1];
}
elsif($conf[0] =~ /lancet/i){
if(!-e "$conf[1]/lancet"){
die "CAN'T FIND lancet IN $conf[1] $!";
}
$LANCET = $conf[1];
}
elsif($conf[0] =~ /manta/i){
if(!-e "$conf[1]/configManta.py"){
die "CAN'T FIND configManta.py IN $conf[1] $!";
}
$MANTA = $conf[1];
}
elsif($conf[0] =~ /^mutect$/i){
if(!-e "$conf[1]/muTect.jar"){
die "CAN'T FIND muTect.jar IN $conf[1] $!";
}
$MUTECT = $conf[1];
}
elsif($conf[0] =~ /picard/i){
if(!-e "$conf[1]/picard.jar"){
die "CAN'T FIND picard.jar IN $conf[1] $!";
}
$PICARD = $conf[1];
}
elsif($conf[0] =~ /pindel/i){
if(!-e "$conf[1]/pindel" or !-e "$conf[1]/pindel2vcf"){
die "CAN'T FIND pindel or pindel2vcf IN $conf[1] $!";
}
$PINDEL = $conf[1];
}
elsif($conf[0] =~ /samtools/i){
if(!-e "$conf[1]/samtools"){
die "CAN'T FIND samtools IN $conf[1] $!";
}
$SAMTOOLS = $conf[1];
}
elsif($conf[0] =~ /scalpel/i){
if(!-e "$conf[1]/scalpel"){
die "CAN'T FIND scalpel IN $conf[1] $!";
}
$SCALPEL = $conf[1];
}
elsif($conf[0] =~ /somaticsniper/i){
if(!-e "$conf[1]/bam-somaticsniper"){
die "CAN'T FIND bam-somaticsniper IN $conf[1] $!";
}
$SOMATIC_SNIPER = $conf[1];
}
elsif($conf[0] =~ /strelka/i){
if(!-e "$conf[1]/bin/configureStrelkaWorkflow.pl"){
die "CAN'T FIND bin/configureStrelkaWorkflow.pl IN $conf[1] $!";
}
$STRELKA = $conf[1];
}
elsif($conf[0] =~ /tabix/i){
if(!-e "$conf[1]/bgzip"){
die "CAN'T FIND tabix IN $conf[1] $!";
}
$TABIX = $conf[1];
}
elsif($conf[0] =~ /vardict_java/i){
if(!-e "$conf[1]/VarDict"){
die "CAN'T FIND VarDict IN $conf[1] $!";
}
$VARDICT_JAVA = $conf[1];
}
elsif($conf[0] =~ /vardict_perl/i){
if(!-e "$conf[1]/testsomatic.R" || !-e "$conf[1]/var2vcf_paired.pl"){
die "CAN'T FIND testsomatic.R OR var2vcf_paired.pl IN $conf[1] $!";
}
$VARDICT_PERL = $conf[1];
}
elsif($conf[0] =~ /varscan/i){
if(!-e "$conf[1]/VarScan.jar"){
die "CAN'T FIND VarScan.jar IN $conf[1] $!";
}
$VARSCAN = $conf[1];
}
elsif($conf[0] =~ /^vep/i){
if(!-e "$conf[1]/vep"){
die "CAN'T FIND VEP IN $conf[1] $!";
}
$VEP = $conf[1];
}
elsif($conf[0] =~ /virmid/i){
if(!-e "$conf[1]/Virmid.jar"){
die "CAN'T FIND Virmid.jar IN $conf[1] $!";
}
$VIRMID = $conf[1];
}
elsif($conf[0] =~ /^java$/i){
if(!-e "$conf[1]/java"){
die "CAN'T FIND java IN $conf[1] $!";
}
$JAVA = $conf[1];
my $path_tmp = $ENV{'PATH'};
$ENV{'JAVA_HOME'} = "";
$ENV{'JAVA_JRE'} = "";
$ENV{'JAVA_LD_LIBRARY_PATH'} = "";
$ENV{'JAVA_LIBS'} = "";
$singularityenv_prepend_path .= ":$conf[1]";
}
elsif($conf[0] =~ /^java7_mutect$/i){
if(!-e "$conf[1]/java"){
die "CAN'T FIND java IN $conf[1] $!";
}
$JAVA7_MUTECT = $conf[1];
}
elsif($conf[0] =~ /^perl$/i){
if(!-e "$conf[1]/perl"){
die "CAN'T FIND perl IN $conf[1] $!";
}
$PERL = $conf[1];
my $path_tmp = $ENV{'PATH'};
$ENV{'PATH'} = "$conf[1]:$path_tmp";
$singularityenv_prepend_path .= ":$conf[1]";
}
elsif($conf[0] =~ /python/i){
if(!-e "$conf[1]/python"){
die "CAN'T FIND python IN $conf[1] $!";
}
$PYTHON = $conf[1];
my $path_tmp = $ENV{'PATH'};
$ENV{'PATH'} = "$conf[1]:$path_tmp";
$singularityenv_prepend_path .= ":$conf[1]";
}
elsif($conf[0] =~ /^r$/i){
if(!-e "$conf[1]/R"){
die "CAN'T FIND R IN $conf[1] $!";
}
my $path_tmp = $ENV{'PATH'};
$ENV{'PATH'} = "$conf[1]:$path_tmp";
$singularityenv_prepend_path .= ":$conf[1]";
}
elsif($conf[0] =~ /^r_facets$/i){
if(!-e "$conf[1]/Rscript"){
die "CAN'T FIND Rscript IN $conf[1] $!";
}
$R_FACETS = $conf[1];
}
elsif($conf[0] =~ /b37_fasta/i){
if(!-e "$conf[1]"){
if($species =~ /^human$|^b37$/i){
die "CAN'T FIND $conf[1] $!";
}
}
$B37_FASTA = $conf[1];
}
elsif($conf[0] =~ /b37_fai/i){
if(!-e "$conf[1]"){
if($species =~ /^human$|^b37$/i){
die "CAN'T FIND $conf[1] $!";
}
}
$B37_FAI = $conf[1];
}
elsif($conf[0] =~ /b37_mm10_hybrid_fasta/i){
if(!-e "$conf[1]"){
if($species =~ /human_hybrid|b37_hybrid|b37_mm10/i){
die "CAN'T FIND $conf[1] $!";
}
}
$B37_MM10_HYBRID_FASTA = $conf[1];
}
elsif($conf[0] =~ /b37_mm10_hybrid_fai/i){
if(!-e "$conf[1]"){
if($species =~ /human_hybrid|b37_hybrid|b37_mm10/i){
die "CAN'T FIND $conf[1] $!";
}
}
$B37_MM10_HYBRID_FAI = $conf[1];
}
elsif($conf[0] =~ /b37_bwa_index/i){
if(!-e "$conf[1]\.bwt" || !-e "$conf[1]\.pac" || !-e "$conf[1]\.ann" || !-e "$conf[1]\.amb" || !-e "$conf[1]\.sa"){
if($species =~ /^b37$/i){
die "CAN'T FIND ALL NECESSARY BWA INDEX FILES FOR B37 WITH PREFIX $conf[1] $!";
}
}
$B37_BWA_INDEX = $conf[1];
}
elsif($conf[0] =~ /b37_mm10_hybrid_bwa_index/i){
if(!-e "$conf[1]\.bwt" || !-e "$conf[1]\.pac" || !-e "$conf[1]\.ann" || !-e "$conf[1]\.amb" || !-e "$conf[1]\.sa"){
if($species =~ /human_hybrid|b37_hybrid|b37_mm10/i){
die "CAN'T FIND ALL NECESSARY BWA INDEX FILES FOR b37-MM10 HYBRID WITH PREFIX $conf[1] $!";
}
}
$B37_MM10_HYBRID_BWA_INDEX = $conf[1];
}
elsif($conf[0] =~ /hg19_fasta/i){
if(!-e "$conf[1]"){
if($species =~ /^hg19$/i){
die "CAN'T FIND $conf[1] $!";
}
}
$HG19_FASTA = $conf[1];
}
elsif($conf[0] =~ /hg19_fai/i){
if(!-e "$conf[1]"){
if($species =~ /^hg19$/i){
die "CAN'T FIND $conf[1] $!";
}
}
$HG19_FAI = $conf[1];
}
elsif($conf[0] =~ /hg19_bwa_index/i){
if(!-e "$conf[1]\.bwt" || !-e "$conf[1]\.pac" || !-e "$conf[1]\.ann" || !-e "$conf[1]\.amb" || !-e "$conf[1]\.sa"){
if($species =~ /hg19/i){
die "CAN'T FIND ALL NECESSARY BWA INDEX FILES FOR HG19 WITH PREFIX $conf[1] $!";
}
}
$HG19_BWA_INDEX = $conf[1];
}
elsif($conf[0] =~ /hg19_mm10_hybrid_fasta/i){
if(!-e "$conf[1]"){
if($species =~ /hg19_hybrid|hg19_mm10/i){
die "CAN'T FIND $conf[1] $!";
}
}
$HG19_MM10_HYBRID_FASTA = $conf[1];
}
elsif($conf[0] =~ /hg19_mm10_hybrid_fai/i){
if(!-e "$conf[1]"){
if($species =~ /hg19_hybrid|hg19_mm10/i){
die "CAN'T FIND $conf[1] $!";
}
}
$HG19_MM10_HYBRID_FAI = $conf[1];
}
elsif($conf[0] =~ /hg19_mm10_hybrid_bwa_index/i){
if(!-e "$conf[1]\.bwt" || !-e "$conf[1]\.pac" || !-e "$conf[1]\.ann" || !-e "$conf[1]\.amb" || !-e "$conf[1]\.sa"){
if($species =~ /hg19_hybrid|hg19_mm10/i){
die "CAN'T FIND ALL NECESSARY BWA INDEX FILES FOR HG19-MM9 HYBRID WITH PREFIX $conf[1] $!";
}
}
$HG19_MM10_HYBRID_BWA_INDEX = $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;
close CONFIG;
my $REF_SEQ = '';
my $REF_FAI = '';
my $BWA_INDEX = '';
my $DB_SNP = "";
my $FACETS_DB_SNP = "";
my $MILLS_1000G = '';
my $HAPMAP = '';
my $OMNI_1000G = '';
my $PHASE1_SNPS_1000G = '';
my $COSMIC = '';
my $COSMIC_HOTSPOTS = '';
if($species =~ /^b37$|human/i){
$DB_SNP = "$Bin/data/b37/dbsnp_138.b37.excluding_sites_after_129.vcf";
$FACETS_DB_SNP = "$Bin/data/b37/dbsnp_137.b37__RmDupsClean__plusPseudo50__DROP_SORT.vcf";
$MILLS_1000G = "$Bin/data/b37/Mills_and_1000G_gold_standard.indels.b37.vcf";
$HAPMAP = "$Bin/data/b37/hapmap_3.3.b37.vcf";
$OMNI_1000G = "$Bin/data/b37/1000G_omni2.5.b37.vcf";
$PHASE1_SNPS_1000G = "$Bin/data/b37/1000G_phase1.snps.high_confidence.b37.vcf";
$COSMIC = "$Bin/data/b37/CosmicCodingMuts_v67_b37_20131024__NDS.vcf";
$COSMIC_HOTSPOTS = "$Bin/data/b37/dmp_cosmic_for_hotspots.vcf";
if($species =~ /human_hybrid|xenograft|b37_mm10/i){
$species = "human_hybrid";
$REF_SEQ = "$B37_MM10_HYBRID_FASTA";
$REF_FAI = "$B37_MM10_HYBRID_FAI";
$BWA_INDEX = "$B37_MM10_HYBRID_BWA_INDEX";
} else {
$species = "b37";
$REF_SEQ = "$B37_FASTA";
$REF_FAI = "$B37_FAI";
$BWA_INDEX = "$B37_BWA_INDEX";
}
}
elsif($species =~ /^hg19$/i){
#die "hg19 is no longer supported in the variants pipeline";
$REF_SEQ = "$HG19_FASTA";
$REF_FAI = "$HG19_FAI";
$BWA_INDEX = "$HG19_BWA_INDEX";
$DB_SNP = "$Bin/data/hg19/dbsnp_138.hg19.excluding_sites_after_129.vcf";
$FACETS_DB_SNP = "$Bin/data/hg19/dbsnp_137.hg19__RmDupsClean__plusPseudo50__DROP_SORT.vcf";
$MILLS_1000G = "$Bin/data/hg19/Mills_and_1000G_gold_standard.indels.hg19.vcf";
$HAPMAP = "$Bin/data/hg19/hapmap_3.3.hg19.vcf";
$OMNI_1000G = "$Bin/data/hg19/1000G_omni2.5.hg19.vcf";
$PHASE1_SNPS_1000G = "$Bin/data/hg19/1000G_phase1.snps.high_confidence.hg19.vcf";
$COSMIC = "$Bin/data/hg19/CosmicCodingMuts_v67_20131024.vcf";
$COSMIC_HOTSPOTS = "$Bin/data/b37/dmp_cosmic_for_hotspots.vcf";
}
elsif($species =~ /hg19_mm10/i){
die "hg19 is no longer supported in the variants pipeline";
$REF_SEQ = "$HG19_MM10_HYBRID_FASTA";
$REF_FAI = "$HG19_MM10_HYBRID_FAI";
$BWA_INDEX = "$HG19_MM10_HYBRID_BWA_INDEX";
$DB_SNP = "$Bin/data/hg19/dbsnp_138.hg19.excluding_sites_after_129.vcf";
$FACETS_DB_SNP = "$Bin/data/hg19/dbsnp_137.hg19__RmDupsClean__plusPseudo50__DROP_SORT.vcf";
$MILLS_1000G = "$Bin/data/hg19/Mills_and_1000G_gold_standard.indels.hg19.vcf";
$HAPMAP = "$Bin/data/hg19/hapmap_3.3.hg19.vcf";
$OMNI_1000G = "$Bin/data/hg19/1000G_omni2.5.hg19.vcf";
$PHASE1_SNPS_1000G = "$Bin/data/hg19/1000G_phase1.snps.high_confidence.hg19.vcf";
$COSMIC = "$Bin/data/hg19/CosmicCodingMuts_v67_20131024.vcf";
$COSMIC_HOTSPOTS = "$Bin/data/b37/dmp_cosmic_for_hotspots.vcf";
}
elsif($species !~ /b37|hybrid|xenograft|b37_mm10/){
die "ONLY SUPPORT FOR b37 or hybrd|xenograft assemblies $!";
}
### make sure all markdup bam files are there before proceeding
open(BGR, "$bamgroup") || die "CAN'T OPEN GROUPING FILE OF MARKDUP BAMS $bamgroup $!";
while(<BGR>){
chomp;
my @bgro = split(/\s+/, $_);
my @bgr = split(/,/, $bgro[1]);
foreach my $bg (@bgr){
if(!-e $bg){
die "file $bg does not exist";
}
}
}
close BGR;
my $targets_bed_padded = "$Bin/targets/$targets/$targets\_targets_plus5bp.bed";
my $target_design = "$Bin/targets/$targets/$targets\__DESIGN.berger";
### std normals prefix; $targets\_norms_title.txt and $targets\_norms\_ALL_intervalnomapqcoverage_loess.txt required
my $target_std_normals = "$Bin/targets/$targets/StdNormals/$targets\_norms";
my $targets_facet = "$Bin/targets/$targets/$targets\_targets_FACETS.ilist";
if(-d $targets){
my @path = split(/\//, $targets);
my $assay = pop @path;
$targets_bed_padded = "$targets/$assay\_targets_plus5bp.bed";
$target_design = "$targets/$assay\__DESIGN.berger";
$targets_facet = "$targets/$assay\_targets_FACETS.ilist";
if($abra){
$target_std_normals = "$targets/StdNormals/$assay\_abra_norms";
}
else{
$target_std_normals = "$targets/StdNormals/$assay\_gatk_norms";
}
}
if(!-e "$targets_bed_padded"){
die "CAN'T LOCATE $targets_bed_padded FOR $targets; REQUIRED FOR SCALPEL or respectively $!";
}
if(!$abra_target){
$abra_target = $targets_bed_padded;
}
if(!-e "$abra_target"){
die "CAN'T LOCATE $abra_target; REQUIRED FOR ABRA $!";
}
#print "\n\n";
#print "-abra_target $abra_target\n";
#print "-targets $targets\n";
#print "\n\n";
my $multipleTargets = '';
### NOTE: THERE SEEMS TO BE SOMETHING WRONG WITH DIPS IN COVERAGE AT TARGET BOUNDARY
### SO NOT USING THE TARGETS FOR ANALYSI
###if($target_bed){
### if(!-e $target_bed){
### die "target file $target_bed cannot be found $!";
### }
### $multipleTargets = "-L $target_bed --interval_set_rule INTERSECTION";
###}
my @ref_chr = ();
open(FAI, "$REF_FAI") or die "CAN'T OPEN FAI FILE $REF_FAI $!";
while(<FAI>){
chomp;
my @line = split(/\s+/, $_);
push @ref_chr, $line[0];
}
close FAI;
my $count = 0;
my %inputFiles = ();
my %processedBams = ();
my @finalBams = ();
my %ran_pr_glob = 0;
my @prg_jids = ();
my $ran_ssf = 0;
my @ssf_jids = ();
my @all_jids = ();
if(!-d $output){
mkdir("$output", 0775) or die "Can't make $output";
}
if(!-d "$output/intFiles"){
mkdir("$output/intFiles", 0775) or die "Can't make $output/intFiles";
}
if(!-d "$output/alignments"){
mkdir("$output/alignments", 0775) or die "Can't make $output/alignments";
}
if(!-d "$output/progress"){
mkdir("$output/progress", 0775) or die "Can't make $output/progress";
}
if(!-d $tempdir){
mkdir("$tempdir", 0775) or die "Can't make $tempdir";
}
my %addParams = (scheduler => "$scheduler", runtime => "500", priority_project=> "$priority_project", priority_group=> "$priority_group", queues => "lau.q,lcg.q,nce.q", rerun => "1", iounits => "1");
my $additionalParams = Schedule::additionalParams(%addParams);
open(IN, "$bamgroup") || die "CAN'T OPEN GROUPING FILE OF MARKDUP BAMS $bamgroup $!";
while(<IN>){
chomp;
my @gpair = split(/\s+/, $_);
my @pair = split(/,/, $gpair[1]);
my @pins = ();
foreach my $pai (@pair){
my @sp = split(/intFiles\//, $pai);
my @sn = split(/\//, $sp[1]);
if($inputFiles{$pai}){
### IN CASE A FILE SHOWS UP MULTIPLE TIMES DUE TO BEING IN MULTIPLE COMPARISONS AND WASN'T COLLAPSED e.g. MET ANALYSIS
### THIS MAKES SURE THAT A FILE ISN'T INCLUDED MULTIPLE TIMES IN PROCESSING
next;
}
push @pins, "-I $pai";
$inputFiles{$pai} = 1;
## store final bams for post-recalibration stats
my $samp = $sn[0];
push @finalBams, "$output/alignments/$pre\_indelRealigned_recal_$samp.bam";
}
if(scalar(@pins) == 0){
### IN CASE ALL ENTRIES IN LINE CONTAINED BAMS ALREADY SEEN IN OTHER COMPARISONS
next;
}
my $bgroup = join(" ", @pins);
my @indelBams = ();
my $ran_ir = 0;
my @ir_jids = ();
foreach my $c (@ref_chr){
if($abra){
my @inBams = ();
my @outBams = ();
my $ran_chr_split_index = 0;
my @chri_jids = ();
foreach my $pin (@pins){
my @inB = split(/\s+/, $pin);
my @bpath = split(/\//, $inB[1]);
my $boi = pop @bpath;
my $ran_chr_split = 0;
my $chrsj = '';
if(!-e "$output/progress/$pre\_$uID\_$boi\_$c\.done" || $step1){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$boi\_$c", cpu => "1", mem => "10", cluster_out => "$output/progress/$pre\_$uID\_$boi\_$c\.log");
my $standardParams = Schedule::queuing(%stdParams);
my %addParams = (scheduler => "$scheduler", runtime => "500", priority_project=> "$priority_project", priority_group=> "$priority_group", rerun => "1", iounits => "2");
my $additionalParams = Schedule::additionalParams(%addParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $SAMTOOLS/samtools view -b -o $inB[1]\_$c\.bam $inB[1] $c`;
$chrsj = "$pre\_$uID\_$boi\_$c";
`/bin/touch $output/progress/$pre\_$uID\_$boi\_$c\.done`;
$ran_chr_split = 1;
}
if(!-e "$output/progress/$pre\_$uID\_$boi\_$c\_INDEX.done" || $ran_chr_split){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$boi\_$c\_INDEX", job_hold => "$chrsj", cpu => "1", mem => "10", cluster_out => "$output/progress/$pre\_$uID\_$boi\_$c\_INDEX.log");
my $standardParams = Schedule::queuing(%stdParams);
my %addParams = (scheduler => "$scheduler", runtime => "500", priority_project=> "$priority_project", priority_group=> "$priority_group", rerun => "1", iounits => "2");
my $additionalParams = Schedule::additionalParams(%addParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $SAMTOOLS/samtools index $inB[1]\_$c\.bam`;
push @chri_jids, "$pre\_$uID\_$boi\_$c\_INDEX";
`/bin/touch $output/progress/$pre\_$uID\_$boi\_$c\_INDEX.done`;
$ran_chr_split_index = 1;
}
push @inBams, "$inB[1]\_$c\.bam";
push @outBams, "$inB[1]\_$c\_ABRA.bam";
}
my $aiBams = join(",", @inBams);
my $aoBams = join(",", @outBams);
my $cij = join(",", @chri_jids);
my $ran_abra = 0;
my $abra_jid = '';
if(!-e "$output/progress/$pre\_$uID\_$gpair[0]\_$c\_ABRA.done" || $ran_chr_split_index){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$gpair[0]\_$c\_ABRA", job_hold => "$cij", cpu => "12", mem => "120", cluster_out => "$output/progress/$pre\_$uID\_$gpair[0]\_$c\_ABRA.log");
my $standardParams = Schedule::queuing(%stdParams);
my %addParams = (scheduler => "$scheduler", runtime => "500", priority_project=> "$priority_project", priority_group=> "$priority_group", rerun => "1", iounits => "4");
my $additionalParams = Schedule::additionalParams(%addParams);
###`$standardParams->{submit} $standardParams->{job_name} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx100g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $ABRA/abra.jar --in $aiBams --out $aoBams --ref $REF_SEQ --bwa-ref $BWA_INDEX --targets $ABRA_TARGETS --working $output/intFiles/abra_$gpair[0] --threads 12`;
print "\$abra_target being passed to abra_wrapper.pl = $abra_target\n\n";
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $PERL/perl $Bin/abra_wrapper.pl -inBams $aiBams -outBams $aoBams -refSeq $REF_SEQ -bwaRef $BWA_INDEX -targets $abra_target -working $output/intFiles/abra_$gpair[0]\_$c -config $config -tempdir $tempdir -log $output/progress/$pre\_$uID\_$gpair[0]\_$c\_ABRA_WRAPPER.log`;
$abra_jid = "$pre\_$uID\_$gpair[0]\_$c\_ABRA";
`/bin/touch $output/progress/$pre\_$uID\_$gpair[0]\_$c\_ABRA.done`;
$ran_abra = 1;
}
my $ran_fm = 0;
my @fm_jids = ();
my @fm_bams = ();
my $bcount = 0;
my $bcount = 0;
foreach my $outBam (@outBams){
$bcount++;
if(!-e "$output/progress/$pre\_$uID\_$gpair[0]\_$bcount\_$c\_FIXMATE.done" || $ran_abra){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$gpair[0]\_$bcount\_$c\_FIXMATE", job_hold => "$abra_jid", cpu => "4", mem => "50", cluster_out => "$output/progress/$pre\_$uID\_$gpair[0]\_$bcount\_$c\_FIXMATE.log");
my $standardParams = Schedule::queuing(%stdParams);
my %addParams = (scheduler => "$scheduler", runtime => "500", priority_project=> "$priority_project", priority_group=> "$priority_group", queues => "lau.q,lcg.q,nce.q", rerun => "1", iounits => "5");
my $additionalParams = Schedule::additionalParams(%addParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx50g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $PICARD/picard.jar FixMateInformation I=$outBam O=$outBam\_FM.bam SORT_ORDER=coordinate VALIDATION_STRINGENCY=LENIENT TMP_DIR=$tempdir MAX_RECORDS_IN_RAM=5000000 CREATE_INDEX=true`;
push @fm_jids, "$pre\_$uID\_$gpair[0]\_$bcount\_$c\_FIXMATE";
`/bin/touch $output/progress/$pre\_$uID\_$gpair[0]\_$bcount\_$c\_FIXMATE.done`;
$ran_fm = 1;
}
push @fm_bams, "I=$outBam\_FM.bam";
}
my $fmj = join(",", @fm_jids);
my $fmb = join(" ", @fm_bams);
if(!-e "$output/progress/$pre\_$uID\_$gpair[0]\_MERGE_$c\_FM.done" || $ran_fm){
sleep(2);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$gpair[0]\_MERGE_$c\_FM", job_hold => "$fmj", cpu => "8", mem => "30", cluster_out => "$output/progress/$pre\_$uID\_$gpair[0]\_MERGE_$c\_FM.log");
my $standardParams = Schedule::queuing(%stdParams);
my %addParams = (scheduler => "$scheduler", runtime => "500", priority_project=> "$priority_project", priority_group=> "$priority_group", queues => "lau.q,lcg.q,nce.q", rerun => "1", iounits => "10");
my $additionalParams = Schedule::additionalParams(%addParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx30g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $PICARD/picard.jar MergeSamFiles $fmb O=$output/intFiles/$pre\_$gpair[0]\_$c\_indelRealigned.bam SORT_ORDER=coordinate VALIDATION_STRINGENCY=LENIENT TMP_DIR=$tempdir CREATE_INDEX=true USE_THREADING=false MAX_RECORDS_IN_RAM=5000000`;
`/bin/touch $output/progress/$pre\_$uID\_$gpair[0]\_MERGE_$c\_FM.done`;
push @ir_jids, "$pre\_$uID\_$gpair[0]\_MERGE_$c\_FM";
$ran_ir = 1;
}
}
elsif($indelrealigner){
my $ran_rtc = 0;
my $rtc_jid = '';
if(!-e "$output/progress/$pre\_$uID\_$gpair[0]\_$c\_RTC.done" || $step1){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$gpair[0]\_$c\_RTC", cpu => "10", mem => "5", cluster_out => "$output/progress/$pre\_$uID\_$gpair[0]\_$c\_RTC.log");
my $standardParams = Schedule::queuing(%stdParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx5g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $GATK/GenomeAnalysisTK.jar -T RealignerTargetCreator -R $REF_SEQ -L $c $multipleTargets --known $MILLS_1000G --known $DB_SNP -S LENIENT -nt 10 -rf BadCigar --downsampling_type NONE --out $output/intFiles/$pre\_$gpair[0]\_$c\_indelRealigner.intervals $bgroup`;
`/bin/touch $output/progress/$pre\_$uID\_$gpair[0]\_$c\_RTC.done`;
$rtc_jid = "$pre\_$uID\_$gpair[0]\_$c\_RTC";
$ran_rtc = 1;
}
### seems to randomly have issues with file locking timeout on the m nodes so not submitting to it anymore
if(!-e "$output/progress/$pre\_$uID\_$gpair[0]\_$c\_IR.done" || $ran_rtc){
sleep(2);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$gpair[0]\_$c\_IR", job_hold => "$rtc_jid", cpu => "2", mem => "15", cluster_out => "$output/progress/$pre\_$uID\_$gpair[0]\_$c\_IR.log");
my $standardParams = Schedule::queuing(%stdParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx15g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $GATK/GenomeAnalysisTK.jar -T IndelRealigner -R $REF_SEQ -L $c $multipleTargets --knownAlleles $MILLS_1000G --knownAlleles $DB_SNP -S LENIENT --targetIntervals $output/intFiles/$pre\_$gpair[0]\_$c\_indelRealigner.intervals --maxReadsForRealignment 500000 --maxReadsInMemory 3000000 --maxReadsForConsensuses 500000 -rf BadCigar --out $output/intFiles/$pre\_$gpair[0]\_$c\_indelRealigned.bam $bgroup`;
`/bin/touch $output/progress/$pre\_$uID\_$gpair[0]\_$c\_IR.done`;
push @ir_jids, "$pre\_$uID\_$gpair[0]\_$c\_IR";
$ran_ir = 1;
}
}
else{ #skip indel realignment
}
push @indelBams, "-I $output/intFiles/$pre\_$gpair[0]\_$c\_indelRealigned.bam";
}
my $irBams ='';
my $irj ='';
if($abra || $indelrealigner){
$irBams = join(" ", @indelBams);
$irj = join(",", @ir_jids);
}
else{ #skipped indel realignment previously
$irBams = $bgroup;
}
my $ran_br = 0;
my $brj = '';
if(!-e "$output/progress/$pre\_$uID\_$gpair[0]\_BR.done" || $ran_ir){
sleep(2);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$gpair[0]\_BR", job_hold => "$irj", cpu => "12", mem => "60", cluster_out => "$output/progress/$pre\_$uID\_$gpair[0]\_BR.log");
my $standardParams = Schedule::queuing(%stdParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx50g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $GATK/GenomeAnalysisTK.jar -T BaseRecalibrator -l INFO -R $REF_SEQ -S LENIENT --knownSites $DB_SNP --knownSites $MILLS_1000G --knownSites $HAPMAP --knownSites $OMNI_1000G --knownSites $PHASE1_SNPS_1000G --covariate ContextCovariate --covariate CycleCovariate --covariate QualityScoreCovariate --covariate ReadGroupCovariate -rf BadCigar --num_cpu_threads_per_data_thread 12 --out $output/intFiles/$pre\_$gpair[0]\_recal_data.grp $irBams`;
`/bin/touch $output/progress/$pre\_$uID\_$gpair[0]\_BR.done`;
$brj = "$pre\_$uID\_$gpair[0]\_BR";
$ran_br = 1;
}
my @indelRecalBams1 = ();
my $ran_pr = 0;
my @pr_jids = ();
foreach my $c (@ref_chr){
if(!-e "$output/progress/$pre\_$uID\_$gpair[0]\_$c\_PR.done" || $ran_br){
my $prBams = '';
if($abra || $indelrealigner){
$prBams = "-I $output/intFiles/$pre\_$gpair[0]\_$c\_indelRealigned.bam";
}
else{ #skipped indel realignment previously
$prBams = $bgroup;
}
sleep(2);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$gpair[0]\_$c\_PR", job_hold => "$brj", cpu => "6", mem => "30", cluster_out => "$output/progress/$pre\_$uID\_$gpair[0]\_$c\_PR.log");
my $standardParams = Schedule::queuing(%stdParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx30g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $GATK/GenomeAnalysisTK.jar -T PrintReads -R $REF_SEQ -L $c $multipleTargets --emit_original_quals -BQSR $output/intFiles/$pre\_$gpair[0]\_recal_data.grp --num_cpu_threads_per_data_thread 6 -rf BadCigar --downsampling_type NONE --out $output/intFiles/$pre\_$gpair[0]\_$c\_indelRealigned_recal.bam $prBams`;
`/bin/touch $output/progress/$pre\_$uID\_$gpair[0]\_$c\_PR.done`;
push @pr_jids, "$pre\_$uID\_$gpair[0]\_$c\_PR";
#push @prg_jids, "$pre\_$uID\_$gpair[0]\_$c\_PR"; ### HC jobs sometimes failed to submit due to holding on too many PR jobs, so we now make a dummy holding job per group, and let HC holdiing on group dummy jobs
$ran_pr = 1;
$ran_pr_glob{"$c"} = 1;
}
push @indelRecalBams1, "I=$output/intFiles/$pre\_$gpair[0]\_$c\_indelRealigned_recal.bam";
push @{$processedBams{"$c"}}, "-I $output/intFiles/$pre\_$gpair[0]\_$c\_indelRealigned_recal.bam";
}
### HC jobs sometimes failed to submit due to holding on too many PR jobs, so we now create a dummy holding job per group, and let HC holdiing on group dummy jobs
my $prj = join(",", @pr_jids);
if($ran_pr)
{
sleep(2);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$gpair[0]\_HOLD_PR", job_hold => "$prj", cpu => "1", mem => "1", cluster_out => "$output/progress/$pre\_$uID\_$gpair[0]\_HOLD_PR.log");
my $standardParams = Schedule::queuing(%stdParams);
my %addParams = (scheduler => "$scheduler", runtime => "10", priority_project=> "$priority_project", priority_group=> "$priority_group", queues => "lau.q,lcg.q,nce.q", rerun => "0", iounits => "0");
my $additionalParams = Schedule::additionalParams(%addParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams sleep 1`;
push @prg_jids, "$pre\_$uID\_$gpair[0]\_HOLD_PR";
}
my $irBams1 = join(" ", @indelRecalBams1);
my $ran_m = 0;
my @merge_jids = ();
if(!-e "$output/progress/$pre\_$uID\_$gpair[0]\_MERGE_PR.done" || $ran_pr){
sleep(2);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$gpair[0]\_MERGE_PR", job_hold => "$prj", cpu => "8", mem => "30", cluster_out => "$output/progress/$pre\_$uID\_$gpair[0]\_MERGE_PR.log");
my $standardParams = Schedule::queuing(%stdParams);
my %addParams = (scheduler => "$scheduler", runtime => "500", priority_project=> "$priority_project", priority_group=> "$priority_group", queues => "lau.q,lcg.q,nce.q", rerun => "1", iounits => "10");
my $additionalParams = Schedule::additionalParams(%addParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx30g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $PICARD/picard.jar MergeSamFiles $irBams1 O=$output/intFiles/$pre\_$gpair[0]\_indelRealigned_recal.bam SORT_ORDER=coordinate VALIDATION_STRINGENCY=LENIENT TMP_DIR=$tempdir CREATE_INDEX=true USE_THREADING=false MAX_RECORDS_IN_RAM=5000000`;
`/bin/touch $output/progress/$pre\_$uID\_$gpair[0]\_MERGE_PR.done`;
push @merge_jids, "$pre\_$uID\_$gpair[0]\_MERGE_PR";
$ran_m = 1;
}
my $mj = join(",", @merge_jids);
if(!-e "$output/progress/$pre\_$uID\_$gpair[0]\_SSF.done" || $ran_m){
sleep(2);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$gpair[0]\_SSF", job_hold => "$mj", cpu => "2", mem => "10", cluster_out => "$output/progress/$pre\_$uID\_$gpair[0]\_SSF.log");
my $standardParams = Schedule::queuing(%stdParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx10g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $GATK/GenomeAnalysisTK.jar -T SplitSamFile -R $REF_SEQ -I $output/intFiles/$pre\_$gpair[0]\_indelRealigned_recal.bam --outputRoot $output/alignments/$pre\_indelRealigned_recal_`;
`/bin/touch $output/progress/$pre\_$uID\_$gpair[0]\_SSF.done`;
push @ssf_jids, "$pre\_$uID\_$gpair[0]\_SSF";
$ran_ssf = 1;
}
}
my $ssfj = join(",", @ssf_jids);
push @all_jids, @ssf_jids;
my @mq_metrics_jid = ();
my @ad_jids = ();
my $ran_mqm = 0;
my $ran_ad = 0;
foreach my $finalBam (@finalBams){
my @sn = split(/\//, $finalBam);
my $samp = $sn[-1];
$samp =~ s/\.bam//g;
$samp =~ s/$pre\_indelRealigned_recal_//g;
if(!-e "$output/progress/$pre\_$uID\_MQ_METRICS_$samp\.done" || $ran_ssf){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_MQ_METRICS_$samp", job_hold => "$ssfj", cpu => "1", mem => "20", cluster_out => "$output/progress/$pre\_$uID\_MQ_METRICS_$samp\.log");
my $standardParams = Schedule::queuing(%stdParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Djava.io.tmpdir=$tempdir -jar $PICARD/picard.jar MeanQualityByCycle INPUT=$finalBam OUTPUT=$output/intFiles/$pre\_MeanQualityByCycle_$samp.txt CHART_OUTPUT=$output/intFiles/$pre\_MeanQualityByCycle_$samp.pdf REFERENCE_SEQUENCE=$REF_SEQ VALIDATION_STRINGENCY=LENIENT ASSUME_SORTED=true TMP_DIR=$tempdir`;
push @mq_metrics_jid, "$pre\_$uID\_MQ_METRICS_$samp";
`/bin/touch $output/progress/$pre\_$uID\_MQ_METRICS_$samp\.done`;
$ran_mqm = 1;
}
## generate *alleledepth file for 'hotspots in normals' qc
if(!-e "$output/progress/$pre\_$uID\_MUT_AD_$samp\.done" || $ran_ssf){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_MUT_AD_$samp", job_hold => "$ssfj", cpu => "1", mem => "2", cluster_out => "$output/progress/$pre\_$uID\_MUT_AD_$samp\.log");
my $standardParams = Schedule::queuing(%stdParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $PERL/perl $Bin/qc/dmp_genotype_allele.pl -fmv $COSMIC_HOTSPOTS -bam $finalBam -rf $REF_SEQ -s $SAMTOOLS -b $BEDTOOLS -o $output/intFiles/$samp -of $pre\_indelRealigned_recal_$samp\.mpileup.alleledepth -mof $pre\_indelRealigned_recal_$samp\.mpileup`;
push @ad_jids, "$pre\_$uID\_MUT_AD_$samp";
`/bin/touch $output/progress/$pre\_$uID\_MUT_AD_$samp\.done`;
$ran_ad = 1;
}
}
my $mqmj = join(",", @mq_metrics_jid);
my $ran_mmqm = 0;
if(!-e "$output/progress/$pre\_$uID\_MERGE_MQ.done" || $ran_mqm){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_MERGE_MQ", job_hold => "$mqmj", cpu => "1", mem => "1", cluster_out => "$output/progress/$pre\_$uID\_MERGE_MQ.log");
my $standardParams = Schedule::queuing(%stdParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $PYTHON/python $Bin/qc/mergeMeanQualityHistograms.py $output '*_MeanQualityByCycle_*.txt' $output/metrics/$pre\_post_recal_MeanQualityByCycle.txt $output/metrics/$pre\_pre_recal_MeanQualityByCycle.txt`;
`/bin/touch $output/progress/$pre\_$uID\_MERGE_MQ.done`;
push @all_jids, "$pre\_$uID\_MERGE_MQ";
$ran_mmqm = 1;
}
my $adj = join(",", @ad_jids);
my $ran_hn = 0;
if(!-e "$output/progress/$pre\_$uID\_HOTSPOTS_NORMALS.done" || $ran_ad){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_HOTSPOTS_NORMALS", job_hold => "$adj", cpu => "1", mem => "1", cluster_out => "$output/progress/$pre\_$uID\_HOTSPOTS_NORMALS.log");
my $standardParams = Schedule::queuing(%stdParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $PYTHON/python $Bin/qc/hotspots_in_normals.py $output/intFiles '*.alleledepth' $COSMIC_HOTSPOTS $pair $output/metrics/$pre\_HotspotsInNormals.txt`;
`/bin/touch $output/progress/$pre\_$uID\_HOTSPOTS_NORMALS.done`;
push @all_jids, "$pre\_$uID\_HOTSPOTS_NORMALS";
$ran_hn = 1;
}
my $allj = join(",", @all_jids);
#if(!-e "$output/progress/$pre\_$uID\_RSYNC_1.done" || $ran_ssf || $ran_mmqm || $ran_hn){
sleep(2);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_RSYNC_1", job_hold => "$allj", cpu => "1", mem => "1", cluster_out => "$output/progress/$pre\_$uID\_RSYNC_1.log");
my $standardParams = Schedule::queuing(%stdParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams /usr/bin/rsync -azvP --exclude 'intFiles' --exclude 'progress' --exclude 'variants' --exclude 'metrics' --exclude 'variants_pipeline' --exclude 'rna' $curDir $rsync`;
push @all_jids, "$pre\_$uID\_RSYNC_1";
`/bin/touch $output/progress/$pre\_$uID\_RSYNC_1.done`;
#}
if($nosnps){
exit(0);
}
if(!-d "$output/variants"){
mkdir("$output/variants", 0775) or die "Can't make $output/variants";
}
if(!-d "$output/variants/snpsIndels"){
mkdir("$output/variants/snpsIndels", 0775) or die "Can't make $output/variants/snpsIndels";
}
if(!-d "$output/variants/snpsIndels/haplotypecaller"){
mkdir("$output/variants/snpsIndels/haplotypecaller", 0775) or die "Can't make $output/variants/snpsIndels/haplotypecaller";
}
my @ugVariants = ();
my @hcVariants = ();
my $ran_ug = 0;
my $ran_hc = 0;
my @ug_jids = ();
my @hc_jids = ();
my $prgj = join(",", @prg_jids);
foreach my $c (@ref_chr){
### NOTE1: GET THIS RANDOM ERROR NOW FOR SNP CALLS
### Unexpectedly couldn't find valid codec for temporary output file
### RERUNNING THE SAME COMMAND SEEMS TO FIX IT
###
### NOTE2: GET SYSTEM MEMORY ISSUE WHEN RUNNING ON THE CLUSTER AND LOTS
### OF INPUT FILES TO UNIFIEDGENOTYPE WITH NUM THREADS > 1 -nt
### NOT A PROBLEM WHEN RUNNING IT WITH LOTS OF INPUT FILES ON RAY
my $irBams2 = join(" ", @{$processedBams{"$c"}});
if($ug){
if(!-e "$output/progress/$pre\_$uID\_$c\_UG.done" || $ran_pr_glob{"$c"}){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$c\_UG", job_hold => "$prgj", cpu => "12", mem => "24", cluster_out => "$output/progress/$pre\_$uID\_$c\_UG.log");
my $standardParams = Schedule::queuing(%stdParams);
`$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx24g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $GATK/GenomeAnalysisTK.jar -T UnifiedGenotyper -R $REF_SEQ --reference_sample_name $species -L $c $multipleTargets --dbsnp $DB_SNP --downsampling_type NONE --annotateNDA --annotation AlleleBalance --annotation AlleleBalanceBySample --annotation HardyWeinberg --genotype_likelihoods_model BOTH --read_filter BadCigar --num_cpu_threads_per_data_thread 12 --out $output/intFiles/$pre\_$c\_UnifiedGenotyper.vcf $irBams2`;