-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathparsedN_dS.py
More file actions
81 lines (57 loc) · 1.65 KB
/
parsedN_dS.py
File metadata and controls
81 lines (57 loc) · 1.65 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
#function for parsing dN/dS outputs
import pandas as pd
import numpy as np
import matplotlib as mp
import matplotlib.pyplot as plt
import numpy as np
def parse_yn00_output():
NUM_COLORS = 32
cm = plt.get_cmap('gist_rainbow')
colors = [cm(1.*i/NUM_COLORS) for i in range(NUM_COLORS)]
dict1 = {'cluster' : [],
'colors' : [],
'dN' : [],
'dS' : []}
for i in range(1269):
filename = str(i) + + '_yn_output'
dN = 0
dS = 0
cluster = int(filename[:filename.index('_')])
output = open(filename)
lines = output.readlines()
for i in range(len(lines)):
lines[i] = lines[i].split()
if len(lines[i]) > 0:
if lines[i][0] == '(B)':
start = i
if lines[i][0] == '(C)':
stop = i
for i in range((start + 8), (stop - 2)):
dN += float(lines[i][7])
dS += float(lines[i][10])
dN, dS = dN / ((stop - 2) - (start + 8)), dS / ((stop - 2) - (start + 8))
if dS != 0:
dNdS = dN / dS
else:
dNdS = 'NAN'
pa = get_cluster_pa(cluster)
dict1['cluster'].append(cluster)
dict1['dN'].append(dN)
dict1['dS'].append(dS)
dict1['colors'].append(colors[int(pa, 2)])
output.close()
return dict1
def get_cluster_pa(cluster):
cluster_pa_file = open('cluster_output_noArea.txt')
cluster_lines = cluster_pa_file.readlines()
line = cluster_lines[cluster]
line = line.split()
rts = line[-5] + line[-4] + line[-3] + line[-2] + line[-1]
rts = rts.replace(',','')[1:-1]
return rts
cluster_pa_file.close()
if __name__ == '__main__':
mydict = parse_yn_output()
df = pd.DataFrame.from_dict(data=graph_dict)
df.plot.scatter(x='dN',y='dS',c='colors',alpha=0.75)
plt.savefig('dN_dS_scatter.png')