-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathplotDist
More file actions
executable file
·91 lines (69 loc) · 1.82 KB
/
Copy pathplotDist
File metadata and controls
executable file
·91 lines (69 loc) · 1.82 KB
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
#!/usr/bin/python
import sys
if len(sys.argv) < 3:
print 'USAGE: plotDist FILENAME INFILE [[INFILE] ...]'
sys.exit(1)
fname = sys.argv[1]
infiles = sys.argv[2:]
logmethods = ['rsat', 'nhmmer', 'mast']
import math
meth = {}
import numpy as np
# Quick read to know which methods are there
for f in infiles:
for l in open(f):
s = l.rstrip().split('\t')
me = s[9]
meth[me] = meth.get(me, None)
def iterScores(method, infiles):
for f in infiles:
for l in open(f):
s = l.rstrip().split('\t')
sc = float(s[10])
me = s[9]
if me == method:
if me in logmethods:
yield -math.log10(sc)
else:
yield sc
for me in meth:
meth[me] = np.fromiter(iterScores(me, infiles), np.float)
import matplotlib
matplotlib.use('Agg')
import matplotlib.pyplot as plt
fig = plt.figure(figsize=(10,10))
colors = ['b', 'r', 'g', 'k']
import numpy as np
nmeth = np.array(meth.keys())
# Array reshape (tricky!)
# 1- Finger crossed for a perfect square
square = np.sqrt( len(nmeth) )
if square.is_integer():
# Yep
rows = cols = int(square)
else:
# Oh snap!
cols = int(square)
rows = len(nmeth) / float(cols)
if not rows.is_integer():
# Some fake signals will be added
rows = int(rows) + 1
rows = int(rows)
i = 0
for m in sorted(meth.keys()):
ax = fig.add_subplot(rows, cols, i)
j = i
while True:
if j > len(colors)-1:
j = i-len(colors)
else:
c = colors[j]
break
ax.hist(meth[m], bins=100, color=c)
ax.set_title('%s'%m)
#ax.set_ylim(0, 1)
#ax.set_xlim(min(pdist),0)
i += 1
plt.tight_layout()
plt.savefig('%s.png'%fname)
plt.savefig('%s.pdf'%fname)