Skip to content

Commit

Permalink
Enable running biomass without Graphviz (#162)
Browse files Browse the repository at this point in the history
* Enable running biomass without Graphviz

* Don't check pygraphviz in dynamic_plot

* Remove _check_pygraphviz

* Update installation

* Remove Graphviz from requirements

* Bump version to 0.9.1
  • Loading branch information
Hiroaki Imoto authored Jul 27, 2022
1 parent f371c55 commit fc464df
Show file tree
Hide file tree
Showing 7 changed files with 22 additions and 41 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ jobs:
run: |
python -m pip install --upgrade pip
python -m pip install flake8 pytest
if [ -f requirements.txt ]; then pip install -r requirements.txt; fi
pip install .[graph]
- name: Lint with flake8
run: |
# stop the build if there are Python syntax errors or undefined names
Expand Down
2 changes: 0 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ $ pip install biomass

BioMASS supports Python 3.7 or newer.

:ledger: **Note: You will need to manually install [Graphviz](https://www.graphviz.org) (version 2.42 or later).**

## References

- Imoto, H., Zhang, S. & Okada, M. A Computational Framework for Prediction and Analysis of Cancer Signaling Dynamics from RNA Sequencing Data—Application to the ErbB Receptor Signaling Pathway. _Cancers_ **12**, 2878 (2020). https://doi.org/10.3390/cancers12102878
Expand Down
23 changes: 14 additions & 9 deletions biomass/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,6 @@
from types import ModuleType
from typing import List, Literal, Optional

import pygraphviz as pgv
from pyvis.network import Network


class NetworkGraph(object):
"""
Expand Down Expand Up @@ -52,6 +49,8 @@ def __init__(self, path: str, biomass_model: ModuleType):
self.viz = biomass_model.Visualization()
self.rxn = biomass_model.ReactionNetwork()

self.graph = None

@property
def path(self) -> str:
return self._path
Expand Down Expand Up @@ -129,7 +128,7 @@ def to_graph(self) -> None:
"""Constructs a directed graph of the model.
Using the pygraphviz library a directed graph of the model is constructed by parsing the equations from
ode.py/reaction_network.py. Equations will be split at the equal sign and an edge is added between the species on the
lefthand side to all species on the righthand side. Self references will not be considered.
lefthand side to all species on the right hand side. Self references will not be considered.
Raises
------
Expand All @@ -141,6 +140,11 @@ def to_graph(self) -> None:
UserWarning
If species equations are detected outside of the ODE section.
"""
try:
import pygraphviz as pgv
except ImportError:
print("pygraphviz is required to run this function.")

use_flux = False
try:
if len(self.rxn.flux(0, self.ival(), self.pval())) > 0:
Expand Down Expand Up @@ -218,9 +222,7 @@ def static_plot(
Creates graph with dot layout in pdf file format. Nodes will be rectangular and colored bisque, edges will have no arrows indicating direction.
"""
try:
_ = self.graph
except AttributeError:
if self.graph is None:
self.to_graph()
if gviz_prog not in (available_layout := ["neato", "dot", "twopi", "circo", "fdp", "nop"]):
raise ValueError(
Expand Down Expand Up @@ -267,8 +269,11 @@ def dynamic_plot(
Creates interactive graph. Controls for physics, manipulation and interaction will be available.
"""
try:
_ = self.graph
except AttributeError:
from pyvis.network import Network
except ImportError:
print("pyvis is required to run this function.")

if self.graph is None:
self.to_graph()
if os.path.splitext(file_name)[1] != ".html":
file_name = file_name + ".html"
Expand Down
2 changes: 1 addition & 1 deletion biomass/version.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
"""BioMASS library version"""
__version__ = "0.9.0"
__version__ = "0.9.1"
28 changes: 2 additions & 26 deletions docs/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -12,32 +12,8 @@ Install BioMASS from PyPI using::
pip install biomass

.. Note::
You will need to manually install `Graphviz <https://www.graphviz.org>`_ (version 2.42 or later).

Linux (Ubuntu and Debian)
^^^^^^^^^^^^^^^^^^^^^^^^^

.. code-block::
$ sudo apt-get install graphviz graphviz-dev
Linux (Fedora and Red Hat)
^^^^^^^^^^^^^^^^^^^^^^^^^^

You may need to replace ``dnf`` with ``yum`` in the example below.

.. code-block::
$ sudo dnf install graphviz graphviz-devel
macOS
^^^^^

Use the Homebrew package manager.

.. code-block::
$ brew install graphviz
If you wish to use `graph visualization functions <https://biomass-core.readthedocs.io/en/latest/graph_visualization.html>`_, install biomass via ``pip install biomass[graph]``.
In that case you will need to manually install `Graphviz <https://www.graphviz.org>`_ (version 2.42 or later).

Development version
-------------------
Expand Down
2 changes: 0 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
matplotlib>=3.0
numpy>=1.17
pandas>=0.24
pygraphviz>=1.9
pyvis>=0.2.1
scipy>=1.6 # integrate.simps was renamed to integrate.simpson (v1.6.0)
seaborn>=0.11.2
tqdm>=4.50.2
4 changes: 4 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ def setup_package():
packages=find_packages(exclude=["tests", "docs"]),
install_requires=get_install_requires(),
extras_require={
"graph": [
"pygraphviz>=1.9",
"pyvis>=0.2.1",
],
"dev": [
"black>=20.8b1",
"flake8",
Expand Down

0 comments on commit fc464df

Please sign in to comment.