bio-systems-biology-flux-balance-analysis
Perform flux balance analysis (FBA) and flux variability analysis (FVA) on genome-scale metabolic models using COBRApy. Predict growth rates, metabolic fluxes, and optimal resource utilization. Use when predicting metabolic phenotypes or optimizing flux distributions.
What this skill does
## Version Compatibility
Reference examples tested with: COBRApy 0.29+
Before using code patterns, verify installed versions match. If versions differ:
- Python: `pip show <package>` then `help(module.function)` to check signatures
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
# Flux Balance Analysis
**"Predict growth rate and metabolic fluxes for my organism"** -> Solve a linear program over a genome-scale metabolic model to find the optimal flux distribution that maximizes biomass (or a custom objective), and assess flux ranges with FVA.
- Python: `model.optimize()`, `cobra.flux_analysis.flux_variability_analysis()` (COBRApy)
## Load Models
```python
import cobra
# Load built-in test models
model = cobra.io.load_model('textbook') # E. coli core (95 reactions)
model = cobra.io.load_model('iJO1366') # Full E. coli (2583 reactions)
# Load from file
model = cobra.io.read_sbml_model('model.xml')
model = cobra.io.load_json_model('model.json')
# BiGG models available at: http://bigg.ucsd.edu/models
```
## Basic FBA
**Goal:** Predict optimal metabolic flux distributions and growth rates for an organism under defined conditions.
**Approach:** Load a genome-scale metabolic model, solve the linear program to maximize the biomass objective function, then inspect flux values and solver status to interpret metabolic phenotype.
```python
import cobra
model = cobra.io.load_model('textbook')
# Run FBA (maximizes objective function, usually biomass)
solution = model.optimize()
# Growth rate interpretation:
# >0.8 h^-1: Fast growth (rich media)
# 0.3-0.8 h^-1: Moderate growth
# <0.3 h^-1: Slow growth or stress
# 0: No growth (lethal condition or missing nutrients)
print(f'Growth rate: {solution.objective_value:.4f} h^-1')
print(f'Status: {solution.status}')
# Access flux values
for rxn in model.reactions[:5]:
print(f'{rxn.id}: {solution.fluxes[rxn.id]:.4f}')
```
## Set Media Conditions
```python
def set_minimal_media(model, carbon_source='EX_glc__D_e', carbon_uptake=10):
'''Configure minimal media conditions
Args:
carbon_source: Exchange reaction ID for carbon source
carbon_uptake: Maximum uptake rate (mmol/gDW/h)
Typical glucose uptake: 10-20 mmol/gDW/h
'''
# Close all exchange reactions
for rxn in model.exchanges:
rxn.lower_bound = 0 # No uptake
# Open essential exchanges
essential = ['EX_o2_e', 'EX_h2o_e', 'EX_h_e', 'EX_nh4_e',
'EX_pi_e', 'EX_so4_e', 'EX_k_e', 'EX_mg2_e']
for ex_id in essential:
if ex_id in model.reactions:
model.reactions.get_by_id(ex_id).lower_bound = -1000
# Set carbon source
if carbon_source in model.reactions:
model.reactions.get_by_id(carbon_source).lower_bound = -carbon_uptake
return model
# Example: Compare growth on different carbon sources
carbon_sources = ['EX_glc__D_e', 'EX_ac_e', 'EX_succ_e']
for cs in carbon_sources:
with model:
set_minimal_media(model, carbon_source=cs)
sol = model.optimize()
print(f'{cs}: Growth = {sol.objective_value:.4f}')
```
## Flux Variability Analysis (FVA)
```python
from cobra.flux_analysis import flux_variability_analysis
# FVA finds the range of flux values for each reaction
# while maintaining optimal (or near-optimal) growth
# Standard FVA (at 100% optimum)
fva = flux_variability_analysis(model)
# FVA at 90% of optimal growth
# fraction_of_optimum=0.9: allows 10% suboptimal solutions
# This reveals alternative optimal flux distributions
fva = flux_variability_analysis(model, fraction_of_optimum=0.9)
# FVA for specific reactions
rxns_of_interest = ['PFK', 'PGI', 'GAPD']
fva = flux_variability_analysis(model, reaction_list=rxns_of_interest)
# Identify essential vs flexible reactions
fva['essential'] = (fva['minimum'] > 0) | (fva['maximum'] < 0)
fva['flexible'] = fva['maximum'] - fva['minimum'] > 0.01
print(fva[['minimum', 'maximum', 'essential', 'flexible']])
```
## Production Envelope
```python
from cobra.flux_analysis import production_envelope
# Analyze tradeoff between growth and product secretion
# Useful for metabolic engineering to find optimal conditions
prod_env = production_envelope(
model,
reactions=['EX_ac_e'], # Product (acetate)
objective='Biomass_Ecoli_core',
points=20
)
# prod_env is a DataFrame with:
# - EX_ac_e: acetate production rate
# - Biomass_Ecoli_core: growth rate at that production level
print(prod_env)
```
## Phenotype Phase Plane
```python
from cobra.flux_analysis import phenotype_phase_plane
# Analyze growth across two varying conditions
# Typically oxygen and carbon uptake
ppp = phenotype_phase_plane(
model,
variables=['EX_glc__D_e', 'EX_o2_e'], # X and Y axes
points=10
)
# Returns growth rate as function of both uptake rates
# Useful for identifying metabolic modes (aerobic vs anaerobic)
```
## Parsimonious FBA (pFBA)
```python
from cobra.flux_analysis import pfba
# pFBA minimizes total flux while achieving optimal growth
# Produces more biologically realistic flux distributions
pfba_solution = pfba(model)
# Compare total flux
fba_total = sum(abs(model.optimize().fluxes))
pfba_total = sum(abs(pfba_solution.fluxes))
print(f'FBA total flux: {fba_total:.1f}')
print(f'pFBA total flux: {pfba_total:.1f}')
```
## Loopless FBA
```python
from cobra.flux_analysis import loopless_solution
# Remove thermodynamically infeasible loops
# Important for realistic flux predictions
solution = loopless_solution(model)
```
## Related Skills
- systems-biology/gene-essentiality - In silico gene knockouts
- systems-biology/context-specific-models - Tissue-specific FBA
- metabolomics/pathway-mapping - Integrate metabolomics data
Related in Ads & Marketing
ads
IncludedMulti-platform paid advertising audit and optimization skill. Analyzes Google, Meta, YouTube, LinkedIn, TikTok, Microsoft, and Apple Ads. 250+ checks with scoring, parallel agents, industry templates, and AI creative generation.
banana
IncludedAI image generation Creative Director powered by Google Gemini Nano Banana models. Use this skill for ANY request involving image creation, editing, visual asset production, or creative direction. Triggers on: generate an image, create a photo, edit this picture, design a logo, make a banner, visual for my anything, and all /banana commands. Handles text-to-image, image editing, multi-turn creative sessions, batch workflows, and brand presets.
rpg-migration-analyzer
IncludedAnalyzes legacy RPG (Report Program Generator) programs from AS/400 and IBM i systems for migration to modern Java applications. Extracts business logic from RPG III/IV/ILE source code, identifies data structures (D-specs), file operations (F-specs), program dependencies (CALLB/CALLP), and converts RPG constructs to Java equivalents. Generates migration reports, complexity estimates, and Java implementation strategies with POJO classes, JPA entities, and service methods. Use when modernizing AS/400 or IBM i legacy systems, analyzing RPG source files (.rpg, .rpgle, .RPGLE), converting RPG to Java, mapping data specifications to Java classes, planning legacy system migration, or when user mentions RPG analysis, Report Program Generator, RPG III/IV/ILE, AS/400 modernization, IBM i migration, packed decimal conversion, or mainframe application rewrite.
brand-library-architect
IncludedBuild a complete brand library for a product — visual asset render pipeline, brand documentation set (BRAND, COPY, MANIFESTO, BIOS, FAQ, GLOSSARY, TONE, PRICING), open-source convention files (README, CONTRIBUTING, SECURITY, CODE_OF_CONDUCT), and a self-contained press kit. This skill should be used when the user asks to "build a brand library / brand kit / press kit / brand assets" for a product, "set up a brand library workflow," "create a positioning manifesto plus visual identity," or any combination of brand documentation + visual asset pipeline. Apply phase-by-phase or run end-to-end. Templates are product-agnostic and use {{TOKEN}} placeholders the skill prompts the user to fill.
writing-tech-post
IncludedAuthors engineering blog posts end-to-end: launch deep-dives, incident postmortems, architecture migrations, performance case studies, tutorials, AI/agent system writeups, security disclosures, and research-to-product translations. Picks the correct archetype, plans the abstraction ladder, enforces an evidence cadence (diagrams, benchmarks, profiles, traces, code, ablations), tunes voice against publisher house styles (Datadog, Vercel, GitHub, AWS, Meta, Cloudflare, Jane Street), and runs a pre-publish gate for narrative momentum and disclosure ethics. Use when drafting a new engineering post, restructuring a draft that feels flat, deciding which evidence form belongs where, validating that depth and product context are balanced, or preparing a postmortem, migration, or performance narrative for external publication. Do not use for API reference documentation, README authoring, marketing copy, release notes, generic SEO content, ghost-written executive thought leadership, or non-engineering long-form essays.
blog-google
IncludedGoogle API integration for blog performance: PageSpeed Insights, CrUX Core Web Vitals with 25-week history, Search Console performance, URL Inspection, Indexing API, GA4 organic traffic, NLP entity analysis for E-E-A-T, YouTube video search for embedding, and Google Ads Keyword Planner. Progressive feature availability based on credential tier (API key, OAuth/service account, GA4, Ads). Shares config with claude-seo at ~/.config/claude-seo/google-api.json. Use when user says "google data", "page speed", "core web vitals", "search console", "indexation", "GA4", "keyword research", "nlp entities", "blog performance", "youtube search", "google api setup".