Skip to content

Commit

Permalink
Remove the deprecated methods (#62)
Browse files Browse the repository at this point in the history
Co-authored-by: jschaff <[email protected]>
  • Loading branch information
ctrl-schaff and jschaff authored Oct 14, 2024
1 parent a0a752d commit 562033e
Show file tree
Hide file tree
Showing 2 changed files with 0 additions and 104 deletions.
73 changes: 0 additions & 73 deletions biothings_annotator/annotator/annotator.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,76 +224,3 @@ def annotate_trapi(
node_d[node_id]["attributes"] = [res]

return node_d

def annotate_trapi_0(
self, trapi_input: Dict, append: bool = False, raw: bool = False, fields: list = None, limit: int = None
):
"""
Deprecated! Kept here for reference for now, pending to be deleted soon.
Annotate a TRAPI input message with node annotator annotations
"""
try:
node_d = get_dotfield_value("message.knowledge_graph.nodes", trapi_input)
assert isinstance(node_d, dict)
except (KeyError, ValueError, AssertionError):
raise TRAPIInputError(trapi_input)

# if limit is set, we truncate the node_d to that size
if limit:
_node_d = {}
i = 0
for node_id in node_d:
i += 1
if i > limit:
break
_node_d[node_id] = node_d[node_id]
node_d = _node_d
del i, _node_d

node_list_by_type = {}
for node_id in node_d:
node_type = parse_curie(node_id, return_type=True, return_id=False)
if node_type:
if node_type not in node_list_by_type:
node_list_by_type[node_type] = [node_id]
else:
node_list_by_type[node_type].append(node_id)
else:
logger.warning("Unsupported Curie prefix: %s. Skipped!", node_id)

for node_type, node_list in node_list_by_type.items():
if node_type not in ANNOTATOR_CLIENTS or not node_list_by_type[node_type]:
# skip for now
continue

# this is the list of original node ids like NCBIGene:1017, should be a unique list
node_list = node_list_by_type[node_type]

# this is the list of query ids like 1017
query_list = [parse_curie(_id, return_type=False, return_id=True) for _id in node_list_by_type[node_type]]
# query_id to original id mapping
node_id_d = dict(zip(query_list, node_list))
res_by_id = self.query_biothings(node_type, query_list, fields=fields)
if not raw:
res_by_id = self.transform(res_by_id, node_type)
for node_id in res_by_id:
orig_node_id = node_id_d[node_id]
res = res_by_id[node_id]
# if not raw:
# if isinstance(res, list):
# # TODO: handle multiple results here
# res = [self.transform(r) for r in res]
# else:
# res = self.transform(res)
res = {
"attribute_type_id": "biothings_annotations",
"value": res,
}
if append:
# append annotations to existing "attributes" field
node_d[orig_node_id]["attributes"].append(res)
else:
# return annotations only
node_d[orig_node_id]["attributes"] = [res]

return node_d
31 changes: 0 additions & 31 deletions biothings_annotator/annotator/transformer.py
Original file line number Diff line number Diff line change
Expand Up @@ -165,37 +165,6 @@ def caching_ncit_descriptions(self):
if ncit_def_d:
self.data_cache["ncit"] = ncit_def_d

def deprecated_transform_add_ncit_description(self, doc):
"""
add ncit_description field to unii object based on unii.ncit field
deprecated now, as ncit_description is now returned directly from mychem.info
"""
if self.node_type != "chem":
return doc

if "ncit" not in self.data_cache:
self.caching_ncit_descriptions()

ncit_def_d = self.data_cache.get("ncit", {})

def _add_ncit_description(unii):
ncit = unii.get("ncit")
ncit = f"NCIT:{ncit}"
if ncit:
ncit_def = ncit_def_d.get(ncit)
if ncit_def:
unii["ncit_description"] = ncit_def

unii = doc.get("unii", {})
if unii:
if isinstance(unii, list):
# in case returned chembl is a list, rare but still possible
for u in unii:
_add_ncit_description(u)
else:
_add_ncit_description(unii)
return doc

def transform_one_doc(self, doc):
"""transform the response from biothings client"""
for fn_name, fn in inspect.getmembers(self, predicate=inspect.ismethod):
Expand Down

0 comments on commit 562033e

Please sign in to comment.