-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path04_predictor_comparisons.Rmd
508 lines (347 loc) · 26.8 KB
/
04_predictor_comparisons.Rmd
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
---
title: "Untitled"
author: "Toni Beltran"
date: "04/03/2024"
output: html_document
---
```{r setup}
library(data.table)
library(ggplot2)
library(GGally)
library(viridis)
library(ggpubr)
base_dir="/path/to/your/files/"
setwd(base_dir)
mutated_domainome_preds<-fread("analysis_files/mutated_domainome_merged_filtered_all_VEPs_final.txt")
#compute correlations by domain
VEP_correlations<-mutated_domainome_preds[!is.na(growthrate) & mut_aa!="*",.(
replicate_r=mean(c(cor(growthrate1,growthrate2,method = "pearson",use = "pairwise.complete.obs"),cor(growthrate2,growthrate3,method = "pearson",use = "pairwise.complete.obs"),cor(growthrate1,growthrate3,method = "pearson",use = "pairwise.complete.obs"))),
replicate_r_spearman=mean(c(cor(growthrate1,growthrate2,method = "spearman",use = "pairwise.complete.obs"),cor(growthrate2,growthrate3,method = "spearman",use = "pairwise.complete.obs"),cor(growthrate1,growthrate3,method = "spearman",use = "pairwise.complete.obs"))),
rsasa_r=cor(growthrate,rsasa_all,method = "pearson",use = "pairwise.complete.obs"),
rsasa_r_spearman=cor(growthrate,rsasa_all,method = "spearman",use = "pairwise.complete.obs"),
esm1v_r=cor(mean_esm1v_prediction,growthrate,method = "pearson",use = "pairwise.complete.obs"),
esm1v_r_spearman=cor(mean_esm1v_prediction,growthrate,method = "spearman",use = "pairwise.complete.obs"),
esm1v_fl_r=cor(mean_esm1v_prediction_fl,growthrate,method = "pearson",use = "pairwise.complete.obs"),
esm1v_fl_r_spearman=cor(mean_esm1v_prediction_fl,growthrate,method = "spearman",use = "pairwise.complete.obs"),
range_esm=diff(quantile(mean_esm1v_prediction_fl,probs=c(0.025,0.975),na.rm=TRUE)),
eve_r=cor(-EVE_new,growthrate,method = "pearson",use = "pairwise.complete.obs"),
eve_r_spearman=cor(-EVE_new,growthrate,method = "spearman",use = "pairwise.complete.obs"),
eve_domain_r=cor(-EVE_score_domain,growthrate,method = "pearson",use = "pairwise.complete.obs"),
eve_domain_r_spearman=cor(-EVE_score_domain,growthrate,method = "spearman",use = "pairwise.complete.obs"),
tranception_r=cor(Tranception_new,growthrate,method = "pearson",use = "pairwise.complete.obs"),
tranception_r_spearman=cor(Tranception_new,growthrate,method = "spearman",use = "pairwise.complete.obs"),
popeve_r=cor(popEVE_new,growthrate,method = "pearson",use = "pairwise.complete.obs"),
popeve_r_spearman=cor(popEVE_new,growthrate,method = "spearman",use = "pairwise.complete.obs"),
rasp_r=cor(-RaSP_score,growthrate,method = "pearson",use = "pairwise.complete.obs"),
rasp_r_spearman=cor(-RaSP_score,growthrate,method = "spearman",use = "pairwise.complete.obs"),
ddmut_ddG_r=cor(ddmut_ddG,growthrate,method = "pearson",use = "pairwise.complete.obs"),
ddmut_ddG_r_spearman=cor(ddmut_ddG,growthrate,method = "spearman",use = "pairwise.complete.obs"),
thermoMPNN_ddG_r=cor(-thermoMPNN_ddG,growthrate,method = "pearson",use = "pairwise.complete.obs"),
thermoMPNN_ddG_r_spearman=cor(-thermoMPNN_ddG,growthrate,method = "spearman",use = "pairwise.complete.obs"),
AlphaMissense_r=cor(-AlphaMissense_fitness,growthrate,method = "pearson",use = "pairwise.complete.obs"),
AlphaMissense_r_spearman=cor(-AlphaMissense_fitness,growthrate,method = "spearman",use = "pairwise.complete.obs"),
foldx_r=cor(-foldx_ddg,growthrate,method = "pearson",use = "pairwise.complete.obs"),
foldx_r_spearman=cor(-foldx_ddg,growthrate,method = "spearman",use = "pairwise.complete.obs"),
N=length(growthrate),
EVE_noNA=length(which(!is.na(EVE_new))),
popEVE_noNA=length(which(!is.na(popEVE_new)))),
by=dom_ID]
VEP_correlations[,popEVE_completeness:=popEVE_noNA/N]
ggplot(VEP_correlations)+
geom_histogram(aes(x=popEVE_completeness))+
xlab("variant coverage (popEVE)")
nrow(VEP_correlations[popEVE_completeness>0.5,])
#spearman's rho
#all
VEP_correlations_spearman.mlt<-data.table(melt(VEP_correlations[,c("dom_ID","tranception_r_spearman","eve_r_spearman","thermoMPNN_ddG_r_spearman","ddmut_ddG_r_spearman","rasp_r_spearman","esm1v_r_spearman","esm1v_fl_r_spearman","popeve_r_spearman","rsasa_r_spearman","AlphaMissense_r_spearman","foldx_r_spearman","eve_domain_r_spearman")],id.var="dom_ID"))
VEP_correlations_spearman.mlt[variable %in% c("esm1v_r_spearman","esm1v_fl_r_spearman","popeve_r_spearman","tranception_r_spearman","eve_r_spearman","eve_domain_r_spearman","AlphaMissense_r_spearman"),
type:="fitness"]
VEP_correlations_spearman.mlt[variable %in% c("ddmut_ddG_r_spearman","rasp_r_spearman","thermoMPNN_ddG_r_spearman","foldx_r_spearman"),
type:="stability"]
VEP_correlations_spearman.mlt[variable %in% c("rsasa_r_spearman"),
type:="sasa"]
VEP_correlations_spearman.mlt$type<-factor(VEP_correlations_spearman.mlt$type,
levels=c("fitness","stability","sasa"))
VEP_correlations_spearman.mlt$variable<-factor(VEP_correlations_spearman.mlt$variable,
levels=c("eve_domain_r_spearman","esm1v_r_spearman","popeve_r_spearman","esm1v_fl_r_spearman","tranception_r_spearman","AlphaMissense_r_spearman","eve_r_spearman",
"thermoMPNN_ddG_r_spearman","foldx_r_spearman","ddmut_ddG_r_spearman","rasp_r_spearman",
"rsasa_r_spearman"))
levels(VEP_correlations_spearman.mlt$variable)<-c("EVE domain","ESM1v\ndomain","popEVE","ESM1v\nfull-length","Tranception","AlphaMissense","EVE","thermoMPNN","FoldX","ddmut","RaSP","rsasa")
#remove outlier (domain with 2 data points for Tranception)
VEP_correlations_spearman.mlt[variable=="Tranception" & value>0.99,value:=NA]
ggplot(VEP_correlations_spearman.mlt)+
geom_violin(aes(y=value,x=variable,col=type,fill=type),alpha=0.5)+
geom_boxplot(aes(y=value,x=variable,col=type),width=0.1,outlier.shape=NA)+
ylab("spearman's r")+
xlab("predictor")+
scale_fill_manual(values=c("#ED1C24","#294599","#FBB040"))+
scale_color_manual(values=c("#ED1C24","#294599","#FBB040"))+
theme_classic()+
theme(axis.text.x=element_text(angle = -90, hjust = 0))+
ylim(c(-0.25,0.85))
ggsave("output_files/Figure3c_VEPs_vs_aPCA.pdf")
summary_stats_spearman_all<-VEP_correlations_spearman.mlt[,.(median_spearman_r=median(value,na.rm=TRUE)),
by="variable"]
#spearman's rho for increasingly stringent subsets of the data
sprho_thresholds<-seq(0.5,0.8,0.05)
sprho_subsets<-data.table()
for (thr in sprho_thresholds){
VEP_correlations_spearman_filtered.mlt<-data.table(melt(VEP_correlations[replicate_r>thr,
c("dom_ID","tranception_r_spearman","eve_r_spearman","thermoMPNN_ddG_r_spearman","foldx_r_spearman","ddmut_ddG_r_spearman","rasp_r_spearman","esm1v_r_spearman","esm1v_fl_r_spearman","popeve_r_spearman","rsasa_r_spearman","AlphaMissense_r_spearman","eve_domain_r_spearman")],id.var="dom_ID"))
VEP_correlations_spearman_filtered.mlt$variable<-factor(VEP_correlations_spearman_filtered.mlt$variable, levels=c("eve_domain_r_spearman","esm1v_r_spearman","popeve_r_spearman","esm1v_fl_r_spearman","tranception_r_spearman","AlphaMissense_r_spearman","eve_r_spearman",
"thermoMPNN_ddG_r_spearman","foldx_r_spearman","ddmut_ddG_r_spearman","rasp_r_spearman",
"rsasa_r_spearman"))
levels(VEP_correlations_spearman_filtered.mlt$variable)<-c("EVE\n domain","ESM1v\ndomain","popEVE","ESM1v\nfull-length","Tranception","AlphaMissense","EVE","thermoMPNN","FoldX","ddmut","RaSP","rsasa")
summary_stats_spearman_all_filtered<-VEP_correlations_spearman_filtered.mlt[,.(median_spearman_r=median(value,na.rm=TRUE)),
by="variable"]
summary_stats_spearman_all_filtered[,sprho_thr:=thr]
sprho_subsets<-rbind(sprho_subsets,
summary_stats_spearman_all_filtered)
}
ggplot(sprho_subsets)+
geom_line(aes(x=sprho_thr,y=median_spearman_r,col=variable))+
geom_point(aes(x=sprho_thr,y=median_spearman_r,col=variable))+
theme_classic()+
xlab("replicate r threshold for domain inclusion")+
ylab("median spearman rho")
ggsave("output_files/median_spearman_rho_quality_filtering.pdf")
#remove zinc fingers
pfamid_description<-fread("analysis_files/pfam_ID_description_table.txt")
pfam_to_scop_class<-fread("analysis_files/PFAM_ID_to_SCOP_class.tsv")
pfam_to_scop_class[scop_class=="a/b",scop_class:="a/b a+b"]
pfam_to_scop_class[scop_class=="a+b",scop_class:="a/b a+b"]
VEP_correlations_spearman.mlt[, c("PFAM_ID") := tstrsplit(dom_ID, "_", fixed = TRUE)[2]]
VEP_correlations_spearman.mlt<-merge(VEP_correlations_spearman.mlt,pfamid_description,by="PFAM_ID",all.x = TRUE)
VEP_correlations_spearman.mlt<-merge(VEP_correlations_spearman.mlt,pfam_to_scop_class,by="PFAM_ID",all.x = TRUE)
ggplot(VEP_correlations_spearman.mlt[!is.na(`zinc finger`),])+
geom_violin(aes(y=value,x=variable,col=type,fill=type),alpha=0.5)+
geom_boxplot(aes(y=value,x=variable,col=type),width=0.1,outlier.shape=NA)+
ylab("spearman's r")+
xlab("predictor")+
ggtitle("no zinc fingers")+
scale_fill_manual(values=c("#ED1C24","#294599","#FBB040"))+
scale_color_manual(values=c("#ED1C24","#294599","#FBB040"))+
theme_classic()+
theme(axis.text.x=element_text(angle = -90, hjust = 0))+
facet_wrap(~`zinc finger`)+
ylim(c(-0.25,0.85))
ggsave("output_files/ED_Figure2a_VEPs_vs_aPCA_zf_vs_nonzf.pdf")
summary_stats_spearman_all_zf<-VEP_correlations_spearman.mlt[`zinc finger`=="zinc finger",.(median_spearman_r=median(value,na.rm=TRUE)),
by="variable"]
summary_stats_spearman_all_nozf<-VEP_correlations_spearman.mlt[`zinc finger`!="zinc finger",.(median_spearman_r=median(value,na.rm=TRUE)),
by="variable"]
#removing domains with homology to the Megascale dataset
hmmer_domains_table<-fread("analysis_files/hmmscan_PFAM_domainome_megascale_homology.tsv")
colnames(hmmer_domains_table)[c(1,2,4,7)]<-c("dom_ID","wt_seq","dataset","domain_family")
families_megascale<-unique(hmmer_domains_table[dataset=="megascale",]$domain_family)
domainome_homolog_free_families<-unique(hmmer_domains_table[dataset=="domainome" & !(domain_family %in% families_megascale),]$domain_family)
domainome_homolog_free<-unique(hmmer_domains_table[dataset=="domainome" & !(domain_family %in% families_megascale),]$dom_ID)
VEP_correlations_spearman.mlt[!(dom_ID %in% domainome_homolog_free),homolog:="yes"]
VEP_correlations_spearman.mlt[dom_ID %in% domainome_homolog_free,homolog:="no"]
ggplot(VEP_correlations_spearman.mlt[`zinc finger`=="",])+
geom_violin(aes(y=value,x=variable,col=type,fill=type),alpha=0.5)+
geom_boxplot(aes(y=value,x=variable,col=type),width=0.1,outlier.shape=NA)+
ylab("spearman's r")+
xlab("predictor")+
ggtitle("homology to Megascale domains (non-zinc finger domains only)")+
scale_fill_manual(values=c("#ED1C24","#294599","#FBB040"))+
scale_color_manual(values=c("#ED1C24","#294599","#FBB040"))+
theme_classic()+
theme(axis.text.x=element_text(angle = -90, hjust = 0))+
facet_wrap(~homolog)+
ylim(c(-0.25,0.85))
ggsave("output_files/ED_Figure2b_VEPs_vs_aPCA_homologfree.pdf")
summary_stats_spearman_homologs<-VEP_correlations_spearman.mlt[`zinc finger`!="zinc finger" & homolog=="yes",.(median_spearman_r=median(value,na.rm=TRUE)),
by="variable"]
summary_stats_spearman_nonhomologs<-VEP_correlations_spearman.mlt[`zinc finger`!="zinc finger" & homolog=="no",.(median_spearman_r=median(value,na.rm=TRUE)),
by="variable"]
#plot example correlations
ggplot(mutated_domainome_preds[dom_ID=="P67809_PF00313_52",])+
geom_point(aes(x=thermoMPNN_ddG,y=scaled_gr))+
scale_x_reverse()+
xlab("thermoMPNN ∆∆G")+
ylab("aPCA normalized fitness")
ggsave("output_files/Figure3b_example_correlations_thermoMPNN.pdf")
ggplot(mutated_domainome_preds[dom_ID=="P67809_PF00313_52",])+
geom_point(aes(x=mean_esm1v_prediction_fl,y=scaled_gr))+
xlab("esm1v prediction (mean)")+
ylab("aPCA normalized fitness")
ggsave("output_files/Figure3b_example_correlations_esm1v.pdf")
#spearman's rho for increasingly stringent subsets of the data
sprho_thresholds_nonZF<-seq(0.5,0.8,0.05)
sprho_subsets_nonZF<-data.table()
for (thr in sprho_thresholds_nonZF){
VEP_correlations_spearman_filtered.mlt<-data.table(melt(VEP_correlations[replicate_r>thr,
c("dom_ID","tranception_r_spearman","eve_r_spearman","thermoMPNN_ddG_r_spearman","ddmut_ddG_r_spearman","foldx_r_spearman","rasp_r_spearman","esm1v_r_spearman","esm1v_fl_r_spearman","popeve_r_spearman","rsasa_r_spearman","AlphaMissense_r_spearman","eve_domain_r_spearman")],id.var="dom_ID"))
VEP_correlations_spearman_filtered.mlt$variable<-factor(VEP_correlations_spearman_filtered.mlt$variable, levels=c("eve_domain_r_spearman","esm1v_r_spearman","popeve_r_spearman","esm1v_fl_r_spearman","tranception_r_spearman","AlphaMissense_r_spearman","eve_r_spearman",
"thermoMPNN_ddG_r_spearman","foldx_r_spearman","ddmut_ddG_r_spearman","rasp_r_spearman",
"rsasa_r_spearman"))
levels(VEP_correlations_spearman_filtered.mlt$variable)<-c("EVE\ndomain","ESM1v\ndomain","popEVE","ESM1v\nfull-length","Tranception","AlphaMissense","EVE","thermoMPNN","FoldX","ddmut","RaSP","rsasa")
VEP_correlations_spearman_filtered.mlt[, c("PFAM_ID") := tstrsplit(dom_ID, "_", fixed = TRUE)[2]]
VEP_correlations_spearman_filtered.mlt<-merge(VEP_correlations_spearman_filtered.mlt,pfamid_description,by="PFAM_ID",all.x = TRUE)
VEP_correlations_spearman_filtered.mlt<-merge(VEP_correlations_spearman_filtered.mlt,pfam_to_scop_class,by="PFAM_ID",all.x = TRUE)
summary_stats_spearman_all_filtered<-VEP_correlations_spearman_filtered.mlt[`zinc finger`!="zinc finger",.(median_spearman_r=median(value,na.rm=TRUE)),
by="variable"]
summary_stats_spearman_all_filtered[,sprho_thr:=thr]
sprho_subsets_nonZF<-rbind(sprho_subsets_nonZF,
summary_stats_spearman_all_filtered)
}
ggplot(sprho_subsets_nonZF)+
geom_line(aes(x=sprho_thr,y=median_spearman_r,col=variable))+
geom_point(aes(x=sprho_thr,y=median_spearman_r,col=variable))+
theme_classic()+
xlab("replicate r threshold for domain inclusion")+
ylab("median spearman rho")
ggsave("output_files/median_spearman_rho_quality_filtering_nonZF.pdf")
```
```{r fraction of evo constraint explained by abundance - by family, fig.height=6, fig.width=8}
#fraction of fitness due to stability accounting for error in aPCA
VEP_correlations[,esm1v_fl_r_attenuation_corrected:=esm1v_fl_r/sqrt(replicate_r)]
VEP_correlations[,explainable_variance:=esm1v_fl_r_attenuation_corrected**2]
VEP_correlations[,esm1v_fl_r_spearman_attenuation_corrected:=esm1v_fl_r_spearman/sqrt(replicate_r_spearman)]
VEP_correlations[,explainable_variance_spearman:=esm1v_fl_r_spearman_attenuation_corrected**2]
ggplot(VEP_correlations)+
geom_point(aes(x=explainable_variance,y=explainable_variance_spearman))+
theme_classic()
ggsave("output_files/ED_Figure2c_parametric_vs_nonparametric_varexplained.pdf")
cor(VEP_correlations$explainable_variance,VEP_correlations$explainable_variance_spearman,
use = "pairwise.complete.obs")
VEP_correlations[, c("PFAM_ID") := tstrsplit(dom_ID, "_", fixed = TRUE)[2]]
VEP_correlations<-merge(VEP_correlations,pfam_to_scop_class,by="PFAM_ID",all.x = TRUE)
VEP_correlations<-merge(VEP_correlations,pfamid_description,by="PFAM_ID",all.x = TRUE)
families_with_5<-names(table(VEP_correlations$PFAM_ID)[which(table(VEP_correlations$PFAM_ID)>4)])
#explainable variance esm1v
medians<-VEP_correlations[PFAM_ID %in% families_with_5,.(median(explainable_variance,na.rm = TRUE)),by="PFAM_ID_description"]
medians<-medians[order(V1,decreasing = TRUE),]
VEP_correlations$PFAM_ID_description<-factor(VEP_correlations$PFAM_ID_description,
levels=medians$PFAM_ID_description)
VEP_correlations[PFAM_ID %in% c("PF00595","PF00018","PF00397","PF00641","PF00643","PF01846","PF00536","PF00627","PF00226","PF14604","PF06467","PF07647","PF00412","PF02198","PF00628"),domain_function := "protein binding"]
VEP_correlations[PFAM_ID %in% c("PF00105","PF00505","PF00157","PF00046","PF00249","PF00313","PF02376"),domain_function := "DNA binding"]
VEP_correlations[PFAM_ID %in% c("PF00013"),domain_function := "RNA binding"]
VEP_correlations[PFAM_ID %in% c("PF00030","PF00096","PF00642"),domain_function := "other/multiple"]
ggplot(VEP_correlations[PFAM_ID %in% families_with_5,])+
geom_violin(aes(x=explainable_variance,y=PFAM_ID_description,fill=scop_class,col=scop_class),alpha=0.5)+
geom_jitter(aes(x=explainable_variance,y=PFAM_ID_description,col=scop_class),size=0.5)+
geom_boxplot(aes(x=explainable_variance,y=PFAM_ID_description),width=0.3,outlier.shape = NA,alpha=0.5)+
scale_color_manual(values=c("#A0ACD7","#ED1C24","#294599","#FBB040"))+
scale_fill_manual(values=c("#A0ACD7","#ED1C24","#294599","#FBB040"))+
theme_classic()
ggsave("output_files/ED_Figure2e_esm1v_vs_aPCA.pdf")
ggplot(VEP_correlations[!is.na(scop_class),])+
geom_violin(aes(x=scop_class,y=explainable_variance,fill=scop_class,col=scop_class),alpha=0.5)+
geom_boxplot(aes(x=scop_class,y=explainable_variance),width=0.15,fill="white",outlier.shape = NA)+
geom_jitter(aes(x=scop_class,y=explainable_variance,col=scop_class))+
scale_color_manual(values=c("#A0ACD7","#ED1C24","#294599","#FBB040"))+
scale_fill_manual(values=c("#A0ACD7","#ED1C24","#294599","#FBB040"))+
theme_classic()
ggsave("output_files/ED_Figure2f_esm1v_vs_aPCA_scopclasses.pdf")
ggplot(VEP_correlations[!is.na(domain_function),])+
geom_violin(aes(x=domain_function,y=explainable_variance,fill=domain_function,col=domain_function),alpha=0.5)+
geom_boxplot(aes(x=domain_function,y=explainable_variance),width=0.15,fill="white",outlier.shape = NA)+
geom_jitter(aes(x=domain_function,y=explainable_variance,col=domain_function))+
scale_color_manual(values=c("lightgrey","lightgrey","lightgrey","lightgrey"))+
scale_fill_manual(values=c("lightgrey","lightgrey","lightgrey","lightgrey"))+
theme_classic()
ggsave("output_files/ED_Figure2g_esm1v_vs_aPCA_domainfunction.pdf")
median(VEP_correlations$explainable_variance,na.rm=TRUE)
median(VEP_correlations[scop_class=="all beta" & N,]$explainable_variance,na.rm=TRUE)
median(VEP_correlations[scop_class=="all alpha",]$explainable_variance,na.rm=TRUE)
median(VEP_correlations[scop_class=="small proteins",]$explainable_variance,na.rm=TRUE)
median(VEP_correlations[scop_class=="a/b a+b",]$explainable_variance,na.rm=TRUE)
```
```{r tsubo}
humanrocklin<-fread("analysis_files/human_variants_rocklin_nobackgrounds")
dupdoms<-c("2LVN.pdb","2L7F.pdb","5FW9.pdb","2KCF.pdb","2M8I.pdb","2M8J.pdb","2M9F.pdb","2M9I.pdb","1SIF.pdb","5ZD0.pdb","6IPY.pdb","2MWB.pdb","2N4R","2N4S","2N4T")
humanrocklin_nodupdoms<-humanrocklin[!(V30 %in% dupdoms),]
humanrocklin_nodupdoms_singles<-humanrocklin_nodupdoms[-unique(c(grep("dmut",V1),grep("_wt",V1),grep("_hnet",V1),grep("ins",V1),grep("del",V1))),]
humanrocklin_nodupdoms_singles[!duplicated(V28),]
humanrocklin_nodupdoms_singles$is_single<-unlist(lapply(humanrocklin_nodupdoms_singles$V1,function(string){
return(length(strsplit(string,"_")[[1]]))
}))
table(humanrocklin_nodupdoms_singles$is_single)
unique(humanrocklin_nodupdoms_singles[is_single==3,]$V30)
unique(humanrocklin_nodupdoms_singles[is_single==1,]$V30)
ggplot()+
geom_col(aes(y=c(5847,55238,80229,536684),x=c("ProthermDB","Mega-scale","MaveDB","Domainome 1.0")))+
xlab("Source")+
ylab("number of human single\nmutant missense variants")
ggsave("output_files/Figure3a_human_missense_counts_comparison.pdf")
```
```{r predictor coverage human}
mutated_domainome_preds_human_missense<-mutated_domainome_preds[!is.na(growthrate) & mut_aa!="*" & Organism=="Homo sapiens (Human)",]
var_count<-c(nrow(mutated_domainome_preds_human_missense[!is.na(EVE_new),]),
nrow(mutated_domainome_preds_human_missense[!is.na(popEVE_new),]),
nrow(mutated_domainome_preds_human_missense[!is.na(Tranception_new),]),
nrow(mutated_domainome_preds_human_missense[!is.na(AlphaMissense_fitness),]),
nrow(mutated_domainome_preds_human_missense[!is.na(mean_esm1v_prediction),]),
nrow(mutated_domainome_preds_human_missense[!is.na(mean_esm1v_prediction_fl),]),
nrow(mutated_domainome_preds_human_missense[!is.na(thermoMPNN_ddG),]),
nrow(mutated_domainome_preds_human_missense[!is.na(ddmut_ddG),]),
nrow(mutated_domainome_preds_human_missense[!is.na(RaSP_score),]),
nrow(mutated_domainome_preds_human_missense[!is.na(foldx_ddg),]),
nrow(mutated_domainome_preds_human_missense[!is.na(EVE_score_domain),]),
nrow(mutated_domainome_preds_human_missense[!is.na(rsasa_all),]))
variant_coverage<-data.table(var_count,predictors=c("EVE","popEVE","Tranception","AlphaMissense","esm1v domain","esm1v full-length","thermoMPNN","ddmut","RaSP","FoldX","EVE domain","rsasa_all"))
variant_coverage[,perc_covered:=var_count/nrow(mutated_domainome_preds_human_missense)]
variant_coverage$predictors<-factor(variant_coverage$predictors,
levels=c("EVE","popEVE","Tranception","AlphaMissense","esm1v domain","esm1v full-length","thermoMPNN","ddmut","RaSP","FoldX","EVE domain","rsasa_all"))
ggplot(variant_coverage)+
geom_col(aes(y=perc_covered,x=predictors))+
theme_classic()+
theme(axis.text.x=element_text(angle = -90, hjust = 0))
supp_table<-mutated_domainome_preds[,c("dom_ID","uniprot_ID","uniprotID_mutation","aa_seq","growthrate","growthrate_sigma","scaled_gr","scaled_gr_sigma","mean_esm1v_prediction","RaSP_score","ddmut_ddG","foldx_ddg","popEVE_new","EVE_new","Tranception_new","EVE_score_domain","rsasa_all","thermoMPNN_ddG","AlphaMissense_fitness","mean_esm1v_prediction_fl","Organism","Gene Names (primary)","Gene Names (synonym)")]
colnames(supp_table)<-c("domain_ID","uniprot_ID","uniprot_ID_mutation","aa_seq","fitness","fitness_sigma","scaled_fitness","scaled_fitness_sigma","ESM1v_domain","RaSP","ddmut","FoldX","popEVE","EVE","Tranception","EVE_domain","rsasa","thermoMPNN","AlphaMissense","ESM1v_full-length","Organism","Gene Names (primary)","Gene Names (synonym)")
write.table(supp_table,
"output_files/ED_Table_5_aPCA_vs_variant_effect_predictors.txt",
sep = "\t", quote=FALSE, row.names = FALSE)
```
```{r stabilizing mutations}
mutated_domainome_preds[,z:=scaled_gr/scaled_gr_sigma]
mutated_domainome_preds[,p_stabilising:=1-pnorm(z)]
mutated_domainome_preds[,fdr_stabilising:=p.adjust(p_stabilising,method="fdr")]
mutated_domainome_preds[,p_destabilising:=pnorm(z)]
mutated_domainome_preds[,fdr_destabilising:=p.adjust(p_destabilising,method="fdr")]
mutated_domainome_preds[,stability_class:="wild type-like"]
mutated_domainome_preds[fdr_stabilising<0.1 & scaled_gr>0.3,stability_class:="stabilizing"]
mutated_domainome_preds[fdr_destabilising<0.1 & scaled_gr<0,stability_class:="mildly destabilizing"]
mutated_domainome_preds[fdr_destabilising<0.1 & scaled_gr<(-0.3),stability_class:="strongly destabilizing"]
mutated_domainome_preds_stab_proportion<-mutated_domainome_preds[,.(stab_proportion=length(which(stability_class=="stabilizing"))/length(which(!is.na(stability_class)))),by="dom_ID"]
ggplot(mutated_domainome_preds_stab_proportion)+
geom_histogram(aes(x=stab_proportion))
ggsave("output_files/stabilizing_fraction_perdomain.pdf")
median(mutated_domainome_preds_stab_proportion$stab_proportion)
mutated_domainome_preds$stability_class<-factor(mutated_domainome_preds$stability_class,
levels=c("stabilizing","wild type-like","mildly destabilizing","strongly destabilizing"))
ggplot(mutated_domainome_preds[dom_ID %in% mutated_domainome_preds_stab_proportion[stab_proportion<0.025,]$dom_ID,])+
geom_violin(aes(y=mean_esm1v_prediction,x=stability_class))+
geom_boxplot(aes(y=mean_esm1v_prediction,x=stability_class),width=0.15,outlier.shape = NA)
ggsave("output_files/stabilizing_ESM1v_scores.pdf")
ggplot(mutated_domainome_preds[dom_ID %in% mutated_domainome_preds_stab_proportion[stab_proportion<0.025,]$dom_ID,])+
geom_violin(aes(y=thermoMPNN_ddG,x=stability_class))+
geom_boxplot(aes(y=thermoMPNN_ddG,x=stability_class),width=0.15,outlier.shape=NA)
ggsave("output_files/stabilizing_thermoMPNN_scores.pdf")
#proportions of mutation types in stability classes
wt_aa_proportions<-prop.table(table(mutated_domainome_preds$wt_aa,mutated_domainome_preds$stability_class),margin=2)
mut_aa_proportions<-prop.table(table(mutated_domainome_preds$mut_aa,mutated_domainome_preds$stability_class),margin=2)
core_proportions<-prop.table(table(mutated_domainome_preds$core,mutated_domainome_preds$stability_class),margin=2)
mut_aa_proportions[,1]/mut_aa_proportions[,4]
#split by core-surface
wt_aa_proportions<-prop.table(table(mutated_domainome_preds[core=="core",]$wt_aa,mutated_domainome_preds[core=="core",]$stability_class),margin=2)
mut_aa_proportions<-prop.table(table(mutated_domainome_preds[core=="core" & mut_aa !="*",]$mut_aa,mutated_domainome_preds[core=="core" & mut_aa!="*",]$stability_class),margin=2)
barplot(log2(mut_aa_proportions[,1]/mut_aa_proportions[,4]),main="stabilizing vs destabilizing - cores")
wt_aa_proportions<-prop.table(table(mutated_domainome_preds[core=="surface",]$wt_aa,mutated_domainome_preds[core=="surface",]$stability_class),margin=2)
mut_aa_proportions<-prop.table(table(mutated_domainome_preds[core=="surface" & mut_aa !="*",]$mut_aa,mutated_domainome_preds[core=="surface" & mut_aa!="*",]$stability_class),margin=2)
barplot(log2(mut_aa_proportions[,1]/mut_aa_proportions[,4]),main="stabilizing vs destabilizing - surfaces")
#proportions of mutation types in stabilizing mutation classes
mutated_domainome_preds[,stabilizing_lowfitness:=NA]
mutated_domainome_preds[stability_class=="stabilizing",stabilizing_lowfitness:="no"]
mutated_domainome_preds[stability_class=="stabilizing" & mean_esm1v_prediction<(-10),stabilizing_lowfitness:="yes"]
wt_aa_proportions<-prop.table(table(mutated_domainome_preds$wt_aa,mutated_domainome_preds$stabilizing_lowfitness),margin=2)
mut_aa_proportions<-prop.table(table(mutated_domainome_preds$mut_aa,mutated_domainome_preds$stabilizing_lowfitness),margin=2)
core_proportions<-prop.table(table(mutated_domainome_preds$core,mutated_domainome_preds$stabilizing_lowfitness),margin=2)
#proportions of core surface and aa in stabilising mutations
mut_aa_proportions_core<-prop.table(table(mutated_domainome_preds[stability_class=="stabilizing" & mut_aa !="*",]$mut_aa,mutated_domainome_preds[stability_class=="stabilizing" & mut_aa !="*",]$core),margin=2)
pdf("output_files/stabilizing_mutaa_enrichments_core_vs_surface.pdf")
barplot(log2(mut_aa_proportions_core[,1]/mut_aa_proportions_core[,2]), main="stabilizing variants - core vs surface enrichments")
dev.off()
```