{
"cells": [
{
"cell_type": "markdown",
"id": "23d08689-2917-427c-80ea-79086d06f04b",
"metadata": {},
"source": [
"### Loading Genome, Media, and Model Builder classes"
]
},
{
"cell_type": "code",
"execution_count": 1,
"id": "5eab526c-6d07-4062-9732-6e534c156314",
"metadata": {},
"outputs": [],
"source": [
"from modelseedpy import MSGenome, MSMedia, MSBuilder"
]
},
{
"cell_type": "markdown",
"id": "599d713f-f4c6-4eef-9a7a-80702db32d8d",
"metadata": {},
"source": [
"#### Read faa genome file\n",
"split= defineds header splitter for gene_id and remainder of the header"
]
},
{
"cell_type": "code",
"execution_count": 2,
"id": "8b897ed8-d599-4f64-9a11-bf863fadcee9",
"metadata": {},
"outputs": [],
"source": [
"genome = MSGenome.from_fasta(\n",
" '../Model Reconstruction/GCF_000005845.2_ASM584v2_protein.faa', \n",
" split=' ')"
]
},
{
"cell_type": "code",
"execution_count": 3,
"id": "1b18fe58-697f-4402-86dc-d760a60f3fd7",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Number of features: 4285\n"
]
}
],
"source": [
"print('Number of features:', len(genome.features))"
]
},
{
"cell_type": "markdown",
"id": "234d74f8-d1d2-4b1d-8ee4-d9bf286bb746",
"metadata": {},
"source": [
"#### Define glucose defined medium"
]
},
{
"cell_type": "code",
"execution_count": 4,
"id": "0feb9437-a0ac-4b2c-a8ee-6f563f594046",
"metadata": {},
"outputs": [],
"source": [
"media = MSMedia.from_dict({\n",
" 'cpd00027': 5, # Glucose uptake\n",
" 'cpd00007': 10, # Oxygen uptake\n",
" 'cpd00149': 1000,\n",
" 'cpd00099': 1000,\n",
" 'cpd00067': 1000,\n",
" 'cpd00063': 1000,\n",
" 'cpd00058': 1000,\n",
" 'cpd00048': 1000,\n",
" 'cpd00034': 1000,\n",
" 'cpd00030': 1000,\n",
" 'cpd00013': 1000,\n",
" 'cpd00009': 1000,\n",
" 'cpd00001': 1000,\n",
" 'cpd00205': 1000,\n",
" 'cpd00254': 1000,\n",
" 'cpd00971': 1000,\n",
" 'cpd10515': 1000,\n",
" 'cpd10516': 1000,\n",
" 'cpd00244': 1000,\n",
"})"
]
},
{
"cell_type": "markdown",
"id": "7b3681c7-fed0-4f0c-872a-42646b17a314",
"metadata": {},
"source": [
"#### Build model withe genome and media\n",
"media is optional, if not provided genome is gapfilled with complete medium"
]
},
{
"cell_type": "code",
"execution_count": 5,
"id": "327b646f-bfa9-4da4-bd2c-d5eeec22a8c2",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
"
\n",
" \n",
" | Name | \n",
" SEED_model | \n",
"
\n",
" | Memory address | \n",
" 0x07f75fa6a2910 | \n",
"
\n",
" | Number of metabolites | \n",
" 1460 | \n",
"
\n",
" | Number of reactions | \n",
" 1781 | \n",
"
\n",
" | Number of groups | \n",
" 0 | \n",
"
\n",
" | Objective expression | \n",
" 1.0*bio1 - 1.0*bio1_reverse_b18f7 | \n",
"
\n",
" | Compartments | \n",
" c0, e0 | \n",
"
\n",
"
"
],
"text/plain": [
""
]
},
"execution_count": 5,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model = MSBuilder.build_metabolic_model('SEED_model', genome, media)\n",
"model"
]
},
{
"cell_type": "code",
"execution_count": 16,
"id": "dcdae05f-2685-4d7f-8b6f-ad01e320b45f",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" \n",
" | Metabolite identifier | cpd00020_c0 | \n",
"
\n",
" | Name | Pyruvate_c0 | \n",
"
\n",
" | Memory address | \n",
" 0x07f75fa6e0250 | \n",
"
\n",
" | Formula | C3H3O3 | \n",
"
\n",
" | Compartment | c0 | \n",
"
\n",
" | In 70 reaction(s) | \n",
" rxn03909_c0, rxn00145_c0, rxn03884_c0, rxn08792_c0, rxn16114_c0, rxn01354_c0, rxn11274_c0, rxn00540_c0, rxn00473_c0, rxn05617_c0, rxn03841_c0, rxn05569_c0, rxn05655_c0, rxn00289_c0, rxn08043_c0,... | \n",
"
\n",
"
"
],
"text/plain": [
""
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cobra_model.metabolites.cpd00020_c0"
]
},