PyViPR Tutorial and PySB interface

Pyvipr is an ipython widget for interactively visualizing systems biology models. It has an interface to both PySB and Tellurium for generating network data and simulating trajectories, and uses Cytoscape.js to render static and dynamic networks. It supports visualization of BioNetGen and SBML models through the PySB importer module.

Start Jupyter Notebook

To start the jupyter notebook just run the following command in the terminal

jupyter notebook

How to interact with the widget

All visualizations have a search button that can be used to find nodes in large networks. This search function displays information about the species label and the type of node (species, reaction, rule, …). Also, there is a fit button to center the nodes into the display area, a layout dropdown to select a layout for the network, and a button to save the visualization into a png file. Additionally, there is a Group button that can be use to embbed selected nodes into a hyper node.

Dynamic visualizations have a play ▶ a pause ❚❚ and refresh button ↻ to control the visualization. In addition, there is a slider that can be grabbed and dragged to go to a specific time point of the simulation.

Gestures supported by cytoscape.js to interact with the widget:

  • Grab and drag background to pan : touch & desktop

  • Pinch to zoom : touch & desktop (with supported trackpad)

  • Mouse wheel to zoom : desktop

  • Two finger trackpad up or down to zoom : desktop

  • Tap to select : touch & desktop

  • Tap background to unselect : desktop

  • Taphold background to unselect : desktop & touch

  • Multiple selection via modifier key (shift, command, control, alt) + tap : desktop

  • Box selection : touch (three finger swipe) & desktop (modifier key + mousedown then drag)

  • Grab and drag nodes : touch & desktop

Additional gestures added by the widget * Click on a nodes to display connecting nodes: touch & desktop * Click on compound nodes to show containing nodes: touch & desktop

PySB interface

Function

Description

sp_view(model)

Shows network of interacting species

sp_comp_view(model)

Shows network of species in their respective compartments

sp_comm_louvain_view(model)

Shows network of species grouped in communities

sp_rxns_bidirectional_view(model)

Shows bipartite network with species and bidirectional rections nodes

sp_rxns_view(model)

Shows bipartite network with species and unidirectional rections nodes

sp_rules_view(model)

Shows bipartite network with species and rules nodes

sp_rules_fxns_view(model)

Shows bipartite network with species and rules nodes. Rules nodes are grouped in the functions they come from

sp_rules_mod_view(model)

Shows bipartite network with species and rules nodes. Rules nodes are grouped in the file modules they come from

projected_species_from_bireactions_view(model)

Shows network of species projected from the bipartite(species, reactions) graph

projected_bireactions_view(model)

Shows network of reactions projected from the bipartite(species, reactions) graph

projected_rules_view(model)

Shows network of rules projected from the bipartite(species, rules) graph

projected_species_from_rules_view(model)

Shows network of species projected from the bipartite(species, rules) graph

highlight_nodes_view(model, species, reactions)

Shows network of species and highlights the species and reactions passed as arguments

atom_rules_view(model, visualize args, ...)

Uses the BioNetGen atom-rules to visualize large rule-base models. Please visit PyViPR documentation for parameter details.

sp_dyn_view(SimulationResult)

Shows a species network. Edges size and color are updated according to reaction rate values. Nodes filling are updated according to concentration

sp_comp_dyn_view(SimulationResult)

Same as sp_dyn_view but species nodes are grouped by the compartments on which they are located

sp_comm_dyn_view(SimulationResult)

Same as sp_dyn_view but species nodes are grouped by communities

Import pyvipr pysb_viz module and a PySB model

[1]:
from pyvipr.examples_models.lopez_embedded import model
import pyvipr.pysb_viz as viz

Species view

In this type of visualization nodes represent molecular species of the model, and the edges represent the reactions that occur among different species.

[2]:
viz.sp_view(model)

Communities view

In this type of visualization nodes represent molecular species of the model, and the edges represent the reaction that occur among different species. Densely connected nodes are grouped into communities that are represented by compound nodes.

