-
Notifications
You must be signed in to change notification settings - Fork 2
/
achab.pl
2426 lines (1711 loc) · 77.3 KB
/
achab.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--affected <comma separated list of samples affected by phenotype (assuming they support the same genotype >
\n--favouriteGeneRef <File with transcript references to extract in a new column (1 transcript by line) >
\n--filterCustomVCF <integer value, penalizes variant if its frequency in the customVCF is greater than [value] (default key of info field : found=[value]) >
\n--filterCustomVCFRegex <string pattern used as regex to search for a specific field to filter customVCF (default key of info field : 'found=') >
\n\n-v|--version < return version number and exit > ";
my $versionOut = "achab v1.0.2";
#################################### VARIABLES INIT ########################
#catch argument for METADATA
my $achabArg = "";
foreach my $a(@ARGV){
$achabArg .= $a." ";
}
my $help;
my $version;
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 = "";
#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;
#threshold to filter out bias related frequent variants
my $filterCustomVCF = "";
my $filterCustomVCFRegex = "";
#vcf parsing and output
my @line;
my $variantID;
my @geneListTemp;
my @geneList;
my $mozaicSamples = "";
my $count = 0;
#Data structure
my @finalSortData;
my $familyGenotype;
my %hashFinalSortData;
my $worksheetTAG = "";
# favourite NM refGene
my $favouriteGeneRef = "";
my @geneRefArray;
my %geneRef_gene;
my $geneRef_line;
#affected samples
my $affected = ""; # next if affected_sample = case or dad or mum
my @affectedArray;
my %hashAffected;
my @nonAffectedArray;
#Variable for genotype checking
my @strangerNULL;
my @strangerREF;
my @strangerHTZ;
my @strangerHMZ;
# METADATA
# inheritance checking test
my $dadVariant = 0.1;
my $mumVariant = 0.1;
my $caseDadVariant = 0.1;
my $caseMumVariant = 0.1;
my $vcfHeader = "";
#$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,
"favouriteGeneRef:s" => \$favouriteGeneRef,
"affected:s" => \$affected,
"filterCustomVCF:s" => \$filterCustomVCF,
"filterCustomVCFRegex:s" => \$filterCustomVCFRegex,
"help|h" => \$help,
"version|v" => \$version);
#check mandatory arguments
if(defined $version){
print("$versionOut\n");
exit(0);
}
if(defined $help){
print("$man\n");
exit(0);
}
if($incfile eq ""){
die("$man\n");
}
#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");
}
#TODO affected samples
#define affected samples List
if($affected ne ""){
chomp $affected;
@affectedArray = split(/,/ , $affected);
foreach my $affSample (@affectedArray){
if (defined $hashAffected{$affSample}){
#nothing to do
}else{
$hashAffected{$affSample} = "affected";
}
}
}
print STDERR "Starting a new fishing trip ... \n" ;
print STDERR "Hope we will catch-a-lot ... \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;
my $refGene = 'refGene';
while( <VCF> ){
$current_line = $_;
chomp $current_line;
#filling dicoParam with VCF header INFO and FORMAT
if ($current_line=~/^##/){
$vcfHeader .= $_;
unless ($current_line=~/Description=/){ next }
#DEBUG print STDERR "Header line\n";
if ($current_line =~ /ID=(.+?),.*?Description="(.+?)"/){
$dicoParam{$1}= $2;
if ($1 eq "Func.refGeneWithVer") {$refGene = "refGeneWithVer"}
#DEBUG print STDERR "info : ". $1 . "\tdescription: ". $2."\n";
next;
}else {print STDERR "pattern not found in this line: ".$current_line ."\n";next}
}elsif($current_line=~/^#CHROM/){
#check sample names or die
$vcfHeader .= $_;
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];
#populate non affected-samples array
if (defined $hashAffected{$line[$sampleIndex]} or (defined $trio and ($line[$sampleIndex] ne $case or $line[$sampleIndex] ne $dad or $line[$sampleIndex] ne $mum)) ){
#do nothing
}else{
push @nonAffectedArray, $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]
}
#TODO check if all samples in affected list are present or die
#specify which sample will be the first in the output, to get genotype comment
# TODO check if it's Ok
if (! defined $trio){
if (@affectedArray){
$case = $affectedArray[0];
}elsif($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 && scalar @affectedArray == 0 ){
# TODO check if all affected samples and case , dad and mum are present
#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();
#create LOEUF decile associated colors dico
my %dicoLOEUFformatColor;
$dicoLOEUFformatColor{'0.0'} = '#FF0000';
$dicoLOEUFformatColor{'1.0'} = '#FF3300';
$dicoLOEUFformatColor{'2.0'} = '#FF6600';
$dicoLOEUFformatColor{'3.0'} = '#FF9900';
$dicoLOEUFformatColor{'4.0'} = '#FFCC00';
$dicoLOEUFformatColor{'5.0'} = '#FFFF00';
$dicoLOEUFformatColor{'6.0'} = '#BFFF00';
$dicoLOEUFformatColor{'7.0'} = '#7FFF00';
$dicoLOEUFformatColor{'8.0'} = '#3FFF00';
$dicoLOEUFformatColor{'9.0'} = '#00FF00';
$dicoLOEUFformatColor{'.'} = '#FFFFFF';
# 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;
# Meta Data worksheet
my $worksheetMETA = $workbook->add_worksheet('META');
$worksheetMETA->freeze_panes( 1, 0 ); # Freeze the first row
my $worksheetLineMETA = 0;
# OMIM worksheets
my $worksheetOMIMDOM = $workbook->add_worksheet('OMIM_DOM');
$worksheetOMIMDOM->freeze_panes( 1, 0 ); # Freeze the first row
my $worksheetLineOMIMDOM = 0;
# OMIM worksheets
my $worksheetOMIMREC = $workbook->add_worksheet('OMIM_REC');
$worksheetOMIMREC->freeze_panes( 1, 0 ); # Freeze the first row
my $worksheetLineOMIMREC = 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){
$worksheetDENOVO = $workbook->add_worksheet('DENOVO');
$worksheetLineDENOVO = 0;
$worksheetDENOVO->freeze_panes( 1, 0 ); # Freeze the first row
$worksheetAR = $workbook->add_worksheet('AR');
$worksheetLineAR = 0;
$worksheetAR->freeze_panes( 1, 0 ); # Freeze the first row
$worksheetHTZcompo = $workbook->add_worksheet('HTZ_compo');
$worksheetLineHTZcompo = 0;
$worksheetHTZcompo->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
#$worksheetDELHMZ = $workbook->add_worksheet('DEL_HMZ');
#$worksheetLineDELHMZ = 0;
#$worksheetDELHMZ->freeze_panes( 1, 0 ); # Freeze the first row
}else{
$worksheetDENOVO = $workbook->add_worksheet('DOM');
$worksheetLineDENOVO = 0;
$worksheetDENOVO->freeze_panes( 1, 0 ); # Freeze the first row
$worksheetAR = $workbook->add_worksheet('REC');
$worksheetLineAR = 0;
$worksheetAR->freeze_panes( 1, 0 ); # Freeze the first row
if ( @affectedArray){
$worksheetSNPmumVsCNVdad = $workbook->add_worksheet('HTZ');
}else{
$worksheetSNPmumVsCNVdad = $workbook->add_worksheet('HMZonly');
}
$worksheetLineSNPmumVsCNVdad = 0;
$worksheetSNPmumVsCNVdad->freeze_panes( 1, 0 ); # Freeze the first row
}
#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];
}
}
}
#Initialize Regex for filtering customVCF (should be like that "wantedKey=" )
if ($filterCustomVCFRegex eq ""){
$filterCustomVCFRegex = "found=";
}else{chomp $filterCustomVCFRegex ;}
#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);
}
#get favourite NM refGene
if($favouriteGeneRef ne ""){
open( GENEREF , "<$favouriteGeneRef")or die("Cannot open your favourite GeneRef file ".$favouriteGeneRef) ;
print STDERR "Processing GeneRef file ... \n" ;
while( <GENEREF> ){
$geneRef_line = $_;
chomp $geneRef_line;
@geneRefArray = split( /\t/, $geneRef_line);
$current_gene = $geneRefArray[0];
if (defined $geneRef_gene{$current_gene}){
#nothing to do
}else{
$geneRef_gene{$current_gene} = $current_gene;
}
}
close(GENEREF);
}
#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;
#Out-of-trio affected samples
my $NTaffectedCmpt = 0;
#Out-of-trio non-affected samples
my $NTnonAffectedCmpt = 0;
#dico for sample sorting (index / dad / mum / control)
my %dicoSamples ;
#first: read VCF headers to get refGene or refGeneWithVer
#my $refGene = 'refGene';
#open( VCF , "<$incfile" )or die("Cannot open vcf file ".$incfile) ;
#while( <VCF> ){
# $current_line = $_;
# if ($current_line=~/^##INFO=<ID=Func.refGeneWithVer,/o) {
# $refGene = 'refGeneWithVer';
# last;
# }
# elsif ($current_line=~/^##INFO=<ID=Func.refGene,/o) {last}
#}
#
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 LOEUF / 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 ;
# TODO Add out-of-trio samples, affected samples first then non-affected samples
if ( scalar @sampleList > 3){
if ( scalar @affectedArray > 0){
for( my $j = 0 ; $j < scalar @affectedArray; $j++){
$NTaffectedCmpt++;
if ($j eq $case or $j eq $dad or $j eq $mum){
$NTaffectedCmpt--;
}else{
$dicoColumnNbr{'Genotype-'.$affectedArray[$j]}= 13+$NTaffectedCmpt;
$dicoSamples{3+$NTaffectedCmpt}{'columnName'} = 'Genotype-'.$affectedArray[$j] ;
}
}
}
if ( scalar @nonAffectedArray > 0){
for( my $k = 0 ; $k < scalar @nonAffectedArray; $k++){
$dicoColumnNbr{'Genotype-'.$nonAffectedArray[$k]}= 14+$NTaffectedCmpt+$k;
$dicoSamples{4+$NTaffectedCmpt+$k}{'columnName'} = 'Genotype-'.$nonAffectedArray[$k] ;
$NTnonAffectedCmpt++;
}
}
}
}else{
#TODO check how many affected samples in this non-trio sample
if ( scalar @affectedArray > 0){
for( my $j = 0 ; $j < scalar @affectedArray; $j++){
$NTaffectedCmpt++;
$dicoColumnNbr{'Genotype-'.$affectedArray[$j]}= 11+$j;
$dicoSamples{$j+1}{'columnName'} = 'Genotype-'.$affectedArray[$j] ;
}
if ( scalar @nonAffectedArray > 0){
for( my $k = 0 ; $k < scalar @nonAffectedArray; $k++){
$dicoColumnNbr{'Genotype-'.$nonAffectedArray[$k]}= 11+$NTaffectedCmpt+$k;
$dicoSamples{$NTaffectedCmpt+$k+1}{'columnName'} = 'Genotype-'.$nonAffectedArray[$k] ;
$NTnonAffectedCmpt++;
}
}
}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++;
}
}
#add favorite gene references into a new column
if($favouriteGeneRef ne ""){
$dicoColumnNbr{'geneRefs'} = $lastColumn ;
$lastColumn++;
}
#custom VCF in last position
if($customVCF_File ne ""){
$dicoColumnNbr{'customVCFannotation'} = $lastColumn ;
$lastColumn++;
}
#TODO add a last column to flag newHope variants
if(defined $newHope){
$dicoColumnNbr{'Variant_Class'} = $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 $pLI_Comment = "LOEUF stands for the \"loss-of-function observed/expected upper bound fraction\". \nIt is a conservative estimate of the observed/expected ratio, based on the upper bound of a Poisson-derived confidence interval around the ratio. \nLow LOEUF scores (Red) indicate strong selection against predicted loss-of-function (pLoF) variation in a given gene, \nwhile high LOEUF scores (green) suggest a relatively higher tolerance to inactivation.";
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 );
$worksheetMETA->write( 0, 0, "METADATA" );
$worksheetOMIMDOM->write_row( 0, 0, \@columnTitles );
$worksheetOMIMREC->write_row( 0, 0, \@columnTitles );
#write comment for pLI => NOW LOEUF is used
$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 OR AFFECTED OR STRANGERS
if (defined $trio){
$worksheetHTZcompo->write_row( 0, 0, \@columnTitles );
$worksheetSNPdadVsCNVmum->write_row( 0, 0, \@columnTitles );
#write pLI - LOEUF comment
$worksheetHTZcompo->write_comment(0,$dicoColumnNbr{'Gene.'.$refGene}, $pLI_Comment, x_scale => 3);
$worksheetSNPdadVsCNVmum->write_comment(0, $dicoColumnNbr{'Gene.'.$refGene}, $pLI_Comment, x_scale => 3);
}
$worksheetAR->write_row( 0, 0, \@columnTitles );
$worksheetDENOVO->write_row( 0, 0, \@columnTitles );
$worksheetSNPmumVsCNVdad->write_row( 0, 0, \@columnTitles );
#write pLI - LOEUF comment
$worksheetAR->write_comment(0, $dicoColumnNbr{'Gene.'.$refGene}, $pLI_Comment, x_scale => 3);
$worksheetDENOVO->write_comment( 0, $dicoColumnNbr{'Gene.'.$refGene}, $pLI_Comment, x_scale => 3);
$worksheetSNPmumVsCNVdad->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;