|
| 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": 2, |
| 39 | + "metadata": {}, |
| 40 | + "outputs": [ |
| 41 | + { |
| 42 | + "name": "stdout", |
| 43 | + "output_type": "stream", |
| 44 | + "text": [ |
| 45 | + "Warning:Community biomass reaction is being altered with input abundances\n" |
| 46 | + ] |
| 47 | + }, |
| 48 | + { |
| 49 | + "data": { |
| 50 | + "text/html": [ |
| 51 | + "<div>\n", |
| 52 | + "<style scoped>\n", |
| 53 | + " .dataframe tbody tr th:only-of-type {\n", |
| 54 | + " vertical-align: middle;\n", |
| 55 | + " }\n", |
| 56 | + "\n", |
| 57 | + " .dataframe tbody tr th {\n", |
| 58 | + " vertical-align: top;\n", |
| 59 | + " }\n", |
| 60 | + "\n", |
| 61 | + " .dataframe thead tr th {\n", |
| 62 | + " text-align: left;\n", |
| 63 | + " }\n", |
| 64 | + "</style>\n", |
| 65 | + "<table border=\"1\" class=\"dataframe\">\n", |
| 66 | + " <thead>\n", |
| 67 | + " <tr>\n", |
| 68 | + " <th></th>\n", |
| 69 | + " <th colspan=\"2\" halign=\"left\">IN_FLUXES</th>\n", |
| 70 | + " <th colspan=\"2\" halign=\"left\">OUT_FLUXES</th>\n", |
| 71 | + " <th colspan=\"2\" halign=\"left\">OBJECTIVES</th>\n", |
| 72 | + " </tr>\n", |
| 73 | + " <tr>\n", |
| 74 | + " <th></th>\n", |
| 75 | + " <th>ID</th>\n", |
| 76 | + " <th>FLUX</th>\n", |
| 77 | + " <th>ID</th>\n", |
| 78 | + " <th>FLUX</th>\n", |
| 79 | + " <th>ID</th>\n", |
| 80 | + " <th>FLUX</th>\n", |
| 81 | + " </tr>\n", |
| 82 | + " </thead>\n", |
| 83 | + " <tbody>\n", |
| 84 | + " <tr>\n", |
| 85 | + " <th>0</th>\n", |
| 86 | + " <td>cpd00067_e0</td>\n", |
| 87 | + " <td>100.000000</td>\n", |
| 88 | + " <td>cpd00001_e0</td>\n", |
| 89 | + " <td>100.000000</td>\n", |
| 90 | + " <td>bio1</td>\n", |
| 91 | + " <td>3.653218</td>\n", |
| 92 | + " </tr>\n", |
| 93 | + " <tr>\n", |
| 94 | + " <th>1</th>\n", |
| 95 | + " <td>cpd00209_e0</td>\n", |
| 96 | + " <td>100.000000</td>\n", |
| 97 | + " <td>cpd00075_e0</td>\n", |
| 98 | + " <td>100.000000</td>\n", |
| 99 | + " <td>NaN</td>\n", |
| 100 | + " <td>NaN</td>\n", |
| 101 | + " </tr>\n", |
| 102 | + " <tr>\n", |
| 103 | + " <th>2</th>\n", |
| 104 | + " <td>cpd00033_e0</td>\n", |
| 105 | + " <td>11.465399</td>\n", |
| 106 | + " <td>cpd00009_e0</td>\n", |
| 107 | + " <td>79.464829</td>\n", |
| 108 | + " <td>NaN</td>\n", |
| 109 | + " <td>NaN</td>\n", |
| 110 | + " </tr>\n", |
| 111 | + " <tr>\n", |
| 112 | + " <th>3</th>\n", |
| 113 | + " <td>cpd00013_e0</td>\n", |
| 114 | + " <td>10.839234</td>\n", |
| 115 | + " <td>cpd00047_e0</td>\n", |
| 116 | + " <td>78.981183</td>\n", |
| 117 | + " <td>NaN</td>\n", |
| 118 | + " <td>NaN</td>\n", |
| 119 | + " </tr>\n", |
| 120 | + " <tr>\n", |
| 121 | + " <th>4</th>\n", |
| 122 | + " <td>cpd00107_e0</td>\n", |
| 123 | + " <td>1.371377</td>\n", |
| 124 | + " <td>cpd11416_c0</td>\n", |
| 125 | + " <td>3.653218</td>\n", |
| 126 | + " <td>NaN</td>\n", |
| 127 | + " <td>NaN</td>\n", |
| 128 | + " </tr>\n", |
| 129 | + " </tbody>\n", |
| 130 | + "</table>\n", |
| 131 | + "</div>" |
| 132 | + ], |
| 133 | + "text/plain": [ |
| 134 | + "<cobra.core.summary.model_summary.ModelSummary at 0x7fdc6e499c90>" |
| 135 | + ] |
| 136 | + }, |
| 137 | + "execution_count": 2, |
| 138 | + "metadata": {}, |
| 139 | + "output_type": "execute_result" |
| 140 | + } |
| 141 | + ], |
| 142 | + "source": [ |
| 143 | + "kbase_api = cobrakbase.KBaseAPI()\n", |
| 144 | + "model = kbase_api.get_from_ws(\"Cjaponicus_Ecoli_Community\",92637)\n", |
| 145 | + "model.solver = 'optlang-cplex'\n", |
| 146 | + "\n", |
| 147 | + "#Applying uptake limit to total carbon uptake by model\n", |
| 148 | + "eup = ElementUptakePkg(model)\n", |
| 149 | + "eup.build_package({\"C\":60})\n", |
| 150 | + "#Applying constraints based on KBase media\n", |
| 151 | + "media = kbase_api.get_from_ws(\"GlucoseM9Media\",91858)\n", |
| 152 | + "kmp = KBaseMediaPkg(model)\n", |
| 153 | + "kmp.build_package(None)\n", |
| 154 | + "#Applying community model kinetic constraints\n", |
| 155 | + "ckp = CommKineticPkg(model)\n", |
| 156 | + "ckp.build_package(2100,{\"1\":0.9,\"2\":0.1})\n", |
| 157 | + "\n", |
| 158 | + "biomass_objective = model.problem.Objective(\n", |
| 159 | + " 1 * model.reactions.bio1.flux_expression,\n", |
| 160 | + " direction='max')\n", |
| 161 | + "model.objective = biomass_objective\n", |
| 162 | + "\n", |
| 163 | + "with open('/Users/chenry/code/ChrisJupyter/CommunityModeling/data/CommunityFBA.lp', 'w') as out:\n", |
| 164 | + " out.write(str(model.solver))\n", |
| 165 | + " \n", |
| 166 | + "sol=model.optimize()\n", |
| 167 | + "model.summary()" |
| 168 | + ] |
| 169 | + }, |
| 170 | + { |
| 171 | + "cell_type": "code", |
| 172 | + "execution_count": null, |
| 173 | + "metadata": {}, |
| 174 | + "outputs": [], |
| 175 | + "source": [] |
| 176 | + } |
| 177 | + ], |
| 178 | + "metadata": { |
| 179 | + "kernelspec": { |
| 180 | + "display_name": "Python 3", |
| 181 | + "language": "python", |
| 182 | + "name": "python3" |
| 183 | + }, |
| 184 | + "language_info": { |
| 185 | + "codemirror_mode": { |
| 186 | + "name": "ipython", |
| 187 | + "version": 3 |
| 188 | + }, |
| 189 | + "file_extension": ".py", |
| 190 | + "mimetype": "text/x-python", |
| 191 | + "name": "python", |
| 192 | + "nbconvert_exporter": "python", |
| 193 | + "pygments_lexer": "ipython3", |
| 194 | + "version": "3.7.6" |
| 195 | + } |
| 196 | + }, |
| 197 | + "nbformat": 4, |
| 198 | + "nbformat_minor": 4 |
| 199 | +} |
0 commit comments