PySB static model visualizations (pyvipr.pysb_viz.static_viz)

class pyvipr.pysb_viz.static_viz.PysbStaticViz(model, generate_eqs=True)[source]

Class to generate static visualizations of systems biology models

Parameters
  • model (pysb.Model) – PySB Model to visualize.

  • generate_eqs (bool) – If True, generate math expressions for reaction rates and species in a model

atom_rules_view(visualize_args, rule_name=None, verbose=False, cleanup=True)[source]

Uses the BioNetGen atom-rules to visualize large rule-base models. For more information regarding atom-rules and its parameters please visit: Sekar et al (2017), Automated visualization of rule-based models https://doi.org/10.1371/journal.pcbi.1005857

The visualize_args parameter contains all the arguments that will be passed to the BioNetGen visualize function. It is a dictionary and supports the following key, value pairs.

  • type

    • conventional => Conventional rule visualization

    • compact => Compact rule visualization (using graph operation nodes)

    • regulatory => Rule-derived regulatory graph

    • opts => Options template for regulatory graph

    • contactmap => Contact map

    • reaction_network => Reaction network

  • suffix

  • str => add suffix string to output filename

  • each

    • 1 => Show all rules in separate GML files

    • 0 => Show all rules the same GML file.

  • opts

    • file path => import options from file

  • background

    • 1 => Enable background

    • 0 => Disable background

  • groups

    • 1 => Enable groups

    • 0 => Disable groups

  • collapse

    • 1 => Enable collapsing of groups

    • 0 => Disable collapsing of groups

  • ruleNames

    • 1 => Enable display of rule names

    • 0 => Disable display of rule names

  • doNotUseContextWhenGrouping

    • 1 => Use permissive edge signature

    • 0 => Use strict edge signature

  • doNotCollapseEdges:

    • 1 => When collapsing nodes, retain duplicate edges

    • 0 => When collapsing nodes, remove duplicate edges

visualize_args: dict

Contains all the arguments that will be passed to the BioNetGen visualize function. The following key, value pairs are available

rule_namestr

Name of the rule to visualize, when each is set to 1 in visualize_args.

cleanupbool, optional

If True (default), delete the temporary files after the simulation is finished. If False, leave them in place. Useful for debugging.

verbosebool or int, optional (default: False)

Sets the verbosity level of the logger. See the logging levels and constants from Python’s logging module for interpretation of integer values. False is equal to the PySB default level (currently WARNING), True is equal to DEBUG.

cluster_rxns_by_rules_view()[source]

Cluster reaction nodes into the rules that generated them

Returns

A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes,edges, parent nodes, positions) to generate a cytoscapejs network.

Return type

dict

compartments_data_graph()[source]

Create a networkx DiGraph. Check for compartments in a model and add the compartments as compound nodes where the species are located

Returns

Graph with model species and compartments

Return type

nx.Digraph

Raises

ValueError – Model has not compartments

static graph_merge_pair_edges(graph, reactions=None)[source]

Merges pair of edges that are reversed

Parameters
  • graph (nx.DiGraph or nx.MultiDiGraph) – The networkx directed graph whose pairs of edges ((u, v), (v, u)) are going to be merged

  • reactions (pysb.ComponentSet) – Model reactions

Returns

Graph that has the information for the visualization of the model

Return type

nx.Digraph

highlight_nodes_view(species=None, reactions=None)[source]

Highlights the species and/or reactions passed as arguments

Parameters
  • species (list-like) – It can be a vector with the indices of the species to be highlighted, or a vector with the concrete pysb.ComplexPattern species to be highlighted

  • reactions (list-like) – A vector of tuples of length 2, where the first entry is the edge source and the second entry is the edge target, entries can be species indices or complex patterns. Or it can be a vector of integers that represent the indices of the reactions to highlight.

Returns

A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes,edges, positions) to generate a cytoscapejs network.

Return type

dict

static merge_nodes(G, nodes, new_node, **attr)[source]

