Commit e734f27e authored by Vítor Pereira's avatar Vítor Pereira
Browse files

UPDATE

parent 310d5c97
.ipynb_checkpoints
\ No newline at end of file
%% Cell type:markdown id: tags:
# MEWpy Simulation
This notebook exemplifies how MEWpy may be used as an interface for COBRApy and REFRAMED.
This notebook exemplifies how MEWpy may be used for phenotype simulation.
%% Cell type:markdown id: tags:
Models can be loaded using MEW, REFRAMED, or COBRApy.
Load a model using REFRAMED:
%% Cell type:code id: tags:
``` python
from reframed.io.sbml import load_cbmodel
model = load_cbmodel('data/e_coli_core.xml.gz')
```
%% Cell type:markdown id: tags:
or using COBRApy:
%% Cell type:code id: tags:
``` python
from cobra.io import read_sbml_model
model = read_sbml_model('data/e_coli_core.xml.gz')
```
%% Cell type:markdown id: tags:
A simulator object provides a common interface to realize the main phenotype analysis tasks. The *get_simulator* function returns a simulator, a wrapper, for the provided model. The simulator interface remains the same regardless of how the model was loaded, using REFRAMED or COBRApy. This simplify the use of both environments and ease the management of future changes and deprecation on their APIs.
%% Cell type:code id: tags:
``` python
from mewpy.simulation import get_simulator
simul = get_simulator(model)
```
%% Cell type:markdown id: tags:
The simulator offers a wide API, and enable to perform basic tasks, such as, list metabolites, reactions, genes, compartments, uptake reactions, and transport reactions:
%% Cell type:code id: tags:
``` python
# first 10 metabolites
simul.metabolites[:10]
```
%%%% Output: execute_result
['glc__D_e',
'gln__L_c',
'gln__L_e',
'glu__L_c',
'glu__L_e',
'glx_c',
'h2o_c',
'h2o_e',
'h_c',
'h_e']
%% Cell type:code id: tags:
``` python
# first 10 metabolites
simul.reactions[:10]
```
%%%% Output: execute_result
['ACALD',
'ACALDt',
'ACKr',
'ACONTa',
'ACONTb',
'ACt2r',
'ADK1',
'AKGDH',
'AKGt2r',
'ALCD2x']
%% Cell type:code id: tags:
``` python
# first 10 genes
simul.genes[:10]
```
%%%% Output: execute_result
['b1241',
'b0351',
's0001',
'b2296',
'b1849',
'b3115',
'b0118',
'b1276',
'b0474',
'b0726']
%% Cell type:code id: tags:
``` python
simul.compartments
```
%%%% Output: execute_result
{'e': 'extracellular space', 'c': 'cytosol'}
%% Cell type:code id: tags:
``` python
simul.get_uptake_reactions()
```
%%%% Output: execute_result
['EX_co2_e',
'EX_glc__D_e',
'EX_h_e',
'EX_h2o_e',
'EX_nh4_e',
'EX_o2_e',
'EX_pi_e']
%% Cell type:code id: tags:
``` python
simul.get_transport_reactions()
```
%%%% Output: execute_result
['ACALDt', 'CO2t', 'FORt', 'H2Ot', 'NH4t', 'O2t']
%% Cell type:markdown id: tags:
A simulator may also be loaded considering environmental conditions, that will be considered during phenotype simulations. In the next example, glucose consumption is limited to 10 mmol/gDW/h in anaerobical conditions.
%% Cell type:code id: tags:
``` python
envcond = {'EX_glc__D_e': (-10.0, 100000.0),
'EX_o2_e':(0,0)}
simul = get_simulator(model,envcond=envcond)
```
%% Cell type:markdown id: tags:
All phenotype simulations will consider the imposed environmental conditions, and as such they only need to be set once. Also, these conditions do not persistently alter the model, which can be reused with a different simulator instance.
%% Cell type:markdown id: tags:
## Phenotype simulation
Phenotype simulations are also run using the simulator instance using the `simulate` method.
%% Cell type:code id: tags:
``` python
# FBA
result = simul.simulate()
# or
result = simul.simulate(method='FBA')
result
```
%% Cell type:markdown id: tags:
Flux Balance Analysis (FBA) can be run without identifying any method, or by passing the 'FBA' as method parameter. Other phenotype simulation methods may also be run using one of the identifiers:
- Flux Balance Analysis: `method = 'FBA'`
- Parsimonious FBA:`method = 'pFBA'`
- Minimization of Metabolic Adjustment:`method = 'MOMA'`
- Linear MOMA: `method = 'lMOMA'`
- Regulatory on/off minimization of metabolic flux: `method = 'ROOM'`
%% Cell type:code id: tags:
``` python
# pFBA
result = simul.simulate(method = 'pFBA')
result
```
%% Cell type:markdown id: tags:
## Reaction fluxes
The phenotype simulation result object, besides containing the objective value and solver status, also include reaction fluxes in the form of a dictionary:
%% Cell type:code id: tags:
``` python
result.fluxes
```
%% Cell type:markdown id: tags:
or as a table (dataframe):
%% Cell type:code id: tags:
``` python
result.dataframe
```
%% Cell type:markdown id: tags:
Individual reaction flux values can be obtained from the dictionary representation. For example, the *triose-phosphate isomerase* (TPI) reaction flux can be obtained from the previous pFBA simulation using the reaction identifier:
%% Cell type:code id: tags:
``` python
result.fluxes['TPI']
```
%% Cell type:markdown id: tags:
To retrieve the net conversion equation invoke the `get_net_conversion` method. Exchange reactions with no flux are not presented.
%% Cell type:code id: tags:
``` python
result.get_net_conversion()
```
%% Cell type:markdown id: tags:
## Retrieving and setting the model objective
The simulation objective, when running FBA or pFBA phenotype simulations, is, by default, the model objective which can be seen using the simulator.
%% Cell type:code id: tags:
``` python
simul.objective
```
%% Cell type:markdown id: tags:
The simulator may also be used to change the model objective, for example, to optimize the ATP maintenance requirement (ATPM):
%% Cell type:code id: tags:
``` python
simul.objective = 'ATPM'
```
%% Cell type:code id: tags:
``` python
simul.objective
```
%% Cell type:code id: tags:
``` python
simul.objective='BIOMASS_Ecoli_core_w_GAM'
```
%% Cell type:markdown id: tags:
## Adding additional constraints to phenotype simulations
Simulations may include additional metabolic constraints on reaction fluxes. From the previous pFBA simulation one can observe that the organism does not produce succinate:
%% Cell type:code id: tags:
``` python
result.fluxes['EX_succ_e']
```
%% Cell type:markdown id: tags:
Additional constraints may be added to the model so that the organism start to produce this aromatic amino acid. We may alter, for example, the *phosphogluconate dehydrogenase* reaction bounds, among others, starting by verifying its initial bounds:
%% Cell type:code id: tags:
``` python
simul.get_reaction_bounds('GND')
```
%% Cell type:code id: tags:
``` python
constraints = {'GND': 0, # deletion
'PYK': 0, # deletion
'ME2': 0, # deletion
}
# run a pFBA simulation accounting with the new constraint
result = simul.simulate(method='pFBA',constraints=constraints)
result.fluxes['EX_succ_e']
```
%% Cell type:markdown id: tags:
Note that the modifications are not persistently applied to the model, they only exist during the simulation.
We also need to verify that the organism continues to grow:
%% Cell type:code id: tags:
``` python
result.fluxes['BIOMASS_Ecoli_core_w_GAM']
```
%% Cell type:markdown id: tags:
We can also plot the production envelope:
%% Cell type:code id: tags:
``` python
%matplotlib inline
from mewpy.visualization.envelope import plot_flux_envelope
plot_flux_envelope(simul,'BIOMASS_Ecoli_core_w_GAM','EX_succ_e',constraints = constraints)
```
%% Cell type:markdown id: tags:
The `simulate` method includes additional parameters, such as the optimization direction. For a full description please refer to the module documentation.
%% Cell type:markdown id: tags:
## Flux Variability Analysis
The simulator interface also allows to perform Flux Variability Analysis (FVA) for L-tyrosine:
%% Cell type:code id: tags:
``` python
# returns a dictionar
simul.FVA(reactions=['EX_succ_e'])
```
%% Cell type:code id: tags:
``` python
# or a data frame
simul.FVA(reactions=['EX_succ_e'],format='df')
```
%% Cell type:markdown id: tags:
By default, MEWpy sets the model objective fraction to 90%, however this fraction may be altered. For example, one might want to consider a fraction of 10% from optimal growth:
%% Cell type:code id: tags:
``` python
simul.FVA(reactions=['EX_succ_e'],obj_frac=0.9)
```
%% Cell type:markdown id: tags:
The FVA simulations are run considering the defined environmental conditions. Additional constraints may be added, or changed, such as the previouly used to increase L-tyrosine production.
%% Cell type:code id: tags:
``` python
simul.FVA(reactions=['EX_succ_e'], constraints=constraints)
```
%% Cell type:markdown id: tags:
COBRApy users may have noticed that this same task would have required many additional coding lines if using the COBRApy API directly.
%% Cell type:markdown id: tags:
## Genes and reactions essentiality
Gene and reaction essentiality tests identify, respectively, the list of genes and reactions whose deletion would prevent the organism to grow.
%% Cell type:code id: tags:
``` python
simul.essential_reactions()
```
%% Cell type:code id: tags:
``` python
simul.essential_genes()
```
%% Cell type:markdown id: tags:
For more options and methods please refer to the MEWpy documentation.
......
bNum,Gene,Rule
b0008,b0008,TRUE
b0080,FruR,NOT surplusFDP
b0113,PdhR,NOT surplusPYR
b0114,aceE, NOT PdhR OR Fis
b0115,aceF, NOT PdhR OR Fis
b0116,b0116,TRUE
b0118,b0118,TRUE
b0351,b0351,TRUE
b0356,b0356,TRUE
b0399,PhoB,PhoR
b0400,PhoR,(NOT (pi_e > 0))
b0451,b0451,TRUE
b0474,b0474,TRUE
b0485,b0485,TRUE
b0720,b0720,TRUE
b0721,sdhC, (NOT (ArcA OR Fnr)) OR Crp OR Fis
b0722,sdhD, (NOT (ArcA OR Fnr)) OR Crp OR Fis
b0723,sdhA, (NOT (ArcA OR Fnr)) OR Crp OR Fis
b0724,sdhB, (NOT (ArcA OR Fnr)) OR Crp OR Fis
b0726,b0726,TRUE
b0727,b0727,TRUE
b0728,b0728,TRUE
b0729,b0729,TRUE
b0733,cydA, (NOT Fnr) OR ArcA
b0734,cydB, (NOT Fnr) OR ArcA
b0755,b0755,TRUE
b0767,b0767,TRUE
b0809,b0809,TRUE
b0810,b0810,TRUE
b0811,b0811,TRUE
b0875,b0875,TRUE
b0902,pflA, ArcA OR (Fnr AND Crp)
b0903,pflB, ArcA OR (Fnr AND Crp)
b0904,focA, ArcA OR (Fnr AND Crp)
b0978,b0978,TRUE
b0979,b0979,TRUE
b1101,ptsG, (NOT Mlc) OR (NOT FruR)
b1136,b1137,TRUE
b1187,FadR,(glc__D_e > 0) OR (NOT ((ac_e > 0)))
b1241,adhE, (NOT (o2_e > 0)) OR (NOT ((o2_e > 0) AND FruR)) OR Fis
b1276,b1276,TRUE
b1297,b1297,TRUE
b1334,Fnr,NOT (o2_e > 0)
b1380,b1380,TRUE
b1478,b1478,TRUE
b1479,b1479,TRUE
b1524,yneH, (NOT (glc__D_e > 0)) OR ((nh4_e > 0) AND (NOT Crp))
b1594,Mlc,(NOT (glc__D_e > 0))
b1602,b1602,TRUE
b1603,b1603,TRUE
b1611,fumC, NOT ArcA
b1612,fumA, NOT (ArcA OR Fnr)
b1621,b1622,TRUE
b1676,pykF, NOT FruR
b1702,pps, FruR
b1723,b1724,TRUE
b1761,gdhA,NOT (Nac OR (glu__L_e > 0))
b1773,b1773,TRUE
b1779,b1779,TRUE
b1812,b1812,TRUE
b1817,manX,CRPnoGLM OR (NOT Mlc)
b1818,manY,CRPnoGLM OR (NOT Mlc)
b1819,manZ,CRPnoGLM OR (NOT Mlc)
b1849,b1849,TRUE
b1852,b1852,TRUE
b1854,b1854,TRUE
b1988,Nac,NRI_low
b2029,b2029,TRUE
b2097,b2097,TRUE
b2133,b2133,TRUE
b2276,nuoN, (NOT (ArcA OR Fnr))
b2277,nuoM, (NOT (ArcA OR Fnr))
b2278,nuoL, (NOT (ArcA OR Fnr))
b2279,nuoK, (NOT (ArcA OR Fnr))
b2280,nuoJ, (NOT (ArcA OR Fnr))
b2281,nuoI, (NOT (ArcA OR Fnr))
b2282,nuoH, (NOT (ArcA OR Fnr))
b2283,nuoG, (NOT (ArcA OR Fnr))
b2284,nuoF, (NOT (ArcA OR Fnr))
b2285,nuoE, (NOT (ArcA OR Fnr))
b2286,nuoC, (NOT (ArcA OR Fnr))
b2287,nuoB, (NOT (ArcA OR Fnr))
b2288,nuoA, (NOT (ArcA OR Fnr))
b2296,b2296,TRUE
b2297,b2297,TRUE
b2415,b2415,TRUE
b2416,b2416,TRUE
b2417,b2417,TRUE
b2458,b2458,TRUE
b2463,b2463,TRUE
b2464,b2464,TRUE
b2465,b2465,TRUE
b2492,focB, ArcA OR (Fnr AND Crp)
b2579,b2579,TRUE
b2587,b2587,TRUE
b2779,b2779,TRUE
b2914,b2914,TRUE
b2925,b2925,TRUE
b2926,b2926,TRUE
b2935,b2935,TRUE
b2975,glcA, (NOT ArcA) AND GlcC
b2976,glcB, (NOT ArcA) AND GlcC
b2980,GlcC,(ac_e > 0)
b2987,pitB, NOT PhoB
b3114,tdcE, Crp OR Fnr
b3115,tdcD, Crp OR Fnr
b3212,gltB, (NOT (NRI_hi AND (glu__L_e > 0)))
b3213,gltD, (NOT (NRI_hi AND (glu__L_e > 0)))
b3236,mdh, NOT ArcA
b3261,Fis,(Biomass_Ecoli_core > 0)
b3357,Crp,CRPnoGLC
b3386,b3386,TRUE
b3403,b3403,TRUE
b3493,b3493,TRUE
b3528,dctA,CRPnoGLM AND (NOT ArcA) AND DcuR
b3603,lldP, NOT ArcA
b3612,b3612,TRUE
b3731,b3731,TRUE
b3732,b3732,TRUE
b3733,b3733,TRUE
b3734,b3734,TRUE
b3735,b3735,TRUE
b3736,b3736,TRUE
b3737,b3737,TRUE
b3738,b3738,TRUE
b3739,b3739,TRUE
b3868,GlnG,NOT (nh4_e > 0)
b3870,glnA,Crp
b3916,b3916,TRUE
b3919,b3919,TRUE
b3925,b3925,TRUE
b3951,pflD, ArcA OR Fnr
b3952,pflC, ArcA OR Fnr
b3956,b3956,TRUE
b3962,b3962,TRUE
b4014,aceB, (NOT IclR) AND ((NOT ArcA) OR FruR)
b4015,aceA, (NOT IclR) AND ((NOT ArcA) OR FruR)
b4018,IclR,FadR
b4025,b4025,TRUE
b4077,b4077,TRUE
b4090,b4090,TRUE
b4122,fumB, Fnr OR Crp OR DcuR
b4124,DcuR,DcuS
b4125,DcuS,(succ_e > 0) OR (fum_e > 0) OR (mal__L_e > 0)
b4151,frdD, Fnr OR DcuR
b4152,frdC, Fnr OR DcuR
b4153,frdB, Fnr OR DcuR
b4154,frdA, Fnr OR DcuR
b4232,b4232,TRUE
b4301,b4301,TRUE
b4395,b4395,TRUE
b4401,ArcA,NOT (o2_e > 0)
s0001,s0001,TRUE
CRPnoGLC,CRPnoGLC,(NOT (glc__D_e > 0))
CRPnoGLM,CRPnoGLM,NOT ((glc__D_e > 0) OR (mal__L_e > 0) OR (lac__D_e > 0))
NRI_hi,NRI_hi,NRI_low
NRI_low,NRI_low,GlnG
surplusFDP,surplusFDP,((NOT (FBP > 0)) AND (NOT ((TKT2 > 0) OR (TALA > 0) OR (PGI > 0)))) OR (fru_e > 0)
surplusPYR,surplusPYR,(NOT ((ME2 > 0) OR (ME1 > 0))) AND (NOT ((GLCpts > 0) OR (PYK > 0) OR (PFK > 0) OR (LDH_D > 0) OR (SUCCt2_2 > 0)))
This diff is collapsed.
This diff is collapsed.
%% Cell type:markdown id: tags:
## Module 3 session 2
# Exercice 1
Nutrient and proteome limited growth.
%% Cell type:code id: tags:
``` python
%matplotlib inline
from reframed.io.sbml import load_cbmodel
import matplotlib.pyplot as plt
from mewpy.simulation import get_simulator
```
%% Cell type:markdown id: tags:
Start by loading the E. coli model iJO1366.
You may use COBRApy or REFRAMED.
%% Cell type:code id: tags:
``` python
model = load_cbmodel('data/iJO1366.xml',flavor='cobra')
simul = get_simulator(model)
```
%% Cell type:markdown id: tags:
Create medium conditions where all nutrients, except glucose, are unlimited. This medium simulates what somehow could be found in batch cultures
%% Cell type:code id: tags:
``` python
GLC = 'R_EX_glc__D_e'
BIOMASS = "R_BIOMASS_Ec_iJO1366_WT_53p95M"
envcond = {rxn:(-10000,10000) for rxn in simul.get_uptake_reactions() if rxn!=GLC}
```
%% Cell type:markdown id: tags:
Redefine the simulation environment considering this medium.
%% Cell type:code id: tags:
``` python
simul = get_simulator(model,envcond=envcond)
simul.objective = BIOMASS
```
%% Cell type:markdown id: tags:
The function bellow plots the glucose dependent growth given a simulation environment
%% Cell type:code id: tags:
``` python
def plot_growth(simul,title=''):
x_values =[]
y_values =[]
for x in range(0,100,5):
c = {GLC:(-x,1000)}
s = simul.simulate(constraints=c)
try: