-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathadd_nativetopcode_column.py
executable file
·53 lines (40 loc) · 1.42 KB
/
add_nativetopcode_column.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
#!/usr/bin/python
from os import popen
import sys
import string
outfile = sys.argv[1]
nativescorefile = sys.argv[2]
# Go through native score file, find which flavors gave which score.
lines = open(nativescorefile).readlines()
cols = string.split(lines[0])
scoreindex = cols.index('score')
flavorindex = cols.index('flavor')
score_flavor_list = []
for line in lines:
cols = string.split(line)
if not( cols[scoreindex] == 'score'):
score_flavor_list.append( [ float(cols[scoreindex]), cols[flavorindex] ])
# Sort by native energy
score_flavor_list.sort()
# Make a mapping from flavor to how the native scores with that flavor.
flavor_to_nativescore = {}
flavor_to_reorder = {}
for i in range( len(score_flavor_list) ):
entry = score_flavor_list[i]
flavor_to_nativescore[ entry[1]] = entry[0]
flavor_to_reorder[ entry[1]] = i
# Now go through outfile and put in two new columns, based on the flavor:
# the native energy for that flavor and a reordered flavor.
lines = open(outfile).readlines()
cols = string.split(lines[1])
flavorindex = cols.index('flavor')
for line in lines:
cols = string.split(line)
print line[:-1], #No newline
if cols[0] == 'SCORE:':
if cols[flavorindex] == 'flavor':
print '%s %s' % ('reorder','nativescore'),
else:
flavor = cols[flavorindex]
print '%d %f' % (flavor_to_reorder[flavor],flavor_to_nativescore[flavor]),
print