-
Notifications
You must be signed in to change notification settings - Fork 18
/
process_alignments_mouse.pl
executable file
·1653 lines (1468 loc) · 99 KB
/
process_alignments_mouse.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 ($pair, $svnRev, $email, $patient, $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, $mutect2, $manta);
my $pre = 'TEMP';
my $output = "results";
my $species = 'mm10';
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,
'step1' => \$step1,
'ug|unifiedgenotyper' => \$ug,
'abra' => \$abra,
'indelrealigner' => \$indelrealigner,
'bamgroup=s' => \$bamgroup,
'svnRev=s' => \$svnRev,
'scheduler=s' => \$scheduler,
'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,
'mutect2' => \$mutect2,
'manta' => \$manta,
'noindelrealign|noir' => \$noindelrealign) or exit(1);
if(!$group || !$config || !$scheduler || !$targets || !$bamgroup || $help){
print <<HELP;
USAGE: process_alignments_hg19.pl -group GROUP -pair PAIR -pre PRE -config CONFIG -species SPECIES -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)
* 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)
* SPECIES: mm10 (default), mouse_hybrid, (mm10_b37), mm10_custom, and mm9
* 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
* -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;
}
my $curDir = `pwd`;
chomp $curDir;
if($output !~ /^\//){
$output = "$curDir/$output";
}
if($pre =~ /^\d+/){
$pre = "s_$pre";
}
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 $GATK = '';
my $GATK4 = '';
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 $VIRMID = '';
my $JAVA = '';
my $JAVA7_MUTECT = '';
my $PYTHON = '';
my $PERL = '';
my $R_FACETS = '';
my $SINGULARITY = '';
my $singularityParams = '';
my $singularityBind = '';
my $singularityenv_prepend_path = "";
my $MM9_FASTA = '';
my $MM9_FAI = '';
my $MM9_BWA_INDEX = '';
my $MM10_FASTA = '';
my $MM10_FAI = '';
my $MM10_BWA_INDEX = '';
my $MM10_B37_HYBRID_FASTA = '';
my $MM10_B37_HYBRID_FAI = '';
my $MM10_B37_HYBRID_BWA_INDEX = '';
my $MM10_HG19_HYBRID_FASTA = '';
my $MM10_HG19_HYBRID_FAI = '';
my $MM10_HG19_HYBRID_BWA_INDEX = '';
my $MM10_CUSTOM_FASTA = '';
my $MM10_CUSTOM_FAI = '';
my $MM10_CUSTOM_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] =~ /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 FIND gatk IN $conf[1] $!";
}
$GATK4 = $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] =~ /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{'PATH'} = "$conf[1]:$path_tmp";
$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];
}
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] =~ /mm9_fasta/i){
if(!-e "$conf[1]"){
if($species =~ /^mm9$/i){
die "CAN'T FIND $conf[1] $!";
}
}
$MM9_FASTA = $conf[1];
}
elsif($conf[0] =~ /mm9_fai/i){
if(!-e "$conf[1]"){
if($species =~ /^mm9$/i){
die "CAN'T FIND $conf[1] $!";
}
}
$MM9_FAI = $conf[1];
}
elsif($conf[0] =~ /mm9_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 =~ /^mm9$/i){
die "CAN'T FIND ALL NECESSARY BWA INDEX FILES FOR MM9 WITH PREFIX $conf[1] $!";
}
}
$MM9_BWA_INDEX = $conf[1];
}
elsif($conf[0] =~ /mm10_fasta/i){
if(!-e "$conf[1]"){
if($species =~ /^mm10$/i){
die "CAN'T FIND $conf[1] $!";
}
}
$MM10_FASTA = $conf[1];
}
elsif($conf[0] =~ /mm10_fai/i){
if(!-e "$conf[1]"){
if($species =~ /^mm10$/i){
die "CAN'T FIND $conf[1] $!";
}
}
$MM10_FAI = $conf[1];
}
elsif($conf[0] =~ /mm10_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 =~ /^mm10$/i){
die "CAN'T FIND ALL NECESSARY BWA INDEX FILES FOR MM10 WITH PREFIX $conf[1] $!";
}
}
$MM10_BWA_INDEX = $conf[1];
}
elsif($conf[0] =~ /mm10_b37_hybrid_fasta/i){
if(!-e "$conf[1]"){
if($species =~ /mouse_hybrid|mm10_b37/i){
die "CAN'T FIND $conf[1] $!";
}
}
$MM10_B37_HYBRID_FASTA = $conf[1];
}
elsif($conf[0] =~ /mm10_b37_hybrid_fai/i){
if(!-e "$conf[1]"){
if($species =~ /mouse_hybrid|mm10_b37/i){
die "CAN'T FIND $conf[1] $!";
}
}
$MM10_B37_HYBRID_FAI = $conf[1];
}
elsif($conf[0] =~ /mm10_b37_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 =~ /mouse_hybrid|mm10_b37/i){
die "CAN'T FIND ALL NECESSARY BWA INDEX FILES FOR b37-MM10 HYBRID WITH PREFIX $conf[1] $!";
}
}
$MM10_B37_HYBRID_BWA_INDEX = $conf[1];
}
elsif($conf[0] =~ /mm10_hg19_hybrid_fasta/i){
if(!-e "$conf[1]"){
if($species =~ /mm10_hg19/i){
die "CAN'T FIND $conf[1] $!";
}
}
$MM10_HG19_HYBRID_FASTA = $conf[1];
}
elsif($conf[0] =~ /mm10_hg19_hybrid_fai/i){
if(!-e "$conf[1]"){
if($species =~ /mm10_hg19/i){
die "CAN'T FIND $conf[1] $!";
}
}
$MM10_HG19_HYBRID_FAI = $conf[1];
}
elsif($conf[0] =~ /mm10_hg19_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 =~ /mm10_hg19/i){
die "CAN'T FIND ALL NECESSARY BWA INDEX FILES FOR HG19-MM9 HYBRID WITH PREFIX $conf[1] $!";
}
}
$MM10_HG19_HYBRID_BWA_INDEX = $conf[1];
}
elsif($conf[0] =~ /mm10_custom_fasta/i){
if(!-e "$conf[1]"){
if($species =~ /mm10_custom/i){
die "CAN'T FIND $conf[1] $!";
}
}
$MM10_CUSTOM_FASTA = $conf[1];
}
elsif($conf[0] =~ /mm10_custom_fai/i){
if(!-e "$conf[1]"){
if($species =~ /mm10_custom/i){
die "CAN'T FIND $conf[1] $!";
}
}
$MM10_CUSTOM_FAI = $conf[1];
}
elsif($conf[0] =~ /mm10_custom_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 =~ /mm10_custom/i){
die "CAN'T FIND ALL NECESSARY BWA INDEX FILES FOR MM10_CUSTOM WITH PREFIX $conf[1] $!";
}
}
$MM10_CUSTOM_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 = "$MM10_FASTA";
my $REF_FAI = "$MM10_FAI";
my $BWA_INDEX = "$MM10_BWA_INDEX";
my $DB_SNP = "$Bin/data/mm10/mm10_snp142.vcf";
my $CHR_M = 'M'; #as of right now default to M. Once we add NCBI assemblies, we can chang it below.
my $CHR_PREFIX = "chr"; #as of right now default to 'chr'. Once we add NCBI assemblies, we can change it below.
##### TEMP
print "species in process_alignments_mouse.pl = $species\n";
##### TEMP
if($species =~ /mouse_hybrid|mm10_b37/i){
$species = "mouse_hybrid";
$REF_SEQ = "$MM10_B37_HYBRID_FASTA";
$REF_FAI = "$MM10_B37_HYBRID_FAI";
$BWA_INDEX = "$MM10_B37_HYBRID_BWA_INDEX";
}
elsif($species =~ /mm10_hg19/i){
$species = "mouse_hybrid";
$REF_SEQ = "$MM10_HG19_HYBRID_FASTA";
$REF_FAI = "$MM10_HG19_HYBRID_FAI";
$BWA_INDEX = "$MM10_HG19_HYBRID_BWA_INDEX";
}
elsif($species =~ /mm10_custom/i){
$REF_SEQ = "$MM10_CUSTOM_FASTA";
$REF_FAI = "$MM10_CUSTOM_FAI";
$BWA_INDEX = "$MM10_CUSTOM_BWA_INDEX";
}
elsif($species =~ /^mm9$/i){
$REF_SEQ = "$MM9_FASTA";
$REF_FAI = "$MM9_FAI";
$BWA_INDEX = "$MM9_BWA_INDEX";
$DB_SNP = "";
}
### 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";
if(-d $targets){
my @path = split(/\//, $targets);
my $assay = pop @path;
$targets_bed_padded = "$targets/$assay\_targets_plus5bp.bed";
}
if(!-e "$targets_bed_padded"){
die "CAN'T LOCATE $targets_bed_padded FOR $targets; REQUIRED FOR SCALPEL $!";
}
if(!$abra_target){
$abra_target = $targets_bed_padded;
}
if(!-e "$abra_target"){
die "CAN'T LOCATE $abra_target; REQUIRED FOR ABRA $!";
}
my $multipleTargets = '';
###if($target){
### if(!-e $target){
### die "target file $target 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}){
next;
}
push @pins, "-I $pai";
$inputFiles{$pai} = 1;
my $samp = $sn[0];
push @finalBams, "$output/alignments/$pre\_indelRealigned_recal_$samp.bam";
}
if(scalar(@pins) == 0){
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 => "90", 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->{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;
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 -S LENIENT --known $DB_SNP -nt 10 -rf BadCigar --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;
}
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 -S LENIENT --knownAlleles $DB_SNP --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 => "40", 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 -Xmx30g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $GATK/GenomeAnalysisTK.jar -T BaseRecalibrator -l INFO -R $REF_SEQ -S LENIENT --knownSites $DB_SNP --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 --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 $ran_mqm = 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;
}
}
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 $allj = join(",", @all_jids);
if(!-e "$output/progress/$pre\_$uID\_RSYNC_1.done" || $ran_ssf || $ran_mmqm){
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' $curDir $rsync`;
push @all_jids, "$pre\_$uID\_RSYNC_1";
`/bin/touch $output/progress/$pre\_$uID\_RSYNC_1.done`;
}
if($nosnps){
exit;
}
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 @iVariants = ();
my @sVariants = ();
my @hcVariants = ();
my $ran_hc = 0;
my $ran_ug_snp = 0;
my $ran_ug_indel = 0;
my @hc_jids = ();
my @ugs_jids = ();
my @ugi_jids = ();
my $prgj = join(",", @prg_jids);
foreach my $c (@ref_chr){
my $irBams2 = join(" ", @{$processedBams{"$c"}});
if($ug){
if(!-e "$output/progress/$pre\_$uID\_$c\_UG_SNP.done" || $ran_pr_glob{"$c"}){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$c\_UG_SNP", job_hold => "$prgj", cpu => "12", mem => "48", cluster_out => "$output/progress/$pre\_$uID\_$c\_UG_SNP.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 SNP --read_filter BadCigar --num_cpu_threads_per_data_thread 12 --out $output/intFiles/$pre\_$c\_UnifiedGenotyper_SNP.vcf $irBams2`;
`/bin/touch $output/progress/$pre\_$uID\_$c\_UG_SNP.done`;
push @ugs_jids, "$pre\_$uID\_$c\_UG_SNP";
$ran_ug_snp = 1;
}
if(!-e "$output/progress/$pre\_$uID\_$c\_UG_INDEL.done" || $ran_pr_glob{"$c"}){
sleep(2);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$c\_UG_INDEL", job_hold => "$prgj", cpu => "12", mem => "48", cluster_out => "$output/progress/$pre\_$uID\_$c\_UG_INDEL.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 --downsampling_type NONE --annotateNDA --annotation AlleleBalance --annotation AlleleBalanceBySample --annotation HardyWeinberg --genotype_likelihoods_model INDEL --read_filter BadCigar --num_cpu_threads_per_data_thread 12 --out $output/intFiles/$pre\_$c\_UnifiedGenotyper_INDEL.vcf $irBams2`;
`/bin/touch $output/progress/$pre\_$uID\_$c\_UG_INDEL.done`;
push @ugi_jids, "$pre\_$uID\_$c\_UG_INDEL";
$ran_ug_indel = 1;
}
push @sVariants, "--variant $output/intFiles/$pre\_$c\_UnifiedGenotyper_SNP.vcf";
push @iVariants, "--variant $output/intFiles/$pre\_$c\_UnifiedGenotyper_INDEL.vcf";
}
if(!-e "$output/progress/$pre\_$uID\_$c\_HC.done" || $ran_pr_glob{"$c"}){
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_$c\_HC", job_hold => "$prgj", cpu => "30", mem => "90", cluster_out => "$output/progress/$pre\_$uID\_$c\_HC.log");
my $standardParams = Schedule::queuing(%stdParams);
my %addParams = (scheduler => "$scheduler", runtime => "500", priority_project=> "$priority_project", priority_group=> "$priority_group", rerun => "1", iounits => "7");
my $additionalParams = Schedule::additionalParams(%addParams);
my $response = "";
my $HC_submission_num = 0;
while($response !~ /is submitted to default queue/ && $HC_submission_num < 10){
my $time = 60 * $HC_submission_num;
`sleep $time `;
$HC_submission_num++;
print "HC Chromosome $c attempt number $HC_submission_num\n";
print "Command: $standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx90g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $GATK/GenomeAnalysisTK.jar -T HaplotypeCaller -R $REF_SEQ -L $c $multipleTargets --dbsnp $DB_SNP --downsampling_type NONE --annotation AlleleBalanceBySample --annotation ClippingRankSumTest --read_filter BadCigar --num_cpu_threads_per_data_thread 30 --out $output/intFiles/$pre\_$c\_HaplotypeCaller.vcf $irBams2";
$response = `$standardParams->{submit} $standardParams->{job_name} $standardParams->{job_hold} $standardParams->{cpu} $standardParams->{mem} $standardParams->{cluster_out} $additionalParams $singularityParams $JAVA/java -Xms256m -Xmx90g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $GATK/GenomeAnalysisTK.jar -T HaplotypeCaller -R $REF_SEQ -L $c $multipleTargets --dbsnp $DB_SNP --downsampling_type NONE --annotation AlleleBalanceBySample --annotation ClippingRankSumTest --read_filter BadCigar --num_cpu_threads_per_data_thread 30 --out $output/intFiles/$pre\_$c\_HaplotypeCaller.vcf $irBams2 2>&1`;
print "Response: $response\n";
if($response !~ /is submitted to default queue/ && $HC_submission_num == 10 && $c eq '1'){
`mail -s "HaplotypeCaller Job Not Working" $email <<< "This is an e-mail letting you know that your variants pipeline run for $pre is not submitting HC jobs to the cluster. Please remove all .done files for haplotype caller and rerun the pipeline." `;
}
}
`/bin/touch $output/progress/$pre\_$uID\_$c\_HC.done`;
push @hc_jids, "$pre\_$uID\_$c\_HC";
$ran_hc = 1;
}
push @hcVariants, "--variant $output/intFiles/$pre\_$c\_HaplotypeCaller.vcf";
}
my $hcVars = join(" " , @hcVariants);
my $ran_cv_hc = 0;
my $hcj = join(",", @hc_jids);
my $cvhcj = '';
if(!-e "$output/progress/$pre\_$uID\_CV_HC.done" || $ran_hc){
sleep(2);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_CV_HC", job_hold => "$hcj", cpu => "1", mem => "20", cluster_out => "$output/progress/$pre\_$uID\_CV_HC.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 $GATK/GenomeAnalysisTK.jar -T CombineVariants -R $REF_SEQ -o $output/variants/snpsIndels/haplotypecaller/$pre\_HaplotypeCaller.vcf --assumeIdenticalSamples $hcVars`;
`/bin/touch $output/progress/$pre\_$uID\_CV_HC.done`;
$cvhcj = "$pre\_$uID\_CV_HC";
$ran_cv_hc = 1;
}
sleep(2);
# Run this anyway, it will go through the function and make sure everything was ran
&generateMaf("$output/variants/snpsIndels/haplotypecaller/$pre\_HaplotypeCaller.vcf", 'haplotypecaller', "$cvhcj,$ssfj", $ran_cv_hc);
if($ug){
if(!-d "$output/variants/snpsIndels/unifiedgenotyper"){
mkdir("$output/variants/snpsIndels/unifiedgenotyper", 0775) or die "Can't make $output/variants/snpsIndels/unifiedgenotyper";
}
my $sVars = join(" " , @sVariants);
my $iVars = join(" " , @iVariants);
my $ran_cv_ug_snp = 0;
my @cvug_jids = ();
my $ugsj = join(",", @ugs_jids);
if(!-e "$output/progress/$pre\_$uID\_CV_UG_SNP.done" || $ran_ug_snp){
sleep(3);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_CV_UG_SNP", job_hold => "$ugsj", cpu => "1", mem => "2", cluster_out => "$output/progress/$pre\_$uID\_CV_UG_SNP.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 -Xmx2g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $GATK/GenomeAnalysisTK.jar -T CombineVariants -R $REF_SEQ -o $output/intFiles/$pre\_UnifiedGenotyper_SNP.vcf --assumeIdenticalSamples $sVars`;
`/bin/touch $output/progress/$pre\_$uID\_CV_UG_SNP.done`;
push @cvug_jids, "$pre\_$uID\_CV_UG_SNP";
$ran_cv_ug_snp = 1;
}
my $ran_cv_ug_indel = 0;
my $ugij = join(",", @ugi_jids);
if(!-e "$output/progress/$pre\_$uID\_CV_UG_INDEL.done" || $ran_ug_indel){
sleep(3);
my %stdParams = (scheduler => "$scheduler", job_name => "$pre\_$uID\_CV_UG_INDEL", job_hold => "$ugij", cpu => "1", mem => "2", cluster_out => "$output/progress/$pre\_$uID\_CV_UG_INDEL.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 -Xmx2g -XX:-UseGCOverheadLimit -Djava.io.tmpdir=$tempdir -jar $GATK/GenomeAnalysisTK.jar -T CombineVariants -R $REF_SEQ -o $output/intFiles/$pre\_UnifiedGenotyper_INDEL.vcf --assumeIdenticalSamples $iVars`;
`/bin/touch $output/progress/$pre\_$uID\_CV_UG_INDEL.done`;
push @cvug_jids, "$pre\_$uID\_CV_UG_INDEL";
$ran_cv_ug_indel = 1;
}
my $cvugj = join(",", @cvug_jids);
if(!-e "$output/progress/$pre\_$uID\_CV_UG_RAW.done" || $ran_cv_ug_snp || $ran_cv_ug_indel){