Merges the selected nodes of the graph G into one new_node, meaning that all the edges that pointed to or from one of these nodes will point to or from the new_node. attr_dict and **attr are defined as in G.add_node.

merge_reactions2rules(graph)[source]

Merges the model reactions into each of the rules from which the reactions come form.

Returns

Dictionary whose keys are tuples of rule name and rule index and the values are the reactions that are generated by each rule

Return type

dict

projected_graph(graph, project_to, reactions=None)[source]

Project a bipartite graph into one of the sets of nodes

Parameters
  • graph (nx.DiGraph) – a networkx bipartite graph

  • project_to (str) – One of the following options species_from_bireactions, species_from_rules, bireactions, rules

  • reactions (pysb.ComponentSet) – Model reactions

Returns

Projected graph

Return type

nx.DiGraph

projected_species_from_bireactions_view()[source]

This is a projection from the species & bidirectioanl reactions bipartite graph

sp_comm_louvain_hierarchy_view(random_state=None)[source]

Use the Louvain algorithm https://en.wikipedia.org/wiki/Louvain_Modularity for community detection to find groups of nodes that are densely connected. It generates the data of all the intermediate clusters obtained during the Louvain algorithm generate to create a network with compound nodes that hold the communities.

Parameters

random_state (int, optional) – Random state seed use by the community detection algorithm, by default None

Returns

A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes,edges, parent nodes, positions) to generate a cytoscapejs network.

Return type

dict

sp_comm_louvain_view(random_state=None)[source]

Use the Louvain algorithm https://en.wikipedia.org/wiki/Louvain_Modularity for community detection to find groups of nodes that are densely connected. It generates the data to create a network with compound nodes that hold the communities.

Parameters

random_state (int, optional) – Random state seed use by the community detection algorithm, by default None

Returns

A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes,edges, parent nodes, positions) to generate a cytoscapejs network.

Return type

dict

sp_comp_view()[source]

Generate a dictionary that contains the information about the species network. Species are grouped by the compartments they belong to

Returns

A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes, parent_nodes, edges, positions) to generate a cytoscapejs network.

Return type

dict

sp_rules_fxns_view()[source]

Generates a dictionary with the info of a bipartite graph where one set of nodes is the model species and the other set is the model rules. Additionally, it adds information of the functions from which the rules come from.

Returns

A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes,edges, parent nodes, positions) to generate a cytoscapejs network.

Return type

dict

sp_rules_graph()[source]

Creates a bipartite nx.DiGraph graph where one set of nodes is the model species and the other set is the model rules.

Returns

Graph that has the information for the visualization of the model

Return type

nx.Digraph

sp_rules_mod_view()[source]

Generates a dictionary with the info of a bipartite graph where one set of nodes is the model species and the other set is the model rules. Additionally, it adds information of the modules from which the rules come from.

Returns

A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes,edges, parent nodes, positions) to generate a cytoscapejs network.

Return type

dict

sp_rules_view()[source]

Generates a dictionary with the info of a bipartite graph where one set of nodes is the model species and the other set is the model rules

Returns

A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes,edges, parent nodes, positions) to generate a cytoscapejs network.

Return type

dict

sp_rxns_bidirectional_graph(two_edges=False)[source]

Creates a bipartite nx.DiGraph graph where one set of nodes is the model species and the other set is the model bidirectional reactions.

Parameters

two_edges (bool) – If true, it draws two edges (in opposite directions) for each reversible reaction

Returns

Graph that has the information for the visualization of the model

Return type

nx.Digraph

sp_rxns_bidirectional_view()[source]

Generate a dictionary with the info of a bipartite graph where one set of nodes is the model species and the other set is the model bidirectional reactions

Returns

A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes,edges, parent nodes, positions) to generate a cytoscapejs network.

Return type

dict

sp_rxns_graph()[source]

Creates a bipartite nx.DiGraph graph where one set of nodes is the model species and the other set is the model unidirectional reactions.

