Skip to content

Commit

Permalink
Store the compartment for created metabolites
Browse files Browse the repository at this point in the history
  • Loading branch information
oxinabox committed Dec 13, 2024
1 parent 0e99b1d commit b4f3850
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/cobra/core/reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -1615,7 +1615,7 @@ def build_reaction_from_string(
except KeyError:
if verbose:
print(f"unknown metabolite '{met_id}' created")
met = Metabolite(met_id)
met = Metabolite(met_id, compartment=compartment or None)
self.add_metabolites({met: num})

def summary(
Expand Down
12 changes: 12 additions & 0 deletions tests/test_core/test_core_reaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -380,6 +380,18 @@ def test_build_from_string(model: Model) -> None:
assert pgi.bounds == (0, 1000)


def test_build_from_string_creating_metabolites() -> None:
# https://github.com/opencobra/cobrapy/issues/1418
model = Model()
reaction = Reaction("R1")
model.add_reactions([reaction])
reaction.build_reaction_from_string("[c]: a --> b")
assert len(model.metabolites) == 2
assert model.metabolites.a.compartment == "c"
assert model.metabolites.b.compartment == "c"
assert model.reaction.R1.compartments == set(["c"])


def test_bounds_setter(model: Model) -> None:
"""Test reaction bounds setter."""
rxn = model.reactions.get_by_id("PGI")
Expand Down

0 comments on commit b4f3850

Please sign in to comment.