-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path22_mochi_homologmodels_evaluation.Rmd
236 lines (167 loc) · 10.3 KB
/
22_mochi_homologmodels_evaluation.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
---
title: "evaluation of homolog model predictions on other DMS datasets"
output: html_document
date: "2024-08-12"
---
```{r load data}
library(data.table)
library(ggplot2)
library(stringr)
library(viridis)
base_dir="/path/to/your/files"
setwd(base_dir)
#read mochi weights
pfamids<-fread("analysis_files/homolog_mochi_input_files/PFAM_IDs",header=FALSE)$V1
read_weights<-function(family,fit_type){
weights<-fread(paste("analysis_files/homolog_mochi_input_files/",family,"_",fit_type,"/weights/weights_Folding.txt",sep=""))
weights[,mut_aa:=substr(id,nchar(id),nchar(id))]
weights[id=="WT",mut_aa:=NA]
weights$mut_aa<-factor(weights$mut_aa,
levels=str_split("QNSTDEKRHGPCMAILVFYW","")[[1]])
features<-fread(paste("analysis_files/homolog_mochi_input_files/",family,"_features_solu.txt",sep=""))
wt_weights<-features[SoluWeight!="",]$SoluWeight
mut_weights<-weights[!is.na(`mean_kcal/mol`) & !(id %in% wt_weights),]
if (fit_type=="folding_linear"){
mut_weights$`mean_kcal/mol`<-mut_weights$`mean_kcal/mol`*(-1)
}
unfolded<-quantile(mut_weights$`mean_kcal/mol`,probs=0.975)
mut_weights[,mean_kcalmol_scaled:=`mean_kcal/mol`/unfolded]
mut_weights[,std_kcalmol_scaled:=`std_kcal/mol`/unfolded]
mut_weights<-mut_weights[,PFAM_ID:=family]
return(mut_weights)
}
homochi_weights<-data.table()
for (pfamid in pfamids){
homochi_weights<-rbind(homochi_weights,read_weights(pfamid,"folding"))
}
#load mappings of homolog domains from Rocklin to our 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")
hmmer_domains_table[dataset=="domainome",PFAM_ID:=tstrsplit(dom_ID,"_")[2]]
for (pfamid in pfamids){
family_IDs<-unique(hmmer_domains_table[PFAM_ID==pfamid & dataset=="domainome",]$domain_family)
hmmer_domains_table[domain_family %in% family_IDs & domain_family !="" & dataset=="megascale",PFAM_ID:=pfamid]
}
#domains in megascale dataset matching mochi models
hmmer_domains_table[dataset=="megascale" & !is.na(PFAM_ID),c("dom_ID","wt_seq","domain_family","PFAM_ID")]
#map rocklin domains to uniprot positions
megascale_mappings_to_uniprot<-fread("analysis_files/megascale_uniprot_mappings_offsets.tsv")
megascale_mappings_to_uniprot[,uniprot_ID:=tstrsplit(uniprot,"\\|")[2]]
#load human pfam alignments
megascale_pfam_alignments<-fread("analysis_files/Pfam-A.human.seqpos_to_alnpos.megascale")
colnames(megascale_pfam_alignments)[c(2,3,6,7)]<-c("pos_uniprot","pos_aln","uniprot_ID","PFAM_ID")
#load rocklin dataset
megascale_data<-fread("analysis_files/K50_dG_Dataset1_Dataset2.csv")
#use offsets to convert rocklin to uniprot positions
megascale_data_uniprot<-merge(megascale_data, megascale_mappings_to_uniprot[,c("pdb_id","uniprot_ID","offset")],
by.x="WT_name", by.y="pdb_id",
all.x=TRUE)
megascale_data_uniprot$pos_domain<-as.numeric(unlist(lapply(megascale_data_uniprot$mut_type,FUN = function(string){
return(substr(string,2,nchar(string)-1))
})))
megascale_data_uniprot[,pos_uniprot:=pos_domain+offset]
megascale_data_uniprot$mut_aa<-unlist(lapply(megascale_data_uniprot$mut_type,FUN = function(string){
return(substr(string,nchar(string),nchar(string)))
}))
#use pfam alignments info to convert uniprot positions to pfam alignment positions
megascale_data_uniprot_pfam<-merge(megascale_data_uniprot,megascale_pfam_alignments,
by=c("uniprot_ID","pos_uniprot"))
#use mapping to mochi weights to convert to mochi weight positions
pfam_alnpos_to_mochi_pos<-fread("analysis_files/homolog_mochi_input_files/mochi_alnpos_to_pfam_alnpos.txt")
megascale_data_uniprot_pfam<-merge(megascale_data_uniprot_pfam,pfam_alnpos_to_mochi_pos[!duplicated(pfam_alnpos_to_mochi_pos)],
by.x=c("PFAM_ID","pos_aln"),by.y=c("PFAM_ID","pos_pfam"))
#merge to mochi weights
megascale_data_uniprot_pfam_mochiweights<-merge(megascale_data_uniprot_pfam,homochi_weights,
by.x = c("PFAM_ID","pos_recoded","mut_aa"),
by.y = c("PFAM_ID","Pos","mut_aa"))
megascale_data_uniprot_pfam_mochiweights$dG_ML<-as.numeric(megascale_data_uniprot_pfam_mochiweights$dG_ML)
megascale_data_uniprot_pfam_mochiweights$ddG_ML<-as.numeric(megascale_data_uniprot_pfam_mochiweights$ddG_ML)
ggplot(megascale_data_uniprot_pfam_mochiweights)+
geom_hex(aes(x=mean_kcalmol_scaled,y=dG_ML))+
facet_wrap(~WT_name)+
scale_color_viridis()
ggsave("output_files/mochi_evaluation_tsuboyama2023_homologs.pdf")
cors_mochi_to_rocklin<-megascale_data_uniprot_pfam_mochiweights[,.(spearman_rhos=cor(-dG_ML,mean_kcalmol_scaled,
use="pairwise.complete.obs",
method="spearman"),
pearson_rs=cor(-dG_ML,mean_kcalmol_scaled,
use="pairwise.complete.obs",
method="pearson"),
PFAM_ID=unique(PFAM_ID)),by="WT_name"]
median(cors_mochi_to_rocklin$spearman_rhos)
median(cors_mochi_to_rocklin$pearson_rs)
table(cors_mochi_to_rocklin$PFAM_ID)
#remove domains present in both (to prevent data leakage)
domains_matching_aPCA_domains<-c("1SN1.pdb","1UZC.pdb","3L1X.pdb","2HBB.pdb","1YU5.pdb","1H92.pdb","1PWT.pdb","2LJ3.pdb","4HCK.pdb","1MJC.pdb","2PDD.pdb","2M51.pdb","1CSQ.pdb","2WQG.pdb","4UZW.pdb","5AHT.pdb","1QLY.pdb","2M8I.pdb","1I6C.pdb","2KCF.pdb","2YSF.pdb")
cors_mochi_to_rocklin[WT_name %in% domains_matching_aPCA_domains,in_aPCA:=TRUE]
cors_mochi_to_rocklin[!(WT_name %in% domains_matching_aPCA_domains),in_aPCA:=FALSE]
median(cors_mochi_to_rocklin[in_aPCA==FALSE,]$pearson_rs)
ggplot(cors_mochi_to_rocklin)+
geom_boxplot(aes(y=pearson_rs,x=in_aPCA))+
geom_jitter(aes(y=pearson_rs,x=in_aPCA),height=0)
ggsave("output_files/Figure5k_performance_on_tsuboyama2023_homologs.pdf")
```
```{r rocklin}
#redo analysis on folding_solu dataset
homochi_weights<-data.table()
for (pfamid in pfamids){
homochi_weights<-rbind(homochi_weights,read_weights(pfamid,"folding_solu"))
}
#load mappings of homolog domains from Rocklin to our 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")
hmmer_domains_table[dataset=="domainome",PFAM_ID:=tstrsplit(dom_ID,"_")[2]]
for (pfamid in pfamids){
family_IDs<-unique(hmmer_domains_table[PFAM_ID==pfamid & dataset=="domainome",]$domain_family)
hmmer_domains_table[domain_family %in% family_IDs & domain_family !="" & dataset=="megascale",PFAM_ID:=pfamid]
}
#domains in megascale dataset matching mochi models
hmmer_domains_table[dataset=="megascale" & !is.na(PFAM_ID),c("dom_ID","wt_seq","domain_family","PFAM_ID")]
#map rocklin domains to uniprot positions
megascale_mappings_to_uniprot<-fread("analysis_files/megascale_uniprot_mappings_offsets.tsv")
megascale_mappings_to_uniprot[,uniprot_ID:=tstrsplit(uniprot,"\\|")[2]]
#load human pfam alignments
megascale_pfam_alignments<-fread("analysis_files/Pfam-A.human.seqpos_to_alnpos.megascale")
colnames(megascale_pfam_alignments)[c(2,3,6,7)]<-c("pos_uniprot","pos_aln","uniprot_ID","PFAM_ID")
#load rocklin dataset
megascale_data<-fread("analysis_files/K50_dG_Dataset1_Dataset2.csv")
#use offsets to convert rocklin to uniprot positions
megascale_data_uniprot<-merge(megascale_data, megascale_mappings_to_uniprot[,c("pdb_id","uniprot_ID","offset")],
by.x="WT_name", by.y="pdb_id",
all.x=TRUE)
megascale_data_uniprot$pos_domain<-as.numeric(unlist(lapply(megascale_data_uniprot$mut_type,FUN = function(string){
return(substr(string,2,nchar(string)-1))
})))
megascale_data_uniprot[,pos_uniprot:=pos_domain+offset]
megascale_data_uniprot$mut_aa<-unlist(lapply(megascale_data_uniprot$mut_type,FUN = function(string){
return(substr(string,nchar(string),nchar(string)))
}))
#use pfam alignments info to convert uniprot positions to pfam alignment positions
megascale_data_uniprot_pfam<-merge(megascale_data_uniprot,megascale_pfam_alignments,
by=c("uniprot_ID","pos_uniprot"))
#use mapping to mochi weights to convert to mochi weight positions
pfam_alnpos_to_mochi_pos<-fread("analysis_files/homolog_mochi_input_files/mochi_alnpos_to_pfam_alnpos.txt")
megascale_data_uniprot_pfam<-merge(megascale_data_uniprot_pfam,pfam_alnpos_to_mochi_pos[!duplicated(pfam_alnpos_to_mochi_pos)],
by.x=c("PFAM_ID","pos_aln"),by.y=c("PFAM_ID","pos_pfam"))
#merge to mochi weights
megascale_data_uniprot_pfam_mochiweights<-merge(megascale_data_uniprot_pfam,homochi_weights,
by.x = c("PFAM_ID","pos_recoded","mut_aa"),
by.y = c("PFAM_ID","Pos","mut_aa"))
megascale_data_uniprot_pfam_mochiweights$dG_ML<-as.numeric(megascale_data_uniprot_pfam_mochiweights$dG_ML)
megascale_data_uniprot_pfam_mochiweights$ddG_ML<-as.numeric(megascale_data_uniprot_pfam_mochiweights$ddG_ML)
ggplot(megascale_data_uniprot_pfam_mochiweights)+
geom_hex(aes(x=mean_kcalmol_scaled,y=dG_ML))+
facet_wrap(~WT_name)+
scale_color_viridis()
ggsave("output_files/mochi_solu_evaluation_tsuboyama2023_homologs.pdf")
cors_mochi_to_rocklin<-megascale_data_uniprot_pfam_mochiweights[,.(spearman_rhos=cor(-dG_ML,mean_kcalmol_scaled,
use="pairwise.complete.obs",
method="spearman"),
pearson_rs=cor(-dG_ML,mean_kcalmol_scaled,
use="pairwise.complete.obs",
method="pearson"),
PFAM_ID=unique(PFAM_ID)),by="WT_name"]
median(cors_mochi_to_rocklin$spearman_rhos)
median(cors_mochi_to_rocklin$pearson_rs)
table(cors_mochi_to_rocklin$PFAM_ID)
```