Skip to content

Commit b4f3850

Browse files
committed
Store the compartment for created metabolites
1 parent 0e99b1d commit b4f3850

File tree

2 files changed

+13
-1
lines changed

2 files changed

+13
-1
lines changed

src/cobra/core/reaction.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1615,7 +1615,7 @@ def build_reaction_from_string(
16151615
except KeyError:
16161616
if verbose:
16171617
print(f"unknown metabolite '{met_id}' created")
1618-
met = Metabolite(met_id)
1618+
met = Metabolite(met_id, compartment=compartment or None)
16191619
self.add_metabolites({met: num})
16201620

16211621
def summary(

tests/test_core/test_core_reaction.py

+12
Original file line numberDiff line numberDiff line change
@@ -380,6 +380,18 @@ def test_build_from_string(model: Model) -> None:
380380
assert pgi.bounds == (0, 1000)
381381

382382

383+
def test_build_from_string_creating_metabolites() -> None:
384+
# https://github.com/opencobra/cobrapy/issues/1418
385+
model = Model()
386+
reaction = Reaction("R1")
387+
model.add_reactions([reaction])
388+
reaction.build_reaction_from_string("[c]: a --> b")
389+
assert len(model.metabolites) == 2
390+
assert model.metabolites.a.compartment == "c"
391+
assert model.metabolites.b.compartment == "c"
392+
assert model.reaction.R1.compartments == set(["c"])
393+
394+
383395
def test_bounds_setter(model: Model) -> None:
384396
"""Test reaction bounds setter."""
385397
rxn = model.reactions.get_by_id("PGI")

0 commit comments

Comments
 (0)