-
Notifications
You must be signed in to change notification settings - Fork 0
/
brite2gator.py
39 lines (30 loc) · 1.1 KB
/
brite2gator.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
import json
kegg = json.loads(open("/Users/kimbrel1/Desktop/working/amino_acid_transport/ko02000_filtered.json", "r").read())
pathways = {}
brite = kegg['name']
for level1 in kegg['children']:
high = level1['name']
for level2 in level1['children']:
mid = level2['name']
for level3 in level2['children']:
low = level3['name']
pathways[low] = {}
# print(f"--- {high}; {mid}; {low} ---")
if 'children' in level3:
for level4 in level3['children']:
line = level4['name']
KO = line.split().pop(0)
# print(f"{KO}***{line}")
pathways[low][KO] = line
for path, data in pathways.items():
paths = []
for KO, description in data.items():
gene_name,description = description.split("; ")
gene_name = gene_name.replace(", ", "/")
gene_name = gene_name.replace(" ", " ")
gene_name = gene_name.replace(" ", "_")
paths.append(gene_name)
# for genes
# print(f"{gene_name}\t{KO}\t{description}\t{path}")
# for paths
print(f"{path}\t{' -> '.join(paths)}")