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

[UPDATE] simulation

parent e0e24eed
%% Cell type:markdown id: tags:
# MEWpy Simulation
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]
```
%% Cell type:code id: tags:
``` python
# first 10 metabolites
simul.reactions[:10]
```
%% Cell type:code id: tags:
``` python
# first 10 genes
simul.genes[:10]
```
%% Cell type:code id: tags:
``` python
simul.compartments
```
%% Cell type:markdown id: tags:
For a more compreensive look at the list of reactions, you may use the `find` function, without any parameters (list all reactions), or by adding a _filter_:
%% Cell type:code id: tags:
``` python
simul.find()
```
%% Cell type:code id: tags:
``` python
simul.find(['EX_','BIO'])
```
%% Cell type:code id: tags:
``` python
# metabolites
simul.find(find_in='m')
```
%% Cell type:code id: tags:
``` python
# metabolites
simul.find(find_in='g')
```
%% Cell type:markdown id: tags:
Listing the uptake reactions:
%% Cell type:code id: tags:
``` python
simul.get_uptake_reactions()
```
%% Cell type:code id: tags:
``` python
simul.get_transport_reactions()
# for a more compreensive listage
simul.find(simul.get_uptake_reactions())
```
%% 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):
or as a table:
%% Cell type:code id: tags:
``` python
result.dataframe
result.find()
```
%% 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:code id: tags:
``` python
result.find(['TPI','BIO'])
```
%% 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
# returns a dictionary
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.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment