Basic model operations#
Operations on bounds, the objective and flux distributions that the other guide pages assume. They work on conventional GEMs and ecModels in both languages: RAVEN toolbox functions in MATLAB, cobrapy idioms in Python. At the end of the page a bound is changed, a flux distribution is computed and inspected, and the ecModel is exported.
Functions#
MATLAB |
Python |
Note |
|---|---|---|
|
sets bounds and the objective |
|
|
runs FBA, or parsimonious FBA with the argument |
|
minimises the total enzyme usage |
||
|
prints the nonzero fluxes |
|
|
|
writes the fluxes to a spreadsheet |
|
writes an SBML file |
Setup#
A loaded model (ecModel in MATLAB, ec_model in Python) and, for the objective, the model adapter parameters params.
Set bounds and the objective#
Set the upper bound of a reaction to ten:
ecModel = setParam(ecModel, 'ub', 'r_0003', 10);
ec_model.reactions.get_by_id("r_0003").upper_bound = 10
Set the lower bound of a reaction to zero:
ecModel = setParam(ecModel, 'lb', 'r_0003', 0);
ec_model.reactions.get_by_id("r_0003").lower_bound = 0
Set the objective to maximize flux through the biomass reaction:
ecModel = setParam(ecModel, 'obj', params.bioRxn, 1);
ec_model.objective = params.bio_rxn
Run flux balance analysis#
Perform FBA, optimising the objective:
sol = solveLP(ecModel);
sol = ec_model.optimize()
Perform parsimonious FBA, optimising the objective and minimizing the total sum of flux:
sol = solveLP(ecModel, 1);
from cobra.flux_analysis import pfba
sol = pfba(ec_model)
GECKO 4: enzyme-aware pFBA
Both languages also offer a variant that minimizes total enzyme usage, the L1 norm of the usage_prot_* fluxes, in place of the total flux of all reactions. It is not part of the original Nature Protocols procedure, and it serves the enzyme-usage inspection done during simulation and analysis. It is not available for light ecModels, which have no usage_prot_* reactions to minimize.
sol = getPfbaEnzymes(ecModel);
from geckopy import pfba_enzymes
sol = pfba_enzymes(ec_model)
Inspect fluxes#
Inspect the nonzero fluxes:
Through exchange reactions (reactions without substrates or without products, as getExchangeRxns defines them; the usage_prot_<id> reactions have the protein pool as substrate and the enzyme pseudometabolite as product, so the list contains prot_pool_exchange and no usage reaction):
printFluxes(ecModel, sol.x)
Through all reactions:
printFluxes(ecModel, sol.x, false)
sol.fluxes is a pandas Series indexed by reaction id, so this is ordinary pandas filtering. Through all reactions:
print(sol.fluxes[sol.fluxes != 0])
Restricted to exchange reactions:
exchange_ids = [r.id for r in ec_model.exchanges]
print(sol.fluxes[exchange_ids][sol.fluxes[exchange_ids] != 0])
Export results and models#
Export the results to a spreadsheet. The file does not carry content from the ec structure and helps to find reaction identifiers quickly:
exportToExcelFormat(ecModel, 'filename.xlsx');
geckopy has no dedicated spreadsheet exporter; write the solution directly with pandas:
sol.fluxes.to_excel("filename.xlsx")
Export the ecModel to an SBML file for use in other constraint-based modelling software:
exportModel(ecModel, 'filename.xml');
import cobra
cobra.io.write_sbml_model(ec_model, "filename.xml")
As on Building an empty ecModel, this plain-cobrapy SBML export does not retain the ec_model.ec fields, the same caveat as MATLAB's exportModel.