-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathwwwachab_dev.pl
More file actions
3639 lines (2638 loc) · 119 KB
/
wwwachab_dev.pl
File metadata and controls
3639 lines (2638 loc) · 119 KB
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
##### wwwachab.pl ####
# Author : Thomas Guignard 2023
# 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 File::Basename;
#use Pod::Usage;
#use List::Util qw(first);
#use Data::Dumper;
#parameters
my $man = "USAGE : \nperl wwwachab.pl
\n--vcf <vcf_file> (mandatory)
\n--outDir <output directory (default = current dir)>
\n--outPrefix <output file prelifx (default = \"\")>
\n--candidates <file with end-of-line separated gene symbols of interest (it will create more tabs, if '#myPathology' is present in the file, a 'myPathology' tab will be created) >
\n--phenolyzerFile <phenolyzer output file suffixed by predicted_gene_scores (it will contribute to the final ranking and top50 genes will be added in METADATA tab) >
\n--popFreqThr <allelic frequency threshold from 0 to 1 default=0.01 (based on gnomAD_genome_ALL or on the first field of --gnomadGenome argument) >
\n--trio (requires case dad and mum option to be filled, but if case dad and mum option are filled, trio mode is automatically activated)
\n\t--case <index_sample_name> (required with trio option)
\n\t--dad <father_sample_name> (required with trio option)
\n\t--mum <mother_sample_name> (required with trio option)
\n--customInfoList <comma separated list of vcf annotation INFO names (each of them 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 nor 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--addCustomVCFRegex (customVCF field matched with customVCFRegex will be added in a new column - it requires customVCF option - default regex is 'found=')
\n--pooledSamples <comma separated list of samples that are pooled (e.g. parents pool in trio context) >
\n--IDSNP <comma separated list of rs ID for identity monitoring (it will convert 0/0 genotype into 0/1 if at least 1 read support ALT base and it will flag cell in yellow, e.g. rs4889990,rs2075559) >
\n--sampleSubset <comma separated list of samples only processed by Achab to the output >
\n--addCaseDepth (case Depth will be added in a new column)
\n--addCaseAB (case Allelic Balance will be added in a new column)
\n--intersectVCF <VCF format File for comparison (if variant matches then 'yes' will be added in new 'intersectVCF' column) >
\n--poorCoverageFile <poor Coverage File (it will annotate OMIM genes if present in the 4th column -requires OMIM genemap2 File- and create an excel file )>
\n--genemap2File <OMIM genemap2 file (it will help to annotate OMIM genes in poor coverage file ) >
\n--skipCaseWT (only if trio mode is activated or in 'duo' if case+dad are defined or if case+mum are defined , it will skip variant if case genotype is 0/0 )
\n--hideACMG (ACMG tab will be empty but information will be reported in the gene comment)
\n--gnomadGenome <comma separated list of gnomad genome annotation fields that will be displayed as gnomAD_Genome comments. First field of the list will be filtered regarding to popFreqThr argument. (default fields are hard-coded gnomAD_genome_ALL like) >
\n--gnomadExome <comma separated list of gnomad exome annotation fields that will be displayed as gnomAD comments. (default fields are hard-coded gnomAD_exome_ALL like) >
\n--MDAPIkey <Path to File containing only MobiDetails API key (default file is MD.apikey in the achab folder) >
\n\n-v|--version < return version number and exit > ";
my $versionOut = "achab version www:1.0.13";
#################################### 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 = "";
my $addCustomVCFRegex;
my $intersectVCF_File = "";
my $intersectVCF_Line;
my @intersectVCF_List;
my %intersectVCF_variant;
#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;
#parents pool
my $pooledSamples = "";
my @pooledSamplesArray;
my %hashPooledSamples;
#identity monitoring
my $IDSNP = "";
my @IDSNPArray;
my %hashIDSNP;
#process only these samples
my $sampleSubset = "";
my @sampleSubsetArray;
#case options
my $addCaseDepth;
my $addCaseAB;
my $skipCaseWT;
my $duo;
#Poor coverage File and omim genemap2 file
my $genemap2_File = "";
my $genemap2_Line;
my @genemap2_List;
my %genemap2_variant;
my $poorCoverage_File = "";
my $poorCoverage_Line;
my @poorCoverage_List;
my %poorCoverage_variant;
#adapt gnomAD names
my $gnomadGenome_names = "";
my @gnomadGenome_List;
my $gnomadGenomeColumn = "gnomAD_genome_ALL";
my $gnomadExome_names = "";
my @gnomadExome_List;
my $gnomadExomeColumn = "gnomAD_exome_ALL";
my $hideACMG;
# METADATA
# inheritance checking test
my $dadVariant = 0;
my $mumVariant = 0;
my $caseDadVariant = 0;
my $caseMumVariant = 0;
my $vcfHeader = "";
my @buttonArray ;
my %tagsHash;
#URL corner
my $mdAPIkey = "";
my $md_line = "";
my $franklinURL = "https://franklin.genoox.com/clinical-db/variant/snp/";
my $build = "hg19";
#$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,
"addCustomVCFRegex" => \$addCustomVCFRegex,
"pooledSamples:s" => \$pooledSamples,
"IDSNP:s" => \$IDSNP,
"sampleSubset:s" => \$sampleSubset,
"addCaseDepth" => \$addCaseDepth,
"addCaseAB" => \$addCaseAB,
"intersectVCF:s" => \$intersectVCF_File,
"poorCoverageFile:s" => \$poorCoverage_File,
"genemap2File:s" => \$genemap2_File,
"skipCaseWT" => \$skipCaseWT,
"hideACMG" => \$hideACMG,
"gnomadGenome:s" => \$gnomadGenome_names,
"gnomadExome:s" => \$gnomadExome_names,
"MDAPIkey:s" => \$mdAPIkey,
"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");
}
#define trio if case dad and mum are defined
if ($case ne "" && $dad ne "" && $mum ne ""){
$trio = "";
}
#define duo (at least) if case and dad and not mum or case and mum and not dad are defined => concern skipCaseWT option only
if ($case ne "" ){
if (($dad ne "" && $mum eq "") || ($dad eq "" && $mum ne "")){
$duo = "";
}
}
#TODO affected samples
#define affected samples List
if($affected ne ""){
chomp $affected;
$affected =~ s/"//g;
if(defined $trio and $case ne ""){
$affected =~ s/$case,//g;
$affected =~ s/,$dad//g;
$affected =~ s/$dad,//g;
$affected =~ s/,$mum//g;
$affected =~ s/$mum,//g;
}
$affected =~ s/,,/,/g;
$affected =~ s/^,//g;
$affected =~ s/,$//g;
@affectedArray = split(/,/ , $affected);
foreach my $affSample (@affectedArray){
if (defined $hashAffected{$affSample}){
#nothing to do
}else{
$hashAffected{$affSample} = "affected";
}
}
}
#pooled samples , check in header
if ($pooledSamples ne ""){
chomp $pooledSamples;
$pooledSamples =~ s/"//g ;
$pooledSamples =~ s/^,//g;
$pooledSamples =~ s/,$//g;
@pooledSamplesArray = split(/,/ , $pooledSamples);
foreach my $pooled (@pooledSamplesArray){
if (defined $hashPooledSamples{$pooled}){
#nothing to do
}else{
$hashPooledSamples{$pooled} = "pooled";
}
}
}
#ID monitoring
if ($IDSNP ne ""){
chomp $IDSNP;
@IDSNPArray = split(/,/ , $IDSNP);
foreach my $rs (@IDSNPArray){
if (defined $hashIDSNP{$rs}){
#nothing to do
}else{
$hashIDSNP{$rs} = "ID";
}
}
}
#gnomad names
if ($gnomadGenome_names ne ""){
chomp $gnomadGenome_names;
@gnomadGenome_List = split(/,/ , $gnomadGenome_names);
$gnomadGenomeColumn = $gnomadGenome_List[0];
}
if ($gnomadExome_names ne ""){
chomp $gnomadExome_names;
@gnomadExome_List = split(/,/ , $gnomadExome_names);
$gnomadExomeColumn = $gnomadExome_List[0];
}
#Samples subset
if ($sampleSubset ne ""){
chomp $sampleSubset;
@sampleSubsetArray = split(/,/ , $sampleSubset);
}
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 .= $_;
#deduce genome build from header , like bcftools command line including with genome fasta
if ($current_line=~/38\.fa/){
$build = "hg38";
}
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++){
if ($sampleSubset ne ""){
switch ($line[$sampleIndex]){
case (\@sampleSubsetArray) {
print STDERR "Found Sample ".$line[$sampleIndex]."\n";
push @sampleList, $line[$sampleIndex];
}else {
print STDERR "Found Sample ".$line[$sampleIndex]."\t--ignored\n";
next;
}
}
}else{
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] eq $case or $line[$sampleIndex] eq $dad or $line[$sampleIndex] eq $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 or in PooledSamples 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
#$tagsHash{'ALL'} = 'ALL_'.$popFreqThr ;
my $worksheet = $workbook->add_worksheet('ALL_'.$popFreqThr);
$worksheet->freeze_panes( 1, 0 ); # Freeze the first row
my $worksheetLine = 1;
$tagsHash{'ACMG'}{'label'} = "DS_ACMG" ;
$tagsHash{'ACMG'}{'count'} = 0 ;
my $worksheetACMG = $workbook->add_worksheet('DS_ACMG');
$worksheetACMG->freeze_panes( 1, 0 ); # Freeze the first row
my $worksheetLineACMG = 1;
# Meta Data worksheet
$tagsHash{'META'}{'label'} = "METADATA" ;
$tagsHash{'META'}{'count'} = 1 ;
my $worksheetMETA = $workbook->add_worksheet('META');
$worksheetMETA->freeze_panes( 1, 0 ); # Freeze the first row
my $worksheetLineMETA = 1;
# OMIM worksheets
$tagsHash{'OMIMDOM'}{'label'} = 'OMIM_DOM' ;
$tagsHash{'OMIMDOM'}{'count'} = 0 ;
my $worksheetOMIMDOM = $workbook->add_worksheet('OMIM_DOM');
$worksheetOMIMDOM->freeze_panes( 1, 0 ); # Freeze the first row
my $worksheetLineOMIMDOM = 1;
# OMIM worksheets
$tagsHash{'OMIMREC'}{'label'} = 'OMIM_REC' ;
$tagsHash{'OMIMREC'}{'count'} = 0 ;
my $worksheetOMIMREC = $workbook->add_worksheet('OMIM_REC');
$worksheetOMIMREC->freeze_panes( 1, 0 ); # Freeze the first row
my $worksheetLineOMIMREC = 1;
#Worksheets initialization
my $worksheetHTZcompo;
my $worksheetAR;
my $worksheetSNPmumVsCNVdad ;
my $worksheetSNPdadVsCNVmum;
my $worksheetDENOVO;
my $worksheetCandidats;
#my $worksheetDELHMZ;
my $worksheetLineHTZcompo = 1 ;
my $worksheetLineAR = 1 ;
my $worksheetLineSNPmumVsCNVdad = 1 ;
my $worksheetLineSNPdadVsCNVmum = 1;
my $worksheetLineDENOVO = 1;
#my $worksheetLineCandidats;
#my $worksheetLineDELHMZ;
#create additionnal sheet in trio analysis
if (defined $trio){
$tagsHash{'DENOVO'}{'label'} = 'DENOVO' ;
$tagsHash{'DENOVO'}{'count'} = 0 ;
$worksheetDENOVO = $workbook->add_worksheet('DENOVO');
$worksheetDENOVO->freeze_panes( 1, 0 ); # Freeze the first row
$tagsHash{'AUTOREC'}{'label'} = 'AR' ;
$tagsHash{'AUTOREC'}{'count'} = 0 ;
$worksheetAR = $workbook->add_worksheet('AR');
$worksheetAR->freeze_panes( 1, 0 ); # Freeze the first row
$tagsHash{'HTZcompo'}{'label'} = 'HTZ_compo' ;
$tagsHash{'HTZcompo'}{'count'} = 0 ;
$worksheetHTZcompo = $workbook->add_worksheet('HTZ_compo');
$worksheetHTZcompo->freeze_panes( 1, 0 ); # Freeze the first row
$tagsHash{'SNPmCNVp'}{'label'} = 'SNVmumVsCNVdad' ;
$tagsHash{'SNPmCNVp'}{'count'} = 0 ;
$worksheetSNPmumVsCNVdad = $workbook->add_worksheet('SNVmumVsCNVdad');
$worksheetSNPmumVsCNVdad->freeze_panes( 1, 0 ); # Freeze the first row
$tagsHash{'SNPpCNVm'}{'label'} = 'SNVdadVsCNVmum' ;
$tagsHash{'SNPpCNVm'}{'count'} = 0 ;
$worksheetSNPdadVsCNVmum = $workbook->add_worksheet('SNVdadVsCNVmum');
$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{
$tagsHash{'DENOVO'}{'label'} = 'DOM' ;
$tagsHash{'DENOVO'}{'count'} = 0 ;
$worksheetDENOVO = $workbook->add_worksheet('DOM');
$worksheetDENOVO->freeze_panes( 1, 0 ); # Freeze the first row
$tagsHash{'AUTOREC'}{'label'} = 'REC' ;
$tagsHash{'AUTOREC'}{'count'} = 0 ;
$worksheetAR = $workbook->add_worksheet('REC');
$worksheetAR->freeze_panes( 1, 0 ); # Freeze the first row
if ( @affectedArray){
$tagsHash{'SNPmCNVp'}{'label'} = 'HTZ' ;
$tagsHash{'SNPmCNVp'}{'count'} = 0 ;
$worksheetSNPmumVsCNVdad = $workbook->add_worksheet('HTZ');
}else{
$tagsHash{'SNPmCNVp'}{'label'} = 'HMZonly' ;
$tagsHash{'SNPmCNVp'}{'count'} = 0 ;
$worksheetSNPmumVsCNVdad = $workbook->add_worksheet('HMZonly');
}
$worksheetSNPmumVsCNVdad->freeze_panes( 1, 0 ); # Freeze the first row
}
#get data from phenolyzer output (predicted_gene_score)
my $current_gene= "";
my $maxLine=0;
my $geneCounter=1;
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];
$phenolyzerGene{$current_gene}{'rank'}= $geneCounter;
$geneCounter ++;
$maxLine=0;
}else{
#keep only OMIM or count nbr of lines
$maxLine+=1;
}
}
close(PHENO);
}
#custom VCF treatment
if($customVCF_File ne ""){
open(CUSTOMVCF , "<$customVCF_File") or die("Cannot open customVCF 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];
}
}
close(CUSTOMVCF);
}
#Initialize Regex for filtering customVCF (should be like that "wantedKey=" )
if ($filterCustomVCFRegex eq ""){
$filterCustomVCFRegex = "found=";
}else{chomp $filterCustomVCFRegex ;}
# intersect VCF treatment
if($intersectVCF_File ne ""){
open(INTERSECTVCF , "<$intersectVCF_File") or die("Cannot open intersectVCF file ".$intersectVCF_File) ;
print STDERR "Processing intersect VCF file ... \n" ;
while( <INTERSECTVCF> ){
$intersectVCF_Line = $_;
#############################################
############## skip header
next if ($intersectVCF_Line=~/^#/);
chomp $intersectVCF_Line;
@intersectVCF_List = split( /\t/, $intersectVCF_Line );
#replace "spaces" by "_"
#$intersectVCF_List[7] =~ s/ /_/g;
#build variant key as CHROM_POS_REF_ALT
if (defined $intersectVCF_variant{$intersectVCF_List[0]."_".$intersectVCF_List[1]."_".$intersectVCF_List[3]."_".$intersectVCF_List[4]}){
#$intersectVCF_variant{$intersectVCF_List[0]."_".$intersectVCF_List[1]."_".$intersectVCF_List[3]."_".$intersectVCF_List[4]} = "yes";
}else{
#$intersectVCF_variant{$intersectVCF_List[0]."_".$intersectVCF_List[1]."_".$intersectVCF_List[3]."_".$intersectVCF_List[4]} = "yes";
$intersectVCF_variant{$intersectVCF_List[0]."_".$intersectVCF_List[1]."_".$intersectVCF_List[3]."_".$intersectVCF_List[4]}{"exists"} = "yes";
$intersectVCF_variant{$intersectVCF_List[0]."_".$intersectVCF_List[1]."_".$intersectVCF_List[3]."_".$intersectVCF_List[4]}{"seen"} = 0;
$intersectVCF_variant{$intersectVCF_List[0]."_".$intersectVCF_List[1]."_".$intersectVCF_List[3]."_".$intersectVCF_List[4]}{"Phenotypes"} = "";
$intersectVCF_variant{$intersectVCF_List[0]."_".$intersectVCF_List[1]."_".$intersectVCF_List[3]."_".$intersectVCF_List[4]}{"CLNSIG"} = "";
$intersectVCF_variant{$intersectVCF_List[0]."_".$intersectVCF_List[1]."_".$intersectVCF_List[3]."_".$intersectVCF_List[4]}{"MPA_impact"} = "";
########### Split INFOS #####################
my %intersectInfo;
my @infoList = split(';', $intersectVCF_List[7] );
foreach my $info (@infoList){
my @infoKeyValue = split('=', $info );
if (scalar @infoKeyValue == 2){
$infoKeyValue[1] =~ s/\\x3d/=/g;
$infoKeyValue[1] =~ s/\\x3b/;/g;
if ($infoKeyValue[0] eq "CLNSIG") {
$intersectVCF_variant{$intersectVCF_List[0]."_".$intersectVCF_List[1]."_".$intersectVCF_List[3]."_".$intersectVCF_List[4]}{"CLNSIG"} = $infoKeyValue[1];
}elsif( $infoKeyValue[0] eq "MPA_impact"){
$intersectVCF_variant{$intersectVCF_List[0]."_".$intersectVCF_List[1]."_".$intersectVCF_List[3]."_".$intersectVCF_List[4]}{"MPA_impact"} = $infoKeyValue[1];
}elsif( $infoKeyValue[0] =~ /^Phenotypes/){
$intersectVCF_variant{$intersectVCF_List[0]."_".$intersectVCF_List[1]."_".$intersectVCF_List[3]."_".$intersectVCF_List[4]}{"Phenotypes"} = $infoKeyValue[1];
}
}
}
}
}# end while
close(INTERSECTVCF);
}
#create sheet for candidats
my $CANDID_TAG = "CANDIDATES";
my %candidWorksheetHash ;
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;
if($candidates_line =~ m/#/ ){
$candidates_line =~ s/#//g;
$CANDID_TAG = "CANDID_".$candidates_line;
$tagsHash{"CANDID_".$candidates_line}{'label'} = $candidates_line;
$tagsHash{"CANDID_".$candidates_line}{'count'} = 0;
#create 1 excel worksheet for each pathology (with # prefixed line)
$candidWorksheetHash{$candidates_line}{'workbook'} = $workbook->add_worksheet($candidates_line);
$candidWorksheetHash{$candidates_line}{'workbook'}->freeze_panes( 1, 0 );
$candidWorksheetHash{$candidates_line}{'line'} = 0;
next;
}
$candidateGene{$candidates_line} .= " ".$CANDID_TAG;
}
close(CANDIDATS);
#$worksheetCandidats = $workbook->add_worksheet('Candidats');
#$worksheetCandidats->freeze_panes( 1, 0 ); # Freeze the first row
# create a generic "candidates" excel worksheet if no disease is given with #
if( keys %candidWorksheetHash == 0 ){
$candidWorksheetHash{'Candidats'}{'workbook'} = $workbook->add_worksheet('Candidates');
$candidWorksheetHash{'Candidats'}{'workbook'}->freeze_panes( 1, 0 ); # Freeze the first row
$candidWorksheetHash{'Candidats'}{'line'} = 0;
$tagsHash{"CANDIDATES"}{'label'} = "Candidates";
$tagsHash{"CANDIDATES"}{'count'} = 0;
}
}
#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);
}
#parse genemap2 file
if ( $genemap2_File ne "" ){
open(GENEMAP2 , "<$genemap2_File") or die("Cannot open genemap2 file ".$genemap2_File) ;
print STDERR "Processing genemap2 file ... \n" ;
while( <GENEMAP2> ){
$genemap2_Line = $_;
#skip header
next if ($genemap2_Line=~/^#/);
chomp $genemap2_Line;
@genemap2_List = split( /\t/, $genemap2_Line );
if (defined $genemap2_List[8] && $genemap2_List[8] ne ""){
if (defined $genemap2_variant{$genemap2_List[8]}){
if (! defined $genemap2_List[12]){
$genemap2_List[12] = "";
}
$genemap2_variant{$genemap2_List[8]} .= ";".$genemap2_List[12];
}else{
$genemap2_variant{$genemap2_List[8]} = $genemap2_List[12];
}
}
}
close(GENEMAP2);
}
#get mobidetails API key from achab script location or argument
if ($mdAPIkey eq ""){
$mdAPIkey = dirname(__FILE__)."/MD.apikey";
}
open( MDAPIKEY , "<$mdAPIkey") or do {print "Didn't find any MoBiDetails APIkey file, expected: ".$mdAPIkey."\n"; $mdAPIkey = ""; } ;
#checkif file is empty
if (-z $mdAPIkey){
$mdAPIkey = "";
print "The MoBiDetails APIkey file: ".$mdAPIkey. " is empty. Please fill it";
}else{
if ($mdAPIkey ne ""){
print STDERR "Processing MDAPIKEY file ... \n" ;
while( <MDAPIKEY> ){
$md_line = $_;
chomp $md_line;
if ($md_line eq ""){
$mdAPIkey = "";
}else{
$mdAPIkey = "https://mobidetails.iurc.montp.inserm.fr/MD/api/variant/create_vcf_str?genome_version=".$build."&api_key=".$md_line."&vcf_str=";
}
}
}
}
close(MDAPIKEY);
#Hash of 81 ACMG incidentalome genes secondary findings SF v3.2 according to https://www.ncbi.nlm.nih.gov/clinvar/docs/acmg/
my %ACMGgene = ("ACTA2" =>1,"ACTC1" =>1,"ACVRL1" =>1,"APC" =>1,"APOB" =>1,"ATP7B" =>1,"BAG3" =>1,"BMPR1A" =>1,"BRCA1" =>1,"BRCA2" =>1,"BTD" =>1,"CACNA1S" =>1,"CALM1" =>1,"CALM2" =>1,"CALM3" =>1,"CASQ2" =>1,"COL3A1" =>1,"DES" =>1,"DSC2" =>1,"DSG2" =>1,"DSP" =>1,"ENG" =>1,"FBN1" =>1,"FLNC" =>1,"GAA" =>1,"GLA" =>1,"HFE" =>1,"HNF1A" =>1,"KCNH2" =>1,"KCNQ1" =>1,"LDLR" =>1,"LMNA" =>1,"MAX" =>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,"PALB2" =>1,"PCSK9" =>1,"PKP2" =>1,"PMS2" =>1,"PRKAG2" =>1,"PTEN" =>1,"RB1" =>1,"RBM20" =>1,"RET" =>1,"RPE65" =>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,"TMEM127" =>1,"TMEM43" =>1,"TNNC1" =>1,"TNNI3" =>1,"TNNT2" =>1,"TP53" =>1,"TPM1" =>1,"TRDN" =>1,"TSC1" =>1,"TSC2" =>1,"TTN" =>1,"TTR" =>1,"VHL" =>1,"WT1" =>1);
#counter for shifting columns according to nbr of sample
my $cmpt = scalar @sampleList;