|
6121 | 6121 | "G.plot(custom_edge_attr=cn.pl.flow_style(P), layout=\"fdp\")" |
6122 | 6122 | ] |
6123 | 6123 | }, |
| 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 | + }, |
6124 | 6204 | { |
6125 | 6205 | "cell_type": "markdown", |
6126 | 6206 | "id": "3f320215-867e-4882-bd9d-5dc94f629054", |
|
0 commit comments