A hands-on tutorial on constraint-based modeling of metabolism using cobrapy.
Constraint-based modeling (CBM) predicts what a metabolic network can do without needing to know enzyme kinetics — parameters that are simply not available at genome scale for most organisms. Instead of simulating reaction rates over time, CBM reconstructs a genome-scale network of all known metabolic reactions (a stoichiometric matrix S) and assumes the cell is at metabolic steady state: for every internal metabolite, production must equal consumption (S·v = 0, where v is the vector of reaction fluxes). Each flux is further bounded above and below, reflecting thermodynamics (reaction reversibility), enzyme capacity, or nutrient availability.
These constraints alone leave a whole space of feasible flux distributions, not a single answer. Flux Balance Analysis (FBA) picks one, by solving a linear program: maximize (or minimize) some objective — classically biomass production, as a proxy for growth rate — subject to those constraints. Because it's just a system of linear (in)equalities, FBA scales to genome-scale networks with thousands of reactions, and it is the workhorse this whole tutorial builds on. Its main limitation is also its main strength: many different flux distributions can achieve the same optimal objective value, which is exactly what Part 4 of this tutorial (FVA, pFBA) is about.
cobrapy is the Python package for
COBRA (COnstraint-Based Reconstruction and Analysis) — the
family of methods described above. It lets you build and inspect metabolic
models with plain Python objects (Model, Reaction, Metabolite,
Gene), read/write standard genome-scale reconstructions (SBML files like
data/iJO1366.xml), and run analyses such as FBA, FVA, pFBA, and gene/
reaction deletions, all backed by a linear programming solver under the
hood. See Ebrahim, Lerman, Palsson & Hyduke (2013), COBRApy:
COnstraints-Based Reconstruction and Analysis for Python, BMC Systems
Biology 7:74 (DOI).
By the end of this tutorial you will be able to:
- Build a small metabolic model from scratch with cobrapy's core objects (metabolites, reactions, genes/GPRs) and understand what a stoichiometric model actually consists of (Part 1).
- Load a real genome-scale model (E. coli iJO1366), inspect it, and run FBA to predict growth rate and flux distributions under different growth conditions — aerobic/anaerobic, different carbon sources (Part 2).
- Simulate in silico single-gene knockouts and evaluate essentiality predictions against real experimental data (Part 3).
- Go beyond a single FBA solution: quantify solution-space flexibility with Flux Variability Analysis, find a more biologically plausible solution with parsimonious FBA, and uncover synthetic lethal gene pairs with double knockouts (Part 4).
-
Create virtual environment
virtualenv -p python3 venv/ -
activate the virtual environment
source venv/bin/activate -
Install requirements
pip install -r requirements.txt -
Install jupyter kernel
pip install ipykernelpython -m ipykernel install --user --name=python3 -
Run jupyter
jupyter notebook
Run the tutorial notebooks using:
- Tutorial 1 - Introduction to cobrapy
- Tutorial 2 - Flux Balance Analysis
- Tutorial 3 - In-silico gene knockout experiments
- Tutorial 4 - Advanced flux analysis
See BIBLIOGRAPHY.md for the experimental papers behind the predictions made in each exercise.