- Python 3: should be available in most modern macOS or Linux installations. Please install if not available. You can check if it is available by running
which python3
on the terminal. - pip for python 3: Check if available by running
which pip3
, it should normally be available with the python 3 installation. Otherwise, please visit https://pip.pypa.io/en/stable/installing/.
All commands mentioned here should be run on the same terminal, sequentially.
Execute:
pip3 install virtualenv
We are going to create a clean environment for our tools, to avoid disrupting other software installations and to avoid any conflicts with other present packages in the system installation.
mkdir -p ~/venvs
virtualenv ~/venvs/metabolic-wb
Now we go into that virtual environment by executing:
source ~/venvs/metabolic-wb/bin/activate
whenever you want to use the tools that we will install here in a new terminal window, you need to execute the above command.
Within the same termina window where you executed the previous command which activated the environment, run:
pip install escher==1.7.3 cobra jupyterlab notebook d3flux
This will install:
- Escher and d3flux for interactive visualization of simulated metabolic networks.
- cobrapy.
- JupyterLab and Notebook for easily working on the web browser and sharing work with colleagues.
More interesting packages that could be installed available here.
From now on, anytime that you need to use these packages, if you are on a new terminal window, execute step 3 again. All the other steps are only needed one time per computer.
On a terminal where you had executed step 3 above at the least, run:
jupyter lab
More details here.
Then select on the file browser to the left, navigate to a folder where you have SBML or cobrapy models in YAML or JSON (or any of the other cobrapy accepted formats). Then on the launcher to the right, on the Notebook section, click on Python3. You should be able in the newly opened tab to execute code which uses cobrapy as you are used.
from cobra.io import read_sbml_model
model = read_sbml_model('my_model.xml')
...
Dear Pablo,
Thank you so much for this tutorial. I am new to programming and flux models etc. and I tried to use cobra in jupyter notebook for two days now! Your approach was the only who worked! Thanks a lot!