|
| 1 | +{ |
| 2 | + "cells": [ |
| 3 | + { |
| 4 | + "cell_type": "code", |
| 5 | + "execution_count": 1, |
| 6 | + "metadata": {}, |
| 7 | + "outputs": [ |
| 8 | + { |
| 9 | + "name": "stdout", |
| 10 | + "output_type": "stream", |
| 11 | + "text": [ |
| 12 | + "cobrakbase 0.2.7\n" |
| 13 | + ] |
| 14 | + } |
| 15 | + ], |
| 16 | + "source": [ |
| 17 | + "import cobra\n", |
| 18 | + "from cobra import Model, Reaction, Metabolite\n", |
| 19 | + "import pandas as pd\n", |
| 20 | + "import cplex\n", |
| 21 | + "import optlang\n", |
| 22 | + "import math\n", |
| 23 | + "import json\n", |
| 24 | + "import sys\n", |
| 25 | + "import cProfile\n", |
| 26 | + "from optlang.symbolics import Zero, add\n", |
| 27 | + "import cobra.util.solver as sutil\n", |
| 28 | + "from cobra.flux_analysis.parsimonious import pfba\n", |
| 29 | + "from IPython.core.display import HTML\n", |
| 30 | + "import cobrakbase\n", |
| 31 | + "sys.path.append(\"/Users/chenry/code/ModelSEEDpy\")\n", |
| 32 | + "#import modelseedpy.fbapkg\n", |
| 33 | + "from modelseedpy import ElementUptakePkg, SimpleThermoPkg, ReactionUsePkg, BilevelPkg, CommKineticPkg,KBaseMediaPkg\n" |
| 34 | + ] |
| 35 | + }, |
| 36 | + { |
| 37 | + "cell_type": "code", |
| 38 | + "execution_count": 3, |
| 39 | + "metadata": {}, |
| 40 | + "outputs": [ |
| 41 | + { |
| 42 | + "name": "stderr", |
| 43 | + "output_type": "stream", |
| 44 | + "text": [ |
| 45 | + "/Users/chenry/opt/anaconda3/lib/python3.7/site-packages/cobra/core/metabolite.py:86 \u001b[1;31mUserWarning\u001b[0m: invalid character '*' found in formula '*'\n", |
| 46 | + "/Users/chenry/opt/anaconda3/lib/python3.7/site-packages/cobra/core/metabolite.py:86 \u001b[1;31mUserWarning\u001b[0m: invalid character '*' found in formula 'C12H20O10*2'\n" |
| 47 | + ] |
| 48 | + }, |
| 49 | + { |
| 50 | + "name": "stdout", |
| 51 | + "output_type": "stream", |
| 52 | + "text": [ |
| 53 | + "Warning:Community biomass reaction is being altered with input abundances\n" |
| 54 | + ] |
| 55 | + }, |
| 56 | + { |
| 57 | + "data": { |
| 58 | + "text/html": [ |
| 59 | + "<div>\n", |
| 60 | + "<style scoped>\n", |
| 61 | + " .dataframe tbody tr th:only-of-type {\n", |
| 62 | + " vertical-align: middle;\n", |
| 63 | + " }\n", |
| 64 | + "\n", |
| 65 | + " .dataframe tbody tr th {\n", |
| 66 | + " vertical-align: top;\n", |
| 67 | + " }\n", |
| 68 | + "\n", |
| 69 | + " .dataframe thead tr th {\n", |
| 70 | + " text-align: left;\n", |
| 71 | + " }\n", |
| 72 | + "</style>\n", |
| 73 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 74 | + " <thead>\n", |
| 75 | + " <tr>\n", |
| 76 | + " <th></th>\n", |
| 77 | + " <th colspan=\"2\" halign=\"left\">IN_FLUXES</th>\n", |
| 78 | + " <th colspan=\"2\" halign=\"left\">OUT_FLUXES</th>\n", |
| 79 | + " <th colspan=\"2\" halign=\"left\">OBJECTIVES</th>\n", |
| 80 | + " </tr>\n", |
| 81 | + " <tr>\n", |
| 82 | + " <th></th>\n", |
| 83 | + " <th>ID</th>\n", |
| 84 | + " <th>FLUX</th>\n", |
| 85 | + " <th>ID</th>\n", |
| 86 | + " <th>FLUX</th>\n", |
| 87 | + " <th>ID</th>\n", |
| 88 | + " <th>FLUX</th>\n", |
| 89 | + " </tr>\n", |
| 90 | + " </thead>\n", |
| 91 | + " <tbody>\n", |
| 92 | + " <tr>\n", |
| 93 | + " <th>0</th>\n", |
| 94 | + " <td>cpd00027_e0</td>\n", |
| 95 | + " <td>5.000000</td>\n", |
| 96 | + " <td>cpd00067_e0</td>\n", |
| 97 | + " <td>8.376452</td>\n", |
| 98 | + " <td>bio1</td>\n", |
| 99 | + " <td>0.173746</td>\n", |
| 100 | + " </tr>\n", |
| 101 | + " <tr>\n", |
| 102 | + " <th>1</th>\n", |
| 103 | + " <td>cpd00013_e0</td>\n", |
| 104 | + " <td>1.933296</td>\n", |
| 105 | + " <td>cpd00001_e0</td>\n", |
| 106 | + " <td>5.178658</td>\n", |
| 107 | + " <td>NaN</td>\n", |
| 108 | + " <td>NaN</td>\n", |
| 109 | + " </tr>\n", |
| 110 | + " <tr>\n", |
| 111 | + " <th>2</th>\n", |
| 112 | + " <td>cpd00009_e0</td>\n", |
| 113 | + " <td>0.237450</td>\n", |
| 114 | + " <td>cpd00011_e0</td>\n", |
| 115 | + " <td>4.568499</td>\n", |
| 116 | + " <td>NaN</td>\n", |
| 117 | + " <td>NaN</td>\n", |
| 118 | + " </tr>\n", |
| 119 | + " <tr>\n", |
| 120 | + " <th>3</th>\n", |
| 121 | + " <td>NaN</td>\n", |
| 122 | + " <td>NaN</td>\n", |
| 123 | + " <td>cpd11640_e0</td>\n", |
| 124 | + " <td>4.389674</td>\n", |
| 125 | + " <td>NaN</td>\n", |
| 126 | + " <td>NaN</td>\n", |
| 127 | + " </tr>\n", |
| 128 | + " <tr>\n", |
| 129 | + " <th>4</th>\n", |
| 130 | + " <td>NaN</td>\n", |
| 131 | + " <td>NaN</td>\n", |
| 132 | + " <td>cpd00029_e0</td>\n", |
| 133 | + " <td>3.432926</td>\n", |
| 134 | + " <td>NaN</td>\n", |
| 135 | + " <td>NaN</td>\n", |
| 136 | + " </tr>\n", |
| 137 | + " <tr>\n", |
| 138 | + " <th>5</th>\n", |
| 139 | + " <td>NaN</td>\n", |
| 140 | + " <td>NaN</td>\n", |
| 141 | + " <td>cpd00141_e0</td>\n", |
| 142 | + " <td>3.128477</td>\n", |
| 143 | + " <td>NaN</td>\n", |
| 144 | + " <td>NaN</td>\n", |
| 145 | + " </tr>\n", |
| 146 | + " <tr>\n", |
| 147 | + " <th>6</th>\n", |
| 148 | + " <td>NaN</td>\n", |
| 149 | + " <td>NaN</td>\n", |
| 150 | + " <td>cpd11416_c0</td>\n", |
| 151 | + " <td>0.173746</td>\n", |
| 152 | + " <td>NaN</td>\n", |
| 153 | + " <td>NaN</td>\n", |
| 154 | + " </tr>\n", |
| 155 | + " </tbody>\n", |
| 156 | + "</table>\n", |
| 157 | + "</div>" |
| 158 | + ], |
| 159 | + "text/plain": [ |
| 160 | + "<cobra.core.summary.model_summary.ModelSummary at 0x7fe590741a50>" |
| 161 | + ] |
| 162 | + }, |
| 163 | + "execution_count": 3, |
| 164 | + "metadata": {}, |
| 165 | + "output_type": "execute_result" |
| 166 | + } |
| 167 | + ], |
| 168 | + "source": [ |
| 169 | + "kbase_api = cobrakbase.KBaseAPI()\n", |
| 170 | + "model = kbase_api.get_from_ws(\"CMM_iAH991V2_iML1515.kb\",40576)\n", |
| 171 | + "model.solver = 'optlang-cplex'\n", |
| 172 | + "\n", |
| 173 | + "#Applying uptake limit to total carbon uptake by model\n", |
| 174 | + "eup = ElementUptakePkg(model)\n", |
| 175 | + "eup.build_package({\"C\":60})\n", |
| 176 | + "#Applying constraints based on KBase media\n", |
| 177 | + "media = kbase_api.get_from_ws(\"Btheta_Ecoli_minimal_media\",40576)\n", |
| 178 | + "kmp = KBaseMediaPkg(model)\n", |
| 179 | + "kmp.build_package(media)\n", |
| 180 | + "#Applying community model kinetic constraints\n", |
| 181 | + "ckp = CommKineticPkg(model)\n", |
| 182 | + "ckp.build_package(2100,{\"1\":0.5,\"2\":0.5})\n", |
| 183 | + "\n", |
| 184 | + "biomass_objective = model.problem.Objective(\n", |
| 185 | + " 1 * model.reactions.bio1.flux_expression,\n", |
| 186 | + " direction='max')\n", |
| 187 | + "model.objective = biomass_objective\n", |
| 188 | + "\n", |
| 189 | + "sol=model.optimize()\n", |
| 190 | + "model.summary()" |
| 191 | + ] |
| 192 | + }, |
| 193 | + { |
| 194 | + "cell_type": "code", |
| 195 | + "execution_count": null, |
| 196 | + "metadata": {}, |
| 197 | + "outputs": [], |
| 198 | + "source": [] |
| 199 | + } |
| 200 | + ], |
| 201 | + "metadata": { |
| 202 | + "kernelspec": { |
| 203 | + "display_name": "Python 3", |
| 204 | + "language": "python", |
| 205 | + "name": "python3" |
| 206 | + }, |
| 207 | + "language_info": { |
| 208 | + "codemirror_mode": { |
| 209 | + "name": "ipython", |
| 210 | + "version": 3 |
| 211 | + }, |
| 212 | + "file_extension": ".py", |
| 213 | + "mimetype": "text/x-python", |
| 214 | + "name": "python", |
| 215 | + "nbconvert_exporter": "python", |
| 216 | + "pygments_lexer": "ipython3", |
| 217 | + "version": "3.7.6" |
| 218 | + } |
| 219 | + }, |
| 220 | + "nbformat": 4, |
| 221 | + "nbformat_minor": 4 |
| 222 | +} |
0 commit comments