Skip to content

Commit 43c55df

Browse files
committed
docs: show example of passing media composition in FBA
1 parent 91e5f6f commit 43c55df

3 files changed

Lines changed: 84 additions & 2 deletions

File tree

.gitignore

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@ my_graph.pkl.gz
66
tests/_notebooks/
77
.asv/results/
88
CLAUDE.md
9+
benchmarks/
10+
resources/
911

1012

1113
########################

.pre-commit-config.yaml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ repos:
2020
- id: pre-commit-update
2121

2222
- repo: https://github.com/astral-sh/ruff-pre-commit
23-
rev: v0.15.4
23+
rev: v0.15.13
2424
hooks:
2525
- id: ruff
2626
args:
@@ -50,7 +50,7 @@ repos:
5050
stages: [commit-msg]
5151

5252
- repo: https://github.com/python-poetry/poetry
53-
rev: 2.3.2
53+
rev: 2.4.1
5454
hooks:
5555
- id: poetry-check
5656
- id: poetry-lock

docs/guide/metabolism/flux-balance-analysis.ipynb

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6121,6 +6121,86 @@
61216121
"G.plot(custom_edge_attr=cn.pl.flow_style(P), layout=\"fdp\")"
61226122
]
61236123
},
6124+
{
6125+
"cell_type": "markdown",
6126+
"id": "custom-media-01",
6127+
"metadata": {},
6128+
"source": [
6129+
"## Passing a custom media composition\n",
6130+
"\n",
6131+
"Media composition is represented as sample-specific reaction bounds. In CORNETO, each sample passed to `MultiSampleFBA` can include exchange reactions with `lower_bound` and `upper_bound` values. For exchange reactions in this model, uptake is a negative flux, so a more negative lower bound allows more uptake.\n",
6132+
"\n",
6133+
"The same data object can also include the biomass objective, which lets us solve several media conditions in one FBA problem."
6134+
]
6135+
},
6136+
{
6137+
"cell_type": "code",
6138+
"execution_count": null,
6139+
"id": "custom-media-02",
6140+
"metadata": {},
6141+
"outputs": [],
6142+
"source": [
6143+
"media = {\n",
6144+
" \"glucose_rich\": {\n",
6145+
" \"EX_glc__D_e\": {\"lower_bound\": -10.0, \"upper_bound\": 1000.0},\n",
6146+
" \"EX_o2_e\": {\"lower_bound\": -20.0, \"upper_bound\": 1000.0},\n",
6147+
" },\n",
6148+
" \"glucose_limited\": {\n",
6149+
" \"EX_glc__D_e\": {\"lower_bound\": -2.0, \"upper_bound\": 1000.0},\n",
6150+
" \"EX_o2_e\": {\"lower_bound\": -20.0, \"upper_bound\": 1000.0},\n",
6151+
" },\n",
6152+
"}\n",
6153+
"\n",
6154+
"media_data = cn.Data.from_cdict(\n",
6155+
" {\n",
6156+
" condition: {\n",
6157+
" \"Biomass_Ecoli_core\": {\"role\": \"objective\"},\n",
6158+
" **bounds,\n",
6159+
" }\n",
6160+
" for condition, bounds in media.items()\n",
6161+
" }\n",
6162+
")\n",
6163+
"\n",
6164+
"media_data"
6165+
]
6166+
},
6167+
{
6168+
"cell_type": "code",
6169+
"execution_count": null,
6170+
"id": "custom-media-03",
6171+
"metadata": {},
6172+
"outputs": [],
6173+
"source": [
6174+
"media_problem = FBA().build(G, media_data)\n",
6175+
"media_problem.solve(solver=\"scipy\");"
6176+
]
6177+
},
6178+
{
6179+
"cell_type": "code",
6180+
"execution_count": null,
6181+
"id": "custom-media-04",
6182+
"metadata": {},
6183+
"outputs": [],
6184+
"source": [
6185+
"reaction_ids = [\"Biomass_Ecoli_core\", \"EX_glc__D_e\", \"EX_o2_e\"]\n",
6186+
"reaction_index = {rid: next(iter(G.get_edges_by_attr(\"id\", rid))) for rid in reaction_ids}\n",
6187+
"\n",
6188+
"pd.DataFrame(\n",
6189+
" {\n",
6190+
" condition: {rid: media_problem.expr.flow[reaction_index[rid], i].value for rid in reaction_ids}\n",
6191+
" for i, condition in enumerate(media_data.samples)\n",
6192+
" }\n",
6193+
")"
6194+
]
6195+
},
6196+
{
6197+
"cell_type": "markdown",
6198+
"id": "custom-media-05",
6199+
"metadata": {},
6200+
"source": [
6201+
"The custom bounds override the default exchange bounds stored in the graph for the matching sample. Here, glucose-limited medium restricts `EX_glc__D_e` uptake and the optimal biomass flux decreases accordingly."
6202+
]
6203+
},
61246204
{
61256205
"cell_type": "markdown",
61266206
"id": "3f320215-867e-4882-bd9d-5dc94f629054",

0 commit comments

Comments
 (0)