#!/usr/bin/env python # coding: utf-8 # # Getting started with cameo # **cameo** reuses and extends model data structures defined by [cobrapy](https://opencobra.github.io/cobrapy/) (**CO**nstraints-**B**ased **R**econstruction and **A**nalysis tool for **Py**thon). So, in addition to following this quick start guide and other **cameo** tutorials, we encourage you to explore cobrapy's [documentation](https://cobrapy.readthedocs.org/en/latest/cobra.core.html) as well. # Step 1: Load a model # ------------------- # # Loading a model is easy. Just import the `~cameo.io.load_model` function. # In[1]: from cameo import load_model # For example, load the most current genome-scale metabolic reconstruction of _Escherichia coli_. # In[2]: model = load_model("iJO1366") # Models, reactions, metabolites, etc., provide return HTML when evaluated in Jupyter notebooks and can thus be easily inspected. # In[3]: model # ## Step 2: Simulate a model # # The model can be simulated by executing `~cameo.core.solver_based_model.SolverBasedModel.solve`. # In[4]: solution = model.solve() # A quick overview of the solution can be obtained in form of a pandas [DataFrame](http://pandas.pydata.org/pandas-docs/stable/generated/pandas.DataFrame.html) (all solution objects in cameo provide access to data frames through a `data_frame` attribute). # In[5]: solution # The data frame is accessible through `solution.data_frame`. # In[6]: solution.data_frame # Data frames make it very easy to process results. For example, let's take a look at reactions with flux != 0 # In[7]: solution.data_frame.query('fluxes != 0') # ## Step 3: Exploring a model # # Objects—models, reactions, metabolites, genes—can easily be explored in the Jupyter notebook, taking advantage of tab completion. For example, place your cursor after the period in `model.reactions.` and press the TAB key. A dialog will appear that allows you to navigate the list of reactions encoded in the model. # In[8]: model.reactions.PGK # delete PGK, place your cursor after the period and press the TAB key. # For example, you can access the E4PD (_Erythrose 4-phosphate dehydrogenase_) reaction in the model. # In[9]: model.reactions.E4PD # Be aware though that due variable naming restrictions in Python dot notation access to reactions (and other objects) might not work in some cases. # In[10]: # model.reactions.12DGR120tipp # uncommenting and running this cell will produce a syntax error # In these cases you need to use the `model.reactions.get_by_id`. # In[11]: model.reactions.get_by_id('12DGR120tipp') # Metabolites are accessible through `model.metabolites`. For example, D-glucose in the cytosolic compartment. # In[12]: model.metabolites.glc__D_c # And it is easy to find the associated reactions # In[13]: model.metabolites.glc__D_c.reactions # A list of the genes encoded in the model can be accessed via `model.genes`. # In[14]: model.genes[0:10] # A few additional attributes have been added that are not available in a [cobrapy](https://opencobra.github.io/cobrapy/) model. For example, exchange reactions that allow certain metabolites to enter or leave the model can be accessed through `model.exchanges`. # In[15]: model.exchanges[0:10] # Or, the current medium can be accessed through `model.medium`. # In[16]: model.medium # It is also possible to get a list of essential reactions ... # In[17]: model.essential_reactions()[0:10] # ... and essential genes. # In[18]: model.essential_genes()[0:10]