psamm.fluxanalysis
– Constraintbased reaction flux analysis¶
Implementation of Flux Balance Analysis.

exception
psamm.fluxanalysis.
FluxBalanceError
(*args, **kwargs)¶ Error indicating that a flux balance cannot be solved.

class
psamm.fluxanalysis.
FluxBalanceProblem
(model, solver)¶ Model as a flux optimization problem with steady state assumption.
Create a representation of the model as an LP optimization problem with steady state assumption, i.e. the concentrations of compounds are always zero.
The problem can be modified and solved as many times as needed. The flux of a reaction can be obtained after solving using
get_flux()
.Parameters:  model –
MetabolicModel
to solve.  solver – LP solver instance to use.

add_thermodynamic
(em=1000)¶ Apply thermodynamic constraints to the model.
Adding these constraints restricts the solution space to only contain solutions that have no internal loops [Schilling00]. This is solved as a MILP problem as described in [Muller13]. The time to solve a problem with thermodynamic constraints is usually much longer than a normal FBA problem.
The
em
parameter is the upper bound on the delta mu reaction variables. This parameter has to be balanced based on the model size since setting the value too low can result in the correct solutions being infeasible and setting the value too high can result in numerical instability which again makes the correct solutions infeasible. The default value should work in all cases as long as the model is not unusually large.

check_constraints
()¶ Optimize without objective to check that solution is possible.
Raises
FluxBalanceError
if no flux solution is possible.

flux_bound
(reaction, direction)¶ Return the flux bound of the reaction.
Direction must be a positive number to obtain the upper bound or a negative number to obtain the lower bound. A value of inf or inf is returned if the problem is unbounded.

flux_expr
(reaction)¶ Get LP expression representing the reaction flux.

get_flux
(reaction)¶ Get resulting flux value for reaction.

get_flux_var
(reaction)¶ Get LP variable representing the reaction flux.

max_min_l1
(reaction, weights={})¶ Maximize flux of reaction then minimize the L1 norm.
During minimization the given reaction will be fixed at the maximum obtained from the first solution. If reaction is a dictionary object, each entry is interpreted as a weight on the objective for that reaction (nonexistent reaction will have zero weight).

maximize
(reaction)¶ Solve the model by maximizing the given reaction.
If reaction is a dictionary object, each entry is interpreted as a weight on the objective for that reaction (nonexistent reaction will have zero weight).

minimize_l1
(weights={})¶ Solve the model by minimizing the L1 norm of the fluxes.
If the weights dictionary is given, the weighted L1 norm if minimized instead. The dictionary contains the weights of each reaction (default 1).

prob
¶ Return the underlying LP problem.
This can be used to add additional constraints on the problem. Calling solve on the underlying problem is not guaranteed to work correctly, instead use the methods on this object that solves the problem or make a subclass with a method that calls
_solve()
.
 model –

psamm.fluxanalysis.
consistency_check
(model, subset, epsilon, tfba, solver)¶ Check that reaction subset of model is consistent using FBA.
Yields all reactions that are not flux consistent. A reaction is consistent if there is at least one flux solution to the model that both respects the model constraints and also allows the reaction in question to have nonzero flux.
This can be determined by running FBA on each reaction in turn and checking whether the flux in the solution is nonzero. Since FBA only tries to maximize the flux (and the flux can be negative for reversible reactions), we have to try to both maximize and minimize the flux. An optimization to this method is implemented such that if checking one reaction results in flux in another unchecked reaction, that reaction will immediately be marked flux consistent.
Parameters:  model – MetabolicModel to check for consistency.
 subset – Subset of model reactions to check.
 epsilon – The threshold at which the flux is considered nonzero.
 tfba – If True enable thermodynamic constraints.
 solver – LP solver instance to use.
Returns: An iterator of flux inconsistent reactions in the subset.

psamm.fluxanalysis.
flux_balance
(model, reaction, tfba, solver)¶ Run flux balance analysis on the given model.
Yields the reaction id and flux value for each reaction in the model.
This is a convenience function for sertting up and running the FluxBalanceProblem. If the FBA is solved for more than one parameter it is recommended to setup and reuse the FluxBalanceProblem manually for a speed up.
This is an implementation of flux balance analysis (FBA) as described in [Orth10] and [Fell86].
Parameters:  model – MetabolicModel to solve.
 reaction – Reaction to maximize. If a dict is given, this instead represents the objective function weights on each reaction.
 tfba – If True enable thermodynamic constraints.
 solver – LP solver instance to use.
Returns: Iterator over reaction ID and reaction flux pairs.

psamm.fluxanalysis.
flux_minimization
(model, fixed, solver, weights={})¶ Minimize flux of all reactions while keeping certain fluxes fixed.
The fixed reactions are given in a dictionary as reaction id to value mapping. The weighted L1norm of the fluxes is minimized.
Parameters:  model – MetabolicModel to solve.
 fixed – dict of additional lower bounds on reaction fluxes.
 solver – LP solver instance to use.
 weights – dict of weights on the L1norm terms.
Returns: An iterator of reaction ID and reaction flux pairs.

psamm.fluxanalysis.
flux_randomization
(model, threshold, tfba, solver)¶ Find a random flux solution on the boundary of the solution space.
The reactions in the threshold dictionary are constrained with the associated lower bound.
Parameters:  model – MetabolicModel to solve.
 threshold – dict of additional lower bounds on reaction fluxes.
 tfba – If True enable thermodynamic constraints.
 solver – LP solver instance to use.
Returns: An iterator of reaction ID and reaction flux pairs.

psamm.fluxanalysis.
flux_variability
(model, reactions, fixed, tfba, solver)¶ Find the variability of each reaction while fixing certain fluxes.
Yields the reaction id, and a tuple of minimum and maximum value for each of the given reactions. The fixed reactions are given in a dictionary as a reaction id to value mapping.
This is an implementation of flux variability analysis (FVA) as described in [Mahadevan03].
Parameters:  model – MetabolicModel to solve.
 reactions – Reactions on which to report variablity.
 fixed – dict of additional lower bounds on reaction fluxes.
 tfba – If True enable thermodynamic constraints.
 solver – LP solver instance to use.
Returns: Iterator over pairs of reaction ID and bounds. Bounds are returned as pairs of lower and upper values.