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 maximise 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 minimising the total sum of flux:
sol = solveLP(ecModel, 1);
from cobra.flux_analysis import pfba
sol = pfba(ec_model)
Enzyme-aware pFBA
getPfbaEnzymes (Python: pfba_enzymes) minimises the total enzyme usage, the L1 norm of the usage_prot_* fluxes, in place of the total flux of all reactions. Enzyme usage and bottlenecks uses it to find the flux distribution with the least enzyme mass. It is not available for light ecModels, which have no usage_prot_* reactions to minimise.
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 contain 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 Build an ecModel, this plain-cobrapy SBML export does not retain the ec_model.ec fields, the same caveat as MATLAB's exportModel.
Troubleshooting#
Problem |
Possible reason |
Solution |
|---|---|---|
Warning |
no reaction of the ecModel has this identifier; |
use the identifier of the ecModel, for example |
Error |
the new lower bound is above the upper bound, or the reverse |
change the other bound first: to raise both bounds, set the upper bound before the lower bound, and to lower both, the lower bound first (Python: set both at once with |
|
the bounds cannot be met together, for example a fixed growth rate above the growth that the protein pool allows |
relax the fixed bounds one at a time to find the bound that makes the problem infeasible |
Error from |
the ecModel is light and has no |
use |
An ecModel read from an SBML file has no |
|
save the ecModel with |