From 5c89fb6f44a0102e71bd8eaf997c8486c6afbbf0 Mon Sep 17 00:00:00 2001 From: sfluegel Date: Thu, 7 May 2026 12:56:04 +0200 Subject: [PATCH] add definitions to chebi graph --- chebi_utils/obo_extractor.py | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/chebi_utils/obo_extractor.py b/chebi_utils/obo_extractor.py index 1fc427f..b50fbfb 100644 --- a/chebi_utils/obo_extractor.py +++ b/chebi_utils/obo_extractor.py @@ -24,6 +24,7 @@ def _term_data(doc: "fastobo.term.TermFrame") -> dict | None: parents: list[str] = [] relations: dict = dict() name: str | None = None + definition: str | None = None smiles: str | None = None subset: str | None = None @@ -50,6 +51,8 @@ def _term_data(doc: "fastobo.term.TermFrame") -> dict | None: parents.append(_chebi_id_to_str(str(clause.term))) elif isinstance(clause, fastobo.term.NameClause): name = str(clause.name) + elif isinstance(clause, fastobo.term.DefClause): + definition = str(clause.definition) elif isinstance(clause, fastobo.term.SubsetClause): subset = str(clause.subset) @@ -58,6 +61,7 @@ def _term_data(doc: "fastobo.term.TermFrame") -> dict | None: "parents": parents, "relations": relations, "name": name, + "definition": definition, "smiles": smiles, "subset": subset, } @@ -104,7 +108,13 @@ def build_chebi_graph(filepath: str | Path) -> nx.DiGraph: continue node_id = term["id"] - graph.add_node(node_id, name=term["name"], smiles=term["smiles"], subset=term["subset"]) + graph.add_node( + node_id, + name=term["name"], + definition=term["definition"], + smiles=term["smiles"], + subset=term["subset"], + ) for parent_id in term["parents"]: graph.add_edge(node_id, parent_id, relation="is_a")