-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget_algorithm.py
More file actions
36 lines (30 loc) · 1.24 KB
/
get_algorithm.py
File metadata and controls
36 lines (30 loc) · 1.24 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
import os, sys
import json
home = os.path.dirname(os.path.abspath(__file__)) #change this line only
pdb_path = "{}/output/".format(home)
def readJSON(pdbid):
# with open('{}/output/{}_graph.json'.format(home, pdbid), 'r') as infile:
# data_string = infile.read()
with open("{}/output/{}_graph.json".format(home,pdbid), 'r') as infile:
json_output = json.load(infile)
return json_output
def convert_coordinates(data, algorithm):
if algorithm == "PCA" or algorithm == "None":
for node in data['nodes']:
node['x'] = node['pca_x']
node['y'] = node['pca_y']
elif algorithm == "RNAScape":
for node in data['nodes']:
node['x'] = node['rnascape_x']
node['y'] = node['rnascape_y']
elif algorithm == "SecondaryStructure":
for node in data['nodes']:
node['x'] = node['viennarna_x']
node['y'] = node['viennarna_y']
return data
if __name__ == "__main__":
data = readJSON(sys.argv[1]) # assumes pre-computed JSON file, reads in pdbid
algorithm = sys.argv[2]
data = convert_coordinates(data, algorithm)
final_json_str = json.dumps(data)
print(final_json_str) #use console output