-
Notifications
You must be signed in to change notification settings - Fork 0
/
3_Anno_functional_impact.R
2475 lines (2100 loc) · 122 KB
/
3_Anno_functional_impact.R
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
library(here)
library(rlang)
library(readr)
library(ggplot2)
library(cowplot)
library(reshape2)
library(corrplot)
library(pROC)
library(ggrepel)
library(ggExtra)
library(sessioninfo)
####################################################################################################
## 3. Annotation of the functional impact of variants
####################################################################################################
gene_families <- c('UGT1', 'UGT2', 'UGT3', 'UGT8')
UGT_genes <- c('UGT1A1', 'UGT1A3', 'UGT1A4', 'UGT1A5', 'UGT1A6', 'UGT1A7', 'UGT1A8', 'UGT1A9', 'UGT1A10',
'UGT2A1', 'UGT2A2', 'UGT2A3', 'UGT2B4', 'UGT2B7', 'UGT2B10', 'UGT2B11', 'UGT2B15', 'UGT2B17', 'UGT2B28',
'UGT3A1', 'UGT3A2',
'UGT8')
UGT1_genes <- c('UGT1A1', 'UGT1A3', 'UGT1A4', 'UGT1A5', 'UGT1A6', 'UGT1A7', 'UGT1A8', 'UGT1A9', 'UGT1A10')
UGT2_genes <- c('UGT2A1', 'UGT2A2', 'UGT2A3', 'UGT2B4', 'UGT2B7', 'UGT2B10', 'UGT2B11', 'UGT2B15', 'UGT2B17', 'UGT2B28')
UGT3_genes <- c('UGT3A1', 'UGT3A2')
UGT8_genes <- c('UGT8')
## Canonical txs of genes
canonical_txs <- list('UGT1A1'= 'ENST00000305208.5', 'UGT1A3'='ENST00000482026.1', 'UGT1A4'='ENST00000373409.3',
'UGT1A5'='ENST00000373414.3', 'UGT1A6'='ENST00000305139.6', 'UGT1A7'='ENST00000373426.3',
'UGT1A8'= 'ENST00000373450.4','UGT1A9'= 'ENST00000354728.4', 'UGT1A10'='ENST00000344644.5',
'UGT2A1'= 'ENST00000503640.1', 'UGT2A2'='ENST00000457664.2', 'UGT2A3'='ENST00000251566.4',
'UGT2B4'='ENST00000305107.6', 'UGT2B7'='ENST00000305231.7', 'UGT2B10'='ENST00000265403.7',
'UGT2B11'= 'ENST00000446444.1', 'UGT2B15'= 'ENST00000338206.5', 'UGT2B17'='ENST00000317746.2',
'UGT2B28'='ENST00000335568.5', 'UGT3A1'= 'ENST00000274278.3', 'UGT3A2'='ENST00000282507.3',
'UGT8'= 'ENST00000310836.6')
canonical_UGT1_txs <- list('UGT1A1'= 'ENST00000305208.5', 'UGT1A3'='ENST00000482026.1', 'UGT1A4'='ENST00000373409.3',
'UGT1A5'='ENST00000373414.3', 'UGT1A6'='ENST00000305139.6', 'UGT1A7'='ENST00000373426.3',
'UGT1A8'= 'ENST00000373450.4','UGT1A9'= 'ENST00000354728.4', 'UGT1A10'='ENST00000344644.5')
canonical_UGT2_txs <- list('UGT2A1'= 'ENST00000503640.1', 'UGT2A2'='ENST00000457664.2', 'UGT2A3'='ENST00000251566.4',
'UGT2B4'='ENST00000305107.6', 'UGT2B7'='ENST00000305231.7', 'UGT2B10'='ENST00000265403.7',
'UGT2B11'= 'ENST00000446444.1', 'UGT2B15'= 'ENST00000338206.5', 'UGT2B17'='ENST00000317746.2',
'UGT2B28'='ENST00000335568.5')
canonical_UGT3_txs <- list('UGT3A1'= 'ENST00000274278.3', 'UGT3A2'='ENST00000282507.3')
canonical_UGT8_txs <- list('UGT8'= 'ENST00000310836.6')
## Load exonic data for each gene
non_minor_alleles_allGenes <- vector()
for (gene in UGT_genes){
exonic_vars <- eval(parse_expr(load(here(paste0('~/Documents/KI_projects/UGT_genetic_profiling_KI/processed-data/01_Data_Processing/', gene, '_exonic_data.Rdata')),
verbose=TRUE)))
## Variants with global allele freqs > 0.5 (not minor allele)
non_minor_alleles <- exonic_vars[which(exonic_vars$Allele_Frequency>0.5), ]
if (dim(non_minor_alleles)[1]!=0){
non_minor_alleles <- cbind(gene, exonic_vars[which(exonic_vars$Allele_Frequency>0.5), ])
non_minor_alleles_allGenes <- rbind(non_minor_alleles_allGenes, non_minor_alleles)
}
assign( paste0(gene, '_exonic_data'), exonic_vars)
}
################################################################################
## 3.1 Functional prediction of missense variants
################################################################################
## Subset to missense variants for all genes
for (gene in UGT_genes){
UGT_exonic_data <- eval(parse_expr(paste0(gene, '_exonic_data')))
missense_vars <- UGT_exonic_data[which(UGT_exonic_data$VEP_Annotation=='missense_variant'),]
assign(paste0(gene, '_missense_vars'), missense_vars)
write.table(missense_vars, file = paste0('processed-data/03_Anno_functional_impact/',
gene, '_missense_variants.csv'), row.names = FALSE, col.names = TRUE, sep = '\t')
}
# _______________________________________________________________________________
# 3.1.1 ANNOVAR input file preparation
# _______________________________________________________________________________
## Necessary columns per variant: Chromosome Start End Reference Alternate
## Start and End are the same for missense variants (single nt mutations)
## Annotate and predict missense variants
for (gene in UGT_genes){
UGT_missense_vars <- eval(parse_expr(paste0(gene, '_missense_vars')))
## Evaluate if reference and alternate alleles are single valid characters (no indels nor missing/null) for all missense variants in each gene
print(paste0(gene, ': ', names(table(
sapply(1:dim(UGT_missense_vars)[1], function(i){
if (UGT_missense_vars$Reference[i] %in% c('A', 'T', 'C', 'G')){TRUE}
else {FALSE}
}))), ' ',
names(table(
sapply(1:dim(UGT_missense_vars)[1], function(i){
if (UGT_missense_vars$Alternate[i] %in% c('A', 'T', 'C', 'G')){TRUE}
else {FALSE}
})))
))
}
# [1] "UGT1A1: TRUE TRUE"
# [1] "UGT1A3: TRUE TRUE"
# [1] "UGT1A4: TRUE TRUE"
# [1] "UGT1A5: TRUE TRUE"
# [1] "UGT1A6: TRUE TRUE"
# [1] "UGT1A7: TRUE TRUE"
# [1] "UGT1A8: TRUE TRUE"
# [1] "UGT1A9: TRUE TRUE"
# [1] "UGT1A10: TRUE TRUE"
# [1] "UGT2A1: TRUE TRUE"
# [1] "UGT2A2: TRUE TRUE"
# [1] "UGT2A3: TRUE TRUE"
# [1] "UGT2B4: TRUE TRUE"
# [1] "UGT2B7: TRUE TRUE"
# [1] "UGT2B10: TRUE TRUE"
# [1] "UGT2B11: TRUE TRUE"
# [1] "UGT2B15: TRUE TRUE"
# [1] "UGT2B17: TRUE TRUE"
# [1] "UGT2B28: TRUE TRUE"
# [1] "UGT3A1: TRUE TRUE"
# [1] "UGT3A2: TRUE TRUE"
# [1] "UGT8: TRUE TRUE"
## Sub datasets with specified columns for ANNOVAR
for (gene in UGT_genes){
UGT_missense_vars <- eval(parse_expr(paste0(gene, '_missense_vars')))
missense_vars_ANNOVAR_format <- data.frame(matrix(ncol=5, nrow=nrow(UGT_missense_vars)))
colnames(missense_vars_ANNOVAR_format) <- c('Chromosome', 'Start', 'End', 'Ref', 'Obs')
missense_vars_ANNOVAR_format$Chromosome <- UGT_missense_vars$Chromosome
missense_vars_ANNOVAR_format$Start <- missense_vars_ANNOVAR_format$End <- UGT_missense_vars$Position
missense_vars_ANNOVAR_format$Ref <- UGT_missense_vars$Reference
missense_vars_ANNOVAR_format$Obs <- UGT_missense_vars$Alternate
assign(paste0(gene, '_missense_vars_ANNOVAR_format'), missense_vars_ANNOVAR_format)
save(missense_vars_ANNOVAR_format, file = paste0('processed-data/03_Anno_functional_impact/ANNOVAR/input_data/',
gene, '_missense_vars_ANNOVAR_format.Rdata'))
write.table(missense_vars_ANNOVAR_format, file = paste0('processed-data/03_Anno_functional_impact/ANNOVAR/input_data/',
gene, '_missense_vars_ANNOVAR_format.txt'), row.names = FALSE, col.names = FALSE, sep = '\t')
write.table(missense_vars_ANNOVAR_format, file = paste0('processed-data/03_Anno_functional_impact/ANNOVAR/input_data/',
gene, '_missense_vars_ANNOVAR_format.csv'), row.names = FALSE, col.names = FALSE, sep = '\t')
}
## --> ANNOVAR was run in 3.1_run_ANNOVAR.sh
# _______________________________________________________________________________
# 3.1.2 Examination of ANNOVAR gene-based annotation output
# _______________________________________________________________________________
## Download ANNOVAR output for each gene
for (gene in UGT_genes){
myanno <- read.csv(paste0('processed-data/03_Anno_functional_impact/ANNOVAR/output_data/myanno', gene, '.hg19_multianno.csv'))
assign(paste0('myanno_', gene), myanno)
}
############################ 1. Confirm all missense variants are annotated as exonic #############################
sapply(UGT_genes, function(gene){names(table(eval(parse_expr(paste0('myanno_', gene, '$Func.refGene')))))})
# $UGT1A1
# [1] "exonic"
#
# $UGT1A3
# [1] "exonic"
#
# $UGT1A4
# [1] "exonic"
#
# $UGT1A5
# [1] "exonic"
#
# $UGT1A6
# [1] "exonic"
#
# $UGT1A7
# [1] "exonic"
#
# $UGT1A8
# [1] "exonic"
#
# $UGT1A9
# [1] "exonic"
#
# $UGT1A10
# [1] "exonic"
#
# $UGT2A1
# [1] "exonic"
#
# $UGT2A2
# [1] "exonic"
#
# $UGT2A3
# [1] "exonic"
#
# $UGT2B4
# [1] "exonic"
#
# $UGT2B7
# [1] "exonic"
#
# $UGT2B10
# [1] "exonic" "exonic;splicing"
#
# $UGT2B11
# [1] "exonic" "exonic;splicing"
#
# $UGT2B15
# [1] "exonic"
#
# $UGT2B17
# [1] "exonic"
#
# $UGT2B28
# [1] "exonic"
#
# $UGT3A1
# [1] "exonic"
#
# $UGT3A2
# [1] "exonic"
#
# $UGT8
# [1] "exonic"
# ----------------------------------------------------------- ? -----------------------------------------------------------
# Evaluate variants found as exonic and splicing |
# ----------------------------------------------------------- ? -----------------------------------------------------------
## In UGT2B10: var 4-69681891-G-A is within exon 1 of NM_001075 and NM_001144767 txs, not in the exon boundaries -> exonic
## This variant is in 5'-UTR of another UGT2B10 tx (NM_001290091)
myanno_UGT2B10[which(myanno_UGT2B10$Func.refGene=='exonic;splicing'), 1:10]
# Chr Start End Ref Alt Func.refGene Gene.refGene GeneDetail.refGene ExonicFunc.refGene
# 4 69681891 69681891 G A exonic;splicing UGT2B10;UGT2B10 NM_001290091:exon1:UTR5 nonsynonymous SNV
# AAChange.refGene
# UGT2B10:NM_001075:exon1:c.G154A:p.V52M,UGT2B10:NM_001144767:exon1:c.G154A:p.V52M
## Corroborate location of variant in NM_001075, the UGT2B10 canonical tx (ENST00000265403.7) and check Exon 1 boundaries
## (Use function location_determination() in ../01_Data_Processing.R)
location_determination(69681891, canonical_UGT2_txs[['UGT2B10']], 'Exon 1')
# "Exon 1"
#
# Start End
# Exon 1 69681738 69682455
# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
## In UGT2B11: variants 4-70066297-G-C and 4-70066297-G-A are both within exon 6 of UGT2B11 NM_001073 tx
## but in exon 3 of LOC105377267 tx
myanno_UGT2B11[which(myanno_UGT2B11$Func.refGene=='exonic;splicing'), 1:10]
# Chr Start End Ref Alt Func.refGene Gene.refGene GeneDetail.refGene ExonicFunc.refGene AAChange.refGene
# 4 70066297 70066297 G C exonic;splicing UGT2B11;LOC105377267 NR_136191:exon3:c.484+1G>C nonsynonymous SNV UGT2B11:NM_001073:exon6:c.C1451G:p.T484S
# 4 70066297 70066297 G A exonic;splicing UGT2B11;LOC105377267 NR_136191:exon3:c.484+1G>A nonsynonymous SNV UGT2B11:NM_001073:exon6:c.C1451T:p.T484I
location_determination(70066297, canonical_UGT2_txs[['UGT2B11']], 'Exon 6')
# "Exon 6"
#
# Start End
# Exon 6 70066437 70066158
# ---------------------------------------------------------------------------------------------------------------------------
################################ 2. Check all missense variants are non-synonymous ################################
sapply(UGT_genes, function(gene){names(table(eval(parse_expr(paste0('myanno_', gene, '$ExonicFunc.refGene')))))})
# $UGT1A1
# [1] "nonsynonymous SNV"
#
# $UGT1A3
# [1] "nonsynonymous SNV"
#
# $UGT1A4
# [1] "nonsynonymous SNV"
#
# $UGT1A5
# [1] "nonsynonymous SNV"
#
# $UGT1A6
# [1] "nonsynonymous SNV"
#
# $UGT1A7
# [1] "nonsynonymous SNV"
#
# $UGT1A8
# [1] "nonsynonymous SNV"
#
# $UGT1A9
# [1] "nonsynonymous SNV"
#
# $UGT1A10
# [1] "nonsynonymous SNV"
#
# $UGT2A1
# [1] "nonsynonymous SNV"
#
# $UGT2A2
# [1] "nonsynonymous SNV"
#
# $UGT2A3
# [1] "nonsynonymous SNV"
#
# $UGT2B4
# [1] "nonsynonymous SNV"
#
# $UGT2B7
# [1] "nonsynonymous SNV"
#
# $UGT2B10
# [1] "nonsynonymous SNV" "startloss"
#
# $UGT2B11
# [1] "nonsynonymous SNV"
#
# $UGT2B15
# [1] "nonsynonymous SNV"
#
# $UGT2B17
# [1] "nonsynonymous SNV"
#
# $UGT2B28
# [1] "nonsynonymous SNV"
#
# $UGT3A1
# [1] "nonsynonymous SNV"
#
# $UGT3A2
# [1] "nonsynonymous SNV"
#
# $UGT8
# [1] "nonsynonymous SNV"
# ----------------------------------------------------------- ? -----------------------------------------------------------
# Evaluate startloss variants: |
# ----------------------------------------------------------- ? -----------------------------------------------------------
## Variant 4-69683774-T-G is non-synonymous (aa change in AAChange.refGene) for NM_001075 and NM_001144767 txs of UGT2B10
## but is start lost for NM_001290091 tx (p.Met1? as protein consequence)
myanno_UGT2B10[which(myanno_UGT2B10$ExonicFunc.refGene=='startloss'), 1:10]
# Chr Start End Ref Alt Func.refGene Gene.refGene GeneDetail.refGene ExonicFunc.refGene
# 4 69683774 69683774 T G exonic UGT2B10 . startloss
# AAChange.refGene
# UGT2B10:NM_001075:exon2:c.T746G:p.M249R,UGT2B10:NM_001144767:exon2:c.T494G:p.M165R,UGT2B10:NM_001290091:exon2:c.T2G:p.M1?
## Corroborate this variant is within exon 2 of canonical tx (NM_001075), not at the beginning of exon 1 (Met)
location_determination(69683774, canonical_UGT2_txs[['UGT2B10']], 'Exon 2')
# "Exon 2"
#
# Start End
# Exon 2 69683747 69683895
# ---------------------------------------------------------------------------------------------------------------------------
########################### 3. Check in which genes the variants are present #############################
sapply(UGT_genes, function(gene){names(table(eval(parse_expr(paste0('myanno_', gene, '$Gene.refGene')))))})
# $UGT1A1
# [1] "UGT1A1" "UGT1A1;UGT1A10;UGT1A3;UGT1A4;UGT1A5;UGT1A6;UGT1A7;UGT1A8;UGT1A9"
#
# $UGT1A3
# [1] "UGT1A1;UGT1A10;UGT1A3;UGT1A4;UGT1A5;UGT1A6;UGT1A7;UGT1A8;UGT1A9" "UGT1A3"
#
# $UGT1A4
# [1] "UGT1A1;UGT1A10;UGT1A3;UGT1A4;UGT1A5;UGT1A6;UGT1A7;UGT1A8;UGT1A9" "UGT1A4"
#
# $UGT1A5
# [1] "UGT1A1;UGT1A10;UGT1A3;UGT1A4;UGT1A5;UGT1A6;UGT1A7;UGT1A8;UGT1A9" "UGT1A5"
#
# $UGT1A6
# [1] "UGT1A1;UGT1A10;UGT1A3;UGT1A4;UGT1A5;UGT1A6;UGT1A7;UGT1A8;UGT1A9" "UGT1A6"
#
# $UGT1A7
# [1] "UGT1A1;UGT1A10;UGT1A3;UGT1A4;UGT1A5;UGT1A6;UGT1A7;UGT1A8;UGT1A9" "UGT1A7"
#
# $UGT1A8
# [1] "UGT1A1;UGT1A10;UGT1A3;UGT1A4;UGT1A5;UGT1A6;UGT1A7;UGT1A8;UGT1A9" "UGT1A8"
#
# $UGT1A9
# [1] "UGT1A1;UGT1A10;UGT1A3;UGT1A4;UGT1A5;UGT1A6;UGT1A7;UGT1A8;UGT1A9" "UGT1A9"
#
# $UGT1A10
# [1] "UGT1A1;UGT1A10;UGT1A3;UGT1A4;UGT1A5;UGT1A6;UGT1A7;UGT1A8;UGT1A9" "UGT1A10"
#
# $UGT2A1
# [1] "UGT2A1" "UGT2A1;UGT2A2"
#
# $UGT2A2
# [1] "UGT2A1;UGT2A2" "UGT2A2"
#
# $UGT2A3
# [1] "UGT2A3"
#
# $UGT2B4
# [1] "UGT2B4"
#
# $UGT2B7
# [1] "UGT2B7"
#
# $UGT2B10
# [1] "UGT2B10" "UGT2B10;UGT2B10"
#
# $UGT2B11
# [1] "UGT2B11" "UGT2B11;LOC105377267"
#
# $UGT2B15
# [1] "UGT2B15"
#
# $UGT2B17
# [1] "UGT2B17"
#
# $UGT2B28
# [1] "UGT2B28"
#
# $UGT3A1
# [1] "UGT3A1"
#
# $UGT3A2
# [1] "UGT3A2"
#
# $UGT8
# [1] "UGT8"
# _______________________________________________________________________________
# 3.1.3 Apply ADME-optimized functionality prediction framework
# _______________________________________________________________________________
## Scores of interest
scores_algorithms <- c('SIFT_score', 'Polyphen2_HDIV_score', 'Polyphen2_HVAR_score', 'LRT_score','MutationAssessor_score', 'FATHMM_score',
'fathmm.MKL_coding_score', 'PROVEAN_score', 'VEST3_score', 'VEST4_score', 'CADD_phred', 'DANN_score', 'MetaSVM_score', 'MetaLR_score',
'REVEL_score', 'PrimateAI_score', 'M.CAP_score', 'ClinPred_score', 'Eigen.PC.raw_coding', 'MutPred_score', 'MVP_score')
## Categorical predictions
cat_pred_algorithms <- c('SIFT_pred', 'Polyphen2_HDIV_pred', 'Polyphen2_HVAR_pred', 'MutationAssessor_pred', 'FATHMM_pred',
'fathmm.MKL_coding_pred', 'PROVEAN_pred', 'MetaSVM_pred', 'MetaLR_pred', 'M.CAP_pred', 'ClinPred_pred', 'LRT_pred', 'PrimateAI_pred')
## Create single dataset for all missense UGT variants and their predicted effects and scores
## Unique variant IDs
for (gene in UGT_genes){
myanno <- eval(parse_expr(paste0('myanno_', gene)))
myanno$Variant_ID <- paste(myanno$Chr, myanno$Start, myanno$Ref, myanno$Alt, sep='-')
assign(paste0('myanno_', gene), myanno)
}
## Total unique UGT variants
unique_UGT_vars <- unique(unlist(sapply(paste0('myanno_', UGT_genes, '$Variant_ID'), function(x){eval(parse_expr(x))})))
variants_predictions <- data.frame(matrix(nrow=0, ncol=37))
colnames(variants_predictions) <- c('Variant_ID', 'Gene.refGene', scores_algorithms, cat_pred_algorithms)
for (UGT_variant in unique_UGT_vars){
## Search variant in each gene dataset
for(gene in UGT_genes){
myanno <- eval(parse_expr(paste0('myanno_', gene)))
if (UGT_variant %in% myanno$Variant_ID){
## For shared variants, assume the predictions are the same across all genes and take the ones reported in the first one
variants_predictions <- rbind(variants_predictions, myanno[which(myanno$Variant_ID==UGT_variant), c('Variant_ID', 'Gene.refGene', scores_algorithms, cat_pred_algorithms)])
break
}
}
}
## Correct category names for FATHMM_pred and PrimateAI_pred (TRUE -> 'T')
variants_predictions$FATHMM_pred <- replace(variants_predictions$FATHMM_pred,
which(variants_predictions$FATHMM_pred==TRUE), 'T')
variants_predictions$PrimateAI_pred <- replace(variants_predictions$PrimateAI_pred,
which(variants_predictions$PrimateAI_pred==TRUE), 'T')
## Standardize variable names for raw scores
colnames(variants_predictions)[c(9, 13, 21, 29)] <- c('fathmm.MKL_score', 'CADD_phred_score', 'Eigen.PC_score', 'fathmm.MKL_pred')
## Add ADME-optimized model scores
## ADME-optimized algorithm thresholds to categorize variants
ADME_thresholds <- list('LRT'='<0.0025',
'MutationAssessor'='>2.0566',
'PROVEAN'='< -3.286',
'VEST3'='>0.4534',
'CADD_phred'='>19.19')
## Categorize variants in D/N by each algorithm using these thresholds
ADME_categorical_predictions <- data.frame(matrix(nrow=dim(variants_predictions)[1], ncol=length(ADME_thresholds)+1))
colnames(ADME_categorical_predictions) <- c('Variant_ID', paste0(names(ADME_thresholds), '_pred'))
ADME_categorical_predictions$Variant_ID <- variants_predictions$Variant_ID
for(algorithm in names(ADME_thresholds)){
## Evaluate if the algorithm score of each variant passes cutoff (1) or not (0)
ADME_categorical_predictions[paste0(algorithm, '_pred')] <- apply(variants_predictions, 1,
function(x){if (x[paste0(algorithm, '_score')]=='.'){'.'}
else if (eval(parse_expr(paste0('as.numeric(x[paste0(algorithm, \'_score\')])', ADME_thresholds[[algorithm]]))) ){1}
else{0} })
}
## Add global ADME scores for each variant
variants_predictions$ADME_score <- signif(apply(ADME_categorical_predictions[,-1], 1, function(x){mean(as.numeric(x[which(x!='.')]))}), digits=3)
## Put '.' of no algorithm used in ADME model returned scores for a variant
variants_predictions$ADME_score[which(is.nan(variants_predictions$ADME_score))] <- '.'
## --> AlphaMissense data for UGT canonical txs were obtained in 3.2_extract_AlphaMissense_scores.sh
# _______________________________________________________________________________
# 3.1.4 Extract AlphaMissense (AM) predictions for all UGT variants
# _______________________________________________________________________________
## Retrieve AM scores and predictions for all variants of a gene (in its canonical tx)
for (gene in UGT_genes){
tx <- canonical_txs[[gene]]
data <- read_tsv(paste0('~/Documents/KI_projects/UGT_genetic_profiling_KI/raw-data/AlphaMissense_data/', tx, '_AlphaMissense_data'), show_col_types = FALSE)
## Add variant IDs
colnames(data) <- c('chr', 'pos', 'ref', 'alt', 'genome', 'uniprot_id', 'transcript_id', 'protein_variant', 'am_pathogenicity', 'am_class')
data$chr <- sapply(data$chr, function(x){strsplit(x, 'chr')[[1]][2]})
data$Variant_ID <- paste(data$chr, data$pos, data$ref, data$alt, sep='-')
assign(paste0(gene, '_AlphaMissense_data'), data)
}
## Search UGT missense variants in AM datasets
AM_score_pred <- function(variant_id){
## Data for each variant
var_data <- vector()
## Search variant within each gene
for(gene in UGT_genes){
AM_data <- eval(parse_expr(paste0(gene, '_AlphaMissense_data')))
if (variant_id %in% AM_data$Variant_ID){
var_data <- rbind(var_data, AM_data[which(AM_data$Variant_ID==variant_id), c('Variant_ID', 'am_pathogenicity', 'am_class')])
}
if (!is.null(dim(var_data))){
## For shared variants with differing scores across genes, take the most pathogenic one (the biggest) and its corresponding class
score <- var_data[order(var_data$am_pathogenicity, decreasing = TRUE),][1,'am_pathogenicity']
class <- var_data[order(var_data$am_pathogenicity, decreasing = TRUE),][1,'am_class']
}
## If variant was not found in any gene dataset (no AM score/pred)
else{
score <- class <- '.'
}
}
return(c(score, class))
}
## Search AM score/pred for all UGT variants
for (i in 1:dim(variants_predictions)[1]){
AM_output <- AM_score_pred(variants_predictions$Variant_ID[i])
variants_predictions$AlphaMissense_score[i] <- AM_output[[1]]
variants_predictions$AlphaMissense_pred[i] <- AM_output[[2]]
}
variants_predictions$AlphaMissense_pred <- replace(replace(replace(variants_predictions$AlphaMissense_pred,
which(variants_predictions$AlphaMissense_pred=='benign'), 'N'),
which(variants_predictions$AlphaMissense_pred=='pathogenic'), 'D'),
which(variants_predictions$AlphaMissense_pred=='ambiguous'), 'U')
save(variants_predictions, file='processed-data/03_Anno_functional_impact/variants_scores_and_predictions.Rdata')
# ____________________________________________________________________________________________
# 3.1.5 Comparison and evaluation of predictive algorithms
# ____________________________________________________________________________________________
#################### 3.1.5.1 Compare predictions of different algorithms ####################
## Real tool names
tool_names <- c('SIFT'='SIFT',
'Polyphen2_HDIV'='PolyPhen-2 HDIV',
'Polyphen2_HVAR'='PolyPhen-2 HVAR',
'MutationAssessor'='MutationAssessor',
'FATHMM'= 'FATHMM',
'fathmm.MKL'='FATHMM-MKL',
'PROVEAN'= 'PROVEAN',
'MetaSVM'='MetaSVM',
'MetaLR'='MetaLR',
'M.CAP'='M-CAP',
'ClinPred'='ClinPred',
'CADD_phred'='CADD',
'DANN'='DANN',
'REVEL'='REVEL',
'Eigen.PC'='Eigen-PC',
'MVP'= 'MVP',
'LRT'='LRT',
'MutPred'='MutPred',
'PrimateAI'='PrimateAI',
'VEST4'='VEST',
'ADME'='ADME',
'AlphaMissense'='AlphaMissense')
## Function to create density plot of raw scores for variants in the different functional categories
score_density_plot <- function(algorithm, predicted_cat_type){
algorithm_score <- paste0(algorithm, '_score')
algorithm_pred <- paste0(algorithm, '_pred')
## Define colors for categories of predicted effect
colors <- list('D'='tomato2', 'T'='skyblue1', 'N'='skyblue1', 'B'='skyblue1', 'P'='lightsalmon',
'H'= 'red4', 'M'='red3', 'L'='dodgerblue3', 'U'='grey90')
if (predicted_cat_type=='new'){
threshold <- algorithms_thresholds[[algorithm]]
numeric_threshold <- as.numeric(gsub('[<, =, >]', '', threshold))
## Subset to variants with algorithm scores (and predictions)
data <- new_variants_predictions[which(eval(parse_expr(paste0('new_variants_predictions$',algorithm_score)))!='.'),]
## Percentage of variants with missing scores/predictions from each algorithm (percentage of missingness)
missingness <- apply(new_variants_predictions, 2, function(x){100*length(which(x=='.'))/dim(new_variants_predictions)[1]})[[algorithm_score]]
## Number of variants with valid output from each algorithm
num_vars <- apply(new_variants_predictions, 2, function(x){length(which(x!='.'))})[[algorithm_score]]
## Density function with score limits
density <- density(as.numeric(data[,algorithm_score]),
from = min(as.numeric(data[,algorithm_score])),
to = max(as.numeric(data[,algorithm_score])))
## Categorize variant scores by defined threshold
df <- data.frame(x = density$x, y = density$y, pred = replace(replace(density$x, which(eval(parse_expr(paste0('density$x', threshold)))), 'D'),
which(!eval(parse_expr(paste0('density$x', threshold)))), 'N'))
if (algorithm=='FATHMM'){
hjust = 0.3
}
else if(algorithm=='VEST4' | algorithm=='DANN' | algorithm=='PrimateAI' | algorithm=='CADD'){
hjust = 1.5
}
else {
hjust = -0.3
}
if (algorithm=='CADD_phred'){score_type <- ' phred score'}
else {score_type <- ' raw score'}
p1 <- ggplot(data = df, aes(x = x, ymin = 0, ymax = y, fill = pred)) +
geom_ribbon(alpha=0.7) +
theme_bw() +
scale_fill_manual(values=colors[names(table(df$pred))]) +
labs(x = paste0(tool_names[algorithm], score_type), y= 'Density', fill='Predicted effect',
subtitle=paste0('Missingness: ', signif(as.numeric(missingness), digits=3), '%; ',
num_vars, ' variants')) +
geom_line(aes(y = y)) +
geom_vline(xintercept = numeric_threshold, color = 'indianred3', linetype='dashed', linewidth=0.6) +
geom_label(aes(x = numeric_threshold, y = max(df$y), color = 'indianred3', label = numeric_threshold),
hjust = hjust, vjust = 3, fontface = 2, fill = "white", show.legend = FALSE)
if(algorithm!='AlphaMissense'){
p1 <- p1 + theme(legend.position='none',
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.subtitle = element_text(size = 10, color = "gray30"),
plot.margin = unit(c(0.2,0.2,0.2,0.2), 'cm'),
axis.text = element_text(size = (10)),
legend.text = element_text(size = 10),
legend.title = element_text(size =11, face='bold'),
axis.title.x = element_text(size = (11.5), face='bold'),
axis.title.y = element_text(size = (11.5)))
}
else{
p1 <- p1 + theme(legend.key = element_rect(fill = "white", colour = "black"),
plot.subtitle = element_text(size = 10, color = "gray30"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.margin = unit(c(0.2,0.2,0.2,0.2), 'cm'),
axis.text = element_text(size = (10)),
legend.text = element_text(size = 10),
legend.title = element_text(size =11, face='bold'),
axis.title.x = element_text(size = (11.5), face='bold'),
axis.title.y = element_text(size = (11.5)))
}
return(p1)
}
else if(predicted_cat_type=='without_Polyphen2_HVAR'){
## HEREE
threshold <- algorithms_thresholds[[algorithm]]
numeric_threshold <- as.numeric(gsub('[<, =, >]', '', threshold))
data <- new_variants_predictions[which(eval(parse_expr(paste0('new_variants_predictions$',algorithm_score)))!='.'),]
missingness <- apply(new_variants_predictions, 2, function(x){100*length(which(x=='.'))/dim(new_variants_predictions)[1]})[[algorithm_score]]
num_vars <- apply(new_variants_predictions, 2, function(x){length(which(x!='.'))})[[algorithm_score]]
## Density function
density <- density(as.numeric(data[,algorithm_score]),
from = min(as.numeric(data[,algorithm_score])),
to = max(as.numeric(data[,algorithm_score])))
df <- data.frame(x = density$x, y = density$y, pred = replace(replace(density$x, which(eval(parse_expr(paste0('density$x', threshold)))), 'D'),
which(!eval(parse_expr(paste0('density$x', threshold)))), 'N'))
if (algorithm=='FATHMM'){
hjust = 0.3
}
else if(algorithm=='VEST4' | algorithm=='DANN' | algorithm=='PrimateAI' | algorithm=='CADD'){
hjust = 1.5
}
else {
hjust = -0.3
}
p1 <- ggplot(data = df, aes(x = x, ymin = 0, ymax = y, fill = pred)) +
geom_ribbon(alpha=0.7) +
theme_bw() +
scale_fill_manual(values=colors[names(table(df$pred))]) +
labs(x = tool_names[algorithm], y= 'Density', fill='Predicted effect',
subtitle=paste0(signif(as.numeric(missingness), digits=3), '% (n=',
num_vars, ')')) +
geom_line(aes(y = y)) +
geom_vline(xintercept = numeric_threshold, color = 'indianred3', linetype='dashed', linewidth=0.6) +
geom_label(aes(x = numeric_threshold, y = max(df$y), color = 'indianred3', label = numeric_threshold),
hjust = hjust, vjust = 3, fontface = 2, fill = "white", show.legend = FALSE)
if(algorithm!='AlphaMissense'){
p1 <- p1 + theme(legend.position='none',
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.subtitle = element_text(size = 10, color = "gray30"),
plot.margin = unit(c(0.2,0.2,0.2,0.2), 'cm'),
axis.text = element_text(size = (8)),
legend.text = element_text(size = 10),
legend.title = element_text(size =11, face='bold'),
axis.title.x = element_text(size = (11.5), face='bold'),
axis.title.y = element_text(size = (11.5)))
}
else{
p1 <- p1 + theme(legend.key = element_rect(fill = "white", colour = "black"),
plot.subtitle = element_text(size = 10, color = "gray30"),
panel.grid.major = element_blank(),
panel.grid.minor = element_blank(),
plot.margin = unit(c(0.2,0.2,0.2,0.2), 'cm'),
axis.text = element_text(size = (8)),
legend.text = element_text(size = 10),
legend.title = element_text(size =11, face='bold'),
axis.title.x = element_text(size = (11.5), face='bold'),
axis.title.y = element_text(size = (11.5)))
}
return(p1)
}
else{
data <- variants_predictions[which(eval(parse_expr(paste0('variants_predictions$',algorithm_score)))!='.'),]
p2 <- ggplot(data = data, aes(x = as.numeric(eval(parse_expr(algorithm_score))))) +
geom_density(alpha=0.6, fill='grey')+
theme_bw() +
labs(x = paste0(tool_names[algorithm], ' raw score'), y= 'Density')
p3 <- ggplot(data = data, aes(x = as.numeric(eval(parse_expr(algorithm_score))),
fill=eval(parse_expr(algorithm_pred))))+
geom_density(alpha=0.6)+
scale_fill_manual(values=colors[names(table(eval(parse_expr(paste0('data$', algorithm_pred)))))]) +
theme_bw() +
labs(x = paste0(tool_names[algorithm], ' raw score'), y= 'Density', fill='Predicted effect')
return(list(p2, p3))
}
}
################## a) Raw scores of variants already predicted as D and N/B/T ##################
## Algorithms already returning categorical predictions
algorithms <- c('SIFT', 'Polyphen2_HDIV', 'Polyphen2_HVAR', 'MutationAssessor', 'FATHMM',
'fathmm.MKL', 'PROVEAN', 'MetaSVM', 'MetaLR', 'M.CAP', 'ClinPred', 'LRT', 'PrimateAI', 'AlphaMissense')
plots <- list()
j=1
for (i in 1:length(algorithms)){
plots[[j]] <- score_density_plot(algorithms[i], 'returned')[[1]]
plots[[j+1]] <- score_density_plot(algorithms[i], 'returned')[[2]]
j=j+2
}
plot_grid(plots[[1]], plots[[2]], plots[[3]], plots[[4]], plots[[5]], plots[[6]], plots[[7]],<
plots[[8]], plots[[9]], plots[[10]], plots[[11]], plots[[12]], plots[[13]], plots[[14]],
plots[[15]], plots[[16]], plots[[17]], plots[[18]], plots[[19]], plots[[20]], plots[[21]], plots[[22]],
plots[[23]], plots[[24]], plots[[25]], plots[[26]], plots[[27]], plots[[28]],
ncol=6, rel_widths = c(rep(c(0.74,1), 14)))
ggsave(filename='plots/03_Anno_functional_impact/Returned_RawScores_density_plots.pdf', width = 30, height = 18)
################## b) Raw scores of variants categorized by defined score thresholds ##################
## Reported/conventional threshold to categorize variants as deleterious (D) (or neutral (N) otherwise) in each algorithm
algorithms_thresholds <- list('SIFT'='<=0.05',
'Polyphen2_HDIV'='>0.452',
'Polyphen2_HVAR'='>0.446',
'MutationAssessor'='>1.9',
'FATHMM'= '<= -1.5',
'fathmm.MKL'='>0.5',
'PROVEAN'= '< -2.282',
'MetaSVM'='>=0',
'MetaLR'='>=0.5',
'M.CAP'='>=0.025',
'ClinPred'='>=0.5',
'CADD_phred'='>15',
'DANN'='>0.96',
'REVEL'='>0.5',
'Eigen.PC'='>=0',
'MVP'= '>0.75',
'LRT'='<0.001',
'MutPred'='>0.5',
'PrimateAI'='>=0.803',
'VEST4'='>0.5',
'ADME'='>0.5',
'AlphaMissense'='>=0.564')
## Categorize variants with these thresholds
categorical_predictions <- data.frame(matrix(nrow=dim(variants_predictions)[1], ncol=length(names(algorithms_thresholds))+1))
colnames(categorical_predictions) <- c('Variant_ID', paste0(names(algorithms_thresholds), '_pred'))
categorical_predictions$Variant_ID <- variants_predictions$Variant_ID
for(algorithm in names(algorithms_thresholds)){
## Check if the algorithm score of each variant is above/below/equal to threshold
categorical_predictions[paste0(algorithm, '_pred')] <- apply(variants_predictions, 1,
function(x){if (x[paste0(algorithm, '_score')]=='.' | x[paste0(algorithm, '_score')]=='-'){'.'}
else if (eval(parse_expr(paste0('as.numeric(x[paste0(algorithm, \'_score\')])', algorithms_thresholds[[algorithm]]))) ){'D'}
else{'N'} })
}
## Bind scores and new binary predictions per algorithm
new_variants_predictions <- cbind(categorical_predictions, variants_predictions[,paste0(names(algorithms_thresholds), '_score')])
new_variants_predictions$MutPred_score <- replace(new_variants_predictions$MutPred_score, which(new_variants_predictions$MutPred_score=='-'), '.')
## Distribution of raw scores in D and N variants defined by cutoffs
plots <- list()
for (i in 1:length(names(algorithms_thresholds))){
plots[[i]] <- score_density_plot(names(algorithms_thresholds)[i], 'new')
}
## Shared legend
legend <- get_legend(
# Create some space to the left of the legend
plots[[22]] + theme(legend.box.margin = margin(0, 0, 0, 1))
)
plots[[22]] <- plots[[22]] + theme(legend.position = 'none',
plot.subtitle = element_text(size = 10, color = "gray30"),
plot.margin = unit(c(0.2,0.2,0.2,0.2), 'cm'))
plot_grid(plots[[1]], plots[[2]], plots[[3]], plots[[4]], plots[[5]], plots[[6]], plots[[7]],
plots[[8]], plots[[9]], plots[[10]], plots[[11]], plots[[12]], plots[[13]], plots[[14]],
plots[[15]], plots[[16]], plots[[17]], plots[[18]], plots[[19]], plots[[20]], plots[[21]], plots[[22]], ncol=5, legend)
ggsave(filename='plots/03_Anno_functional_impact/New_RawScores_density_plots.pdf', width = 14.5, height = 13)
## Exclude Polyphen2-HVAR
no_Polyphen2_HVAR <- names(algorithms_thresholds)[names(algorithms_thresholds)!='Polyphen2_HVAR']
plots <- list()
for (i in 1:length(no_Polyphen2_HVAR)){
plots[[i]] <- score_density_plot(no_Polyphen2_HVAR[i], 'without_Polyphen2_HVAR')
}
legend <- get_legend(
plots[[21]] + theme(legend.position = 'right',
legend.box.margin = margin(0, 0, 0, 1))
)
plots[[21]] <- plots[[21]] + theme(legend.position = 'none',
plot.subtitle = element_text(size = 10, color = "gray30"),
plot.margin = unit(c(0.2,0.2,0.2,0.2), 'cm'))
plot_grid(plots[[1]], plots[[2]], plots[[3]], plots[[4]], plots[[5]], plots[[6]], plots[[7]],
plots[[8]], plots[[9]], plots[[10]], plots[[11]], plots[[12]], plots[[13]], plots[[14]],
plots[[15]], plots[[16]], plots[[17]], plots[[18]], plots[[19]], plots[[20]], plots[[21]],
ncol=7, legend, align = 'vh')
ggsave(filename='plots/03_Anno_functional_impact/New_RawScores_density_plots_without_Polyphen2_HVAR.pdf', width = 11.8, height = 7.7)
# ------------------------------------------------------------------------------
## Correlation between raw scores from each pair of methods
## Exclude Polyphen2_HVAR
new_variants_predictions_wP <- new_variants_predictions[,-4]
algorithms_thresholds_wP <- algorithms_thresholds[-3]
raw_scores <- as.data.frame(apply(new_variants_predictions_wP[,paste0(names(algorithms_thresholds_wP), '_score')], 2, as.numeric))
corr <- matrix(nrow=21, ncol = 21)
colnames(corr) <- rownames(corr) <- colnames(raw_scores)
for (i in 1:length(colnames(raw_scores))){
for (j in 1:length(colnames(raw_scores))){
## Subset to variants with valid scores in both algorithms
raw_scores_subset <- raw_scores[which(!is.na(raw_scores[,colnames(raw_scores)[i]]) & !is.na(raw_scores[,colnames(raw_scores)[j]])),]
corr[i, j] <- signif(cor(raw_scores_subset[,colnames(raw_scores)[i]], raw_scores_subset[,colnames(raw_scores)[j]], method = 'pearson'), digits=2)
}
}
whole_corr <- corr
colnames(corr) <- rownames(corr) <- tool_names[-3]
## Half matrix
corr[lower.tri(corr)] <- NA
## Take absolute corr
corr <- abs(corr)
half_corr_data <- melt(corr, na.rm = TRUE)
half_corr_data$value <- signif(as.numeric(half_corr_data$value), digits = 3)
## Mean corr coeff
unique_half_corr_data <- half_corr_data[which(half_corr_data$value!=1), ]
mean(unique_half_corr_data$value)
# [1] 0.5612857
## Highest corr coeffs
unique_half_corr_data[order(unique_half_corr_data$value, decreasing = TRUE), ][1:4,]
# Var1 Var2 value
# MetaSVM MetaLR 0.93
# CADD phred Eigen-PC 0.93
# MetaSVM REVEL 0.88
# ClinPred ADME 0.85
## Percentage of high coeffs (|r|>0.5)
length(which(unique_half_corr_data$value>0.5))/dim(unique_half_corr_data)[1]*100
# [1] 63.80952
## Percentage of medium coeffs (0.3=<|r|=<0.5)
length(which(unique_half_corr_data$value>=0.3 & unique_half_corr_data$value<=0.5))/dim(unique_half_corr_data)[1]*100
# [1] 27.14286
## Percentage of low coeffs (|r|<0.3)
length(which(unique_half_corr_data$value<0.3))/dim(unique_half_corr_data)[1]*100
# [1] 9.047619
# ------------------------------------------------------------------------------
## Agreement proportion between predictions from each pair of methods
predictions <- as.data.frame(new_variants_predictions_wP[,paste0(names(algorithms_thresholds_wP), '_pred')])
agreement_prop <- matrix(ncol=21, nrow=21)
colnames(agreement_prop) <- rownames(agreement_prop) <- colnames(predictions)
for (i in 1:length(colnames(predictions))){
for(j in 1:length(colnames(predictions))){
## Subset to variants with predictions from both algorithms
predictions_subset <- predictions[which(!is.na(predictions[,colnames(predictions)[i]]) & !is.na(predictions[,colnames(predictions)[j]])),]
## Evaluate if predictions from algorithm 1 and 2 are different or the same for each variant
comparisons <- apply(predictions_subset[,c(colnames(predictions)[i], colnames(predictions)[j])], 1, function(x){if(x[1]==x[2]){'equal'}else{'diff'}})
agreement_prop[i, j]<- table(comparisons)['equal']/dim(predictions_subset)[1]
}
}
whole_agreement_prop <- agreement_prop
## Half matrix
colnames(agreement_prop) <- rownames(agreement_prop) <- tool_names[-3]
agreement_prop[lower.tri(agreement_prop)] <- NA
half_agreement_prop <- melt(agreement_prop, na.rm = TRUE)
half_agreement_prop$value <- signif(as.numeric(half_agreement_prop$value), digits = 3)
pdf(file = "plots/03_Anno_functional_impact/Compare_algorithms_outcomes.pdf", width = 10, height = 6)
par(mfrow=c(1,2))
corrplot(corr, method="color",
diag=FALSE,
type="upper",
addCoef.col = "black",
tl.cex = 0.4,
tl.col = 'black',
number.cex = 0.4,
cl.cex = 0.4,
col.lim = c(0,1),
col=colorRampPalette(c("white","white","white", 'mistyrose2',"tomato2", 'firebrick4'))(100)
)
corrplot(agreement_prop, method="color",
diag=FALSE,
type="upper",
addCoef.col = "black",
tl.cex = 0.4,
tl.col = 'black',
number.cex = 0.4,
cl.cex = 0.4,
col.lim = c(0,1),
col=colorRampPalette(c("white","white", 'darkseagreen2', "darkgreen"))(100)
)
dev.off()
## Mean prop
unique_half_agreement_prop <- half_agreement_prop[which(half_agreement_prop$value!=1), ]