cobrapy
Constraints-Based Reconstruction and Analysis for Python. Used for modeling large-scale metabolic networks in microorganisms.
Best use case
cobrapy is best used when you need a repeatable AI agent workflow instead of a one-off prompt.
Constraints-Based Reconstruction and Analysis for Python. Used for modeling large-scale metabolic networks in microorganisms.
Teams using cobrapy should expect a more consistent output, faster repeated execution, less prompt rewriting.
When to use this skill
- You want a reusable workflow that can be run more than once with consistent structure.
When not to use this skill
- You only need a quick one-off answer and do not need a reusable workflow.
- You cannot install or maintain the underlying files, dependencies, or repository context.
Installation
Claude Code / Cursor / Codex
Manual Installation
- Download SKILL.md from GitHub
- Place it in
.claude/skills/cobrapy/SKILL.mdinside your project - Restart your AI agent — it will auto-discover the skill
How cobrapy Compares
| Feature / Agent | cobrapy | Standard Approach |
|---|---|---|
| Platform Support | Not specified | Limited / Varies |
| Context Awareness | High | Baseline |
| Installation Complexity | Unknown | N/A |
Frequently Asked Questions
What does this skill do?
Constraints-Based Reconstruction and Analysis for Python. Used for modeling large-scale metabolic networks in microorganisms.
Where can I find the source code?
You can find the source code on GitHub using the link provided at the top of the page.
SKILL.md Source
# COBRApy - Metabolic Modeling
Models the "metabolism" of a cell as a linear optimization problem. Used to predict bacterial growth under different conditions or design GMO strains.
## When to Use
- Predicting microbial growth rates under different nutrient conditions.
- Designing metabolic engineering strategies (knockouts, additions).
- Understanding metabolic flux distributions.
- Comparing metabolic capabilities across organisms.
- Identifying essential genes and reactions.
## Core Principles
### Flux Balance Analysis (FBA)
Optimizes metabolic fluxes to maximize biomass production (or other objectives) subject to stoichiometric constraints.
### Gene-Protein-Reaction (GPR)
Genes encode proteins (enzymes) that catalyze reactions. Knockouts affect reaction availability.
### Constraints
Reaction bounds (lower/upper limits) represent enzyme capacity or nutrient availability.
## Quick Reference
### Standard Imports
```python
import cobra
from cobra.io import load_model, save_model
```
### Basic Patterns
```python
# 1. Load model (e.g., E. coli)
model = cobra.io.load_model("iJO1366")
# Or: model = cobra.io.read_sbml_model("model.xml")
# 2. Run Flux Balance Analysis (FBA)
solution = model.optimize()
print(f"Growth rate: {solution.objective_value:.4f}")
print(f"Status: {solution.status}")
# 3. Knockout simulation (Gene essentiality)
with model:
model.genes.get_by_id("b0002").knock_out()
print(f"Growth after knockout: {model.optimize().objective_value:.4f}")
# 4. Change medium (nutrient availability)
model.medium = {
'EX_glc__D_e': 10.0, # Glucose uptake
'EX_o2_e': 1000.0 # Oxygen
}
solution = model.optimize()
```
## Critical Rules
### ✅ DO
- **Check solution status** - Ensure status is 'optimal' before using results.
- **Use context managers** - Wrap modifications in `with model:` to avoid permanent changes.
- **Set appropriate bounds** - Reaction bounds should reflect biological reality.
- **Validate model** - Use `model.validate()` to check for common issues.
### ❌ DON'T
- **Don't ignore infeasible solutions** - If optimization fails, check constraints and bounds.
- **Don't modify model in place** - Use context managers or copy the model first.
- **Don't assume all reactions are active** - Many reactions have zero flux in optimal solution.
## Advanced Patterns
### Flux Variability Analysis (FVA)
```python
from cobra.flux_analysis import flux_variability_analysis
# Find range of possible fluxes for each reaction
fva_result = flux_variability_analysis(model, model.reactions)
```
### Gene Essentiality Analysis
```python
# Test which genes are essential for growth
from cobra.flux_analysis import single_gene_deletion
deletion_results = single_gene_deletion(model)
essential_genes = deletion_results[deletion_results['growth'] < 0.01]
```
### Adding Custom Reactions
```python
# Add a new reaction to the model
new_reaction = cobra.Reaction("NEW_RXN")
new_reaction.add_metabolites({
model.metabolites.get_by_id("glc__D_c"): -1,
model.metabolites.get_by_id("atp_c"): -1,
model.metabolites.get_by_id("adp_c"): 1,
})
new_reaction.lower_bound = 0
new_reaction.upper_bound = 1000
model.add_reactions([new_reaction])
```
COBRApy transforms metabolic networks into computable models, enabling researchers to predict and engineer cellular behavior at the systems level.Related Skills
xgboost-lightgbm
Industry-standard gradient boosting libraries for tabular data and structured datasets. XGBoost and LightGBM excel at classification and regression tasks on tables, CSVs, and databases. Use when working with tabular machine learning, gradient boosting trees, Kaggle competitions, feature importance analysis, hyperparameter tuning, or when you need state-of-the-art performance on structured data.
xarray
N-dimensional labeled arrays and datasets in Python. Built on top of NumPy and Dask. It introduces labels in the form of dimensions, coordinates, and attributes on top of raw NumPy-like arrays, making data analysis in physical sciences more intuitive and less error-prone. Use for working with multi-dimensional scientific data, NetCDF/GRIB/Zarr files, climate/weather/oceanographic datasets, remote sensing, geospatial imaging, large out-of-memory datasets with Dask, and labeled array operations.
transformers
State-of-the-art Machine Learning for PyTorch, TensorFlow, and JAX. Provides thousands of pretrained models to perform tasks on different modalities such as text, vision, and audio. The industry standard for Large Language Models (LLMs) and foundation models in science.
tqdm
A fast, extensible progress bar for Python and CLI. Instantly makes your loops show a smart progress meter with ETA, iterations per second, and customizable statistics. Minimal overhead. Use for monitoring long-running loops, simulations, data processing, ML training, file downloads, I/O operations, command-line tools, pandas operations, parallel tasks, and nested progress bars.
tensorflow
Comprehensive deep learning framework for building, training, and deploying neural networks. TensorFlow provides tf.keras high-level API for model construction, tf.data for efficient data pipelines, and tf.function for graph-mode optimization. Use when working with: neural network training and inference, image classification/detection/segmentation, NLP/text processing with embeddings or transformers, time series forecasting, generative models (VAE, GAN), transfer learning with pretrained models, custom training loops with GradientTape, GPU/TPU accelerated computation, or any deep learning task.
sympy
Comprehensive guide for SymPy - Python library for symbolic mathematics. Use for symbolic expressions, calculus (derivatives, integrals, limits, series), equation solving (algebraic, differential, systems), linear algebra, simplification, matrix operations, special functions, code generation, and mathematical proofs. Essential for analytical mathematics and computer algebra.
sunpy
The community-developed free and open-source software package for solar physics. Provides tools for data search and download, coordinate transformations specific to solar physics, and powerful image processing through the Map object. Use when working with solar data, solar images (EUV, magnetograms, white light), solar coordinates (Helioprojective, Heliographic), Fido data search, solar time series, differential rotation, limb fitting, or multi-instrument solar analysis (AIA, HMI, GOES).
statsmodels
Advanced statistical modeling and hypothesis testing. Complementary to SciPy's stats module, it provides classes and functions for the estimation of many different statistical models, as well as for conducting statistical tests and statistical data exploration. Use for linear regression, GLM, time series analysis, ANOVA, survival analysis, causal inference, and statistical hypothesis testing. Load when working with OLS, WLS, logistic regression, Poisson regression, ARIMA, SARIMAX, statistical diagnostics, p-values, confidence intervals, or R-style statistical analysis.
spacy-nltk
Natural Language Processing for text analysis, corpus linguistics, and production NLP pipelines. spaCy provides fast production-grade tokenization, POS tagging, NER, dependency parsing, and custom model training. NLTK provides classical corpus linguistics, linguistic analysis, VADER sentiment, collocation analysis, and access to standard linguistic corpora. Use when: processing and analyzing text data, extracting named entities (people, orgs, locations, dates), dependency parsing and syntactic analysis, building text classification pipelines, performing corpus-level linguistic analysis (frequency, collocations, readability), sentiment analysis, lemmatization and stemming, working with multilingual text, training custom NER or text classifiers, or any task requiring structured understanding of natural language beyond simple string operations.
sktime-tsfresh
Time series machine learning layer (Tier 1): integration of **sktime** and **tsfresh** for building production-grade pipelines that transform raw time series into tabular feature representations suitable for classical machine-learning models. *sktime* provides a unified, sklearn-compatible interface for time-series data types, transformations, and pipelines, while *tsfresh* enables large-scale automated extraction of statistical, spectral, and autocorrelation features, with optional statistically grounded feature relevance selection (FRESH).
sklearn-explainability
Advanced sub-skill for scikit-learn focused on model interpretability, feature importance, and diagnostic tools. Covers global and local explanations using built-in inspection tools and SHAP/LIME integrations.
sklearn-advanced
Professional sub-skill for scikit-learn focused on robust pipeline architecture, custom estimator development, advanced feature engineering, and rigorous model validation. Covers Target Encoding, Nested Cross-Validation, and Production Deployment.