Skip to content

Commit

Permalink
Support CARVEME and GAPSEQ external IDs (#1404)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
cdiener authored Sep 4, 2024
1 parent 9d580d6 commit f6567ea
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 2 deletions.
3 changes: 3 additions & 0 deletions release-notes/next-release.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
6 changes: 5 additions & 1 deletion src/cobra/medium/annotations.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@
"intracellular",
"intracellular region",
"intracellular space",
"c0", # GAPSEQ
"C_c", # CARVEME
],
"er": ["endoplasmic reticulum"],
"erm": ["endoplasmic reticulum membrane"],
Expand All @@ -68,6 +70,8 @@
"extra-organism",
"external",
"external medium",
"e0", # GAPSEQ
"C_e", # CARVEME
],
"f": ["flagellum", "bacterial-type flagellum"],
"g": ["golgi", "golgi apparatus"],
Expand All @@ -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"],
Expand Down
2 changes: 1 addition & 1 deletion src/cobra/medium/boundary_types.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
15 changes: 15 additions & 0 deletions tests/test_medium/test_boundary_types.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
"""Test functionalities of boundary type detection functions."""

import logging

import pytest

from cobra.core import Metabolite, Model, Reaction
Expand Down Expand Up @@ -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):
Expand Down

0 comments on commit f6567ea

Please sign in to comment.