forked from gyorilab/indra_spine
-
Notifications
You must be signed in to change notification settings - Fork 0
/
spine_ner.py
48 lines (45 loc) · 1.57 KB
/
spine_ner.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
from indra_cogex.sources.odinson.grammars import Rule
from indra_cogex.sources.odinson.client import process_rules
import gilda
import pandas as pd
from collections import defaultdict
from gilda.process import normalize
from pyobo.gilda_utils import get_gilda_terms
spine_file = '/Users/sangeethavempati/Documents/GitHub/reach/bioresources/src/main/resources/org/clulab/reach/kb/spine.tsv'
#reformat terms
df = pd.read_csv(spine_file, sep='\t', header=None, names=['name', 'id'])
#for each id, make a list of the corresponding brain regions
id_to_names = defaultdict(list)
for name,identifier in df.values:
id_to_names[identifier].append(name)
terms = []
#label terms with the same id as synonyms
for identifier, names in id_to_names.items():
#label everything except the first as synonyms
name,*synonyms = names
term = gilda.term.Term(
norm_text=normalize(name),
text=name,
db="spine",
id=identifier,
entry_name=name,
status="name",
source="spine",
)
terms.append(term)
for synonym in synonyms:
term = gilda.term.Term(
norm_text=normalize(synonym),
text=synonym,
db="spine",
id=identifier,
entry_name=name,
status="synonym",
source="spine",
)
terms.append(term)
terms.extend(get_gilda_terms('UBERON'))
terms.extend(get_gilda_terms('fma'))
#terms.extend(get_gilda_terms('ncit'))
grounder = gilda.Grounder(terms)
grounder