Skip to content

Commit 2dcad82

Browse files
authored
Merge branch 'master' into search_page
2 parents 49f51c9 + 48e4e64 commit 2dcad82

File tree

3 files changed

+20
-27
lines changed

3 files changed

+20
-27
lines changed

indra/databases/chebi_client.py

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
import os
22
import logging
33
import requests
4-
from lxml import etree
54
from functools import lru_cache, cmp_to_key
65
from indra.util import read_unicode_csv
76
from indra.databases.obo_client import OboClient
@@ -10,10 +9,6 @@
109

1110
logger = logging.getLogger(__name__)
1211

13-
# Namespaces used in the XML
14-
chebi_xml_ns = {'n': 'http://schemas.xmlsoap.org/soap/envelope/',
15-
'c': 'https://www.ebi.ac.uk/webservices/chebi'}
16-
1712

1813
def _add_prefix(chid):
1914
if chid and not chid.startswith('CHEBI:'):
@@ -162,29 +157,17 @@ def get_chebi_entry_from_web(chebi_id):
162157
163158
Returns
164159
-------
165-
xml.etree.ElementTree.Element
166-
An ElementTree element representing the ChEBI entry.
160+
dict
161+
A dictionary containing the ChEBI entry data. If the lookup
162+
fails, None is returned.
167163
"""
168-
url_base = 'http://www.ebi.ac.uk/webservices/chebi/2.0/test/'
169-
url_fmt = url_base + 'getCompleteEntity?chebiId=%s'
164+
url_fmt = 'https://www.ebi.ac.uk/chebi/backend/api/public/compound/%s/'
170165
resp = requests.get(url_fmt % chebi_id)
171166
if resp.status_code != 200:
172167
logger.warning("Got bad code form CHEBI client: %s" % resp.status_code)
173168
return None
174-
tree = etree.fromstring(resp.content)
175-
path = 'n:Body/c:getCompleteEntityResponse/c:return'
176-
elem = tree.find(path, namespaces=chebi_xml_ns)
177-
return elem
178-
179-
180-
def _get_chebi_value_from_entry(entry, key):
181-
if entry is None:
182-
return None
183-
path = 'c:%s' % key
184-
elem = entry.find(path, namespaces=chebi_xml_ns)
185-
if elem is not None:
186-
return elem.text
187-
return None
169+
data = resp.json()
170+
return data
188171

189172

190173
def get_chebi_name_from_id_web(chebi_id):
@@ -201,8 +184,8 @@ def get_chebi_name_from_id_web(chebi_id):
201184
The name corresponding to the given ChEBI ID. If the lookup
202185
fails, None is returned.
203186
"""
204-
entry = get_chebi_entry_from_web(chebi_id)
205-
return _get_chebi_value_from_entry(entry, 'chebiAsciiName')
187+
json_data = get_chebi_entry_from_web(chebi_id)
188+
return json_data.get('name') if json_data else None
206189

207190

208191
def get_inchi_key(chebi_id):
@@ -219,8 +202,11 @@ def get_inchi_key(chebi_id):
219202
The InChIKey corresponding to the given ChEBI ID. If the lookup
220203
fails, None is returned.
221204
"""
222-
entry = get_chebi_entry_from_web(chebi_id)
223-
return _get_chebi_value_from_entry(entry, 'inchiKey')
205+
json_data = get_chebi_entry_from_web(chebi_id)
206+
if not json_data:
207+
return None
208+
structure_data = json_data.get('default_structure')
209+
return structure_data.get('standard_inchi_key') if structure_data else None
224210

225211

226212
def get_primary_id(chebi_id):

indra/resources/grounding/misgrounding_map.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -305,3 +305,4 @@ Sn,HGNC,11127
305305
CIs,HGNC,7701
306306
autosomal dominant,HGNC,7106
307307
DIO,CHEBI,CHEBI:52032
308+
HS,HGNC,6853

indra/tests/test_indranet_assembler.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -337,3 +337,9 @@ def test_stmt_to_rows():
337337
assert len(rows) == 1
338338
assert rows[0] == ['a', 'b', 'HGNC', '1', 'TEXT', 'b', None, None,
339339
'Activation', 1, 8197018847132618, 1, {None: 1}, None]
340+
341+
source_count = {-25125767941752990: {'db1': 1}}
342+
rows = statement_to_rows(st2, source_counts=source_count)
343+
assert rows[0] == ['a', 'c', 'HGNC', '1', 'TEXT', 'c', None, None,
344+
'Inhibition', 1, -25125767941752990, 0.76, {'db1': 1}, None]
345+

0 commit comments

Comments
 (0)