From f6567eae233a98a999423966b60e3983bc068513 Mon Sep 17 00:00:00 2001 From: Christian Diener Date: Wed, 4 Sep 2024 20:48:21 +0200 Subject: [PATCH] Support CARVEME and GAPSEQ external IDs (#1404) * add more external ID patterns * add RNs * add tests * fix isort * yes isort, I will add some random spaces here, makes perfect sense * of course black, please join the party * you drunk black, go home --- release-notes/next-release.md | 3 +++ src/cobra/medium/annotations.py | 6 +++++- src/cobra/medium/boundary_types.py | 2 +- tests/test_medium/test_boundary_types.py | 15 +++++++++++++++ 4 files changed, 24 insertions(+), 2 deletions(-) diff --git a/release-notes/next-release.md b/release-notes/next-release.md index 0cca0da86..c75df3de0 100644 --- a/release-notes/next-release.md +++ b/release-notes/next-release.md @@ -9,7 +9,10 @@ * Fixed a bug with SBML group parsing that affects the Debian package. ## Other + * Adding a duplicate boundary reaction (with `add_boundary`) no longer errors, but instead just returns the existing reaction. +* Automatic detection of the external comprtment now recognizes CARVEME and GAPSEQ ids and will no longer + show a warning for models generated with those tools. ## Deprecated features diff --git a/src/cobra/medium/annotations.py b/src/cobra/medium/annotations.py index bda673e75..461e49089 100644 --- a/src/cobra/medium/annotations.py +++ b/src/cobra/medium/annotations.py @@ -55,6 +55,8 @@ "intracellular", "intracellular region", "intracellular space", + "c0", # GAPSEQ + "C_c", # CARVEME ], "er": ["endoplasmic reticulum"], "erm": ["endoplasmic reticulum membrane"], @@ -68,6 +70,8 @@ "extra-organism", "external", "external medium", + "e0", # GAPSEQ + "C_e", # CARVEME ], "f": ["flagellum", "bacterial-type flagellum"], "g": ["golgi", "golgi apparatus"], @@ -78,7 +82,7 @@ "mm": ["mitochondrial membrane"], "m": ["mitochondrion", "mitochondria"], "n": ["nucleus"], - "p": ["periplasm", "periplasmic space"], + "p": ["periplasm", "periplasmic space", "p0", "C_p"], # GAPSEQ # CARVEME "x": ["peroxisome", "glyoxysome"], "u": ["thylakoid"], "vm": ["vacuolar membrane"], diff --git a/src/cobra/medium/boundary_types.py b/src/cobra/medium/boundary_types.py index 2a0338f9d..971480f57 100644 --- a/src/cobra/medium/boundary_types.py +++ b/src/cobra/medium/boundary_types.py @@ -94,7 +94,7 @@ def find_external_compartment(model: "Model") -> str: "Consider renaming your compartments using " "`Model.compartments` to fix this." ) - return most[0] + return most.iloc[0] # No info in the model, so give up raise RuntimeError( diff --git a/tests/test_medium/test_boundary_types.py b/tests/test_medium/test_boundary_types.py index 2299d5165..a459ded44 100644 --- a/tests/test_medium/test_boundary_types.py +++ b/tests/test_medium/test_boundary_types.py @@ -1,5 +1,7 @@ """Test functionalities of boundary type detection functions.""" +import logging + import pytest from cobra.core import Metabolite, Model, Reaction @@ -40,6 +42,19 @@ def test_find_external_compartment_multi(model: Model) -> None: find_external_compartment(model) +@pytest.mark.parametrize("compartment", ["C_e", "e0"]) +def test_find_external_popular_reconstructions( + model: Model, compartment, caplog +) -> None: + """Test some additional id formats.""" + for ex in model.exchanges: + ex.reactants[0].compartment = compartment + with caplog.at_level(logging.WARNING): + external = find_external_compartment(model) + assert external == compartment + assert "complete nonsense" not in caplog.text + + def test_no_names_or_boundary_reactions(empty_model: Model) -> None: """Test absence of name or boundary reactions.""" with pytest.raises(RuntimeError):