Returns

Graph that has the information for the visualization of the model

Return type

nx.Digraph

sp_rxns_view()[source]

Generates a dictionary with the info of a bipartite graph where one set of nodes is the model species and the other set is the unidirectional reactions

Returns

A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes,edges, parent nodes, positions) to generate a cytoscapejs network.

Return type

dict

sp_view()[source]

Generate a dictionary that contains the species network information

Examples

>>> from pysb.examples.earm_1_0 import model
>>> viz = PysbStaticViz(model)
>>> data = viz.sp_view()
Returns

A Dictionary object that can be converted into Cytoscape.js JSON. This dictionary contains all the information (nodes,edges, positions) to generate a cytoscapejs network.

Return type

dict

species_graph()[source]

Creates a nx.DiGraph graph of the model species interactions

Returns

Graph that has the information for the visualization of the model

Return type

nx.Digraph

pyvipr.pysb_viz.static_viz.parse_name(spec)[source]

Function that writes short names of the species to name the nodes. It counts how many times a monomer_pattern is present in the complex pattern an its states then it takes only the monomer name and its state to write a shorter name to name the nodes.

Parameters

spec (pysb.ComplexPattern) – Name of species to parse

Returns

Return type

Parsed name of species

PySB Dynamic model visualizations (pyvipr.pysb_viz.dynamic_viz)

class pyvipr.pysb_viz.dynamic_viz.PysbDynamicViz(simulation, sim_idx=0, cmap='RdBu_r')[source]

Class to visualize the dynamics of systems biology models defined in PySB format.

Parameters
  • simulation (pysb SimulationResult) – A SimulationResult instance of the model that is going to be visualized.

  • sim_idx (Index of simulation to be visualized) –

  • cmap (str or Colormap instance) – The colormap used to map the reaction rate values to RGBA colors. For more information visit: https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html

dynamic_sp_comm_view(type_viz='consumption', random_state=None)[source]

Same as dynamic_view() but the species nodes are grouped by the communities they belong to. Communities are obtained using the Louvain algorithm.

Parameters
  • type_viz (str) – Type of visualization. It can be consumption to see how species are being consumed or production to see how the species are being produced.

  • random_state (int) – Seed used by the random generator in community detection

Returns

A Dictionary Object with all nodes and edges information that can be converted into Cytoscape.js JSON to be visualized

Return type

dict

dynamic_sp_comp_view(type_viz='consumption')[source]

Same as dynamic_view() but the species nodes are grouped by the compartments they belong to

dynamic_sp_view(type_viz='consumption')[source]

Generates a dictionary with the model dynamics data that can be converted in the Cytoscape.js JSON format

Parameters

type_viz (str) – Type of the dynamic visualization, it can be ‘consumption’ or ‘production’

Examples

>>> from pysb.examples.earm_1_0 import model
>>> from pysb.simulator import ScipyOdeSimulator
>>> import pyvipr.pysb_viz.dynamic_viz as viz
>>> import numpy as np
>>> tspan = np.linspace(0, 20000)
>>> sim = ScipyOdeSimulator(model, tspan).run()
>>> dyn_viz = viz.PysbDynamicViz(sim)
>>> data = dyn_viz.dynamic_sp_view()
Returns

A Dictionary Object with all nodes and edges information that can be converted into Cytoscape.js JSON to be visualized

Return type

dict

edges_colors_sizes()[source]

This function obtains values for the size and color of the edges in the network. The color is a representation of the percentage of flux going through an edge. The edge size is a representation of the relative value of the reaction normalized to the maximum value that the edge can attain during the whole simulation.

Returns

Three dictionaries. The first one contains the information of the edge sizes at all time points. The second one contains the information of the edge colors at all time points. The third one contains the values of the reaction rates at all time points.

Return type

tuple

matrix_bidirectional_rates(rxns_idxs=None)[source]

Obtains the values of the reaction rates at all the time points of the simulation

Returns

