-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathplot_qa.py
90 lines (73 loc) · 2.47 KB
/
plot_qa.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
import sys
from math import *
from collections import defaultdict
import matplotlib.pyplot as plt
def s2d(s):
d0=sqrt(5)
d=100 # for CASP we cap the distance at 100 angstroms
if s>0.0004: # this is the S score for 100 angstroms
if s>=1:
d=0
else:
d=sqrt(1/s-1)*d0
return d
def parse_qa(f):
qa_dict = defaultdict(list)
ignore_lst = ['PFRMAT', 'TARGET', 'AUTHOR', 'REMARK', 'MODEL', 'QMODE', 'END']
with open(f) as qa_f:
acc = ''
method = ''
for l in qa_f:
l_arr = l.strip().split()
# replace unpredicted positions
l_arr = [100 if x=='X' else x for x in l_arr]
if l.startswith('METHOD'):
if not method:
method = l_arr[1]
if '*' in method:
method = 'Pcons'
continue
else:
continue
if l_arr[0] in ignore_lst:
continue
try:
float(l_arr[0])
#if method == 'Pcons':
# qa_dict[acc] += map(s2d, map(float, l_arr))
#else:
qa_dict[acc] += map(float, l_arr)
except ValueError:
acc = l_arr[0]
#if method == 'Pcons':
# qa_dict[acc] = map(s2d, map(float, l_arr[2:]))
#else:
qa_dict[acc] = map(float, l_arr[2:])
return method, qa_dict
def plot_qa(f_lst, outf_prefix=''):
data = defaultdict(dict)
for f in f_lst:
method, qa_dict = parse_qa(f)
for acc, qa_lst in qa_dict.iteritems():
data[acc][method] = qa_lst
for acc, method_dict in data.iteritems():
fig = plt.figure(figsize=(10,4))
ax = plt.axes()
plot_lst = []
label_lst = []
for method, qa_lst in method_dict.iteritems():
x = xrange(len(qa_lst))
plt.plot(x, qa_lst, label=method)
#plot_lst.append(plt.plot(x, qa_lst))
#label_lst.append(method)
#plt.legend(plot_lst, label_lst)
ax.legend(loc='upper center', bbox_to_anchor=(0.5, 1.15), ncol=4)
#plt.show()
plt.ylim(0,30)
outf = '%s%s.qa.png' % (outf_prefix, acc)
plt.savefig(outf)
plt.close()
if __name__ == '__main__':
outf_prefix = sys.argv[1]
f_lst = sys.argv[2:]
plot_qa(f_lst, outf_prefix=outf_prefix)