Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Set correct flux bounds #866

Merged
merged 9 commits into from Jul 5, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
15 changes: 6 additions & 9 deletions cobra/core/reaction.py
Expand Up @@ -25,7 +25,7 @@
from cobra.util.util import format_long_string


CONFIGURATION = Configuration()
config = Configuration()

# precompiled regular expressions
# Matches and/or in a gene reaction rule
Expand Down Expand Up @@ -88,9 +88,9 @@ def __init__(self, id=None, name='', subsystem='', lower_bound=0.0,

# from cameo ...
self._lower_bound = lower_bound if lower_bound is not None else \
CONFIGURATION.lower_bound
config.lower_bound
self._upper_bound = upper_bound if upper_bound is not None else \
CONFIGURATION.upper_bound
config.upper_bound

def _set_id_with_model(self, value):
if value in self.model.reactions:
Expand Down Expand Up @@ -1050,23 +1050,20 @@ def build_reaction_from_string(self, reaction_str, verbose=True,
# reversible case
arrow_match = reversible_arrow_finder.search(reaction_str)
if arrow_match is not None:
self.lower_bound = -1000
self.upper_bound = 1000
self.bounds = config.lower_bound, config.upper_bound
else: # irreversible
# try forward
arrow_match = forward_arrow_finder.search(reaction_str)
if arrow_match is not None:
self.upper_bound = 1000
self.lower_bound = 0
self.bounds = 0, config.upper_bound
else:
# must be reverse
arrow_match = reverse_arrow_finder.search(reaction_str)
if arrow_match is None:
raise ValueError("no suitable arrow found in '%s'" %
reaction_str)
else:
self.upper_bound = 0
self.lower_bound = -1000
self.bounds = config.lower_bound, 0
reactant_str = reaction_str[:arrow_match.start()].strip()
product_str = reaction_str[arrow_match.end():].strip()

Expand Down
15 changes: 14 additions & 1 deletion cobra/test/test_core/test_core_reaction.py
Expand Up @@ -10,9 +10,10 @@
import pytest
import six

from cobra.core import Metabolite, Model, Reaction
from cobra.core import Configuration, Metabolite, Model, Reaction


config = Configuration()
stable_optlang = ["glpk", "cplex", "gurobi"]


Expand Down Expand Up @@ -269,6 +270,18 @@ def test_build_from_string(model):
assert model.metabolites.foo
assert len(model.metabolites) == m

with model:
old_bounds = config.bounds
assert old_bounds == (-1000, 1000)
config.bounds = (-5, 5)
pgi.build_reaction_from_string("g6p_c <--> f6p_c + new",
verbose=False)
assert pgi.bounds == (-5, 5)
config.bounds = old_bounds
pgi.build_reaction_from_string("g6p_c --> f6p_c + new",
verbose=False)
assert pgi.bounds == (0, 1000)


def test_bounds_setter(model):
rxn = model.reactions.get_by_id("PGI")
Expand Down