Skip to content

Commit

Permalink
Make FVA a bit faster. (#286)
Browse files Browse the repository at this point in the history
The FVA in cobrapy alternated between optimizing via minimum
and maximum, but the minimum solutions tend to be closer
to each other than the maximum solutions. Thus, a better
recycling strategy for the solution basis is to minimize
all reactions first followed by maximizing them. This is also
the algorithm described in the original publication.
  • Loading branch information
cdiener authored and hredestig committed Oct 7, 2016
1 parent c599664 commit 643ebf7
Showing 1 changed file with 11 additions and 12 deletions.
23 changes: 11 additions & 12 deletions cobra/flux_analysis/variability.py
Original file line number Diff line number Diff line change
Expand Up @@ -50,18 +50,17 @@ def flux_variability_analysis(cobra_model, reaction_list=None,
def calculate_lp_variability(lp, solver, cobra_model, reaction_list,
**solver_args):
"""calculate max and min of selected variables in an LP"""
fva_results = {}
for r in reaction_list:
r_id = str(r)
i = cobra_model.reactions.index(r_id)
fva_results[r_id] = {}
solver.change_variable_objective(lp, i, 1.)
solver.solve_problem(lp, objective_sense="maximize", **solver_args)
fva_results[r_id]["maximum"] = solver.get_objective_value(lp)
solver.solve_problem(lp, objective_sense="minimize", **solver_args)
fva_results[r_id]["minimum"] = solver.get_objective_value(lp)
# revert the problem to how it was before
solver.change_variable_objective(lp, i, 0.)
fva_results = {str(r): {} for r in reaction_list}
for what in ("minimum", "maximum"):
sense = "minimize" if what == "minimum" else "maximize"
for r in reaction_list:
r_id = str(r)
i = cobra_model.reactions.index(r_id)
solver.change_variable_objective(lp, i, 1.)
solver.solve_problem(lp, objective_sense=sense, **solver_args)
fva_results[r_id][what] = solver.get_objective_value(lp)
# revert the problem to how it was before
solver.change_variable_objective(lp, i, 0.)
return fva_results


Expand Down

0 comments on commit 643ebf7

Please sign in to comment.