-
Notifications
You must be signed in to change notification settings - Fork 0
/
roc.py
189 lines (138 loc) · 5.11 KB
/
roc.py
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
import pandas as pd
import numpy as np
import math
import matplotlib.pyplot as plt
data = pd.read_csv("results/master.csv")
"""
#---Data---
foldx_x = np.load("results/foldx_x.npy")
foldx_y = np.load("results/foldx_y.npy")
missense3d_x = np.load("results/missense3d_x.npy")
missense3d_y = np.load("results/missense3d_y.npy")
thresholds = np.load("results/roc_thresholds.npy")
x_hori = list(np.arange(0,1.1, 0.1))
y_hori = list(np.arange(0,1.1, 0.1))
#Clean data
for i in range(len(foldx_x)):
if i < 81:
foldx_x[i] = np.nan
"""
def check_accuracy_foldx(threshold):
true_positive = 0
false_positive = 0
true_negative = 0
false_negative = 0
for i in range(data.shape[0]):
if data.loc[i, "ddG"] >= threshold: #Positve
if data.loc[i, "foldx_ddG"] >= threshold:
true_positive = true_positive + 1
elif data.loc[i, "foldx_ddG"] < threshold:
false_negative = false_negative + 1
else:
exit()
else: #negative
if data.loc[i, "foldx_ddG"] < threshold:
true_negative = true_negative + 1
elif data.loc[i, "foldx_ddG"] >= threshold:
false_positive = false_positive + 1
else:
exit()
return [true_positive, false_positive, true_negative, false_negative]
def check_accuracy_missense(threshold):
true_positive = 0
false_positive = 0
true_negative = 0
false_negative = 0
for i in range(data.shape[0]):
if data.loc[i, "ddG"] >= threshold: #Positve
if int(data.loc[i, "missense_damaging"]) == 1:
true_positive = true_positive + 1
else:
false_negative = false_negative + 1
else: #negative
if int(data.loc[i, "missense_damaging"]) == 0:
true_negative = true_negative + 1
else:
false_positive = false_positive + 1
return [true_positive, false_positive, true_negative, false_negative]
def TPR(true_positive, false_positive, true_negative, false_negative):
return true_positive / (true_positive + false_negative)
def FPR(true_positive, false_positive, true_negative, false_negative):
return false_positive / (false_positive + true_negative)
thresholds = list(np.arange(-20, 30, 0.5))
foldx_TPR = []
foldx_FPR = []
for threshold in thresholds:
print(threshold)
true_positive, false_positive, true_negative, false_negative = check_accuracy_foldx(threshold)
try:
foldx_TPR.append(TPR(true_positive, false_positive, true_negative, false_negative))
except:
foldx_TPR.append(np.nan)
try:
foldx_FPR.append(FPR(true_positive, false_positive, true_negative, false_negative))
except:
foldx_FPR.append(np.nan)
missense_TPR = []
missense_FPR = []
thresholds = [1.0, 1.5, 2.0]
for threshold in thresholds:
print(threshold)
true_positive, false_positive, true_negative, false_negative = check_accuracy_missense(threshold)
try:
missense_TPR.append(TPR(true_positive, false_positive, true_negative, false_negative))
except:
missense_TPR.append(np.nan)
try:
missense_FPR.append(FPR(true_positive, false_positive, true_negative, false_negative))
except:
missense_FPR.append(np.nan)
print(foldx_TPR, foldx_FPR)
#---Parameters---
foldx_toi = [100,103, 105, 107, 110, 112,116, 118, 120]
missense3d_toi = [100,103, 105, 107, 110, 112,114,116, 118, 120]
#---Figure---
plt.figure(figsize = (6,6))
plt.plot(foldx_FPR,foldx_TPR, label="FoldX")
plt.scatter(missense_FPR,missense_TPR, color= "orange", label="Missense3D")
#plt.plot(x_hori, y_hori, linestyle="dashed")
plt.xlabel("False Positive Rate")
plt.ylabel("True Postive Rate")
plt.xlim(0,1)
plt.ylim(0,1)
#plt.title("ROC curve of FoldX and Missense3D predictions of thermal\nstability with relation to varying ddG threshold (HotMusic dataset)")
plt.legend()
x_hori = list(np.arange(0,1.1, 0.1))
y_hori = list(np.arange(0,1.1, 0.1))
plt.plot(x_hori, y_hori, linestyle="dashed")
"""
for threshold in foldx_toi:
plt.text(foldx_x[threshold] - 0.06, foldx_y[threshold] + 0.01, str(abs(round(thresholds[threshold],3))))
plt.scatter(foldx_x[threshold], foldx_y[threshold], c="teal")
for threshold in missense3d_toi:
plt.text(missense3d_x[threshold] - 0.06, missense3d_y[threshold] + 0.01, str(abs(round(thresholds[threshold],3))))
plt.scatter(missense3d_x[threshold], missense3d_y[threshold], c="orange")
#Calc AUROC
AUROC = 0
for i in range(1, len(foldx_x)):
base = (foldx_x[i-1] - foldx_x[i]) * foldx_y[i]
top = ((foldx_x[i-1] - foldx_x[i]) * (foldx_y[i-1] - foldx_y[i])) / 2
total = base + top
print(total)
if math.isnan(total):
pass
else:
AUROC = AUROC + total
print("FoldX", AUROC)
AUROC = 0
for i in range(1, len(foldx_x)):
base = (missense3d_x[i-1] - missense3d_x[i]) * missense3d_y[i]
top = ((missense3d_x[i-1] - missense3d_x[i]) * (missense3d_y[i-1] - missense3d_y[i])) / 2
total = base + top
if math.isnan(total):
pass
else:
AUROC = AUROC + total
print("Missense3D", AUROC)
"""
plt.show()