COBRApy is a package for constraints-based modeling of biological networks
cobrapy - constraint-based reconstruction and analysis in python
What is cobrapy?
COBRA methods are widely used for genome-scale modeling of metabolic networks in both prokaryotes and eukaryotes. cobrapy is a constraint-based modeling package that is designed to accommodate the biological complexity of the next generation of COBRA models and provides access to commonly used COBRA methods, such as flux balance analysis, flux variability analysis, and gene deletion analyses.
Our aim with cobrapy is to provide useful, efficient infrastructure for:
- creating and managing metabolic models
- accessing popular solvers
- analyzing models with methods such as FVA, FBA, pFBA, MOMA etc.
- inspecting models and drawing conclusions on gene essentiality, testing consequences of knock-outs etc.
Our goal with cobrapy is for it to be useful on its own, and for it to be the natural choice of infrastructure for developers that want to build new COBRA related python packages for e.g. visualization, strain-design and data driven analysis. By re-using the same classes and design principles, we can make new methods both easier to implement and easier to use, thereby bringing the power of COBRA to more researchers.
More information about opencobra is available at the website.
If you use cobrapy in a scientific publication, please cite doi:10.1186/1752-0509-7-74
pip install cobra
In case you downloaded the source code, run:
pip install -e .
In the cobrapy directory. For further information, please follow the detailed installation instructions.
Contributions are always welcome! Please read the contributions guideline to get started.
The cobrapy source is released under both the GPL and LGPL licenses. You may choose which license you choose to use the software under. However, please note that binary packages which include GLPK (such as the binary wheels distributed at https://pypi.python.org/pypi/cobra) will be bound by its license as well.
This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License or the Lesser GNU General Public License as published by the Free Software Foundation, either version 2 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
Installation of cobrapy
All releases require Python 2.7+ or 3.4+ to be installed before proceeding. Mac OS X (10.7+) and Ubuntu ship with Python. Windows users without python can download and install python from the python website. Please note that though Anaconda and other python distributions may work with cobrapy, they are not explicitly supported (yet!).
Stable version installation
cobrapy can be installed with any recent installation of pip. Instructions for several operating systems are below:
Mac OS X or Linux
- install pip.
- In a terminal, run sudo pip install cobra
We highly recommend updating pip beforehand (pip install pip --upgrade).
The preferred installation method on Windows is also to use pip. The latest Windows installers for Python 2.7 and 3.4 include pip, so if you use those you will already have pip.
- In a terminal, run C:\Python27\Scripts\pip.exe install cobra (you may need to adjust the path accordingly).
To install without pip, you will need to download and use the appropriate installer for your version of python from the python package index.
Installation for development
Get the detailed contribution instructions for contributing to cobrapy.
Installation of optional dependencies
On windows, these can downloaded from [this site] (http://www.lfd.uci.edu/~gohlke/pythonlibs/). On Mac/Linux, they can be installed using pip, or from the OS package manager (e.g brew, apt, yum).
- libsbml >= 5.10 to read/write SBML level 2
- Windows libsbml installer
- Use sudo pip install python-libsbml on Mac/Linux
- lxml to speed up read/write of SBML level 3 files.
- numpy >= 1.6.1 for double deletions
- scipy >= 0.11 for ArrayBasedModel and saving to *.mat files.
- pytest and pytest-benchmark are required for testing
You can install all packages directly by
pip install "cobra[all]"
cobrapy comes with bindings to the GNU Linear Programming Kit ([glpk] (http://www.gnu.org/software/glpk/)) using its own bindings called “cglpk” in cobrapy. In addition, cobrapy currently supports these linear programming solvers:
- ILOG/CPLEX (available with Academic and Commercial licenses).
- QSopt_ex esolver
- coin-or clp and cbc through cylp.
ILOG/CPLEX, MOSEK, and Gurobi are commercial software packages that currently provide free licenses for academics and support both linear and quadratic programming. GLPK and clp are open source linear programming solvers; however, they may not be as robust as the commercial solvers for mixed-integer and quadratic programming. QSopt_ex esolver is also open source, and can solve linear programs using rational operations, giving exact solutions.
Testing your installation
While it is not a hard requirement for using cobrapy, you need pytest and pytest-benchmark to run its tests. First do
pip install pytest pytest-benchmark
or to install cobrapy directly with the test dependencies
pip install "cobra[test]"
Then start python and type the following into the Python shell
from cobra.test import test_all test_all()
You should see some skipped tests and expected failures, and the function should return True.