Skip to content

Commit

Permalink
fix(metacyc): remove reaction nodes with non-canonical mcID
Browse files Browse the repository at this point in the history
Some metabolic reactions have compartments, substrates and/or other information in their mcID and
displayName. They always have a related reaction that doesn't have those parts, so we remove those
extra reactions found in the SBML file.

fix #19
  • Loading branch information
y1zhou committed Feb 16, 2022
1 parent b1a71e3 commit c495b71
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
11 changes: 11 additions & 0 deletions metabolike/db/metacyc.py
Original file line number Diff line number Diff line change
Expand Up @@ -414,6 +414,17 @@ def merge_nodes(
val=attr_val,
)

def delete_bad_reaction_nodes(self):
"""
Delete reaction nodes with non-canonical mcIds and all their relationships.
"""
self.write(
"""
MATCH (r:Reaction) WHERE r.displayName <> r.canonicalId
DETACH DELETE r;
"""
)

def get_view_of_pathway(self, pathway_id: str):
"""
Get the view of a pathway.
Expand Down
11 changes: 11 additions & 0 deletions metabolike/parser/metacyc.py
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,10 @@ def setup(self, create_db: bool = True, **kwargs):
self.reaction_to_graph(rxn, rxn_dat)
logger.debug(f"Added extra info for reaction {rxn}")

# Remove additional reactions in the SBML file that have
# non-canonical IDs
self.db.delete_bad_reaction_nodes()

# Read pathways file if given
if self.input_files["pathways"]:
logger.info("Creating pathway links")
Expand Down Expand Up @@ -354,6 +358,13 @@ def reaction_to_graph(self, rxn_id: str, rxn_dat: Dict[str, List[List[str]]]):
return
lines = rxn_dat[canonical_id]
props: Dict[str, Union[str, List[str]]] = {"canonicalId": canonical_id}

# Don't bother with parsing the other attributes if the canonical ID
# is not the displayName (the node will be deleted anyway)
if canonical_id != rxn_id:
self.db.add_props_to_node("Reaction", "displayName", rxn_id, props)
return

for k, v in lines:
# SYNONYMS is a special case because it is a list
if k in {"SYNONYMS", "TYPES"}:
Expand Down

1 comment on commit c495b71

@y1zhou
Copy link
Owner Author

@y1zhou y1zhou commented on c495b71 Feb 21, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixes #18, not #19.

Please sign in to comment.