-
Notifications
You must be signed in to change notification settings - Fork 2
/
neoscan.pl
585 lines (503 loc) · 25.7 KB
/
neoscan.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
#########Song Cao###########
# last updated date: 12/21/2016 #
### updated 1/3/2018 ###
### updated 08/11/2018 ##
### use docker image for submitting jobs to research-hpc queue ##
#!/usr/bin/perl
use strict;
use warnings;
use Getopt::Long;
#use POSIX;
my $version = 1.2;
#color code
my $red = "\e[31m";
my $gray = "\e[37m";
my $yellow = "\e[33m";
my $green = "\e[32m";
my $purple = "\e[35m";
my $cyan = "\e[36m";
my $normal = "\e[0m";
#usage information
(my $usage = <<OUT) =~ s/\t+//g;
This script will predict neoantigen for somatic variants in cancer sample
Pipeline version: $version
$yellow Usage: perl $0 --rdir --log --bamfq --bed --step --rna --refdir $normal
<rdir> = full path of the folder holding files for this sequence run
<log> = full path of the folder saving log files
<bam> = 1, input is bam; 0, input is fastq: default 1
<rna> =1, input data is rna, otherwise is dna
<bed> = bed file for annotation: ensembl: /gscmnt/gc2518/dinglab/scao/db/ensembl38.85/proteome-first.bed
refseq: /gscmnt/gc2518/dinglab/scao/db/refseq_hg38_june29/proteome.bed
<refdir> = ref directory: /gscmnt/gc2518/dinglab/scao/db/refseq_hg38_june29
<step_number> run this pipeline step by step. (running the whole pipeline if step number is 0)
$red [1] Generate fasta snv and indel
[2] Generate peptide for snv and indel
$green [3] Run HLA type
$purple [4] Run netMHC
[5] parse netMHC result
$cyan [6] generate report summary
$normal
OUT
my $step_number = -1;
my $help = 0;
my $run_dir="";
my $log_dir="";
my $hla = 1;
my $s_bam_fq =1;
my $s_rna=1;
my $db_ref_bed="/gscmnt/gc2518/dinglab/scao/db/ensembl38.85/proteome-first.bed";
#my $db_ref_bed="/gscmnt/gc2518/dinglab/scao/db/refseq_hg38_june29/proteome.bed";
my $h38_fa="/gscmnt/gc2518/dinglab/scao/db/refseq_hg38_june29";
my $status = &GetOptions (
"step=i" => \$step_number,
"rdir=s" => \$run_dir,
"bed=s" => \$db_ref_bed,
"refdir=s" => \$h38_fa,
"bam=i" => \$s_bam_fq,
"rna=i" => \$s_rna,
"log=s" => \$log_dir,
"help" => \$help
);
if ($help || $run_dir eq "" || $log_dir eq "" || $step_number<0) {
print $usage;
exit;
}
#die $usage unless @ARGV == 2;
#my ( $run_dir, $step_number ) = @ARGV;
if ($run_dir =~/(.+)\/$/) {
$run_dir = $1;
}
#die $usage unless ($step_number >=0)&&(($step_number <= 10) || ($step_number>=12));
#my $email = "scao\@wustl\.edu";
my $HOME = $ENV{HOME};
my $working_name= (split(/\//,$run_dir))[-1];
my $HOME1=$log_dir;;
#store job files here
if (! -d $HOME1."/tmpNeo") {
`mkdir $HOME1"/tmpNeo"`;
}
my $job_files_dir = $HOME1."/tmpNeo";
#store SGE output and error files here
if (! -d $HOME1."/LSF_DIR_Neo") {
`mkdir $HOME1"/LSF_DIR_Neo"`;
}
my $lsf_file_dir = $HOME1."/LSF_DIR_Neo";
## hlaminer for genotype, netMHC for neoantigen prediction ##
my $db_hla_abc_cds="/gscmnt/gc2523/dinglab/neoantigen/human_DB/HLA_ABC_CDS.fasta";
my $optitype="/gscmnt/gc2518/dinglab/scao/home/tools/anaconda3/bin/OptiTypePipeline.py";
my $f_allele="/gscmnt/gc2523/dinglab/neoantigen/netMHC-4.0/Linux_x86_64/data/allelelist";
my $netMHC="/gscmnt/gc2523/dinglab/neoantigen/netMHC-4.0/netMHC";
my $samtools="/usr/bin/samtools";
#my $db_ref_bed="/gscmnt/gc2518/dinglab/scao/db/refseq_hg38_june29/proteome.bed";
#my $h38_fa="/gscmnt/gc2518/dinglab/scao/db/refseq_hg38_june29";
my $f_opti_config = "/gscmnt/gc2518/dinglab/scao/home/git/neoscan/config.ini";
#my $db_cdna="/gscmnt/gc3027/dinglab/medseq/fasta/human/Homo_sapiens.GRCh37.70.cdna.all.fa";
#my $db_sanger_qs="/gscmnt/gc2523/dinglab/neoantigen/neoantigen-scan/quality_sanger.table.2col.tsv";
my $run_script_path = `dirname $0`;
chomp $run_script_path;
my $run_script_path_perl = "/usr/bin/perl ".$run_script_path."/";
my $run_script_path_python = "/usr/bin/python ".$run_script_path."/";
#my $hold_RM_job = "norm";
my $current_job_file = "";#cannot be empty
my $hold_job_file = "";
my $bsub_com = "";
my $sample_full_path = "";
my $sample_name = "";
opendir(DH, $run_dir) or die "Cannot open dir $run_dir: $!\n";
my @sample_dir_list = readdir DH;
close DH;
if ($step_number < 6) {
#begin to process each sample
for (my $i=0;$i<@sample_dir_list;$i++) {#use the for loop instead. the foreach loop has some problem to pass the global variable $sample_name to the sub functions
$sample_name = $sample_dir_list[$i];
if (!($sample_name =~ /\./ || $sample_name=~/worklog/)) {
$sample_full_path = $run_dir."/".$sample_name;
if (-d $sample_full_path) { # is a full path directory containing a sample
print $yellow, "\nSubmitting jobs for the sample ",$sample_name, "...",$normal, "\n";
$current_job_file="";
if ($step_number == 1) {
&bsub_fa();
}
elsif ($step_number == 2) {
&bsub_pep(1);
} elsif ($step_number == 3) {
&bsub_hla(1);
} elsif ($step_number == 4) {
&bsub_netmhc(1);
}elsif ($step_number == 5) {
&bsub_parsemhc(1);
}
}
}
}
}
if($step_number==6)
{
print "generate the final report\n";
&bsub_final_report();
}
sub bsub_fa{
#my $cdhitReport = $sample_full_path."/".$sample_name.".fa.cdhitReport";
$current_job_file = "j1_fa_".$sample_name.".sh";
#my $IN_sam = $sample_full_path."/".$sample_name.".exome.sam";
my $lsf_out=$lsf_file_dir."/".$current_job_file.".out";
my $lsf_err=$lsf_file_dir."/".$current_job_file.".err";
`rm $lsf_out`;
`rm $lsf_err`;
open(FA, ">$job_files_dir/$current_job_file") or die $!;
print FA "#!/bin/bash\n";
#print FA "#BSUB -n 1\n";
#print FA "#BSUB -R \"rusage[mem=30000]\"","\n";
#print FA "#BSUB -M 30000000\n";
# print FA "#BSUB -o $lsf_file_dir","/","$current_job_file.out\n";
# print FA "#BSUB -e $lsf_file_dir","/","$current_job_file.err\n";
# print FA "#BSUB -q ding-lab\n";
print FA "#BSUB -J $current_job_file\n";
# print FA "#BSUB -w \"$hold_job_file\"","\n";
print FA "f_vcf_indel=".$sample_full_path."/$sample_name.indel.vcf\n";
print FA "f_vcf_snp=".$sample_full_path."/$sample_name.snp.vcf\n";
print FA "f_fa_indel_wt=".$sample_full_path."/$sample_name.indel.vcf.fa-indel-wt.fasta\n";
print FA "f_fa_indel_mut=".$sample_full_path."/$sample_name.indel.vcf.fa-indel-mut.fasta\n";
print FA "f_fa_snv_wt=".$sample_full_path."/$sample_name.snp.vcf.fa-snv-wt.fasta\n";
print FA "f_fa_snv_mut=".$sample_full_path."/$sample_name.snp.vcf.fa-snv-mut.fasta\n";
print FA "f_fa_all=".$sample_full_path."/$sample_name.transcript.fa\n";
print FA 'if [ -s $f_vcf_snp ]',"\n";
print FA "then\n";
print FA " ".$run_script_path_perl."fasta_seq_for_snv_using_refseq_bed.pl $db_ref_bed $h38_fa \${f_vcf_snp}"."\n";
print FA "cat \${f_fa_snv_mut} > \${f_fa_all}","\n";
print FA "fi\n\n";
print FA 'if [ -s $f_vcf_indel ]',"\n";
print FA "then\n";
print FA " ".$run_script_path_perl."fasta_seq_for_indel_using_refseq_bed.pl $db_ref_bed $h38_fa \${f_vcf_indel}"."\n";
print FA "cat \${f_fa_indel_mut} >> \${f_fa_all}","\n";
print FA "fi\n\n";
print FA "";
close FA;
#$bsub_com = "bsub < $job_files_dir/$current_job_file\n";
my $sh_file=$job_files_dir."/".$current_job_file;
$bsub_com = "bsub -q research-hpc -n 1 -R \"select[mem>30000] rusage[mem=30000]\" -M 30000000 -a \'docker(registry.gsc.wustl.edu/genome/genome_perl_environment)\' -o $lsf_out -e $lsf_err sh $sh_file\n";
system ( $bsub_com );
}
##step 2: get peptide sequences for transcript with indel and snv mutations ##
sub bsub_pep{
my ($step_by_step) = @_;
if ($step_by_step) {
$hold_job_file = "";
}
else{
$hold_job_file = $current_job_file;
}
#my $cdhitReport = $sample_full_path."/".$sample_name.".fa.cdhitReport";
$current_job_file = "j2_pep_".$sample_name.".sh";
my $lsf_out=$lsf_file_dir."/".$current_job_file.".out";
my $lsf_err=$lsf_file_dir."/".$current_job_file.".err";
`rm $lsf_out`;
`rm $lsf_err`;
#my $IN_sam = $sample_full_path."/".$sample_name.".exome.sam";
open(PEP, ">$job_files_dir/$current_job_file") or die $!;
print PEP "#!/bin/bash\n";
# print PEP "#BSUB -n 1\n";
# print PEP "#BSUB -R \"rusage[mem=30000]\"","\n";
# print PEP "#BSUB -M 30000000\n";
# print PEP "#BSUB -q ding-lab\n";
# print PEP "#BSUB -o $lsf_file_dir","/","$current_job_file.out\n";
# print PEP "#BSUB -e $lsf_file_dir","/","$current_job_file.err\n";
# print PEP "#BSUB -J $current_job_file\n";
# print PEP "#BSUB -w \"$hold_job_file\"","\n";
print PEP "f_vcf_indel=".$sample_full_path."/$sample_name.indel.vcf\n";
print PEP "f_vcf_snp=".$sample_full_path."/$sample_name.snp.vcf\n";
print PEP "f_pep_indel_wt=".$sample_full_path."/$sample_name.indel.vcf.proteome-indel-wt.fasta\n";
print PEP "f_pep_indel_mut=".$sample_full_path."/$sample_name.indel.vcf.proteome-indel-mut.fasta\n";
print PEP "f_pep_snv_wt=".$sample_full_path."/$sample_name.snp.vcf.proteome-snv-wt.fasta\n";
print PEP "f_pep_snv_mut=".$sample_full_path."/$sample_name.snp.vcf.proteome-snv-mut.fasta\n";
#print PEP "f_pep_all=".$sample_full_path."/$sample_name.pep.fa\n";
print PEP 'if [ -s $f_vcf_snp ]',"\n";
print PEP "then\n";
print PEP " ".$run_script_path_perl."protein_seq_for_snv_using_refseq_bed.pl $db_ref_bed $h38_fa \${f_vcf_snp}"."\n";
#print PEP "cat \${f_pep_snv_mut} > \${f_pep_all}","\n";
print PEP "fi\n\n";
print PEP 'if [ -s $f_vcf_indel ]',"\n";
print PEP "then\n";
print PEP " ".$run_script_path_perl."protein_seq_for_indel_using_refseq_bed.pl $db_ref_bed $h38_fa \${f_vcf_indel}"."\n";
# print PEP "cat \${f_pep_indel_mut} >> \${f_pep_all}","\n";
print PEP "fi\n\n";
print PEP "";
close PEP;
my $sh_file=$job_files_dir."/".$current_job_file;
# $bsub_com = "bsub -q research-hpc -n 1 -R \"select[mem>30000] rusage[mem=30000]\" -M 30000000 -a \'docker(registry.gsc.wustl.edu/genome/genome_perl_environment)\' -w $hold_job_file -o $lsf_out -e $lsf_err sh $sh_file\n";
$bsub_com = "bsub -q research-hpc -n 1 -R \"select[mem>30000] rusage[mem=30000]\" -M 30000000 -a \'docker(registry.gsc.wustl.edu/genome/genome_perl_environment)\' -o $lsf_out -e $lsf_err sh $sh_file\n";
#$bsub_com = "bsub < $job_files_dir/$current_job_file\n";
system ( $bsub_com );
}
##step 3: use bwa to align the hla reference to get HLA genotypet ##
sub bsub_hla{
#my $cdhitReport = $sample_full_path."/".$sample_name.".fa.cdhitReport";
my ($step_by_step) = @_;
if ($step_by_step) {
$hold_job_file = "";
}else{
$hold_job_file = $current_job_file;
}
$current_job_file = "j3_hla_".$sample_name.".sh";
my $lsf_out=$lsf_file_dir."/".$current_job_file.".out";
my $lsf_err=$lsf_file_dir."/".$current_job_file.".err";
`rm $lsf_out`;
`rm $lsf_err`;
my $IN_bam = $sample_full_path."/".$sample_name.".bam";
my $f_fq_1=$sample_full_path."/".$sample_name.".1.fq";
my $f_fq_2=$sample_full_path."/".$sample_name.".2.fq";
# my $HLA_MT_sam=$sample_full_path."/".$sample_name.".rnaseq.mapped.sam";
my $dir_hla=$sample_full_path."/hla";
#if(-d $dir_hla) { `rm $dir_hla`; }
my $f_hla_type=`find $dir_hla -name \'*.tsv\'`;
chomp($f_hla_type);
print $f_hla_type,"\n";
# if(-e $f_hla_type) { print "existing \n"; }
if ((! -e $IN_bam) && ((!-e $f_fq_1) || (! -e $f_fq_2)) && (!-e $f_hla_type)) {#make sure there is a input fasta file
print $red, "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n";
print "Warning: there is no input bam or fq file for bwa:\n";
print "File $IN_bam does not exist!\n";
#last;
#die "Please check command line argument!", $normal, "\n\n";
}
#if (! -s $IN_bam) {#make sure input fasta file is not empty
# print $red, "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&\n";
# die "Warning: Died because $IN_bam is empty!", $normal, "\n\n";
#}
open(HLA, ">$job_files_dir/$current_job_file") or die $!;
# my $f_fq_1=$sample_full_path."/".$sample_name.".1.fq";
# my $f_fq_2=$sample_full_path."/".$sample_name.".2.fq";
print HLA "#!/bin/bash\n";
#print HLA "#BSUB -n 1\n";
#print HLA "#BSUB -R \"rusage[mem=30000]\"","\n";
#print HLA "#BSUB -M 30000000\n";
#print HLA "#BSUB -q ding-lab\n";
#print HLA "#BSUB -w \"$hold_job_file\"","\n";
#print HLA "#BSUB -o $lsf_file_dir","/","$current_job_file.out\n";
#print HLA "#BSUB -e $lsf_file_dir","/","$current_job_file.err\n";
#print HLA "#BSUB -J $current_job_file\n";
print HLA "HLA_IN=".$sample_full_path."/".$sample_name.".bam\n";
print HLA "HLA_sorted=".$sample_full_path."/".$sample_name.".sorted\n";
print HLA "HLA_sorted_bam=".$sample_full_path."/".$sample_name.".sorted.bam\n";
print HLA "HLA_tsv=".$sample_full_path."/HLA_alleles.tsv\n";
print HLA "f_optitype_hla=".$sample_full_path."/hla/notexisting.tsv\n";
# print HLA "dir_hla=".$sample_full_path."/hla\n";
print HLA "if [ $s_bam_fq -eq 1 ]\n";
print HLA "then\n";
print HLA 'if [ -f $IN_bam ]',"\n"; # input file exist
print HLA "then\n";
print HLA "$samtools sort -n \${HLA_IN} \${HLA_sorted}","\n";
print HLA "$samtools view \${HLA_sorted_bam} | perl -ne \'\$l=\$_; \$f_q1=\"$f_fq_1\"; \$f_q2=\"$f_fq_2\"; if(\$first==0) { open(OUT1,\">\$f_q1\"); open(OUT2,\">\$f_q2\"); \$first=1;} \@ss=split(\"\\t\",\$l); \$flag=\$ss[1]; \$cigar=\$ss[5]; if((\$flag & 0x100) || (\$flag & 0x800) || (\$cigar=~/H/)) { next; } \$id=\$ss[0]; \$seq=\$ss[9]; \$q=\$ss[10]; if(\$id=~/\\/1\$/ || (\$flag & 0x40) ) { \$r1=\$id; \$r1=~s/\\/1\$//g; \$seq1=\$seq; \$q1=\$q; } if(\$id=~/\\/2\$/ || (\$flag & 0x80)) { \$r2=\$id; \$r2=~s/\\/2\$//g; \$seq2=\$seq; \$q2=\$q; } if((\$r1 eq \$r2)) { print OUT1 \"\@\",\$r1,\"/1\",\"\\n\"; print OUT1 \$seq1,\"\\n\"; print OUT1 \"+\",\"\\n\"; print OUT1 \$q1,\"\\n\"; print OUT2 \"\@\",\$r1,\"/2\",\"\\n\"; print OUT2 \$seq2,\"\\n\"; print OUT2 \"+\",\"\\n\"; print OUT2 \$q2,\"\\n\";}\'","\n";
print HLA " fi\n";
print HLA "fi\n";
print HLA "if [ -f $f_fq_1 ] && [ -f $f_fq_2 ]","\n"; # input file exist
print HLA "then\n";
print HLA "if [ $s_rna -eq 1 ]\n";
print HLA "then\n";
print HLA "if [ -d $dir_hla ]","\n";
print HLA "then\n";
print HLA "f_optitype_hla=`find $dir_hla -name '*tsv'`","\n";
print HLA "fi\n";
print HLA "if [ -z \${f_optitype_hla} ] || [ ! -f \${f_optitype_hla} ]\n";
print HLA "then\n";
print HLA "if [ -d $dir_hla ]","\n";
print HLA "then\n";
print HLA "rm -rf $dir_hla\n";
print HLA "fi\n";
print HLA "$optitype -i $f_fq_1 $f_fq_2 -c $f_opti_config --rna -v -o $dir_hla"."\n";
# print HLA "done\n";
print HLA "fi\n";
print HLA "else\n";
# print HLA "while [ ! -f \${f_optitype_hla} ]\n";
# print HLA "do\n";
print HLA "if [ ! -f \${f_optitype_hla} ]\n";
print HLA "then\n";
print HLA "if [ -d $dir_hla ]","\n";
print HLA "then\n";
print HLA "rm -rf $dir_hla\n";
print HLA "fi\n";
print HLA "$optitype -i $f_fq_1 $f_fq_2 -c $f_opti_config --dna -v -o $dir_hla"."\n";
# print HLA "done\n";
print HLA " fi\n";
print HLA " fi\n";
#print HLA " ".$run_script_path_perl."parseHLAresult.pl \${f_optitype_hla} \${HLA_tsv}"."\n";
print HLA "if [ -d $dir_hla ]","\n";
print HLA "then\n";
print HLA "f_optitype_hla=`find $dir_hla -name '*tsv'`","\n";
print HLA "fi\n";
### finish hla type, then delete ##
print HLA "if [ ! -z \${f_optitype_hla} ] && [ -f \${f_optitype_hla} ]\n";
print HLA "then\n";
print HLA "rm \${HLA_sorted_bam}","\n";
print HLA "rm $f_fq_1","\n";
print HLA "rm $f_fq_2","\n";
print HLA " fi\n";
print HLA " fi\n";
print HLA "if [ -d $dir_hla ]","\n";
print HLA "then\n";
print HLA "f_optitype_hla=`find $dir_hla -name '*tsv'`","\n";
print HLA "fi\n";
print HLA "if [ ! -z \${f_optitype_hla} ] && [ -f \${f_optitype_hla} ]\n";
print HLA "then\n";
print HLA " ".$run_script_path_perl."parseHLAresult.pl \${f_optitype_hla} \${HLA_tsv}"."\n";
print HLA "fi\n";
close HLA;
my $sh_file=$job_files_dir."/".$current_job_file;
$bsub_com = "bsub -q research-hpc -n 1 -R \"select[mem>200000] rusage[mem=200000]\" -M 200000000 -a \'docker(registry.gsc.wustl.edu/genome/genome_perl_environment)\' -w \"$hold_job_file\" -o $lsf_out -e $lsf_err sh $sh_file\n";
system ( $bsub_com );
}
sub bsub_netmhc{
my ($step_by_step) = @_;
if ($step_by_step) {
$hold_job_file = "";
}else{
$hold_job_file = $current_job_file;
}
#my $cdhitReport = $sample_full_path."/".$sample_name.".fa.cdhitReport";
$current_job_file = "j4_bind_".$sample_name.".sh";
my $lsf_out=$lsf_file_dir."/".$current_job_file.".out";
my $lsf_err=$lsf_file_dir."/".$current_job_file.".err";
`rm $lsf_out`;
`rm $lsf_err`;
#my $IN_sam = $sample_full_path."/".$sample_name.".exome.sam";
open(MHC, ">$job_files_dir/$current_job_file") or die $!;
print MHC "#!/bin/bash\n";
#print MHC "#BSUB -n 1\n";
#print MHC "#BSUB -R \"rusage[mem=30000]\"","\n";
#print MHC "#BSUB -M 30000000\n";
#print MHC "#BSUB -q ding-lab\n";
# print MHC "#BSUB -o $lsf_file_dir","/","$current_job_file.out\n";
# print MHC "#BSUB -e $lsf_file_dir","/","$current_job_file.err\n";
# print MHC "#BSUB -J $current_job_file\n";
# print MHC "#BSUB -w \"$hold_job_file\"","\n";
print MHC "f_pep_indel_wt=".$sample_full_path."/$sample_name.indel.vcf.proteome-indel-wt.fasta\n";
print MHC "f_pep_indel_mut=".$sample_full_path."/$sample_name.indel.vcf.proteome-indel-mut.fasta\n";
print MHC "f_pep_snv_wt=".$sample_full_path."/$sample_name.snp.vcf.proteome-snv-wt.fasta\n";
print MHC "f_pep_snv_mut=".$sample_full_path."/$sample_name.snp.vcf.proteome-snv-mut.fasta\n";
print MHC "f_pep_snv_mut_v1=".$sample_full_path."/$sample_name.snp.vcf.proteome-snv-mut.v1.fasta\n";
print MHC "f_pep_snv_mut_v2=".$sample_full_path."/$sample_name.snp.vcf.proteome-snv-mut.v2.fasta\n";
# print MHC "f_pep=".$sample_full_path."/$sample_name.pep.fa\n";
print MHC "HLA_tsv=".$sample_full_path."/HLA_alleles.tsv\n";
print MHC "f_netMHC_result=".$sample_full_path."/netMHC4.0.out.append.txt\n";
print MHC "f_netMHC_result_snv=".$sample_full_path."/netMHC4.0.out.append.snv.txt\n";
print MHC "f_netMHC_result_indel=".$sample_full_path."/netMHC4.0.out.append.indel.txt\n";
#print MHC "f_out=".$sample_full_path."/result_neoantigen\n";
print MHC " ".$run_script_path_perl."generate_mut_peptide_snv.pl $db_ref_bed \${f_pep_snv_wt} \${f_pep_snv_mut} \${f_pep_snv_mut_v1}\n";
print MHC " ".$run_script_path_perl."remove_duplicate_mut_peptide_snv.pl \${f_pep_snv_mut_v1} \${f_pep_snv_mut_v2}\n";
print MHC " ".$run_script_path_python."runNetMHC4.py -a \${HLA_tsv} -f \${f_pep_snv_mut_v2} -p 8,9,10,11 -o $sample_full_path -n $netMHC -v $f_allele"."\n";
print MHC "mv \${f_netMHC_result} \${f_netMHC_result_snv}\n";
print MHC " ".$run_script_path_python."runNetMHC4.py -a \${HLA_tsv} -f \${f_pep_indel_mut} -p 8,9,10,11 -o $sample_full_path -n $netMHC -v $f_allele"."\n";
print MHC "mv \${f_netMHC_result} \${f_netMHC_result_indel}\n";
### check if netMHC prediction is successfully finished, indel
print MHC 'if [ -f $f_netMHC_result_indel ] ',"\n"; # file exist
print MHC "then\n";
print MHC ' grep "Error" ${f_netMHC_result_indel}',"\n";
print MHC ' CHECK=$?',"\n";
print MHC ' while [ ${CHECK} -eq 0 ] ',"\n"; # grep success, file not finish
print MHC " do\n";
print MHC " ".$run_script_path_python."runNetMHC4.py -a \${HLA_tsv} -f \${f_pep_indel_mut} -p 8,9,10,11 -o $sample_full_path -n $netMHC -v $f_allele"."\n";
print MHC "mv \${f_netMHC_result} \${f_netMHC_result_indel}\n";
print MHC ' grep "Error" ${f_netMHC_result_indel}',"\n";
print MHC ' CHECK=$?',"\n";
print MHC " done\n";
print MHC " fi\n";
### check if netMHC prediction is successfully finished, indel
print MHC 'if [ -f $f_netMHC_result_snv ] ',"\n"; # file exist
print MHC "then\n";
print MHC ' grep "Error" ${f_netMHC_result_snv}',"\n";
print MHC ' CHECK=$?',"\n";
print MHC ' while [ ${CHECK} -eq 0 ] ',"\n"; # grep success, file not finish
print MHC " do\n";
print MHC " ".$run_script_path_python."runNetMHC4.py -a \${HLA_tsv} -f \${f_pep_snv_mut_v2} -p 8,9,10,11 -o $sample_full_path -n $netMHC -v $f_allele"."\n";
print MHC "mv \${f_netMHC_result} \${f_netMHC_result_snv}\n";
print MHC ' grep "Error" ${f_netMHC_result_snv}',"\n";
print MHC ' CHECK=$?',"\n";
print MHC " done\n";
print MHC " fi\n";
close MHC;
my $sh_file=$job_files_dir."/".$current_job_file;
# $bsub_com = "bsub -q research-hpc -n 1 -R \"select[mem>30000] rusage[mem=30000]\" -M 30000000 -a \'docker(registry.gsc.wustl.edu/genome/genome_perl_environment)\' -o $lsf_out -e $lsf_err sh $sh_file\n";
$bsub_com = "LSF_DOCKER_PRESERVE_ENVIRONMENT=false bsub -q research-hpc -n 1 -R \"select[mem>30000] rusage[mem=30000]\" -M 30000000 -a \'docker(scao/dailybox)\' -o $lsf_out -e $lsf_err sh $sh_file\n";
system ( $bsub_com );
}
sub bsub_parsemhc{
my ($step_by_step) = @_;
if ($step_by_step) {
$hold_job_file = "";
}else{
$hold_job_file = $current_job_file;
}
#my $cdhitReport = $sample_full_path."/".$sample_name.".fa.cdhitReport";
$current_job_file = "j5_parsebind_".$sample_name.".sh";
my $lsf_out=$lsf_file_dir."/".$current_job_file.".out";
my $lsf_err=$lsf_file_dir."/".$current_job_file.".err";
`rm $lsf_out`;
`rm $lsf_err`;
#my $IN_sam = $sample_full_path."/".$sample_name.".exome.sam";
open(PMHC, ">$job_files_dir/$current_job_file") or die $!;
print PMHC "#!/bin/bash\n";
# print PMHC "#BSUB -n 1\n";
# print PMHC "#BSUB -R \"rusage[mem=30000]\"","\n";
# print PMHC "#BSUB -M 30000000\n";
# print PMHC "#BSUB -q ding-lab\n";
# print PMHC "#BSUB -o $lsf_file_dir","/","$current_job_file.out\n";
# print PMHC "#BSUB -e $lsf_file_dir","/","$current_job_file.err\n";
# print PMHC "#BSUB -J $current_job_file\n";
# print PMHC "#BSUB -w \"$hold_job_file\"","\n";
print PMHC "f_indel=".$sample_full_path."/$sample_name.indel.vcf\n";
print PMHC "f_snv=".$sample_full_path."/$sample_name.snp.vcf\n";
print PMHC "f_indel_wt_fa=".$sample_full_path."/$sample_name.indel.vcf.proteome-indel-wt.fasta\n";
print PMHC "f_snv_wt_fa=".$sample_full_path."/$sample_name.snp.vcf.proteome-snv-wt.fasta\n";
print PMHC "f_indel_mut_fa=".$sample_full_path."/$sample_name.indel.vcf.proteome-indel-mut.fasta\n";
print PMHC "f_snv_mut_fa=".$sample_full_path."/$sample_name.snp.vcf.proteome-snv-mut.fasta\n";
print PMHC "f_netMHC_result_snv=".$sample_full_path."/netMHC4.0.out.append.snv.txt\n";
print PMHC "f_netMHC_result_indel=".$sample_full_path."/netMHC4.0.out.append.indel.txt\n";
print PMHC "f_snv_out=".$sample_full_path."/$sample_name.neoantigen.snv.tsv\n";
print PMHC "f_indel_out=".$sample_full_path."/$sample_name.neoantigen.indel.tsv\n";
print PMHC "f_snv_sum=".$sample_full_path."/$sample_name.neo.snv.summary\n";
print PMHC "f_indel_sum=".$sample_full_path."/$sample_name.neo.indel.summary\n";
# print PMHC "f_min=".$sample_full_path."/$sample_name.neo.summary.min\n";
print PMHC " ".$run_script_path_perl."parseNetMHC4result.pl \${f_netMHC_result_snv} \${f_indel_wt_fa} \${f_snv_wt_fa} \${f_snv_out}"."\n";
print PMHC " ".$run_script_path_perl."reportSummary.pl \${f_snv_out} \${f_indel} \${f_snv} \${f_indel_mut_fa} \${f_snv_mut_fa} \${f_snv_sum}"."\n";
print PMHC " ".$run_script_path_perl."parseNetMHC4result.pl \${f_netMHC_result_indel} \${f_indel_wt_fa} \${f_snv_wt_fa} \${f_indel_out}"."\n";
print PMHC " ".$run_script_path_perl."reportSummary.pl \${f_indel_out} \${f_indel} \${f_snv} \${f_indel_mut_fa} \${f_snv_mut_fa} \${f_indel_sum}"."\n";
close PMHC;
my $sh_file=$job_files_dir."/".$current_job_file;
$bsub_com = "bsub -q research-hpc -n 1 -R \"select[mem>30000] rusage[mem=30000]\" -M 30000000 -a \'docker(registry.gsc.wustl.edu/genome/genome_perl_environment)\' -w \"$hold_job_file\" -o $lsf_out -e $lsf_err sh $sh_file\n";
system ( $bsub_com );
}
sub bsub_final_report()
{
my ($step_by_step) = @_;
if ($step_by_step) {
$hold_job_file = "";
}else{
$hold_job_file = $current_job_file;
}
#my $cdhitReport = $sample_full_path."/".$sample_name.".fa.cdhitReport";
$current_job_file = "j6_final_report_".$working_name.".sh";
#my $IN_sam = $sample_full_path."/".$sample_name.".exome.sam";
my $lsf_out=$lsf_file_dir."/".$current_job_file.".out";
my $lsf_err=$lsf_file_dir."/".$current_job_file.".err";
`rm $lsf_out`;
`rm $lsf_err`;
open(REP, ">$job_files_dir/$current_job_file") or die $!;
print REP "#!/bin/bash\n";
#print REP "#BSUB -n 1\n";
#print REP "#BSUB -R \"rusage[mem=30000]\"","\n";
#print REP "#BSUB -M 30000000\n";
#print REP "#BSUB -o $lsf_file_dir","/","$current_job_file.out\n";
#print REP "#BSUB -e $lsf_file_dir","/","$current_job_file.err\n";
#print REP "#BSUB -q ding-lab\n";
#print REP "#BSUB -J $current_job_file\n";
#print REP "#BSUB -w \"$hold_job_file\"","\n";
print REP " ".$run_script_path_perl."generate_report_summary_2.pl $run_dir"."\n";
close REP;
#$bsub_com = "bsub < $job_files_dir/$current_job_file\n";
#system ( $bsub_com );
my $sh_file=$job_files_dir."/".$current_job_file;
# $bsub_com = "bsub -q research-hpc -n 1 -R \"select[mem>30000] rusage[mem=30000]\" -M 30000000 -a \'docker(registry.gsc.wustl.edu/genome/genome_perl_environment)\' -w $hold_job_file -o $lsf_out -e $lsf_err sh $sh_file\n";
$bsub_com = "bsub -q research-hpc -n 1 -R \"select[mem>30000] rusage[mem=30000]\" -M 30000000 -a \'docker(registry.gsc.wustl.edu/genome/genome_perl_environment)\' -w \"$hold_job_file\" -o $lsf_out -e $lsf_err sh $sh_file\n";
#$bsub_com = "bsub < $job_files_dir/$current_job_file\n";
system ( $bsub_com );
}