forked from bio-ontology-research-group/deepgozero
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannots_plot.py
58 lines (53 loc) · 1.66 KB
/
annots_plot.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
from matplotlib import pyplot as plt
import click as ck
import numpy as np
from collections import Counter
import pandas as pd
@ck.command()
def main():
counts = Counter()
annots = {}
cnt = 0
with open('zero_completely.txt') as f:
for line in f:
it = line.strip().split()
if len(it) > 2:
go_id, n = it[0], int(it[2])
annots[go_id] = n
counts[n] += 1
counts = [v for c, v in counts.most_common(10)]
counts = pd.Series(counts)
perfs = get_average_performance(annots)
print(perfs)
ax = counts.plot(kind="bar")
rects = ax.patches
labels = ['',] + perfs
for rect, label in zip(rects, labels):
height = rect.get_height()
ax.text(
rect.get_x() + rect.get_width() / 2, height + 5, label, ha="center", va="bottom"
)
ax.set_xticklabels(np.arange(10), rotation=0)
ax.set_title('Distribution of classes with annotations < 10')
ax.set_xlabel('Number of annotations')
ax.set_ylabel('Number of classes')
plt.savefig('annots-num.eps')
def get_average_performance(annots):
aucs = {}
with open('data/results/result_zero_10.txt') as f:
for line in f:
if not line.startswith('GO:'):
continue
it = line.strip().split()
go_id, auc = it[0], float(it[1])
if go_id in annots:
n = annots[go_id]
if n not in aucs:
aucs[n] = []
aucs[n].append(auc)
avgs = []
for i in range(1, 10):
avgs.append(f'{np.mean(aucs[i]):.3f}')
return avgs
if __name__ == '__main__':
main()