-
Notifications
You must be signed in to change notification settings - Fork 1
/
anyfam-goaliases.py
55 lines (46 loc) · 1.25 KB
/
anyfam-goaliases.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
import pronto, six, csv
from sys import *
"""
Input:
SELECT DISTINCT ?p ?l ?a ?go
{
?p p:P680 [ ps:P680 ?func; pq:P4390 wd:Q39893449; ].
?func wdt:P686 ?go.
?p rdfs:label ?l.
FILTER( LANG(?l) = 'en' )
OPTIONAL {
?p skos:altLabel ?a.
FILTER( LANG(?l) = LANG(?a) )
}
}
"""
def reduce(s): return "".join([c.lower() for c in s if c.isalnum()])
reader = csv.DictReader(open('t.tab', 'r'), delimiter='\t')
efs = {}
for item in reader:
iturl = item.get('p')
qit = iturl[iturl.rfind('/')+1:]
goid = item.get('go')
lab = item.get('l')
al = item.get('a')
ef = efs.get(qit)
if ef is None or len(ef) == 0:
if al is None:
efs[qit] = (set([reduce(lab)]),goid)
else:
efs[qit] = (set([reduce(lab),reduce(al)]),goid)
else:
ef[0].add(reduce(al))
ont = pronto.Ontology('/home/ralf/go-ontology/src/ontology/go-edit.obo')
id_als = set()
for qit in efs.keys():
names,goid = efs.get(qit)
term = ont.terms.get(goid)
if term is None:
#print(goid)
continue
exact = False
for s in term.synonyms:
d = s.desc.replace(' activity', '')
if s.scope == 'EXACT' and reduce(d) not in names:
print('{}|Aen|"{}"'.format(qit, d))