Constraint-based reconstruction and analysis (COBRA) for metabolic models; use when you need to simulate growth/production, analyze flux ranges, or run knockout and medium studies from SBML/JSON/YAML models.
62
75%
Does it follow best practices?
Run evals on this skill
Adds up to 20 points to the overall score
View guide
Passed
No findings from the security scan
Fix and improve this skill with Tessl
tessl review fix ./scientific-skills/Data Analysis/cobrapy/SKILL.mdreferences/ for task-specific guidance.Python: 3.10+. Repository baseline for current packaged skills.Third-party packages: not explicitly version-pinned in this skill package. Add pinned versions if this skill needs stricter environment control.Skill directory: 20260316/scientific-skills/Data Analytics/cobrapy
No packaged executable script was detected.
Use the documented workflow in SKILL.md together with the references/assets in this folder.Example run plan:
SKILL.md.references/ contains supporting rules, prompts, or checklists.Use this skill when you need to perform constraint-based analysis on metabolic networks, especially for:
model.medium; compute minimal media (optionally MILP-based).cobra (COBRApy) — version varies by environment (commonly >=0.20)glpk / swiglpk (often default)cplex (optional)gurobi (optional)pandasmatplotlibThe following script is a complete, runnable example that loads a built-in model, runs FBA, performs FVA, runs a gene knockout, adjusts medium, and samples fluxes.
# cobrapy_example.py
from cobra.io import load_model
from cobra.flux_analysis import flux_variability_analysis, single_gene_deletion, pfba
from cobra.sampling import sample
def main():
# 1) Load a model (built-in test model)
model = load_model("textbook") # E. coli core model
# 2) Run standard FBA
sol = model.optimize()
print("=== FBA ===")
print("Status:", sol.status)
print("Objective (growth):", sol.objective_value)
# 3) Run pFBA (minimize total flux at optimal growth)
pfba_sol = pfba(model)
print("\n=== pFBA ===")
print("Objective (growth):", pfba_sol.objective_value)
# 4) Flux Variability Analysis at 90% of optimum
print("\n=== FVA (90% optimum) ===")
fva = flux_variability_analysis(model, fraction_of_optimum=0.9)
print(fva.head())
# 5) Single gene deletion screen (may take time on large models)
print("\n=== Single Gene Deletion (first 5 rows) ===")
del_res = single_gene_deletion(model)
print(del_res.head())
# 6) Medium modification (must re-assign the full dict)
print("\n=== Medium ===")
medium = model.medium
# Example: limit glucose uptake (exchange IDs depend on the model)
if "EX_glc__D_e" in medium:
medium["EX_glc__D_e"] = 5.0
model.medium = medium
sol2 = model.optimize()
print("Growth after limiting glucose:", sol2.objective_value)
else:
print("Model has no EX_glc__D_e in medium; skipping medium edit.")
# 7) Flux sampling (small n for quick demo)
print("\n=== Flux Sampling ===")
samples = sample(model, n=200, method="optgp")
print(samples.head())
if __name__ == "__main__":
main()Run:
python cobrapy_example.pymodel.optimize() solves the LP and returns a Solution with:
solution.status (e.g., optimal)solution.objective_valuesolution.fluxes (pandas Series of reaction fluxes)lower_bound = 0.lower_bound < 0.reaction.bounds = (lb, ub) to set both consistently.reaction.gene_reaction_rule encodes Boolean logic:
"gene1 and gene2" means both genes required."gene1 or gene2" means either gene sufficient.flux_variability_analysis(model, fraction_of_optimum=x) constrains the objective to be at least x * optimum before computing per-reaction min/max.loopless=True attempts to remove thermodynamically infeasible loops (typically more expensive).with model: creates a reversible sandbox:
sample(..., method="optgp") uses OptGP (often parallelizable); method="achr" uses ACHR.OptGPSampler.validate).model.medium is a dictionary mapping exchange reaction IDs to allowed uptake rates.model.medium = medium.gapfill(model, universal) searches for a minimal set of reactions from universal that restores feasibility (commonly formulated as MILP/optimization with penalties).with model: when testing removals/additions to avoid permanently mutating the model.cobrapy_result.md unless the skill documentation defines a better convention.Run this minimal verification path before full execution when possible:
No local script validation step is required for this skill.Expected output format:
Result file: cobrapy_result.md
Validation summary: PASS/FAIL with brief notes
Assumptions: explicit list if anyf5ef65b
If you maintain this skill, you can claim it as your own. Once claimed, you can manage eval scenarios, bundle related skills, attach documentation or rules, and ensure cross-agent compatibility.