Flux Balance Analysis

The PyFBA.fba modules include code for developing the stoichiometric matrix, adding reaction bounds and compound bounds, identifying reactions involved in uptake and secretion, and running the FBA.

Methods associated with creating the stoichiometric matrix

PyFBA.fba.create_stoichiometric_matrix.create_stoichiometric_matrix(reactions_to_run, reactions, compounds, media, biomass_equation, uptake_secretion=None, verbose=False)

Given the reactions data and a list of RIDs to include, build a stoichiometric matrix and load that into the linear solver.

The uptake and secretion reactions (sometimes called boundary reactions) are reactions that allow compounds to flow into the media and secreted compounds away from the cell. You can either provide these (e.g. if you are parsing an XML (SBML) file, or we will calculate them for you based on your media and reactions.

We also take this opportunity to set the objective function (as it is a member of the SM).

Parameters:
  • uptake_secretion (dict of Reaction) – An optional hash of uptake and secretion reactions that should be added to the model
  • compounds (dict) – a dict of the compounds present
  • reactions (dict) – a dict of all the reactions
  • reactions_to_run (set) – just the reaction ids that we want to include in our model
  • media (set) – a set of compounds that would make up the media
  • biomass_equation (metabolism.Reaction) – the biomass_equation equation as a Reaction object
  • verbose (bool) – print more information
Returns:

Sorted lists of all the compounds and reactions in the model, and a revised reactions dict that includes the uptake and secretion reactions

Return type:

list, list, dict

Adding the limits to the reactions and compounds

PyFBA.fba.bounds.compound_bounds(cp, lower=0, upper=0)

Impose constraints on the compounds. These constraints limit what the variation of each compound can be and is essentially 0 for most compounds except those that are in the media or otherwise external.

This is the zero flux vector.

Parameters:
cp: the list of compound ids lower: the default lower value upper: the default upper value
PyFBA.fba.bounds.reaction_bounds(reactions, reactions_to_run, media, lower=-1000.0, mid=0.0, upper=1000.0, verbose=False)

Set the bounds for each reaction. We set the reactions to run between either lower/mid, mid/upper, or lower/upper depending on whether the reaction runs <=, =>, or <=> respectively.

Parameters:
  • reactions (dict of metabolism.Reaction) – The dict of all reactions we know about
  • reactions_to_run (set) – The sorted list of reactions to run
  • media (set) – The media compounds
  • lower (float) – The default lower bound
  • mid (float) – The default mid value (typically 0)
  • upper (float) – The default upper bound
Returns:

A dict of the reaction ID and the tuple of bounds

Return type:

dict

Identifying the reactions that are uptake and secretion reactions

PyFBA.fba.external_reactions.remove_uptake_and_secretion_reactions(reactions)

Remove all the uptake and secretion reactions added to a model, eg. when you are running multiple simulations. :param reactions: The reactions dict :type reactions: dict :return: The enzymes, compounds, and reactions data structure :rtype: dict

PyFBA.fba.external_reactions.uptake_and_secretion_reactions(model_compounds, compounds)

Figure out which compounds can be taken up from the media and/or secreted into the media. We provide an endless reaction for these which allows them to be taken up and/or secreted without affecting the rest of the stoichiometric matrix

We also add a reaction for biomass_equation

Parameters:
  • model_compounds (set) – A set of the identifiers of all the compounds we have identified so far
  • compounds (dict) – the dict of all the compounds
Returns:

A hash of new uptake and secretion reactions we have identified

Return type:

hash

Running the FBA and retrieving the results

PyFBA.fba.run_fba.run_fba(compounds, reactions, reactions_to_run, media, biomass_equation, uptake_secretion={}, verbose=False)

Run an fba for a set of data. We required the reactions object, a list of reactions to run, the media, and the biomass_equation equation.

With all of these we run the fba and return:

Parameters:
  • uptake_secretion (dict of Reaction) – A hash of uptake and secretion reactions that should be added to the model. Calculated if not provided.
  • compounds (dict) – The dict of all compounds
  • reactions (dict) – The dict of all reactions
  • reactions_to_run (set) – the reactions to run
  • media (set) – An array of compound.Compound objects representing the media
  • biomass_equation (network.reaction.Reaction) – The biomass_equation equation
  • verbose (bool) – Print more output
Returns:

which type of linear resolution, the output value of the model, whether the model grew

Return type:

(str, float, bool)