-
Notifications
You must be signed in to change notification settings - Fork 0
/
merge_json.py
executable file
·37 lines (29 loc) · 995 Bytes
/
merge_json.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
#!/usr/bin/python
from __future__ import print_function
import sys
import os
import subprocess
import glob
import re
import json
def main(argv):
pdbs = glob.glob('./pdb/*.pdb')
descriptors = glob.glob('./motif/*')
#Transform PDB list into accessors
acc_re = re.compile('\/(\w+)\.pdb$')
pdbs = [acc_re.search(x, re.IGNORECASE).group(1) for x in pdbs]
#Clean descriptors
descriptor_re = re.compile('\/(\w+)$')
descriptors = [descriptor_re.search(x, re.IGNORECASE).group(1) for x in descriptors]
descriptors.sort()
mega_json = []
for descriptor in descriptors:
for pdb in pdbs:
file_path = './output/' + descriptor + '/' + pdb + '.json'
json_data = open(file_path).read()
data = json.loads(json_data)
# mega_json.setdefault(descriptor, {})[pdb] = data
mega_json += data
print(json.dumps(mega_json, indent=2, sort_keys=True))
if __name__ == "__main__":
main(sys.argv[1:])