Array with the reaction rates values

Return type

np.ndarray

node_data()[source]

Obtains the species concentration values and the relative concentration compared with the maximum concentration across all time points

Returns

Two dictionaries. The first one has the species concentration. The second one has the relative species concentrations

Return type

tuple

PySB visualization views (pyvipr.pysb_viz.views)

pyvipr.pysb_viz.views.sp_view(model, layout_name='cose-bilkent')[source]

Render a visualization of the interactions between the species in a model.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.sp_comp_view(model, layout_name='cose-bilkent')[source]

Render a visualization of the interactions between the species in a model. The species nodes are grouped by the compartments they belong to.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.sp_comm_louvain_view(model, layout_name='klay', random_state=None)[source]

Render a visualization of the interactions between the species in a model. The species nodes are grouped by the communities detected by the Louvain algorithm: https://en.wikipedia.org/wiki/Louvain_Modularity.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

  • random_state (int) – Random state seed use by the community detection algorithm

pyvipr.pysb_viz.views.sp_comm_louvain_hierarchy_view(model, layout_name='klay', random_state=None)[source]

Render a visualization of the interactions between the species in a model. The species nodes are grouped by the communities detected by the Louvain algorithm: https://en.wikipedia.org/wiki/Louvain_Modularity.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

  • random_state (int) – Random state seed use by the community detection algorithm

pyvipr.pysb_viz.views.sp_comm_greedy_view(model, layout_name='klay')[source]

Render a visualization of the interactions between the species in a model. The species nodes are grouped by the communities detected by the Clauset-Newman-Moore greedy modularity maximization algorithm implemented in Networkx

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.sp_comm_asyn_lpa_view(model, random_state=None, layout_name='klay')[source]

Render a visualization of the interactions between the species in a model. The species nodes are grouped by the communities detected by the asynchronous label propagation algorithm implemented in Networkx.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

  • random_state (int) – Random state seed use by the community detection algorithm

pyvipr.pysb_viz.views.sp_comm_label_propagation_view(model, layout_name='klay')[source]

Render a visualization of the interactions between the species in a model. The species nodes are grouped by the communities detected by the label propagation algorithm implemented in Networkx.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.sp_comm_girvan_newman_view(model, layout_name='klay')[source]

Render a visualization of the interactions between the species in a model. The species nodes are grouped by the communities detected by the Girvan-Newman method implemented in Networkx.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.sp_comm_asyn_fluidc_view(model, k, max_iter=100, random_state=None, layout_name='fcose')[source]

Render a visualization of the interactions between the species in a model. The species nodes are grouped by the communities detected by the asynchronous label propagation algorithm implemented in Networkx.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • k (int) – The number of communities to be found

  • max_iter (int) – The number of maximum iterations allowed

  • random_state (int) – Random state seed use by the community detection algorithm

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.sp_rxns_bidirectional_view(model, layout_name='cose-bilkent')[source]

Render a visualization of a bipartite graph where one set of nodes are the molecular species in the model and the other set are the bidirectional reactions.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.sp_rxns_view(model, layout_name='cose-bilkent')[source]

Render a visualization of a bipartite graph where one set of nodes are the molecular species in the model and the other set are the unidirectional reactions.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.sp_rules_view(model, layout_name='cose-bilkent')[source]

Render a visualization of a bipartite graph where one set of nodes are the molecular species in the model and the other set are the rules.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.sp_rules_fxns_view(model, layout_name='cose-bilkent')[source]

Render a visualization of a bipartite graph where one set of nodes are the molecular species in the model and the other set are the rules. Additionally, rules are grouped by the macros that created them.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.sp_rules_mod_view(model, layout_name='cose-bilkent')[source]

Render a visualization of a bipartite graph where one set of nodes are the molecular species in the model and the other set are the rules. Additionally, rules are grouped by the modules where they are defined.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.projected_species_from_bireactions_view(model, layout_name='cose-bilkent')[source]

Render a visualization of the interactions between species in a model.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.projected_bireactions_view(model, layout_name='cose-bilkent')[source]

Render a visualization of the interaction between the reaction in a model

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.projected_rules_view(model, layout_name='cose-bilkent')[source]

Render a visualization of the interactions between rules in a model.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.projected_species_from_rules_view(model, layout_name='cose-bilkent')[source]

Render a visualization of a bipartite graph where one set of nodes are the molecular species in the model and the other set are the rules.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.cluster_rxns_by_rules_view(model, layout_name='fcose')[source]

Render a visualization of the interactions between the reactions in a model. Reaction nodes are grouped by the rules that generated them.

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • layout_name (str) – Layout to use

pyvipr.pysb_viz.views.sp_dyn_view(simulation, sim_idx=0, process='consumption', layout_name='cose-bilkent', cmap='RdBu_r')[source]

Render a dynamic visualization of the simulation

Parameters
  • simulation (pysb.SimulationResult) – Simulation result to visualize

  • sim_idx (int) – Index of simulation to be visualized

  • process (str) – Type of the dynamic visualization, it can be ‘consumption’ or ‘production’

  • layout_name (str) – Layout to use

  • cmap (str or Colormap instance) – The colormap used to map the reaction rate values to RGBA colors. For more information visit: https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html

pyvipr.pysb_viz.views.sp_comp_dyn_view(simulation, sim_idx=0, process='consumption', layout_name='cose-bilkent', cmap='RdBu_r')[source]

Render a dynamic visualization of the simulation. The species nodes are grouped by the compartments they belong to.

Parameters
  • simulation (pysb.SimulationResult object) – Simulation result to visualize dynamically

  • sim_idx (int) – Index of simulation to be visualized

  • process (str) – Type of the dynamic visualization, it can be ‘consumption’ or ‘production’

  • layout_name (str) – Layout to use

  • cmap (str or Colormap instance) – The colormap used to map the reaction rate values to RGBA colors. For more information visit: https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html

pyvipr.pysb_viz.views.sp_comm_dyn_view(simulation, sim_idx=0, process='consumption', layout_name='klay', cmap='RdBu_r', random_state=None)[source]

Render a dynamic visualization of the simulation. The species nodes are grouped by the communities detected by the Louvain algorithm

Parameters
  • simulation (pysb.SimulationResult object) – Simulation result to visualize dynamically

  • sim_idx (int) – Index of simulation to be visualized

  • process (str) – Type of the dynamic visualization, it can be ‘consumption’ or ‘production’

  • layout_name (str) – Layout to use

  • cmap (str or Colormap instance) – The colormap used to map the reaction rate values to RGBA colors. For more information visit: https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html

  • random_state (int) – Random state seed use by the community detection algorithm

pyvipr.pysb_viz.views.sim_model_dyn_view(model, tspan, param_values=None, type_of_viz='dynamic_view', process='consumption', cmap='RdBu_r', layout_name='cose-bilkent')[source]

Render a dynamic visualization of the model using the tspan and param_values passed to the function

Parameters
  • model (pysb.model or str) – Model to visualize. It can be a pysb model, or the file path to an an SBML or BNGL model

  • tspan (vector-like, optional) – Time values over which to simulate. The first and last values define the time range.

  • param_values (vector-like or dict, optional) – Values to use for every parameter in the model. Ordering is determined by the order of model.parameters. If passed as a dictionary, keys must be parameter names. If not specified, parameter values will be taken directly from model.parameters.

  • type_of_viz (str) – Type of visualization. It can only be sp_dyn_view, sp_comp_dyn_view or sp_comm_dyn_view

  • process (str) – Type of the dynamic visualization, it can be ‘consumption’ or ‘production’

  • cmap (str or Colormap instance) – The colormap used to map the reaction rate values to RGBA colors. For more information visit: https://matplotlib.org/3.1.0/tutorials/colors/colormaps.html

  • layout_name (str) – Layout name to use