
{
"cell_type": "code",
"execution_count": 15,
"id": "cab0b84e-57ac-4baf-8886-6fc2140af9d6",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"\n",
" \n",
" \n",
" | Reaction identifier | rxn00148_c0 | \n",
"
\n",
" | Name | ATP:pyruvate 2-O-phosphotransferase_c0 | \n",
"
\n",
" | Memory address | \n",
" 0x07f75fa8e1940 | \n",
"
\n",
" | Stoichiometry | \n",
" \n",
" cpd00002_c0 + cpd00020_c0 --> cpd00008_c0 + cpd00061_c0 + cpd00067_c0 \n",
" ATP_c0 + Pyruvate_c0 --> ADP_c0 + Phosphoenolpyruvate_c0 + H+_c0 \n",
" | \n",
"
\n",
" | GPR | (NP_416191.1) or (NP_416368.1) | \n",
"
\n",
" | Lower bound | 0 | \n",
"
\n",
" | Upper bound | 1000 | \n",
"
\n",
"
\n",
" "
],
"text/plain": [
""
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"cobra_model.reactions.rxn00148_c0"
]
},
{
"cell_type": "code",
"execution_count": 6,
"id": "dae0db89-1807-4dc5-86f3-6ca6bf9b67c9",
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"medium size: 170\n"
]
}
],
"source": [
"print('medium size:', len(model.medium))"
]
},
{
"cell_type": "markdown",
"id": "285d72ae-5852-4e84-aca0-8d7e1cb4d68e",
"metadata": {},
"source": [
"#### Perform flux analysis\n",
"modelseedpy returns cobrapy model object any flux analysis method of cobrapy or compatible with cobrapy can be performed over a modelseedpy model"
]
},
{
"cell_type": "code",
"execution_count": 7,
"id": "4e773f47-244e-4b41-84e9-3db079d9d09c",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"complete medium growth \n"
]
}
],
"source": [
"growth = model.optimize()\n",
"print('complete medium growth', growth)"
]
},
{
"cell_type": "markdown",
"id": "a79269aa-434f-4aa0-9876-a5456a3cc9ac",
"metadata": {},
"source": [
"#### KBaseMediaPkg\n",
"Helper function to assign media object to model, alternative cobrapy model.medium can also be used"
]
},
{
"cell_type": "code",
"execution_count": 8,
"id": "9e957967-d426-4c3a-b820-f3d3031c677f",
"metadata": {},
"outputs": [],
"source": [
"from modelseedpy import KBaseMediaPkg\n",
"pkg = KBaseMediaPkg(model)\n",
"pkg.build_package(media)"
]
},
{
"cell_type": "code",
"execution_count": 9,
"id": "b7c16cd1-7b26-49e9-85b4-2f684b9e870c",
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"Objective
1.0 bio1 = 0.7615585525394607
Uptake
\n",
" \n",
" \n",
" | Metabolite | \n",
" Reaction | \n",
" Flux | \n",
" C-Number | \n",
" C-Flux | \n",
"
\n",
" \n",
" \n",
" \n",
" | cpd00007_e0 | \n",
" EX_cpd00007_e0 | \n",
" 0.01603 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00009_e0 | \n",
" EX_cpd00009_e0 | \n",
" 0.6188 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00013_e0 | \n",
" EX_cpd00013_e0 | \n",
" 7.227 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00027_e0 | \n",
" EX_cpd00027_e0 | \n",
" 5 | \n",
" 6 | \n",
" 100.00% | \n",
"
\n",
" \n",
" | cpd00030_e0 | \n",
" EX_cpd00030_e0 | \n",
" 0.002137 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00034_e0 | \n",
" EX_cpd00034_e0 | \n",
" 0.002137 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00048_e0 | \n",
" EX_cpd00048_e0 | \n",
" 0.1724 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00058_e0 | \n",
" EX_cpd00058_e0 | \n",
" 0.002137 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00063_e0 | \n",
" EX_cpd00063_e0 | \n",
" 0.002137 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00099_e0 | \n",
" EX_cpd00099_e0 | \n",
" 0.002137 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00149_e0 | \n",
" EX_cpd00149_e0 | \n",
" 0.002137 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00205_e0 | \n",
" EX_cpd00205_e0 | \n",
" 0.002137 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00254_e0 | \n",
" EX_cpd00254_e0 | \n",
" 0.002137 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd10515_e0 | \n",
" EX_cpd10515_e0 | \n",
" 0.006411 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd10516_e0 | \n",
" EX_cpd10516_e0 | \n",
" 0.002137 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd17041_c0 | \n",
" rxn13782_c0 | \n",
" 0.7616 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd17042_c0 | \n",
" rxn13783_c0 | \n",
" 0.7616 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd17043_c0 | \n",
" rxn13784_c0 | \n",
" 0.7616 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
"
Secretion
\n",
" \n",
" \n",
" | Metabolite | \n",
" Reaction | \n",
" Flux | \n",
" C-Number | \n",
" C-Flux | \n",
"
\n",
" \n",
" \n",
" \n",
" | cpd00001_e0 | \n",
" EX_cpd00001_e0 | \n",
" -20.69 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00075_e0 | \n",
" EX_cpd00075_e0 | \n",
" -0.6905 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
" | cpd00116_e0 | \n",
" EX_cpd00116_e0 | \n",
" -0.002137 | \n",
" 1 | \n",
" 4.35% | \n",
"
\n",
" \n",
" | cpd15378_e0 | \n",
" EX_cpd15378_e0 | \n",
" -0.002137 | \n",
" 7 | \n",
" 30.43% | \n",
"
\n",
" \n",
" | cpd02701_c0 | \n",
" SK_cpd02701_c0 | \n",
" -0.002137 | \n",
" 15 | \n",
" 65.22% | \n",
"
\n",
" \n",
" | cpd11416_c0 | \n",
" SK_cpd11416_c0 | \n",
" -0.7616 | \n",
" 0 | \n",
" 0.00% | \n",
"
\n",
" \n",
"
"
],
"text/plain": [
""
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"model.summary()"
]
},
{
"cell_type": "markdown",
"id": "8ef4d959-2d1a-49bf-b6ab-957447f1b5c3",
"metadata": {},
"source": [
"#### Save model to KBase\n",
"ModelSEEDpy-KBase (currently cobrakbase) allows KBase workspace interaction. The KBaseAPI allows fetch and save data from narrative.\n",
"\n",
"kbase = KBaseAPI(TOKEN) requires a token that can be obtained from a login session of KBase. Token can be saved to ~/.kbase/token to avoid sharing token to python script."
]
},
{
"cell_type": "code",
"execution_count": 10,
"id": "c3fea0fd-b4e5-493f-a0fd-cdbd18789dac",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"cobrakbase 0.2.8\n"
]
}
],
"source": [
"from cobrakbase import KBaseAPI\n",
"kbase = KBaseAPI()"
]
},
{
"cell_type": "markdown",
"id": "783f5149-3a92-45e8-9de6-35de22618750",
"metadata": {},
"source": [
"Save model to workspace 96314 this is the workspace id that can be found in the url example: https://narrative.kbase.us/narrative/96314"
]
},
{
"cell_type": "code",
"execution_count": 11,
"id": "bf458280-68e6-4129-871a-bbba91d21231",
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"[[2,\n",
" 'SEED_model',\n",
" 'KBaseFBA.FBAModel-14.0',\n",
" '2021-08-02T04:04:48+0000',\n",
" 2,\n",
" 'filipeliu',\n",
" 96314,\n",
" 'filipeliu:narrative_1627876602308',\n",
" '2216489998bda8f0eba69540db9648bf',\n",
" 1610666,\n",
" {'Number gapgens': '0',\n",
" 'Type': 'GenomeScale',\n",
" 'Number gapfills': '0',\n",
" 'Source ID': 'SEED_model',\n",
" 'Number biomasses': '1',\n",
" 'Number compartments': '2',\n",
" 'Source': 'ModelSEEDpy',\n",
" 'Number compounds': '1460',\n",
" 'Number reactions': '1606',\n",
" 'Name': 'SEED_model'}]]"
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"kbase.save_object('SEED_model', 96314, 'KBaseFBA.FBAModel', model)"
]
},
{
"cell_type": "code",
"execution_count": 12,
"id": "d7ca458f-e4d0-4118-a833-74d65a493682",
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"Narrative.1627876602308 KBaseNarrative.Narrative-4.0\n",
"SEED_model KBaseFBA.FBAModel-14.0\n"
]
}
],
"source": [
"for o in kbase.list_objects(96314):\n",
" print(o[1], o[2])"
]
},
{
"cell_type": "code",
"execution_count": null,
"id": "b23a3f38-94d1-4c64-a29d-91de5ead1158",
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"kernelspec": {
"display_name": "Python 3",
"language": "python",
"name": "python3"
},
"language_info": {
"codemirror_mode": {
"name": "ipython",
"version": 3
},
"file_extension": ".py",
"mimetype": "text/x-python",
"name": "python",
"nbconvert_exporter": "python",
"pygments_lexer": "ipython3",
"version": "3.8.10"
}
},
"nbformat": 4,
"nbformat_minor": 5
}