-
Notifications
You must be signed in to change notification settings - Fork 2
/
achab_exportJSON2.pl
1927 lines (1318 loc) · 60 KB
/
achab_exportJSON2.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
##### achab.pl ####
# Author : Thomas Guignard 2018
# Description :
# Create an User friendly Excel file from an MPA annotated VCF file.
use strict;
use warnings;
use Getopt::Long;
use Excel::Writer::XLSX;
use Switch;
#use Pod::Usage;
#use List::Util qw(first);
#use Data::Dumper;
#parameters
my $man = "USAGE : \nperl achab.pl
\n--vcf <vcf_file>
\n--outDir <output directory (default = current dir)>
\n--outPrefix <output file prelifx (default = \"\")>
\n--candidates <file with gene symbol of interest>
\n--phenolyzerFile <phenolyzer output file suffixed by predicted_gene_scores>
\n--popFreqThr <allelic frequency threshold from 0 to 1 default=0.01>
\n--trio (requires case dad and mum option to be filled)
\n\t--case <index_sample_name>
\n\t--dad <father_sample_name>
\n\t--mum <mother_sample_name>
\n--customInfoList <comma separated list of vcf-info names (will be added in a new column)>
\n--filterList <comma separated list of VCF FILTER to output (default='PASS', included )>
\n--cnvGeneList <File with gene symbol + annotation (1 tab separated), involved by parallel CNV calling >
\n--customVCF <VCF format File with custom annotation (if variant matches then INFO field annotations will be added in new column)>
\n--mozaicRate <mozaic rate value from 0 to 1, it will color 0/1 genotype according to this value (default=0.2 as 20%)>
\n--mozaicDP <ALT variant Depth, number of read supporting ALT, it will give darker color to the 0/1 genotype (default=5)>
\n--newHope (only popFreqThr filter is applied (no more FILTER or MPA_ranking))>;
\n--JSON (output to JSON file format)";
#\n--newHope (output only NON PASS or MPA_rank = 8 variants, default=output FILTER=PASS and MPAranking < 8 variants )>";
my $help;
my $current_line;
my $incfile = "";
my $outDir = ".";
my $outPrefix = "";
my $case = "";
my $mum = "";
my $dad = "";
my $caller = "";
my $trio;
my $popFreqThr = "";
my $filterList = "";
my @filterArray;
my $newHope;
my $sampleNames = "";
my @sampleList;
my $customInfoList = "";
my @custInfList;
my $mozaicRate = "" ;
my $mozaicDP = "";
my $JSONarg;
#stuff for files
my $candidates = "";
my %candidateGene;
my $candidates_line;
my $phenolyzerFile = "";
my $phenolyzer_Line;
my @phenolyzer_List;
my %phenolyzerGene;
my $cnvGeneList = "";
my %cnvGene;
my $cnvGene_Line;
my @cnvGene_List;
my $customVCF_File = "";
my $customVCF_Line;
my @customVCF_List;
my %customVCF_variant;
#vcf parsing and output
my @line;
my $variantID;
my @geneListTemp;
my @geneList;
my $mozaicSamples = "";
my $count = 0;
my @finalSortData;
my $familyGenotype;
my %hashFinalSortData;
#JSON export
my %hashMetaJSON;
my %hashVariantJSON;
#$arguments = GetOptions( "vcf=s" => \$incfile ) or pod2usage(-vcf => "$0: argument required\n") ;
GetOptions( "vcf=s" => \$incfile,
"case=s" => \$case,
"dad=s" => \$dad,
"mum=s" => \$mum,
"trio" => \$trio,
"candidates:s" => \$candidates,
"outDir=s" => \$outDir,
"outPrefix:s" => \$outPrefix,
"phenolyzerFile:s" => \$phenolyzerFile,
"popFreqThr=s" => \$popFreqThr,
"customInfoList:s" => \$customInfoList,
"filterList:s" => \$filterList,
"cnvGeneList:s" => \$cnvGeneList,
"customVCF:s" => \$customVCF_File,
"mozaicRate:s" => \$mozaicRate,
"mozaicDP:s" => \$mozaicDP,
"newHope" => \$newHope,
"JSON" => \$JSONarg,
"help|h" => \$help);
#check mandatory arguments
if(defined $help || $incfile eq ""){
die("$man");
}
#add underscore to output prefix
if($outPrefix ne ""){
$outPrefix .= "_";
}
#define popFreqThr
if( $popFreqThr eq ""){
$popFreqThr = 0.01;
}
#define filter List
if($filterList ne ""){
@filterArray = split(/,/ , $filterList)
}
#default filter is PASS
unshift @filterArray, "PASS";
#check mozaic parameters
if($mozaicRate eq ""){
$mozaicRate = 0.2;
}
if($mozaicDP eq ""){
$mozaicDP = 5;
}
#check sample list param
if(defined $trio && ($case eq "" || $dad eq "" || $mum eq "")){
die("TRIO option requires 3 sample names. Please, give --case, --dad and --mum sample name arguments.\n");
}
print STDERR "Starting a new fishing trip ... \n" ;
print STDERR "Processing vcf file ... \n" ;
open( VCF , "<$incfile" )or die("Cannot open vcf file $incfile") ;
#TODO check if header contains required INFO
#Parse VCF header to fill the dictionnary of parameters
print STDERR "Parsing VCF header in order to get sample names and to check if required informations are present ... \n";
my %dicoParam;
%hashMetaJSON = {'meta'=>{ 'created'=>0,
'caller'=>0,
'fields'=>0,
'samples'=>0,
'sets'=>0}};
while( <VCF> ){
$current_line = $_;
chomp $current_line;
#filling dicoParam with VCF header INFO and FORMAT
if ($current_line=~/^##/){
unless ($current_line=~/Description=/){ next }
#DEBUG print STDERR "Header line\n";
if ($current_line =~ /ID=(.+?),.*?Description="(.+?)"/){
$dicoParam{$1}= $2;
#DEBUG print STDERR "info : ". $1 . "\tdescription: ". $2."\n";
push @hashMetaJSON{'fields'}, {'name'=> $1, 'description'=> $2, 'visible'=> 'true','index'=>1} ;
next;
}else {print STDERR "pattern not found in this line: ".$current_line ."\n";next}
}elsif($current_line=~/^#CHROM/){
#check sample names or die
if (defined $trio){
#check if case sample name is found
unless ($current_line=~/\Q$case/){die("$case is not found as a sample in the VCF, please check case name.\n$current_line\n")}
unless ($current_line=~/\Q$dad/){die("$dad is not found as a sample in the VCF, please check dad name.\n$current_line\n")}
unless ($current_line=~/\Q$mum/){die("$mum is not found as a sample in the VCF, please check mum name.\n$current_line\n")}
}
@line = split (/\t/ , $current_line);
for( my $sampleIndex = 9 ; $sampleIndex < scalar @line; $sampleIndex++){
print STDERR "Found Sample ".$line[$sampleIndex]."\n";
push @sampleList, $line[$sampleIndex];
#for each final position for sample
# foreach my $finCol (keys %dicoSamples){
#DEBUG
# if ($dicoSamples{$finCol}{'columnName'} eq "Genotype-".$line[$sampleIndex] ){
# $dicoSamples{$finCol}{'columnIndex'} = $sampleIndex;
# last;
# }
# }
# foreach my $name (@sampleList)
#if($line[$sampleIndex]
}
if($case eq ""){
$case = $sampleList[0];
}
#exclude to treat trio with too much sample
print STDERR "\nTotal Samples : ".scalar @sampleList."\n";
if(scalar @sampleList > 3 && defined $trio){
die("Found more than 3 samples. TRIO analysis is not supported with more than 3 samples.\n");
}
}else {last}
}
close(VCF);
# Create a new Excel workbook
#
my $workbook;
if ($outDir eq "." || -d $outDir) {
if(defined $newHope){
# Create a "new hope Excel" aka NON-PASS + MPA_RANKING=8 variants
$workbook = Excel::Writer::XLSX->new( $outDir."/".$outPrefix."achab_catch_newHope.xlsx" );
}else{
$workbook = Excel::Writer::XLSX->new( $outDir."/".$outPrefix."achab_catch.xlsx" );
}
}else {
die("No directory $outDir");
}
#create default color background when pLI values are absent
my $format_pLI = $workbook->add_format(bg_color => '#FFFFFF');
my $format_mozaic = $workbook->add_format(bg_color => 'purple');
#$format_pLI -> set_pattern();
# Add all worksheets
my $worksheet = $workbook->add_worksheet('ALL_'.$popFreqThr);
$worksheet->freeze_panes( 1, 0 ); # Freeze the first row
my $worksheetLine = 0;
my $worksheetACMG = $workbook->add_worksheet('DS_ACMG');
$worksheetACMG->freeze_panes( 1, 0 ); # Freeze the first row
my $worksheetLineACMG = 0;
#Worksheets initialization
my $worksheetHTZcompo;
my $worksheetAR;
my $worksheetSNPmumVsCNVdad ;
my $worksheetSNPdadVsCNVmum;
my $worksheetDENOVO;
my $worksheetCandidats;
#my $worksheetDELHMZ;
my $worksheetLineHTZcompo ;
my $worksheetLineAR ;
my $worksheetLineSNPmumVsCNVdad ;
my $worksheetLineSNPdadVsCNVmum ;
my $worksheetLineDENOVO ;
my $worksheetLineCandidats;
#my $worksheetLineDELHMZ;
#create additionnal sheet in trio analysis
if (defined $trio){
$worksheetHTZcompo = $workbook->add_worksheet('HTZ_compo');
$worksheetLineHTZcompo = 0;
$worksheetHTZcompo->freeze_panes( 1, 0 ); # Freeze the first row
$worksheetAR = $workbook->add_worksheet('AR');
$worksheetLineAR = 0;
$worksheetAR->freeze_panes( 1, 0 ); # Freeze the first row
$worksheetSNPmumVsCNVdad = $workbook->add_worksheet('SNVmumVsCNVdad');
$worksheetLineSNPmumVsCNVdad = 0;
$worksheetSNPmumVsCNVdad->freeze_panes( 1, 0 ); # Freeze the first row
$worksheetSNPdadVsCNVmum = $workbook->add_worksheet('SNVdadVsCNVmum');
$worksheetLineSNPdadVsCNVmum = 0;
$worksheetSNPdadVsCNVmum->freeze_panes( 1, 0 ); # Freeze the first row
$worksheetDENOVO = $workbook->add_worksheet('DENOVO');
$worksheetLineDENOVO = 0;
$worksheetDENOVO->freeze_panes( 1, 0 ); # Freeze the first row
#$worksheetDELHMZ = $workbook->add_worksheet('DEL_HMZ');
#$worksheetLineDELHMZ = 0;
#$worksheetDELHMZ->freeze_panes( 1, 0 ); # Freeze the first row
#$worksheetDELHMZ->autofilter('A1:AN1000'); # Add autofilter
}
#get data from phenolyzer output (predicted_gene_score)
my $current_gene= "";
my $maxLine=0;
if($phenolyzerFile ne ""){
open(PHENO , "<$phenolyzerFile") or die("Cannot open phenolyzer file ".$phenolyzerFile) ;
print STDERR "Processing phenolyzer file ... \n" ;
while( <PHENO> ){
next if($_ =~/^Tuple number/);
$phenolyzer_Line = $_;
chomp $phenolyzer_Line;
if($phenolyzer_Line=~/ID:/){
#should write it for previous gene, not the current one $phenolyzerGene{$current_gene}{'comment'} = $maxLine." lines of features.\n";
@phenolyzer_List = split( /\t/, $phenolyzer_Line);
$current_gene = $phenolyzer_List[0];
$phenolyzerGene{$current_gene}{'Raw'}= $phenolyzer_List[2];
$phenolyzerGene{$current_gene}{'comment'}= $phenolyzer_List[1]."\n".$phenolyzer_List[3]."\n";
$phenolyzerGene{$current_gene}{'normalized'}= $phenolyzer_List[3];
$maxLine=0;
}else{
#keep only OMIM or count nbr of lines
$maxLine+=1;
}
}
close(PHENO);
}
if($customVCF_File ne ""){
open(CUSTOMVCF , "<$customVCF_File") or die("Cannot open phenolyzer file ".$customVCF_File) ;
print STDERR "Processing custom VCF file ... \n" ;
while( <CUSTOMVCF> ){
$customVCF_Line = $_;
#############################################
############## skip header
next if ($customVCF_Line=~/^#/);
chomp $customVCF_Line;
@customVCF_List = split( /\t/, $customVCF_Line );
#replace "spaces" by "_"
$customVCF_List[7] =~ s/ /_/g;
#build variant key as CHROM_POS_REF_ALT
if (defined $customVCF_variant{$customVCF_List[0]."_".$customVCF_List[1]."_".$customVCF_List[3]."_".$customVCF_List[4]}){
$customVCF_variant{$customVCF_List[0]."_".$customVCF_List[1]."_".$customVCF_List[3]."_".$customVCF_List[4]} .= ";".$customVCF_List[7];
}else{
$customVCF_variant{$customVCF_List[0]."_".$customVCF_List[1]."_".$customVCF_List[3]."_".$customVCF_List[4]} = $customVCF_List[7];
}
}
}
#create sheet for candidats
if($candidates ne ""){
open( CANDIDATS , "<$candidates")or die("Cannot open candidates file ".$candidates) ;
print STDERR "Processing candidates file ... \n" ;
while( <CANDIDATS> ){
$candidates_line = $_;
chomp $candidates_line;
$candidateGene{$candidates_line} = 1;
}
close(CANDIDATS);
$worksheetCandidats = $workbook->add_worksheet('Candidats');
$worksheetCandidats->freeze_panes( 1, 0 ); # Freeze the first row
}
#get gene involved in CNV
if ($cnvGeneList ne ""){
open( CNVGENES , "<$cnvGeneList")or die("Cannot open cnvGeneList file ".$cnvGeneList) ;
print STDERR "Processing CNV Gene file ... \n" ;
while( <CNVGENES> ){
$cnvGene_Line = $_;
chomp $cnvGene_Line;
@cnvGene_List = split( /\t/, $cnvGene_Line);
$current_gene = $cnvGene_List[0];
if (defined $cnvGene{$current_gene}){
#nothing to do
}else{
$cnvGene{$current_gene} = "CNV : ".$current_gene;
}
if(defined $cnvGene_List[1]){
$cnvGene{$current_gene} .= " => ".$cnvGene_List[1].";";
chomp $cnvGene{$current_gene};
}
}
close(CNVGENES);
}
#Hash of ACMG incidentalome genes
my %ACMGgene = ("ACTA2" =>1,"ACTC1" =>1,"APC" =>1,"APOB" =>1,"ATP7B" =>1,"BMPR1A" =>1,"BRCA1" =>1,"BRCA2" =>1,"CACNA1S" =>1,"COL3A1" =>1,"DSC2" =>1,"DSG2" =>1,"DSP" =>1,"FBN1" =>1,"GLA" =>1,"KCNH2" =>1,"KCNQ1" =>1,"LDLR" =>1,"LMNA" =>1,"MEN1" =>1,"MLH1" =>1,"MSH2" =>1,"MSH6" =>1,"MUTYH" =>1,"MYBPC3" =>1,"MYH11" =>1,"MYH7" =>1,"MYL2" =>1,"MYL3" =>1,"NF2" =>1,"OTC" =>1,"PCSK9" =>1,"PKP2" =>1,"PMS2" =>1,"PRKAG2" =>1,"PTEN" =>1,"RB1" =>1,"RET" =>1,"RYR1" =>1,"RYR2" =>1,"SCN5A" =>1,"SDHAF2" =>1,"SDHB" =>1,"SDHC" =>1,"SDHD" =>1,"SMAD3" =>1,"SMAD4" =>1,"STK11" =>1,"TGFBR1" =>1,"TGFBR2" =>1,"TMEM43" =>1,"TNNI3" =>1,"TNNT2" =>1,"TP53" =>1,"TPM1" =>1,"TSC1" =>1,"TSC2" =>1,"VHL" =>1,"WT1"=>1);
#counter for shifting columns according to nbr of sample
my $cmpt = scalar @sampleList;
#dico for sample sorting (index / dad / mum / control)
my %dicoSamples ;
#
my %dicoColumnNbr;
$dicoColumnNbr{'MPA_ranking'}= 0; #+ comment MPA scores and related scores
$dicoColumnNbr{'MPA_impact'}= 1; #+ comment MPA scores and related scores
$dicoColumnNbr{'Phenolyzer'}= 2; #Phenolyzer raw score + comment Normalized score
$dicoColumnNbr{'Gene.refGene'}= 3; #Gene Name + comment pLi / Function_description / tissue specificity
$dicoColumnNbr{'Phenotypes.refGene'}= 4; #OMIM + comment Disease_description
$dicoColumnNbr{'gnomAD_genome_ALL'}= 5; #Pop Freq + comment ethny
$dicoColumnNbr{'gnomAD_exome_ALL'}= 6; #as well
$dicoColumnNbr{'CLNSIG'}= 7; #CLinvar
$dicoColumnNbr{'InterVar_automated'}= 8; #+ comment ACMG status
$dicoColumnNbr{'SecondHit-CNV'}= 9; #TODO
$dicoColumnNbr{'Func.refGene'}= 10; # + comment ExonicFunc / AAChange / GeneDetail
if (defined $trio){
$dicoColumnNbr{'Genotype-'.$case}= 11;
$dicoColumnNbr{'Genotype-'.$dad}= 12;
$dicoColumnNbr{'Genotype-'.$mum}= 13;
$dicoSamples{1}{'columnName'} = 'Genotype-'.$case ;
$dicoSamples{2}{'columnName'} = 'Genotype-'.$dad ;
$dicoSamples{3}{'columnName'} = 'Genotype-'.$mum ;
}else{
for( my $i = 0 ; $i < scalar @sampleList; $i++){
$dicoColumnNbr{'Genotype-'.$sampleList[$i]}= 11+$i; # + comment qual / caller / DP AD AB
$dicoSamples{$i+1}{'columnName'} = 'Genotype-'.$sampleList[$i] ;
}
}
$dicoColumnNbr{'#CHROM'}= 11+$cmpt ;
$dicoColumnNbr{'POS'}= 12+$cmpt ;
$dicoColumnNbr{'ID'}= 13+$cmpt ;
$dicoColumnNbr{'REF'}= 14+$cmpt ;
$dicoColumnNbr{'ALT'}= 15+$cmpt ;
$dicoColumnNbr{'FILTER'}= 16+$cmpt ;
#Add custom Info in additionnal columns
my $lastColumn = 17+$cmpt;
if($customInfoList ne ""){
chomp $customInfoList;
@custInfList = split(/,/, $customInfoList);
foreach my $customInfo (@custInfList){
$dicoColumnNbr{$customInfo} = $lastColumn ;
$lastColumn++;
}
}
#custom VCF in last position
if($customVCF_File ne ""){
$dicoColumnNbr{'customVCFannotation'} = $lastColumn ;
$lastColumn++;
}
#Define column title order
my @columnTitles;
foreach my $key (sort { $dicoColumnNbr{$a} <=> $dicoColumnNbr{$b} } keys %dicoColumnNbr) {
push @columnTitles, $key;
#DEBUG print STDERR $key."\n";
}
#final strings for comment
my $commentGenotype;
my $commentMPAscore;
my $commentGnomADExomeScore;
my $commentGnomADGenomeScore;
my $commentInterVar;
my $commentFunc;
my $commentPhenotype;
my $commentClinvar;
#define sorted arrays with score for comment
my @CommentMPA_score = ("MPA_ranking",
"MPA_final_score",
"MPA_impact",
"MPA_adjusted",
"MPA_available",
"MPA_deleterious",
"\n--- SPLICE ---",
'dbscSNV_ADA_SCORE',
'dbscSNV_RF_SCORE',
'spliceai_filtered',
#'DS_AG',
#'DS_AL',
#'DS_DG',
#'DS_DL',
"\n--- MISSENSE ---",
'LRT_pred',
'SIFT_pred',
'FATHMM_pred',
'MetaLR_pred',
'MetaSVM_pred',
'PROVEAN_pred',
'Polyphen2_HDIV_pred',
'Polyphen2_HVAR_pred',
'MutationTaster_pred',
'fathmm-MKL_coding_pred');
my $pLI_Comment = "pLI - the probability of being loss-of-function intolerant (intolerant of both heterozygous and homozygous lof variants)\npRec - the probability of being intolerant of homozygous, but not heterozygous lof variants\npNull - the probability of being tolerant of both heterozygous and homozygous lof variants";
my @CommentGnomadGenome = ('gnomAD_genome_ALL',
'gnomAD_genome_AFR',
'gnomAD_genome_AMR',
'gnomAD_genome_ASJ',
'gnomAD_genome_EAS',
'gnomAD_genome_FIN',
'gnomAD_genome_NFE',
'gnomAD_genome_OTH');
my @CommentGnomadExome = ('gnomAD_exome_ALL',
'gnomAD_exome_AFR',
'gnomAD_exome_AMR',
'gnomAD_exome_ASJ',
'gnomAD_exome_EAS',
'gnomAD_exome_FIN',
'gnomAD_exome_NFE',
'gnomAD_exome_OTH');
my %CommentInterVar = (
'PVS1' => "Certain types of variants (e.g., nonsense, frameshift, canonical +- 1 or 2 splice sites, initiation codon, single exon or multiexon deletion) in a gene where LOF is a known mechanism of diseas",
'PS1' => "Same amino acid change as a previously established pathogenic variant regardless of nucleotide change
Example: Val->Leu caused by either G>C or G>T in the same codon",
'PS2' => "De novo (both maternity and paternity confirmed) in a patient with the disease and no family history",
'PS3' => "Well-established in vitro or in vivo functional studies supportive of a damaging effect on the gene or gene product",
'PS4' => "The prevalence of the variant in affected individuals is significantly increased compared with the prevalence in controls; OR>5 in all the gwas, the dataset is from gwasdb jjwanglab.org/gwasdb",
'PM1' => "Located in a mutational hot spot and/or critical and well-established functional domain (e.g., active site of an enzyme) without benign variation",
'PM2' => "Absent from controls (or at extremely low frequency if recessive) (Table 6) in Exome Sequencing Project, 1000 Genomes Project, or Exome Aggregation Consortium",
'PM3' => "For recessive disorders, detected in trans with a pathogenic variant",
'PM4' => "Protein length changes as a result of in-frame deletions/insertions in a nonrepeat region or stop-loss variants",
'PM5' => "Novel missense change at an amino acid residue where a different missense change determined to be pathogenic has been seen before;Example: Arg156His is pathogenic; now you observe Arg156Cys",
'PM6' => "Assumed de novo, but without confirmation of paternity and maternity",
'PP1' => "Cosegregation with disease in multiple affected family members in a gene definitively known to cause the disease",
'PP2' => "Missense variant in a gene that has a low rate of benign missense variation and in which missense variants are a common mechanism of disease",
'PP3' => "Multiple lines of computational evidence support a deleterious effect on the gene or gene product (conservation, evolutionary, splicing impact, etc.) sfit for conservation, GERP++_RS for evolutionary, splicing impact from dbNSFP",
'PP4' => "Patient's phenotype or family history is highly specific for a disease with a single genetic etiology",
'PP5' => "Reputable source recently reports variant as pathogenic, but the evidence is not available to the laboratory to perform an independent evaluation",
'BA1' => "BA1 Allele frequency is >5% in Exome Sequencing Project, 1000 Genomes Project, or Exome Aggregation Consortium",
'BS1' => "Allele frequency is greater than expected for disorder (see Table 6) > 1% in ESP6500all ExAc? need to check more",
'BS2' => "Observed in a healthy adult individual for a recessive (homozygous), dominant (heterozygous), or X-linked (hemizygous) disorder, with full penetrance expected at an early age, check ExAC_ALL",
'BS3' => "Well-established in vitro or in vivo functional studies show no damaging effect on protein function or splicing",
'BS4' => "Lack of segregation in affected members of a family",
'BP1' => "Missense variant in a gene for which primarily truncating variants are known to cause disease truncating: stop_gain / frameshift deletion/ nonframshift deletion
We defined Protein truncating variants (4) (table S1) as single-nucleotide variants (SNVs) predicted to introduce a premature stop codon or to disrupt a splice site, small insertions or deletions (indels) predicted to disrupt a transcript reading frame, and larger deletions ",
'BP2' => "Observed in trans with a pathogenic variant for a fully penetrant dominant gene/disorder or observed in cis with a pathogenic variant in any inheritance pattern",
'BP3' => "In-frame deletions/insertions in a repetitive region without a known function if the repetitive region is in the domain, this BP3 should not be applied.",
'BP4' => "Multiple lines of computational evidence suggest no impact on gene or gene product (conservation, evolutionary,splicing impact, etc.)",
'BP5' => "Variant found in a case with an alternate molecular basis for disease.
check the genes whether are for mutilfactor disorder. The reviewers suggeset to disable the OMIM morbidmap for BP5",
'BP6' => "Reputable source recently reports variant as benign, but the evidence is not available to the laboratory to perform an independent evaluation; Check the ClinVar column to see whether this is \"benign\".",
'BP7' => "A synonymous (silent) variant for which splicing prediction algorithms predict no impact to the
splice consensus sequence nor the creation of a new splice site AND the nucleotide is not highly conserved"
);
my @CommentFunc = ( 'ExonicFunc.refGene',
'AAChange.refGene',
'GeneDetail.refGene');
my @CommentPhenotype = ( 'Disease_description.refGene');
my @CommentClinvar = ( 'CLNREVSTAT',
'CLNDN',
'CLNALLELEID',
'CLNDISDB');
#########FILLING COLUMN TITLES FOR SHEETS
$worksheet->write_row( 0, 0, \@columnTitles );
$worksheetACMG->write_row( 0, 0, \@columnTitles );
#write comment for pLI
$worksheet->write_comment( 0, $dicoColumnNbr{'Gene.refGene'}, $pLI_Comment, x_scale => 3 );
$worksheetACMG->write_comment( 0, $dicoColumnNbr{'Gene.refGene'}, $pLI_Comment, x_scale => 3 );
#FILLING COLUMN TITLES FOR TRIO SHEETS
if (defined $trio){
$worksheetHTZcompo->write_row( 0, 0, \@columnTitles );
$worksheetAR->write_row( 0, 0, \@columnTitles );
$worksheetSNPmumVsCNVdad->write_row( 0, 0, \@columnTitles );
$worksheetSNPdadVsCNVmum->write_row( 0, 0, \@columnTitles );
$worksheetDENOVO->write_row( 0, 0, \@columnTitles );
#write pLI comment
$worksheetHTZcompo->write_comment(0,$dicoColumnNbr{'Gene.refGene'}, $pLI_Comment, x_scale => 3);
$worksheetAR->write_comment(0, $dicoColumnNbr{'Gene.refGene'}, $pLI_Comment, x_scale => 3);
$worksheetSNPmumVsCNVdad->write_comment(0, $dicoColumnNbr{'Gene.refGene'}, $pLI_Comment, x_scale => 3);
$worksheetSNPdadVsCNVmum->write_comment(0, $dicoColumnNbr{'Gene.refGene'}, $pLI_Comment, x_scale => 3);
$worksheetDENOVO->write_comment( 0, $dicoColumnNbr{'Gene.refGene'}, $pLI_Comment, x_scale => 3);
}
#FILLING COLUMN TITLES FOR CANDIDATES SHEET
if($candidates ne ""){
$worksheetCandidats->write_row( 0, 0, \@columnTitles );
$worksheetCandidats->write_comment(0, $dicoColumnNbr{'Gene.refGene'}, $pLI_Comment, x_scale => 3 );
}
####################################################################
#
#
#
#
my %dicoGeneForHTZcompo;
my $previousGene ="";
my $filterBool;
$dicoGeneForHTZcompo{$previousGene}{'ok'}=0;
$dicoGeneForHTZcompo{$previousGene}{'cnt'}=0;
#############################################
################## Start parsing VCF
open( VCF , "<$incfile" )or die("Cannot open vcf file ".$incfile) ;
while( <VCF> ){
$current_line = $_;
$count++;
#############################################
############## skip header
next if ($current_line=~/^##/);
chomp $current_line;
@line = split( /\t/, $current_line );
#DEBUG print STDERR $dicoColumnNbr{'Gene.refGene'}."\n";
#############################################
############## Treatment for First line to create header of the output
if ( $line[0] eq "#CHROM" ) {
#############CHECK IF $nbrSample == $cmpt else exit error nbr sample
#find correct index for samples of the family
#for each sample position
for( my $sampleIndex = 9 ; $sampleIndex < scalar @line; $sampleIndex++){
#for each final position for sample
foreach my $finCol (keys %dicoSamples){
#DEBUG
if ($dicoSamples{$finCol}{'columnName'} eq "Genotype-".$line[$sampleIndex] ){
$dicoSamples{$finCol}{'columnIndex'} = $sampleIndex;
last;
}
}
# foreach my $name (@sampleList)
#if($line[$sampleIndex]
}
######### Increase row number
$worksheetLine ++;
$worksheetLineACMG ++;
if (defined $trio){
$worksheetLineHTZcompo ++;
$worksheetLineHTZcompo ++;
$worksheetLineAR ++;
$worksheetLineSNPmumVsCNVdad ++;
$worksheetLineSNPdadVsCNVmum ++;
$worksheetLineDENOVO ++;
}
if($candidates ne ""){
$worksheetLineCandidats ++;
}
next;
#############################################
##############################
########## start to compute variant lines
}else {
#initialise final printable string
@finalSortData = ("");
$mozaicSamples = "";
my $alt="";
my $ref="";
#Split line with tab
#DEBUG print $current_line,"\n";
#filling output line with classical first vcf columns
$finalSortData[$dicoColumnNbr{'#CHROM'}]= $line[0];
$finalSortData[$dicoColumnNbr{'POS'}]= $line[1];
$finalSortData[$dicoColumnNbr{'ID'}]= $line[2];
$finalSortData[$dicoColumnNbr{'REF'}]= $line[3];
$finalSortData[$dicoColumnNbr{'ALT'}]= $line[4];
$finalSortData[$dicoColumnNbr{'FILTER'}]= $line[6];
#concatenate chrom_POS_REF_ALT to get variant ID
$variantID = $line[0]."_".$line[1]."_".$line[3]."_".$line[4]."_".$count;
#$variantID = $line[0]."_".$line[1]."_".$line[3]."_".$line[4]."_".$caller;
#############################################
########### Split INFOS #####################
my %dicoInfo;
my @infoList = split(';', $line[7] );
foreach my $info (@infoList){
my @infoKeyValue = split('=', $info );
if (scalar @infoKeyValue == 2){
$infoKeyValue[1] =~ s/\\x3d/=/g;
$infoKeyValue[1] =~ s/\\x3b/;/g;
$dicoInfo{$infoKeyValue[0]} = $infoKeyValue[1];
#DEBUG
#print $infoKeyValue[1]."\n";
}
}
#DEBUG
#print Dumper(\%dicoInfo);
#select only x% pop freq
#Use pop freq threshold as an input parameter (default = 1%)
next if((undef $JSONarg &&) ($dicoInfo{'gnomAD_genome_ALL'} ne ".") && ($dicoInfo{'gnomAD_genome_ALL'} >= $popFreqThr) );
#FILTERING according to newHope option and filterList option
$filterBool = 0;
if(defined $newHope){
#Keep only NON PASS or PASS + MPA ranking = 8
#next if ($finalSortData[$dicoColumnNbr{'FILTER'}] eq "PASS" && $dicoInfo{'MPA_ranking'} < 8);
#switch ($finalSortData[$dicoColumnNbr{'FILTER'}]){
# case (\@filterArray) { $filterBool=1 };
#}
#next if($filterBool == 1);
#next if($dicoInfo{'MPA_ranking'} < 8 );
}else{
#remove NON PASS variant and remove MPA_Ranking = 8
switch ($finalSortData[$dicoColumnNbr{'FILTER'}]){
case (\@filterArray) {$filterBool=0}
else {$filterBool=1}
}
if (undef $JSONarg){
next if ($filterBool == 1);
next if( $dicoInfo{'MPA_ranking'} == 10);
#next if ($finalSortData[$dicoColumnNbr{'FILTER'}] ne "PASS");
}
}
#filling output line, check if INFO exists in the VCF
foreach my $keys (sort keys %dicoColumnNbr){
# print "keysListe\t#".$keys."#\n";
if (defined $dicoInfo{$keys}){
$finalSortData[$dicoColumnNbr{$keys}] = $dicoInfo{$keys};
#DEBUG
#print "finalSort\t".$finalSortData[$dicoColumnNbr{$keys}]."\n";
#print "dicoInfo\t".$dicoInfo{$keys}."\n";
#print "keys\t".$keys."\n";
}
}
#split multiple gene names
@geneListTemp = split(';', $finalSortData[$dicoColumnNbr{'Gene.refGene'}] );
#uniq genes names
@geneList = do { my %seen; grep { !$seen{$_}++ } @geneListTemp };
#Phenolyzer Column
if($phenolyzerFile ne ""){
#@geneList = split(';', $finalSortData[$dicoColumnNbr{'Gene.refGene'}] );
my $phenoScoreMax=0;
foreach my $geneName (@geneList){
#if (defined $phenolyzerGene{$finalSortData[$dicoColumnNbr{'Gene.refGene'}]} )
if (defined $phenolyzerGene{$geneName} ){
if( ! defined $finalSortData[$dicoColumnNbr{'Phenolyzer'}]){
$finalSortData[$dicoColumnNbr{'Phenolyzer'}] = $phenolyzerGene{$geneName}{'Raw'};
}elsif($phenolyzerGene{$geneName}{'Raw'} > $finalSortData[$dicoColumnNbr{'Phenolyzer'}]){
$finalSortData[$dicoColumnNbr{'Phenolyzer'}] = $phenolyzerGene{$geneName}{'Raw'};
if($phenoScoreMax < $phenolyzerGene{$geneName}{'normalized'}){
$phenoScoreMax = $phenolyzerGene{$geneName}{'normalized'};
}
}
}
}
#refine MPA_rank with phenolyzer normalized score
$finalSortData[$dicoColumnNbr{'MPA_ranking'}] += (0.001-($phenoScoreMax/1000 )) ;
}
#CNV GENES
if($cnvGeneList ne ""){
#@geneList = split(';', $finalSortData[$dicoColumnNbr{'Gene.refGene'}] );
foreach my $geneName (@geneList){
#print $geneName."\n";
if (defined $cnvGene{$geneName} ){
#print $geneName."toto\n";
$finalSortData[$dicoColumnNbr{'SecondHit-CNV'}] .= $cnvGene{$geneName}."_";
#print $finalSortData[$dicoColumnNbr{'SecondHit-CNV'}]."\n";
}
}
}
#MPA COMMENT
#create string with array
$commentMPAscore = "";
foreach my $keys (@CommentMPA_score){
if (defined $dicoInfo{$keys} ){
if($keys eq "spliceai_filtered"){
my @dicoSplice = split(';', $dicoInfo{$keys} );
if (scalar @dicoSplice > 2){
foreach my $spliceData (@dicoSplice){
if ($spliceData=~/^DS_/){
$commentMPAscore .= $keys."\t ".$spliceData."\n";
}
}
}else{
$commentMPAscore .= $keys."\t= ".$dicoInfo{$keys}."\n";
}
}else{
$commentMPAscore .= $keys."\t= ".$dicoInfo{$keys}."\n";
}
}else{
$commentMPAscore .= $keys."\n";
}
}
#refine MPA_rank with pLI
if(($finalSortData[$dicoColumnNbr{'MPA_ranking'}] >= 5 && $finalSortData[$dicoColumnNbr{'MPA_ranking'}] < 6 )|| ($finalSortData[$dicoColumnNbr{'MPA_ranking'}] >= 7 && $finalSortData[$dicoColumnNbr{'MPA_ranking'}] < 8 ) || ($finalSortData[$dicoColumnNbr{'MPA_ranking'}] >= 9 && $finalSortData[$dicoColumnNbr{'MPA_ranking'}] < 10 ) ){
#$format_pLI = $workbook->add_format(bg_color => $hashFinalSortData{$finalSortData[$dicoColumnNbr{'MPA_ranking'}]}{$variantID}{'colorpLI'});
if(defined $dicoInfo{'Missense_Z_score.refGene'} && $dicoInfo{'Missense_Z_score.refGene'} ne "." ){
$finalSortData[$dicoColumnNbr{'MPA_ranking'}] += (0.0001-((($dicoInfo{"Missense_Z_score.refGene"}+8.64)/22.52)/10000 )) ;
}else{
$finalSortData[$dicoColumnNbr{'MPA_ranking'}] += 0.0001;