Skip to content

Commit 06aab6d

Browse files
fix: predicted pathways containing exchange reactions for native compounds (#234)
A change of `model.exchanges` in upstream cobrapy has led to the incorporation of DM_ reactions for native compounds (H+, H2O, CO2, etc.) into the `PathwayPredictor.model` (host model + universal model). I have replaced `model.exchanges` with `model.boundary` (which has the same behavior as `model.exchanges` had in the past).
1 parent dbabb60 commit 06aab6d

File tree

10 files changed

+17
-17
lines changed

10 files changed

+17
-17
lines changed

cameo/core/utils.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ def medium(model):
4848
reaction_names = []
4949
lower_bounds = []
5050
upper_bounds = []
51-
for ex in model.exchanges:
51+
for ex in model.boundary:
5252
metabolite = list(ex.metabolites.keys())[0]
5353
coeff = ex.metabolites[metabolite]
5454
if coeff * ex.lower_bound > 0:
@@ -107,7 +107,7 @@ def load_medium(model, medium_def, copy=False, delimiter="\t"):
107107

108108
def _load_medium_from_dict(model, medium_def):
109109
assert isinstance(medium_def, dict)
110-
for ex_reaction in model.exchanges:
110+
for ex_reaction in model.boundary:
111111
ex_reaction.lower_bound = medium_def.get(ex_reaction.id, 0)
112112

113113

@@ -126,7 +126,7 @@ def _load_medium_from_file(model, file_path, delimiter="\t"):
126126

127127
def _load_medium_from_dataframe(model, medium_df):
128128
assert isinstance(medium_df, DataFrame)
129-
for ex_reaction in model.exchanges:
129+
for ex_reaction in model.boundary:
130130
if ex_reaction.id in medium_df.reaction_id.values:
131131
medium_row = medium_df[medium_df.reaction_id == ex_reaction.id]
132132
ex_reaction.lower_bound = medium_row.lower_bound.values[0]

cameo/flux_analysis/analysis.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ def find_blocked_reactions(model):
169169
170170
"""
171171
with model:
172-
for exchange in model.exchanges:
172+
for exchange in model.boundary:
173173
exchange.bounds = (-9999, 9999)
174174
fva_solution = flux_variability_analysis(model)
175175
return frozenset(

cameo/flux_analysis/structural.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -302,7 +302,7 @@ def __init__(self, model, reactions=None, c=1e-5, copy=True, change_bounds=True)
302302
self._elementary_mode_generator = self.__generate_elementary_modes()
303303

304304
def __set_exchange_bounds(self):
305-
exchanges = self.model.exchanges
305+
exchanges = self.model.boundary
306306
min_bound = min(exchange.lower_bound for exchange in exchanges)
307307
max_bound = max(exchange.upper_bound for exchange in exchanges)
308308
for exchange in exchanges:

cameo/flux_analysis/util.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def remove_infeasible_cycles(model, fluxes, fix=()):
4949
"""
5050
with model:
5151
# make sure the original object is restored
52-
exchange_reactions = model.exchanges
52+
exchange_reactions = model.boundary
5353
exchange_ids = [exchange.id for exchange in exchange_reactions]
5454
internal_reactions = [reaction for reaction in model.reactions if reaction.id not in exchange_ids]
5555
for exchange in exchange_reactions:

cameo/strain_design/deterministic/flux_variability_based.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -197,8 +197,8 @@ def __init__(self, design_space_model, objective, variables=None, reference_mode
197197
reference_blocked_reactions = find_blocked_reactions_nullspace(self.reference_model, self.reference_nullspace)
198198
self.exclude += [reaction.id for reaction in reference_blocked_reactions]
199199

200-
self.exclude += [reaction.id for reaction in self.design_space_model.exchanges]
201-
self.exclude += [reaction.id for reaction in self.reference_model.exchanges]
200+
self.exclude += [reaction.id for reaction in self.design_space_model.boundary]
201+
self.exclude += [reaction.id for reaction in self.reference_model.boundary]
202202

203203
self.exclude += [reaction.id for reaction in self.design_space_model.reactions
204204
if _BIOMASS_RE_.match(reaction.id)]
@@ -856,7 +856,7 @@ def run(self, target=None, max_enforced_flux=0.9, number_of_results=10, exclude=
856856
ndecimals = config.ndecimals
857857

858858
# Exclude list
859-
exclude = list(exclude) + model.exchanges
859+
exclude = list(exclude) + model.boundary
860860
exclude_ids = [target.id]
861861
for reaction in exclude:
862862
if isinstance(reaction, Reaction):

cameo/strain_design/deterministic/linear_programming.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def _reduce_to_nullspace(self, reactions):
157157
def _build_problem(self, exclude_reactions, use_nullspace_simplification):
158158
logger.debug("Starting to formulate OptKnock problem")
159159

160-
self.essential_reactions = find_essential_reactions(self._model, processes=1).union(self._model.exchanges)
160+
self.essential_reactions = find_essential_reactions(self._model, processes=1).union(self._model.boundary)
161161
if exclude_reactions:
162162
self.exclude_reactions = set.union(
163163
self.essential_reactions,

cameo/strain_design/heuristic/evolutionary/optimization.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -678,7 +678,7 @@ def __init__(self, reactions=None, essential_reactions=None, use_nullspace_simpl
678678
if use_nullspace_simplification:
679679
ns = nullspace(create_stoichiometric_array(self.model))
680680
dead_ends = set(find_blocked_reactions_nullspace(self.model, ns=ns))
681-
exchanges = set(self.model.exchanges)
681+
exchanges = set(self.model.boundary)
682682
reactions = [
683683
r for r in self.model.reactions
684684
if (r not in exchanges) and (
@@ -694,7 +694,7 @@ def __init__(self, reactions=None, essential_reactions=None, use_nullspace_simpl
694694
else:
695695
groups = None
696696
to_keep = set(r.id for r in self.model.reactions)
697-
to_keep.difference_update(r.id for r in self.model.exchanges)
697+
to_keep.difference_update(r.id for r in self.model.boundary)
698698
to_keep.difference_update(self.essential_reactions)
699699
to_keep = list(to_keep)
700700

cameo/strain_design/pathway_prediction/pathway_predictor.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -246,7 +246,7 @@ def __init__(self, model, universal_model=None, mapping=None, compartment_regexp
246246
except SolverNotFound:
247247
logger.info('cplex not available for pathway predictions.')
248248

249-
self.new_reactions = self._extend_model(model.exchanges)
249+
self.new_reactions = self._extend_model(model.boundary)
250250

251251
logger.debug("Adding adapter reactions to connect model with universal model.")
252252
self.adpater_reactions = util.create_adapter_reactions(model.metabolites, self.universal_model,
@@ -421,7 +421,7 @@ def _add_switches(self, reactions):
421421
self._y_vars_ids = [var.name for var in y_vars]
422422

423423
def _extend_model(self, original_exchanges):
424-
for exchange in self.model.exchanges:
424+
for exchange in self.model.boundary:
425425
if len(exchange.reactants) > 0 >= exchange.lower_bound:
426426
exchange.upper_bound = 999999.
427427

@@ -431,7 +431,7 @@ def _extend_model(self, original_exchanges):
431431
r in original_exchanges for m, coeff in six.iteritems(r.metabolites)
432432
if len(r.metabolites) == 1 and coeff < 0 < r.upper_bound]
433433

434-
universal_exchanges = self.universal_model.exchanges
434+
universal_exchanges = self.universal_model.boundary
435435
for reaction in self.universal_model.reactions:
436436
if reaction in self.model.reactions:
437437
continue

tests/conftest.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def iaf1260(data_directory):
4242
@pytest.fixture(scope="session")
4343
def universal_model(data_directory):
4444
universal = load_model(join(data_directory, 'iJO1366.xml'), sanitize=False)
45-
universal.remove_reactions(universal.exchanges)
45+
universal.remove_reactions(universal.boundary)
4646
return universal
4747

4848

tests/test_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
MODELS = os.path.dirname(models.__file__)
2828

2929
UNIVERSALMODEL = load_model(os.path.join(MODELS, 'json/iJO1366.json'))
30-
UNIVERSALMODEL.remove_reactions(UNIVERSALMODEL.exchanges)
30+
UNIVERSALMODEL.remove_reactions(UNIVERSALMODEL.boundary)
3131

3232

3333
def test_api():

0 commit comments

Comments
 (0)