[3]:
viz.sp_comm_louvain_view(model, layout_name='klay', random_state=1)

Bipartite graph with species and bidirectional reactions nodes

There are two different sets of nodes in this visualization. Molecular species nodes and reaction nodes that indicate how species react. Reaction nodes have incoming edges that connect it with reactant species and outgoing edges that connect it with the product of the reaction.

[4]:
viz.sp_rxns_bidirectional_view(model)

Bipartite graph with species and rules nodes

There are two different sets of nodes in this visualization. Molecular species nodes and rules nodes that indicate how species react. Rules nodes have incoming edges that connect it with reactant species and outgoing edges that connect it with the product of the rule.

[5]:
viz.sp_rules_view(model, layout_name='cose-bilkent')

Bipartite graph with species and rules nodes from incorrect model

[6]:
from pyvipr.examples_models.earm_incorrect import model as model_incorrect
viz.sp_rules_view(model_incorrect, layout_name='cose-bilkent')

Bipartite graph with species and rules nodes. Rules are grouped by the functions that were used to create them.

There are two different sets of nodes in this visualization. Molecular species nodes and rules nodes that indicate how species react. Rules nodes have incoming edges that connect it with reactant species and outgoing edges that connect it with the product of the rule. Additionally, rules are grouped by the python functions that were used to create them.

[7]:
viz.sp_rules_fxns_view(model, layout_name='fcose')

Bipartite graph with species and rules nodes. Rules are grouped by the modules they come from

There are two different sets of nodes in this visualization. Molecular species nodes and rules nodes that indicate how species react. Rules nodes have incoming edges that connect it with reactant species and outgoing edges that connect it with the product of the rule. Additionally, rules are grouped by the python files where the rules were defined.

[8]:
viz.sp_rules_mod_view(model, layout_name='fcose')

Species graph grouped by the compartment in which they are located

In this type of visualization nodes represent molecular species of the model, and the edges represent the reaction that occur among different species. Additionally, nodes are grouped by the cellular compartment they belong to.

Note: In order to use this type of visualization your model must have compartments defined.

[9]:
from pyvipr.examples_models.organelle_transport import model as model_compartments
viz.sp_comp_view(model_compartments)

Using a BioNetGen file (.bngl) to visualize the model

This widget accepts models defined in the BioNetGen format. All the static visualizations are available for this format. It requires the extension of the file to be .bngl

[10]:
import os
import pyvipr.examples_models as models
models_path = os.path.dirname(models.__file__)
organelle_model_path = os.path.join(models_path, 'organelle_transport.bngl')
[11]:
viz.sp_view(organelle_model_path)

Visualizing a large rule-based model using the atom-rules graph

[12]:
opts_path = os.path.join(models_path, 'ensemble_1_bng/ensemble_1_opts.txt')
ensemble_model_path = os.path.join(models_path, 'ensemble_1_bng/ensemble_1.bngl')
visualize_compressed = {'type': 'regulatory',
                        'opts': opts_path,
                        'groups': 1, 'collapse': 1, 'doNotUseContextWhenGrouping': 1, 'ruleNames': 1,
                        'removeReactantContext': 1, 'suffix': 'compressed'}
viz.atom_rules_view(ensemble_model_path, visualize_compressed)

Dynamic visualization of a model

In this type of visualization nodes represent molecular species of the model, and the edges represent the reaction that occur among different species. The node pie charts are a representation of the concentration relative to the maximum concentration across all time points. The thickness of the edges is a representation of the order of magnitude of the reaction rates.

We first simulate the model with pysb and pass the SimulationResult to the widget

[13]:
import numpy as np
from pysb.simulator import ScipyOdeSimulator
from pyvipr.examples_models.mm_two_paths_model import model as model_dynamic

tspan = np.linspace(0, 20000, 100)
sim_compartments = ScipyOdeSimulator(model, tspan, compiler='python').run()
[14]:
viz.sp_comm_dyn_view(sim_compartments, random_state=1)
[ ]: