Set up the conda environment
conda create -n escher python=3.8
conda activate escher
pip install escher
Cautions
jupyter
tool -- and not the jupyter lab
project. As of today, there is an issue with jupyter lab
preventing the Builder object to be shown.To start, from a terminal
conda activate escher
jupyter notebook escher_tutorial_20201208.ipynb
import cobra
import json
import escher
from escher import Builder
builder
object¶The builder
object is the bread and butter of the Escher Jupyter API. It provides a unique interface to deal with maps, models and data.
# help(Builder)
To create a new one, simply:
builder = Builder()
builder
Without more instructions, the widget is empty: we do not specified which map to use. Notice it's look very similar to what we can see using the web interface of Escher. We can actually use the embedded menu to set map, model and / or data. But, ..., let's use Python command line instructions instead :)
Using the model_json
argument, we tell Escher that we want to use the entities listed in the iJO1366
metabolic model. This is a the E. coli model published in 2011, by Palsson et al, publicly available on the BiGG database http://bigg.ucsd.edu/models/iJO1366.
! wget -nc http://bigg.ucsd.edu/static/models/iJO1366.json
builder = Builder(model_json='iJO1366.json') # Creating a new builder
builder
--2020-12-09 14:30:36-- http://bigg.ucsd.edu/static/models/iJO1366.json Resolving bigg.ucsd.edu (bigg.ucsd.edu)... 169.228.33.117 Connecting to bigg.ucsd.edu (bigg.ucsd.edu)|169.228.33.117|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 2948407 (2,8M) [application/json] Saving to: ‘iJO1366.json’ iJO1366.json 100%[===================>] 2,81M 823KB/s in 3,5s 2020-12-09 14:30:40 (823 KB/s) - ‘iJO1366.json’ saved [2948407/2948407]
Nothing new... apparently. Actually, while we did not specified how to show the entities listed in the model, yet these entities are available. For instance, one can create a new map for E. coli following these steps:
glu
)Nodes and arrows can be reorganized. Tips: in fullscreen mode, Ctrl-Z
to undo changes.
Notice: change will be lost if the notebook cell is executed again.
To save the map, one can go to Map > Save map JSON
from the builder menu.
There is a collection of maps available from the Escher website:
for item in escher.list_available_maps():
print(item)
{'organism': 'Saccharomyces cerevisiae', 'map_name': 'iMM904.Central carbon metabolism'} {'organism': 'Homo sapiens', 'map_name': 'RECON1.Inositol retinol metabolism'} {'organism': 'Homo sapiens', 'map_name': 'RECON1.Glycolysis TCA PPP'} {'organism': 'Homo sapiens', 'map_name': 'RECON1.Tryptophan metabolism'} {'organism': 'Homo sapiens', 'map_name': 'RECON1.Carbohydrate metabolism'} {'organism': 'Homo sapiens', 'map_name': 'RECON1.Amino acid metabolism (partial)'} {'organism': 'Escherichia coli', 'map_name': 'iJO1366.Nucleotide metabolism'} {'organism': 'Escherichia coli', 'map_name': 'iJO1366.Fatty acid biosynthesis (saturated)'} {'organism': 'Escherichia coli', 'map_name': 'iJO1366.Nucleotide and histidine biosynthesis'} {'organism': 'Escherichia coli', 'map_name': 'e_coli_core.Core metabolism'} {'organism': 'Escherichia coli', 'map_name': 'iJO1366.Central metabolism'} {'organism': 'Escherichia coli', 'map_name': 'iJO1366.Fatty acid beta-oxidation'}
To load one of these maps we use the map_name
argument. Here, it's the core metabolism associated to E. coli:
builder = Builder(map_name='e_coli_core.Core metabolism') # Need internet connexion
builder
Downloading Map from https://escher.github.io/1-0-0/6/maps/Escherichia%20coli/e_coli_core.Core%20metabolism.json
From there, one can:
We can also load the map we created (and saved) previously using the map_json
argument:
Builder(map_json='new_map_tuto.json')
Let's point out a strong limitation. Here,
map_name
(based on the iJO1366 model)builder = Builder(map_name='iJO1366.Central metabolism')
! wget -nc http://bigg.ucsd.edu/static/models/iYO844.json
builder.model = cobra.io.load_json_model('iYO844.json')
builder.highlight_missing = True
builder
Downloading Map from https://escher.github.io/1-0-0/6/maps/Escherichia%20coli/iJO1366.Central%20metabolism.json --2020-12-09 14:30:41-- http://bigg.ucsd.edu/static/models/iYO844.json Resolving bigg.ucsd.edu (bigg.ucsd.edu)... 169.228.33.117 Connecting to bigg.ucsd.edu (bigg.ucsd.edu)|169.228.33.117|:80... connected. HTTP request sent, awaiting response... 200 OK Length: 1646638 (1,6M) [application/json] Saving to: ‘iYO844.json’ iYO844.json 100%[===================>] 1,57M 856KB/s in 1,9s 2020-12-09 14:30:43 (856 KB/s) - ‘iYO844.json’ saved [1646638/1646638]
Reactions in red are those described in the B. subtilis model. Some of them are likely to exist in B. subtilis cells, but they are not mapped either because not described in the model, or not referenced with the same reaction ID.
What to do in such situation? There is no easy solution:
Escher provides methods to overlay user data on top of the metabolic maps.
These data can be provided by files, or be the results of simulation performed "on the fly" using the model.
Using the builder.reaction_data
attribute
builder = Builder(map_name='iJO1366.Central metabolism')
! wget -nc https://escher.readthedocs.io/en/latest/_static/example_data/S3_iJO1366_anaerobic_FBA_flux.json
with open('S3_iJO1366_anaerobic_FBA_flux.json') as ifh:
builder.reaction_data = json.load(ifh)
builder
Downloading Map from https://escher.github.io/1-0-0/6/maps/Escherichia%20coli/iJO1366.Central%20metabolism.json --2020-12-09 14:30:45-- https://escher.readthedocs.io/en/latest/_static/example_data/S3_iJO1366_anaerobic_FBA_flux.json Resolving escher.readthedocs.io (escher.readthedocs.io)... 2606:4700::6811:2052, 2606:4700::6811:2152, 104.17.33.82, ... Connecting to escher.readthedocs.io (escher.readthedocs.io)|2606:4700::6811:2052|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [application/json] Saving to: ‘S3_iJO1366_anaerobic_FBA_flux.json’ S3_iJO1366_anaerobi [ <=> ] 9,38K --.-KB/s in 0s 2020-12-09 14:30:45 (42,2 MB/s) - ‘S3_iJO1366_anaerobic_FBA_flux.json’ saved [9606]
The view can be refined after the generation. The builder widget is automatically updated.
> Simplify the map by hiding metabolites considered as secondary
builder.hide_secondary_metabolites = True
builder.hide_all_labels = False
> Customize the scale
builder.reaction_scale = [
{ 'type': 'min', 'color': '#000000', 'size': 12 },
{ 'type': 'median', 'color': '#ffffff', 'size': 25 },
{ 'type': 'max', 'color': '#ff0000', 'size': 50 }
]
> There are available scale presets
builder.reaction_scale_preset = 'GaBuRd'
> Make all the arrows three times as thick
builder.reaction_scale = [
{k: v * 3 if k == 'size' else v for k, v in x.items()}
for x in builder.reaction_scale
]
Using the builder.metabolite_data
attribute
builder = Builder(map_name='iJO1366.Central metabolism')
! wget -nc https://escher.readthedocs.io/en/latest/_static/example_data/metabolite_data_iJO1366.json
with open('metabolite_data_iJO1366.json') as ifh:
builder.metabolite_data = json.load(ifh)
builder
Downloading Map from https://escher.github.io/1-0-0/6/maps/Escherichia%20coli/iJO1366.Central%20metabolism.json --2020-12-09 14:30:45-- https://escher.readthedocs.io/en/latest/_static/example_data/metabolite_data_iJO1366.json Resolving escher.readthedocs.io (escher.readthedocs.io)... 2606:4700::6811:2052, 2606:4700::6811:2152, 104.17.33.82, ... Connecting to escher.readthedocs.io (escher.readthedocs.io)|2606:4700::6811:2052|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [application/json] Saving to: ‘metabolite_data_iJO1366.json’ metabolite_data_iJO [ <=> ] 48,07K --.-KB/s in 0,001s 2020-12-09 14:30:45 (72,1 MB/s) - ‘metabolite_data_iJO1366.json’ saved [49222]
Using the builder.gene_data
.
builder = Builder(map_name='iJO1366.Central metabolism')
! wget -nc https://escher.readthedocs.io/en/latest/_static/example_data/gene_data_names_iJO1366.json
with open('gene_data_names_iJO1366.json') as ifh:
builder.gene_data = json.load(ifh)
builder
Downloading Map from https://escher.github.io/1-0-0/6/maps/Escherichia%20coli/iJO1366.Central%20metabolism.json --2020-12-09 14:30:46-- https://escher.readthedocs.io/en/latest/_static/example_data/gene_data_names_iJO1366.json Resolving escher.readthedocs.io (escher.readthedocs.io)... 2606:4700::6811:2052, 2606:4700::6811:2152, 104.17.33.82, ... Connecting to escher.readthedocs.io (escher.readthedocs.io)|2606:4700::6811:2052|:443... connected. HTTP request sent, awaiting response... 200 OK Length: unspecified [application/json] Saving to: ‘gene_data_names_iJO1366.json’ gene_data_names_iJO [ <=> ] 36,55K --.-KB/s in 0,001s 2020-12-09 14:30:46 (30,6 MB/s) - ‘gene_data_names_iJO1366.json’ saved [37432]
Escher enables cobra simulation directly from the Builder
object. To perform this, the model should be loaded.
FBA simulation optimizing biomass production in E. coli cells:
builder = Builder(map_name='iJO1366.Central metabolism')
! wget -nc http://bigg.ucsd.edu/static/models/iJO1366.json
builder.model = cobra.io.load_json_model('iJO1366.json')
solution = builder.model.optimize()
builder.reaction_data = solution.fluxes
builder
Downloading Map from https://escher.github.io/1-0-0/6/maps/Escherichia%20coli/iJO1366.Central%20metabolism.json File ‘iJO1366.json’ already there; not retrieving.
Add some data for metabolites
builder.metabolite_data = solution.shadow_prices