Skip to content
Snippets Groups Projects
Commit 79ba53e4 authored by João Eduardo Levandoski's avatar João Eduardo Levandoski
Browse files

Upload medium test

parent c923260a
No related branches found
No related tags found
No related merge requests found
%% Cell type:markdown id: tags:
# Install packages
%% Cell type:code id: tags:
```
!pip install cobra --quiet
```
%% Output
 |████████████████████████████████| 1.2 MB 5.0 MB/s
 |████████████████████████████████| 2.3 MB 41.1 MB/s
 |████████████████████████████████| 147 kB 46.7 MB/s
 |████████████████████████████████| 237 kB 73.9 MB/s
 |████████████████████████████████| 6.8 MB 44.8 MB/s
 |████████████████████████████████| 109 kB 69.0 MB/s
 |████████████████████████████████| 84 kB 3.5 MB/s
 |████████████████████████████████| 44 kB 2.5 MB/s
 |████████████████████████████████| 68 kB 5.4 MB/s
 |████████████████████████████████| 80 kB 7.0 MB/s
 |████████████████████████████████| 54 kB 3.0 MB/s
 |████████████████████████████████| 51 kB 4.6 MB/s
 |████████████████████████████████| 546 kB 47.2 MB/s
[?25h
%% Cell type:markdown id: tags:
# Import libraries
%% Cell type:code id: tags:
```
import cobra
from cobra.io import load_matlab_model, save_json_model, load_json_model, write_sbml_model, load_model, read_sbml_model
from cobra.flux_analysis import flux_variability_analysis
import numpy as np
import pandas as pd
import seaborn as sns
import matplotlib.pyplot as plt
from scipy.ndimage.filters import gaussian_filter
```
%% Cell type:markdown id: tags:
# Mount drive
%% Cell type:markdown id: tags:
## Here you need to insert the path for yout model
%% Cell type:code id: tags:
```
from google.colab import drive
drive.mount('/gdrive')
```
%% Output
Mounted at /gdrive
%% Cell type:code id: tags:
```
!ls /gdrive/MyDrive/mestrado/iGEM_unicamp/fba_analysis/
```
%% Output
41598_2017_6918_MOESM1_ESM.xml
449_2020_2299_MOESM3_ESM.mat
cobrapy_fba_diferentes_meios.ipynb
cobrapy_testes.ipynb
figs
FVA_max_min.gsheet
kinetic_parameters_estimation.ipynb
medium_test_cobrapy_oslo.ipynb
medium_test_cobrapy_oslo_versao_com_so4.ipynb
Resultados_e_todo_list_models.gdoc
results_from_nh4_o2_comb.npy
results_from_nh4_o2_FO_Cellulose_comb.npy
results_from_nh4_so4_FO_biomass.npy
results_from_nh4_so4_FO_Cellulose2.npy
results_from_nh4_so4_FO_Cellulose.npy
Solutions_GKOProblem_70_cellObjs.csv
Solutions_GKOProblem.csv
versao1_cobrapy.ipynb
versao2_cobrapy.ipynb
%% Cell type:code id: tags:
```
%cd /gdrive/MyDrive/mestrado/iGEM_unicamp/fba_analysis/
```
%% Output
/gdrive/MyDrive/mestrado/iGEM_unicamp/fba_analysis
%% Cell type:code id: tags:
```
!ls
```
%% Output
41598_2017_6918_MOESM1_ESM.xml
449_2020_2299_MOESM3_ESM.mat
cobrapy_fba_diferentes_meios.ipynb
cobrapy_testes.ipynb
figs
FVA_max_min.gsheet
kinetic_parameters_estimation.ipynb
medium_test_cobrapy_oslo.ipynb
medium_test_cobrapy_oslo_versao_com_so4.ipynb
Resultados_e_todo_list_models.gdoc
results_from_nh4_o2_comb.npy
results_from_nh4_o2_FO_Cellulose_comb.npy
results_from_nh4_so4_FO_biomass.npy
results_from_nh4_so4_FO_Cellulose2.npy
results_from_nh4_so4_FO_Cellulose.npy
Solutions_GKOProblem_70_cellObjs.csv
Solutions_GKOProblem.csv
versao1_cobrapy.ipynb
versao2_cobrapy.ipynb
%% Cell type:markdown id: tags:
# Open Model
%% Cell type:code id: tags:
```
modelo = '449_2020_2299_MOESM3_ESM.mat'
```
%% Cell type:code id: tags:
```
```
%% Cell type:code id: tags:
```
model = load_matlab_model(modelo)
```
%% Output
WARNING:cobra.io.mat:This model seems to have confidenceScores instead of rxnConfidenceScores field. Will use confidenceScores for what rxnConfidenceScores represents.
WARNING:cobra.io.mat:This model seems to have metCharge instead of metCharges field. Will use metCharge for what metCharges represents.
WARNING:cobra.io.mat:No defined compartments in model model. Compartments will be deduced heuristically using regular expressions.
WARNING:cobra.io.mat:Using regular expression found the following compartments:c, e
%% Cell type:code id: tags:
```
model.medium
```
%% Output
{'EX_pi(e)': 1000.0,
'EX_glc(e)': 10.0,
'EX_nh4(e)': 1000.0,
'EX_h(e)': 1000.0,
'EX_o2(e)': 1000.0,
'EX_h2o(e)': 1000.0,
'EX_so4(e)': 1000.0,
'CYStex': 1000.0}
%% Cell type:code id: tags:
```
# save_json_model(model, "komagataeibacter_xylinus.json")
# write_sbml_model(model, "komagataeibacter_xylinus.xml")
```
%% Cell type:code id: tags:
```
print(len(model.reactions))
print(len(model.metabolites))
print(len(model.genes))
```
%% Output
918
865
640
%% Cell type:code id: tags:
```
model
```
%% Output
<Model model at 0x7fce39620590>
%% Cell type:markdown id: tags:
# Set the objective function
%% Cell type:code id: tags:
```
model.objective = "EX_biomass" # CELtexpp
model.objective = "CELtexpp"
```
%% Cell type:code id: tags:
```
print(model.objective.expression)
print(model.objective.direction)
```
%% Output
1.0*CELtexpp - 1.0*CELtexpp_reverse_29bf6
max
%% Cell type:code id: tags:
```
exchanges_reactions = {'EX_pi(e)',
'EX_glc(e)',
'EX_nh4(e)',
'EX_h(e)',
'EX_o2(e)',
'EX_h2o(e)',
'EX_so4(e)',
'CYStex'}
for id in exchanges_reactions:
r = model.reactions.get_by_id(id)
print(id, r.bounds)
```
%% Output
EX_pi(e) (-1000.0, 1000.0)
EX_h2o(e) (-1000.0, 1000.0)
EX_o2(e) (-1000.0, 0.0)
CYStex (-1000.0, 1000.0)
EX_glc(e) (-10.0, -10.0)
EX_nh4(e) (-1000.0, 1000.0)
EX_h(e) (-1000.0, 1000.0)
EX_so4(e) (-1000.0, 1000.0)
%% Cell type:code id: tags:
```
```
%% Cell type:markdown id: tags:
# Checking model
%% Cell type:code id: tags:
```
solution = model.optimize()
print(solution)
```
%% Output
<Solution 0.709 at 0x7fce31c378d0>
%% Cell type:code id: tags:
```
solution.fluxes
```
%% Output
PGMT -0.106366
GLGC 0.106366
HEX1 10.000000
PGI -18.024638
FBP 0.000000
...
CYStex 0.000000
CHORt2 0.000000
CYTDt2pp 0.000000
SO4tex 0.159904
5MTRtpp 0.020635
Name: fluxes, Length: 918, dtype: float64
%% Cell type:markdown id: tags:
# Loops
%% Cell type:markdown id: tags:
## Fluxes $NH_4$ and $O_2$
%% Cell type:code id: tags:
```
```
%% Cell type:code id: tags:
```
ranges_for_uptakes = np.logspace(-3, 3, 100)
ranges = (ranges_for_uptakes, ranges_for_uptakes)
combination_limits = np.array(np.meshgrid(*ranges))
combinations = combination_limits.T.reshape(-1, len(ranges))
full_combinations = np.array([])
lim_glc = 10
i = 0
for comb in combinations:
lim_nh4, lim_o2 = comb
medium_new = {'EX_pi(e)': 1000,
'EX_glc(e)': lim_glc,
'EX_nh4(e)': lim_nh4,
'EX_h(e)': 1000,
'EX_o2(e)': lim_o2,
'EX_h2o(e)': 1000,
'EX_so4(e)': 0
}
model.medium = medium_new
solution = model.optimize()
reactions_fluxes = [solution.fluxes.EX_biomass, solution.fluxes.CELtexpp]
uptakes = comb
outputs = np.array([solution.fluxes.EX_biomass, solution.fluxes.CELtexpp])
full_line = np.array([*uptakes, *outputs])
full_combinations = np.array([*full_combinations,full_line])
```
%% Cell type:code id: tags:
```
medium_new
```
%% Output
{'EX_pi(e)': 1000,
'EX_glc(e)': 10,
'EX_nh4(e)': 1000.0,
'EX_h(e)': 1000,
'EX_o2(e)': 1000.0,
'EX_h2o(e)': 1000,
'EX_so4(e)': 1}
%% Cell type:code id: tags:
```
# full_combinations_foBC = full_combinations
# full_combinations_foBio = full_combinations
```
%% Cell type:markdown id: tags:
### Recomendation - Save the results, because take a time to run
%% Cell type:code id: tags:
```
!ls
```
%% Output
41598_2017_6918_MOESM1_ESM.xml
449_2020_2299_MOESM3_ESM.mat
cobrapy_fba_diferentes_meios.ipynb
cobrapy_testes.ipynb
figs
FVA_max_min.gsheet
kinetic_parameters_estimation.ipynb
medium_test_cobrapy_oslo.ipynb
medium_test_cobrapy_oslo_versao_com_so4.ipynb
Resultados_e_todo_list_models.gdoc
results_from_nh4_o2_comb.npy
results_from_nh4_o2_FO_Cellulose_comb.npy
results_from_nh4_so4_FO_biomass.npy
results_from_nh4_so4_FO_Cellulose2.npy
results_from_nh4_so4_FO_Cellulose.npy
Solutions_GKOProblem_70_cellObjs.csv
Solutions_GKOProblem.csv
versao1_cobrapy.ipynb
versao2_cobrapy.ipynb
%% Cell type:code id: tags:
```
# np.save("results_from_nh4_o2_FO_Cellulose_comb_2.npy", full_combinations)
full_combinations_foBC = np.load("results_from_nh4_o2_FO_Cellulose_comb.npy") #open previous results
full_combinations_foBio = np.load("results_from_nh4_o2_comb.npy") #open previous results
```
%% Cell type:markdown id: tags:
#### Organize data
%% Cell type:code id: tags:
```
columns_bio = int(np.sqrt(len(full_combinations_foBio[:,0])))
z_bio = full_combinations_foBio[:, 2].reshape(columns_bio, columns_bio)
x_bio, y_bio = full_combinations_foBio[:, 0], full_combinations_foBio[:, 1]
```
%% Cell type:code id: tags:
```
columns_bc = int(np.sqrt(len(full_combinations_foBC[:,0])))
z_bc = full_combinations_foBC[:, 3].reshape(columns_bc, columns_bc)
x_bc, y_bc = full_combinations_foBC[:, 0], full_combinations_foBC[:, 1]
```
%% Cell type:markdown id: tags:
#### Plot the results
%% Cell type:code id: tags:
```
xs = np.round_(x_bio[::columns_bio], decimals=4)
ys = np.round_(y_bio[0:columns_bio], decimals=4)
mat = gaussian_filter(z_bio, sigma=0)
mapa = pd.DataFrame(data=mat, index=ys, columns=xs)
# plt.savefig('figs/biomass_production.png', dpi=300, format='png')
fig = plt.figure(figsize=(15, 10))
ax = fig.add_subplot(1, 1, 1)
mesh = ax.pcolormesh(xs, ys, mapa, cmap='hot')
ax.set_xlabel('NH4_Flux [mmol/gDCW.h]')
ax.set_ylabel('O2_Flux [mmol/gDCW.h]')
ax.set_yscale('log')
ax.set_xscale('log')
# ax.xaxis.set_major_locator(ticker.MultipleLocator(25))
# ax.yaxis.set_major_locator(ticker.MultipleLocator(.05))
ax.set_title('Medium Influence in specific growth rate')
# plt.savefig('figs/biomass_production.png', dpi=300, format='png')
cbar = fig.colorbar(mesh, ax=ax)
cbar.set_label('Specific growth rate [1/h]')
# cbar.locator = ticker.MultipleLocator(.05)
# cbar.update_ticks()
```
%% Output
%% Cell type:code id: tags:
```
xs = np.round_(x_bc[::columns_bio], decimals=4)
ys = np.round_(y_bc[0:columns_bio], decimals=4)
mat = gaussian_filter(z_bc, sigma=0)
mapa = pd.DataFrame(data=mat, index=ys, columns=xs)
fig = plt.figure(figsize=(15, 10))
ax = fig.add_subplot(1, 1, 1)
mesh = ax.pcolormesh(xs, ys, mapa, cmap='hot')
ax.set_xlabel('NH4_Flux [mmol/gDCW.h]')
ax.set_ylabel('O2_Flux [mmol/gDCW.h]')
ax.set_yscale('log')
ax.set_xscale('log')
# ax.xaxis.set_major_locator(ticker.MultipleLocator(25))
# ax.yaxis.set_major_locator(ticker.MultipleLocator(.05))
ax.set_title('Medium Influence in Cellulose Production')
# plt.savefig('figs/biomass_production.png', dpi=300, format='png')
cbar = fig.colorbar(mesh, ax=ax)
cbar.set_label('Cellulose [mmol/gDCW.h]')
# cbar.locator = ticker.MultipleLocator(.05)
# cbar.update_ticks()
```
%% Output
%% Cell type:code id: tags:
```
```
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment