-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcmp-molfunc-aliases.py
58 lines (51 loc) · 1.53 KB
/
cmp-molfunc-aliases.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
53
54
55
56
57
import pronto, six, csv
from sys import *
reader = csv.DictReader(open('goid.tab', 'r'), delimiter='\t')
efs = {}
for item in reader:
go = item.get('goid')
iturl = item.get('item')
it = iturl[iturl.rfind('/')+1:]
git = efs.get(go)
if git is None:
efs[go] = it
else:
print('============= {}'.format(go))
def reduce(s): return "".join([c.lower() for c in s if c.isalnum()])
ont = pronto.Ontology('/home/ralf/go-ontology/src/ontology/go-edit.obo')
odict = {}
for term in ont.terms.values():
goid = term.id
if goid[:3] != 'GO:':
continue
goit = efs.get(goid)
if goit is None:
continue
ns = term.other.get('namespace')
if ns is None:
continue
if ns[0] != 'molecular_function':
continue
odict[reduce(term.name).replace('activity', '')] = goit
for s in term.synonyms:
if s.scope == 'EXACT':
odict[reduce(s.desc).replace('activity', '')] = goit
reader = csv.DictReader(open('enzfam+func.tab', 'r'), delimiter='\t')
efus = {}
for item in reader:
lab = item.get('pLabel')
iturl = item.get('p')
it = iturl[iturl.rfind('/')+1:]
furl = item.get('func')
if furl is None or len(furl) == 0:
fit = None
else:
fit = furl[furl.rfind('/')+1:]
m = odict.get(reduce(lab))
if m is None:
if fit is None:
continue
else:
print('{}|P680|{}|P4390|Q39894595|S248|Q77546004'.format(it, fit))
else:
print('{}|P680|{}|P4390|Q39893449|S248|Q77546004'.format(it, m))