-
Notifications
You must be signed in to change notification settings - Fork 4
/
plotting.py
191 lines (155 loc) · 6.14 KB
/
plotting.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
190
191
import numpy as np
import networkx as nx
import matplotlib as mpl
import matplotlib.pyplot as plt
from misc import zeros
from misc import load_data
# Helper class: To do some plotting
def main():
data = load_data()
hgraph = nx.Graph(data.humanppi)
fgraph = nx.Graph(data.functions)
# plot_degree(hgraph)
# plot_cp_degree(hgraph)
#plot_fn_degree(hgraph, fgraph)
plot_fn_cp_weight(hgraph, fgraph)
def plot_degree(hgraph):
cps = [p for p in hgraph.nodes() if p.is_cancer_protein()]
ps = [p for p in hgraph.nodes() if not p.is_cancer_protein()]
cp_degrees_cp = [p.degree(hgraph) for p in cps]
avg_cp = round(np.mean(cp_degrees_cp), 2)
std_cp = round(np.std(cp_degrees_cp), 2)
cp_degrees = [p.degree(hgraph) for p in ps]
avg = round(np.mean(cp_degrees), 2)
std = round(np.std(cp_degrees), 2)
lims = 50
b = 20
bins = np.linspace(0, lims, b)
kwargs = {'bins': bins,
'normed': True,
'histtype': 'bar',
'color': ['g', 'r'],
'label': ['Normal Proteins', 'Cancer Proteins'],
'alpha': 0.7
}
plt.hist([cp_degrees, cp_degrees_cp], **kwargs)
plt.legend(loc='upper right')
#plt.title('Distribution of the number of edges')
plt.xlim(0, lims)
plt.xticks(np.linspace(0, lims, lims / 5 + 1))
plt.ylabel('Normalized frequency')
plt.xlabel('Number of edges')
plt.text(15, 0.08, 'Normal proteins: Avg: %s Std: %s' %
(str(avg), str(std)))
plt.text(15, 0.07, 'Cancer proteins: Avg: %s Std: %s' %
(str(avg_cp), str(std_cp)))
filepathname = 'report/degrees_combined.png'
plt.savefig(filepathname, bbox_inches='tight')
print('Done!' + ' Check this folder => ' + filepathname)
plt.show()
def plot_cp_degree(hgraph):
cps = [p for p in hgraph.nodes() if p.is_cancer_protein()]
ps = [p for p in hgraph.nodes() if not p.is_cancer_protein()]
cp_degrees_cp = [p.cp_degree(hgraph) for p in cps]
avg_cp = round(np.mean(cp_degrees_cp), 2)
std_cp = round(np.std(cp_degrees_cp), 2)
cp_degrees = [p.cp_degree(hgraph) for p in ps]
avg = round(np.mean(cp_degrees), 2)
std = round(np.std(cp_degrees), 2)
lims = 15
b = 10
bins = np.linspace(0, lims, b)
kwargs = {'bins': bins,
'normed': True,
'histtype': 'bar',
'color': ['g', 'r'],
'label': ['Normal Proteins', 'Cancer Proteins'],
'alpha': 0.7
}
plt.hist([cp_degrees, cp_degrees_cp], **kwargs)
plt.legend(loc='upper right')
#plt.title('Distribution of the number of cancer protein neighbors')
plt.xlim(0, lims)
plt.xticks(np.linspace(0, lims, lims / 5 + 1))
plt.ylabel('Normalized frequency')
plt.xlabel('Number of cancer protein neighbors')
plt.text(5, 0.25, 'Normal proteins: Avg: %s Std: %s' %
(str(avg), str(std)))
plt.text(5, 0.22, 'Cancer proteins: Avg: %s Std: %s' %
(str(avg_cp), str(std_cp)))
filepathname = 'report/cp_degrees_combined.png'
plt.savefig(filepathname, bbox_inches='tight')
print('Done!' + ' Check this folder => ' + filepathname)
plt.show()
def plot_fn_degree(hgraph, fgraph):
proteins_in_fgraph = [p for p in fgraph.nodes()
if not p.is_function()]
cps = [p for p in proteins_in_fgraph if p.is_cancer_protein()]
ps = [p for p in proteins_in_fgraph if not p.is_cancer_protein()]
cps_fn_degrees = [p.degree(fgraph) for p in cps]
avg_cp = round(np.mean(cps_fn_degrees), 2)
std_cp = round(np.std(cps_fn_degrees), 2)
ps_fn_degrees = [p.degree(fgraph) for p in ps]
avg = round(np.mean(ps_fn_degrees), 2)
std = round(np.std(ps_fn_degrees), 2)
lims = 60
b = 30
bins = np.linspace(0, lims, b)
kwargs = {'bins': bins,
'normed': True,
'histtype': 'bar',
'color': ['g', 'r'],
'label': ['Normal Proteins', 'Cancer Proteins'],
'alpha': 0.7
}
plt.hist([ps_fn_degrees, cps_fn_degrees], **kwargs)
plt.legend(loc='upper right')
plt.xlim(0, lims)
plt.xticks(np.linspace(0, lims, lims / 5 + 1))
plt.ylabel('Normalized frequency')
plt.xlabel('Number of functions')
plt.text(20, 0.05, 'Normal proteins: Avg: %s Std: %s' %
(str(avg), str(std)))
plt.text(20, 0.045, 'Cancer proteins: Avg: %s Std: %s' %
(str(avg_cp), str(std_cp)))
filepathname = 'report/fn_degrees_combined.png'
plt.savefig(filepathname, bbox_inches='tight')
print('Done!' + ' Check this folder => ' + filepathname)
plt.show()
def plot_fn_cp_weight(hgraph, fgraph):
proteins_in_fgraph = [p for p in fgraph.nodes()
if not p.is_function()]
cps = [p for p in proteins_in_fgraph if p.is_cancer_protein()]
ps = [p for p in proteins_in_fgraph if not p.is_cancer_protein()]
cps_fn_cp_weight = [p.fn_cp_weight(hgraph, fgraph) for p in cps]
avg_cp = round(np.mean(cps_fn_cp_weight), 2)
std_cp = round(np.std(cps_fn_cp_weight), 2)
ps_fn_cp_weight = [p.fn_cp_weight(hgraph, fgraph) for p in ps]
avg = round(np.mean(ps_fn_cp_weight), 2)
std = round(np.std(ps_fn_cp_weight), 2)
lims = 80000
b = 15
bins = np.linspace(0, lims, b)
kwargs = {'bins': bins,
'normed': True,
'histtype': 'bar',
'color': ['g', 'r'],
'label': ['Normal Proteins', 'Cancer Proteins'],
'alpha': 0.7
}
plt.hist([ps_fn_cp_weight, cps_fn_cp_weight], **kwargs)
plt.legend(loc='upper right')
plt.xlim(0, lims)
plt.xticks(np.linspace(0, lims, 11))
plt.ylabel('Normalized frequency')
plt.xlabel('Assigned weight')
plt.text(15000, 0.00007, 'Normal proteins: Avg: %s Std: %s' %
(str(avg), str(std)))
plt.text(15000, 0.00006, 'Cancer proteins: Avg: %s Std: %s' %
(str(avg_cp), str(std_cp)))
filepathname = 'report/fn_w_combined.png'
plt.savefig(filepathname, bbox_inches='tight')
print('Done!' + ' Check this folder => ' + filepathname)
plt.show()
if __name__ == '__main__':
main()