Skip to content
This repository was archived by the owner on Feb 9, 2024. It is now read-only.

Commit e53ae56

Browse files
committed
Initial commit of project notebooks for the team
1 parent ed3f386 commit e53ae56

28 files changed

+736802
-0
lines changed

Diff for: CommunityModeling/AimeeCommunityFBA.ipynb

+199
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,199 @@
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+
}

Diff for: CommunityModeling/AimeeCommunityModel.ipynb

+166
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,166 @@
1+
{
2+
"cells": [
3+
{
4+
"cell_type": "code",
5+
"execution_count": 4,
6+
"metadata": {},
7+
"outputs": [],
8+
"source": [
9+
"# import cobra\n",
10+
"from cobra import Model, Reaction, Metabolite\n",
11+
"import pandas as pd\n",
12+
"import cplex\n",
13+
"import optlang\n",
14+
"import math\n",
15+
"import json\n",
16+
"import sys\n",
17+
"from optlang.symbolics import Zero, add\n",
18+
"import cobra.util.solver as sutil\n",
19+
"from cobra.flux_analysis.parsimonious import pfba\n",
20+
"from IPython.core.display import HTML\n",
21+
"import cobrakbase\n",
22+
"#sys.path.append(\"/Users/chandhanavoleti/Documents/SULI/ModelSEEDpy/ModelSEEDpy\")\n",
23+
"sys.path.append(\"/Users/chenry/code/ModelSEEDpy\")\n",
24+
"#import modelseedpy.fbapkg\n",
25+
"from modelseedpy import MSPackageManager"
26+
]
27+
},
28+
{
29+
"cell_type": "code",
30+
"execution_count": 5,
31+
"metadata": {},
32+
"outputs": [],
33+
"source": [
34+
"kbase_api = cobrakbase.KBaseAPI()\n",
35+
"model = kbase_api.get_from_ws(\"Hot_Lake_seven.mdl\",93544)\n",
36+
"media = kbase_api.get_from_ws(\"HotLakeMedia\",40576)\n",
37+
"pkgmgr = MSPackageManager.get_pkg_mgr(model,1)\n",
38+
"pkgmgr.addpkgs([\"ElementUptakePkg\",\"KBaseMediaPkg\"])\n",
39+
"pkgmgr.getpkg(\"ElementUptakePkg\").build_package({\"C\":60})\n",
40+
"pkgmgr.getpkg(\"KBaseMediaPkg\").build_package(media)"
41+
]
42+
},
43+
{
44+
"cell_type": "code",
45+
"execution_count": 6,
46+
"metadata": {},
47+
"outputs": [
48+
{
49+
"name": "stdout",
50+
"output_type": "stream",
51+
"text": [
52+
"['BilevelPkg', 'CommKineticPkg', 'ElementUptakePkg', 'FlexibleBiomassPkg', 'FluxFittingPkg', 'FullThermoPkg', 'GapfillingPkg', 'KBaseMediaPkg', 'MetaboFBAPkg', 'ProblemReplicationPkg', 'ProteomeFittingPkg', 'ReactionUsePkg', 'RevBinPkg', 'SimpleThermoPkg', 'TotalFluxPkg']\n",
53+
"['ElementUptakePkg', 'KBaseMediaPkg']\n"
54+
]
55+
}
56+
],
57+
"source": [
58+
"print(pkgmgr.list_available_packages())\n",
59+
"print(pkgmgr.list_active_packages())"
60+
]
61+
},
62+
{
63+
"cell_type": "code",
64+
"execution_count": 4,
65+
"metadata": {},
66+
"outputs": [
67+
{
68+
"ename": "AttributeError",
69+
"evalue": "'NoneType' object has no attribute 'solver'",
70+
"output_type": "error",
71+
"traceback": [
72+
"\u001b[0;31m---------------------------------------------------------------------------\u001b[0m",
73+
"\u001b[0;31mAttributeError\u001b[0m Traceback (most recent call last)",
74+
"\u001b[0;32m<ipython-input-4-8fd2053ae1dc>\u001b[0m in \u001b[0;36m<module>\u001b[0;34m\u001b[0m\n\u001b[1;32m 1\u001b[0m \u001b[0mkbase_api\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mcobrakbase\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mKBaseAPI\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 2\u001b[0m \u001b[0mmodel\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0mkbase_api\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0mget_from_ws\u001b[0m\u001b[0;34m(\u001b[0m\u001b[0;34m\"CMM_iAH991V2_iML1515.kb\"\u001b[0m\u001b[0;34m,\u001b[0m\u001b[0;36m91858\u001b[0m\u001b[0;34m)\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0;32m----> 3\u001b[0;31m \u001b[0mmodel\u001b[0m\u001b[0;34m.\u001b[0m\u001b[0msolver\u001b[0m \u001b[0;34m=\u001b[0m \u001b[0;34m'optlang-cplex'\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n\u001b[0m\u001b[1;32m 4\u001b[0m \u001b[0;34m\u001b[0m\u001b[0m\n\u001b[1;32m 5\u001b[0m \u001b[0;31m#Applying uptake limit to total carbon uptake by model\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0;34m\u001b[0m\u001b[0m\n",
75+
"\u001b[0;31mAttributeError\u001b[0m: 'NoneType' object has no attribute 'solver'"
76+
]
77+
}
78+
],
79+
"source": [
80+
"kbase_api = cobrakbase.KBaseAPI()\n",
81+
"model = kbase_api.get_from_ws(\"CMM_iAH991V2_iML1515.kb\",91858)\n",
82+
"model.solver = 'optlang-cplex'\n",
83+
"\n",
84+
"#Applying uptake limit to total carbon uptake by model\n",
85+
"eup = ElementUptakePkg(model)\n",
86+
"eup.build_package({\"C\":60})\n",
87+
"#Applying constraints based on KBase media\n",
88+
"media = kbase_api.get_from_ws(\"Btheta_Ecoli_minimal_media\",40576)"
89+
]
90+
},
91+
{
92+
"cell_type": "code",
93+
"execution_count": null,
94+
"metadata": {},
95+
"outputs": [],
96+
"source": [
97+
"model"
98+
]
99+
},
100+
{
101+
"cell_type": "code",
102+
"execution_count": null,
103+
"metadata": {},
104+
"outputs": [],
105+
"source": [
106+
"model.reactions.EX_cpd00098_e0"
107+
]
108+
},
109+
{
110+
"cell_type": "code",
111+
"execution_count": null,
112+
"metadata": {},
113+
"outputs": [],
114+
"source": []
115+
},
116+
{
117+
"cell_type": "code",
118+
"execution_count": null,
119+
"metadata": {},
120+
"outputs": [],
121+
"source": [
122+
"kmp = KBaseMediaPkg(model)\n",
123+
"kmp.build_package(media)\n",
124+
"#Applying community model kinetic constraints\n",
125+
"ckp = CommKineticPkg(model)\n",
126+
"ckp.build_package(2100,{\"1\":0.5,\"2\":0.5})\n",
127+
"\n",
128+
"biomass_objective = model.problem.Objective(\n",
129+
" 1 * model.reactions.bio1.flux_expression,\n",
130+
" direction='max')\n",
131+
"model.objective = biomass_objective\n",
132+
"\n",
133+
"sol=model.optimize()\n",
134+
"model.summary()"
135+
]
136+
},
137+
{
138+
"cell_type": "code",
139+
"execution_count": null,
140+
"metadata": {},
141+
"outputs": [],
142+
"source": []
143+
}
144+
],
145+
"metadata": {
146+
"kernelspec": {
147+
"display_name": "Python 3",
148+
"language": "python",
149+
"name": "python3"
150+
},
151+
"language_info": {
152+
"codemirror_mode": {
153+
"name": "ipython",
154+
"version": 3
155+
},
156+
"file_extension": ".py",
157+
"mimetype": "text/x-python",
158+
"name": "python",
159+
"nbconvert_exporter": "python",
160+
"pygments_lexer": "ipython3",
161+
"version": "3.7.6"
162+
}
163+
},
164+
"nbformat": 4,
165+
"nbformat_minor": 5
166+
}

0 commit comments

Comments
 (0)