Cobrapy Dynamic
All-in-one skill covering constraint, based, metabolic, modeling. Includes structured workflows, validation checks, and reusable patterns for scientific.
COBRApy Dynamic
A scientific computing skill for constraint-based metabolic modeling using COBRApy — the Python library implementing Constraint-Based Reconstruction and Analysis methods for genome-scale metabolic models. COBRApy Dynamic helps you load metabolic models, run flux balance analysis (FBA), perform gene knockout simulations, and analyze metabolic network capabilities.
When to Use This Skill
Choose COBRApy Dynamic when:
- Running flux balance analysis (FBA) on genome-scale metabolic models
- Simulating gene knockouts and their effects on growth
- Analyzing metabolic flux distributions and pathway usage
- Working with SBML metabolic models from BiGG or other repositories
Consider alternatives when:
- You need kinetic modeling (use COPASI or PySCeS)
- You need pathway visualization (use Escher or KEGG)
- You need metabolomics data analysis (use MetaboAnalyst)
- You need de novo model reconstruction (use ModelSEED or CarveMe)
Quick Start
claude "Run FBA on the E. coli core model and find essential genes"
import cobra from cobra.io import load_model # Load a model from BiGG repository model = load_model("textbook") # E. coli core model print(f"Metabolites: {len(model.metabolites)}") print(f"Reactions: {len(model.reactions)}") print(f"Genes: {len(model.genes)}") # Run Flux Balance Analysis solution = model.optimize() print(f"\nGrowth rate: {solution.objective_value:.4f} h⁻¹") print(f"Status: {solution.status}") # Show key fluxes for rxn in ["PFK", "PYK", "CS", "ATPM"]: flux = solution.fluxes[rxn] print(f" {rxn}: {flux:.4f} mmol/gDW/h")
Core Concepts
FBA Fundamentals
| Concept | Description | COBRApy Method |
|---|---|---|
| Objective Function | What to optimize (usually growth) | model.objective |
| Constraints | Reaction bounds, mass balance | reaction.bounds |
| FBA Solution | Optimal flux distribution | model.optimize() |
| Shadow Prices | Metabolite value to objective | solution.shadow_prices |
| Reduced Costs | Reaction value to objective | solution.reduced_costs |
Gene Knockout Analysis
# Single gene knockout from cobra.flux_analysis import single_gene_deletion results = single_gene_deletion(model) essential_genes = results[results["growth"] < 0.01] print(f"Essential genes: {len(essential_genes)}/{len(model.genes)}") for gene_id in essential_genes.index[:10]: gene = model.genes.get_by_id(list(gene_id)[0]) print(f" {gene.id}: {gene.name}") # Double gene knockout (synthetic lethality) from cobra.flux_analysis import double_gene_deletion double_ko = double_gene_deletion(model) synthetic_lethal = double_ko[ (double_ko["growth"] < 0.01) & (double_ko.index.map(lambda x: len(x) == 2)) ]
Media and Environment Simulation
# Simulate different growth media with model: # Anaerobic conditions model.reactions.get_by_id("EX_o2_e").lower_bound = 0 anaerobic = model.optimize() print(f"Anaerobic growth: {anaerobic.objective_value:.4f}") # Glucose-limited model.reactions.get_by_id("EX_glc__D_e").lower_bound = -5 # Reduce glucose limited = model.optimize() print(f"Glucose-limited growth: {limited.objective_value:.4f}") # Original model unchanged (context manager) aerobic = model.optimize() print(f"Aerobic growth: {aerobic.objective_value:.4f}")
Configuration
| Parameter | Description | Default |
|---|---|---|
solver | LP solver (glpk, cplex, gurobi) | glpk |
objective | Optimization target reaction | Biomass reaction |
tolerance | Numerical tolerance for solver | 1e-7 |
model_format | Input format (SBML, JSON, YAML) | Auto-detect |
processes | Parallel processes for deletions | 1 |
Best Practices
-
Use context managers for temporary model changes. Wrap modifications in
with model:blocks so changes are automatically reverted. This prevents accidentally modifying the base model during exploratory analysis. -
Validate the model before analysis. Run
cobra.flux_analysis.model_analysis.validate(model)to check for common issues: blocked reactions, dead-end metabolites, and thermodynamically infeasible cycles. Fix these before drawing biological conclusions. -
Use loopless FBA for biologically meaningful fluxes. Standard FBA may produce thermodynamically infeasible flux loops. Use
cobra.flux_analysis.loopless.loopless_solution(model)for flux distributions that respect thermodynamic constraints. -
Check solver status before using results. Always verify
solution.status == "optimal"before interpreting fluxes. Infeasible or unbounded solutions indicate model issues (conflicting constraints or missing bounds). -
Compare results against experimental data. FBA predicts optimal growth, not necessarily actual cellular behavior. Validate predictions against published growth rates, secretion rates, and gene essentiality data for your organism.
Common Issues
FBA returns zero growth rate. The model likely lacks an essential nutrient. Check exchange reaction bounds (model.medium) to ensure required carbon source, nitrogen, and cofactors are available. Set appropriate lower bounds on exchange reactions for available nutrients.
Solver reports infeasible solution. Conflicting constraints make the problem unsolvable. Common causes: exchange reactions too restrictive, maintenance ATP requirement higher than possible production, or incorrect reaction directionality. Relax constraints one at a time to identify the conflict.
Gene knockout predictions don't match experimental data. FBA predicts optimal behavior — cells may not operate optimally. Use MOMA (Minimization of Metabolic Adjustment) instead of FBA for knockout predictions, as it better captures the suboptimal flux redistribution after gene deletion.
Reviews
No reviews yet. Be the first to review this template!
Similar Templates
Full-Stack Code Reviewer
Comprehensive code review skill that checks for security vulnerabilities, performance issues, accessibility, and best practices across frontend and backend code.
Test Suite Generator
Generates comprehensive test suites with unit tests, integration tests, and edge cases. Supports Jest, Vitest, Pytest, and Go testing.
Pro Architecture Workspace
Battle-tested skill for architectural, decision, making, framework. Includes structured workflows, validation checks, and reusable patterns for development.