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

Commit 294905c

Browse files
committed
Adding carbon source analysis
1 parent 549aaa3 commit 294905c

8 files changed

+296352
-1
lines changed
+121
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
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+
"python version 3.7.6\n",
13+
"cobrakbase 0.2.8\n",
14+
"Required modules loaded\n"
15+
]
16+
}
17+
],
18+
"source": [
19+
"import platform\n",
20+
"print(\"python version \" + platform.python_version())\n",
21+
"import sys\n",
22+
"import json\n",
23+
"import cobra\n",
24+
"import cplex\n",
25+
"import re\n",
26+
"import os\n",
27+
"from os.path import exists\n",
28+
"import logging\n",
29+
"from configparser import ConfigParser\n",
30+
"config = ConfigParser()\n",
31+
"config.read(\"config.cfg\")\n",
32+
"paths = config.get(\"script\", \"syspaths\").split(\";\")\n",
33+
"for path in paths:\n",
34+
" sys.path.append(path)\n",
35+
"import cobrakbase\n",
36+
"import cobra\n",
37+
"from escher import Builder\n",
38+
"from optlang.symbolics import Zero, add\n",
39+
"from modelseedpy import MSPackageManager, MSGapfill, FBAHelper, MSGrowthPhenotypes, MSModelUtil, MSATPCorrection\n",
40+
"from cobrakbase.core.kbasefba.newmodeltemplate_builder import NewModelTemplateBuilder\n",
41+
"from annotation_ontology_api.annotation_ontology_apiServiceClient import annotation_ontology_api\n",
42+
"from modelseedpy.helpers import get_template\n",
43+
"from sklearn.metrics import r2_score\n",
44+
"%matplotlib inline\n",
45+
"import matplotlib.pyplot as plt\n",
46+
"import pandas as pd\n",
47+
"from IPython.display import HTML\n",
48+
"print(\"Required modules loaded\")"
49+
]
50+
},
51+
{
52+
"cell_type": "code",
53+
"execution_count": 6,
54+
"metadata": {},
55+
"outputs": [],
56+
"source": [
57+
"#First we pull all the Biolog datasets out of Kbase\n",
58+
"#kbase_api = cobrakbase.KBaseAPI()\n",
59+
"biologs = kbase_api.list_objects(101536, object_type=\"KBasePhenotypes.PhenotypeSet\", include_metadata=True)\n",
60+
"genome_biologs = {}\n",
61+
"for item in biologs:\n",
62+
" if \"GenomeID\" in item[10]:\n",
63+
" kbpheno = kbase_api.get_object(item[1], 101536)\n",
64+
" genome_biologs[item[10][\"GenomeID\"]] = MSGrowthPhenotypes.from_kbase_object(kbpheno,kbase_api)\n",
65+
"#Now we iterate over the biolog datasets, pull the model, and simulate the phenotypes\n",
66+
"template = kbase_api.get_from_ws(\"GramNegModelTemplateV3\",\"NewKBaseModelTemplates\")\n",
67+
"pheno_frequency = {}\n",
68+
"pheno_reactions = {}\n",
69+
"for genome in genome_biologs:\n",
70+
" if exists(\"GFModels/RAST/\"+genome+\".json\"):\n",
71+
" model = cobra.io.load_json_model(\"GFModels/RAST/\"+genome+\".json\")\n",
72+
" for pheno in genome_biologs[genome].phenotypes:\n",
73+
" if pheno.id not in pheno_frequency:\n",
74+
" pheno_frequency[pheno.id] = 0\n",
75+
" pheno_reactions[pheno.id] = {}\n",
76+
" pheno_frequency[pheno.id] += 1\n",
77+
" if pheno.growth > 0:\n",
78+
" output = pheno.simulate(model,add_missing_exchanges=True,save_fluxes=True,pfba=True)\n",
79+
" if output[\"growth\"] < 0.00001:\n",
80+
" pheno.gapfill_model_for_phenotype(model,[template],None,add_missing_exchanges=True)\n",
81+
" output = pheno.simulate(model,add_missing_exchanges=True,save_fluxes=True,pfba=True)\n",
82+
" if output[\"growth\"] > 0.01:\n",
83+
" for rxn, value in output[\"fluxes\"].items():\n",
84+
" if abs(value) > 0:\n",
85+
" if rxn not in pheno_reactions[pheno.id]:\n",
86+
" pheno_reactions[pheno.id][rxn] = 0\n",
87+
" pheno_reactions[pheno.id][rxn] += 1\n",
88+
" df = pd.DataFrame(pheno_reactions)\n",
89+
" df.to_csv(\"BiologFeatureAnalysis.csv\")"
90+
]
91+
},
92+
{
93+
"cell_type": "code",
94+
"execution_count": null,
95+
"metadata": {},
96+
"outputs": [],
97+
"source": []
98+
}
99+
],
100+
"metadata": {
101+
"kernelspec": {
102+
"display_name": "Python 3",
103+
"language": "python",
104+
"name": "python3"
105+
},
106+
"language_info": {
107+
"codemirror_mode": {
108+
"name": "ipython",
109+
"version": 3
110+
},
111+
"file_extension": ".py",
112+
"mimetype": "text/x-python",
113+
"name": "python",
114+
"nbconvert_exporter": "python",
115+
"pygments_lexer": "ipython3",
116+
"version": "3.7.6"
117+
}
118+
},
119+
"nbformat": 4,
120+
"nbformat_minor": 4
121+
}

0 commit comments

Comments
 (0)