graphspace_python.graphs.classes package

Submodules

graphspace_python.graphs.classes.gsgraph module

class graphspace_python.graphs.classes.gsgraph.GSGraph(*args, **kwargs)[source]

Bases: networkx.classes.digraph.DiGraph

GSGraph class.

A GSGraph stores the details of a graph that is understood by GraphSpace.

It stores nodes and edges of a graph with some data attributes in an organised json structure.

It also stores the style attributes of the respective nodes and edges in an organised json structure.

It holds the information about the graph such as name, tags and viewability status.

It provides methods to define, modify and delete the details of the graph.

name

Name of graph.

Type:str
is_public

Visibility status of graph. Has value 0 if graph is private, 1 if graph is public.

Type:int
style_json

Json representation for graph style.

Type:dict
graph_json

Json representation for graph structure.

Type:dict
tags

Tags of graph.

Type:List[str]
data

Metadata of graph.

Type:dict
node

Json representation for nodes of graph.

Type:dict
edge

Json representation for edges of graph.

Type:dict
ALLOWED_ARROW_FILL = ['filled', 'hollow']
ALLOWED_ARROW_SHAPES = ['tee', 'triangle', 'triangle-tee', 'triangle-backcurve', 'square', 'circle', 'diamond', 'none']
ALLOWED_EDGE_STYLES = ['solid', 'dotted', 'dashed']
ALLOWED_NODE_BACKGROUND_REPEAT = ['no-repeat', 'repeat-x', 'repeat-y', 'repeat']
ALLOWED_NODE_BORDER_STYLES = ['solid', 'dotted', 'dashed', 'double']
ALLOWED_NODE_SHAPES = ['rectangle', 'roundrectangle', 'ellipse', 'triangle', 'pentagon', 'hexagon', 'heptagon', 'octagon', 'star', 'diamond', 'vee', 'rhomboid']
ALLOWED_NODE_TEXT_TRANSFORM = ['none', 'uppercase', 'lowercase']
ALLOWED_NODE_TEXT_WRAP = ['none', 'wrap']
ALLOWED_TEXT_BACKROUND_SHAPE = ['rectangle', 'roundrectangle']
ALLOWED_TEXT_HALIGN = ['left', 'center', 'right']
ALLOWED_TEXT_VALIGN = ['top', 'center', 'bottom']
ALLOWED_TEXT_WRAP = ['wrap', 'none']
EDGE_COLOR_ATTRIBUTES = ['line-color', 'source-arrow-color', 'mid-source-arrow-color', 'target-arrow-color', 'mid-target-arrow-color']
NODE_COLOR_ATTRIBUTES = ['background-color', 'border-color', 'color', 'text-outline-color', 'text-shadow-color', 'text-border-color']
add_edge(source, target, attr_dict=None, directed=False, popup=None, k=None, **attr)[source]

Add an edge to the graph.

Parameters:
  • source (str) – Source node.
  • target (str) – Target node.
  • attr_dict (dict, optional) – Json representation of edge data. Defaults to None.
  • directed (bool, optional) – True if edge is directed, else False. Defaults to False.
  • popup (str, optional) – A string that will be displayed in a popup window when the user clicks the edge. This string can be HTML-formatted information, e.g., Gene Ontology annotations and database links for a protein; or types, mechanism, and database sources for an interaction.
  • k (int, optional) – An integer-valued attribute for the edge, which denotes a rank. Through this attribute, GraphSpace allows the user to filter nodes and edges in a network visualization.
  • **attr – Arbitrary keyword arguments.

Example

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.add_node('a', popup='sample node popup text', label='A')
>>> G.add_node('b', popup='sample node popup text', label='B')
>>> G.add_edge('a', 'b', directed=True, popup='sample edge popup')
>>> G.edges(data=True)
[('a', 'b', {'source': 'a', 'popup': 'sample edge popup',
'is_directed': True, 'target': 'b'})]
add_edge_style(source, target, attr_dict=None, directed=False, color='#000000', width=1.0, arrow_shape='triangle', edge_style='solid', arrow_fill='filled')[source]

Add styling for an edge whose source and target nodes are provided.

Parameters:
  • source (str) – Unique ID of the source node.
  • target (str) – Unique ID of the target node.
  • attr_dict (dict, optional) – Json representation of style of edge. Defaults to None.
  • color (str, optional) – Hexadecimal representation of the color (e.g., #000000), or the color name. Defaults to black.
  • directed (bool, optional) – If True, draw the edge as directed. Defaults to False.
  • width (float, optional) – Width of the edge. Defaults to 1.0.
  • arrow_shape (str, optional) – Shape of arrow head. Defaults to ‘triangle’. See ALLOWED_ARROW_SHAPES for more details.
  • edge_style (str, optional) – Style of edge. Defaults to ‘solid’. See ALLOWED_EDGE_STYLES for more details.
  • arrow_fill (str, optional) – Fill of arrow. Defaults to ‘filled’. See ALLOWED_ARROW_FILL for more details.

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.add_edge_style('a', 'b', directed=True, edge_style='dotted')
>>> G.add_edge_style('b', 'c', arrow_shape='tee', arrow_fill='hollow')
>>> G.get_style_json()
{'style': [{'style': {'width': 1.0, 'line-color': '#000000', 'target-arrow-shape':
'triangle', 'line-style': 'dotted', 'target-arrow-fill': 'filled', 'target-arrow-color':
'#000000'}, 'selector': 'edge[source="a"][target="b"]'}, {'style': {'width': 1.0,
'line-color': '#000000', 'target-arrow-shape': 'none', 'line-style': 'solid',
'target-arrow-fill': 'hollow', 'target-arrow-color': '#000000'}, 'selector':
'edge[source="b"][target="c"]'}]}
add_node(node_name, attr_dict=None, parent=None, label=None, popup=None, k=None, **attr)[source]

Add a node to the graph.

Parameters:
  • node_name (str) – Name of node.
  • attr_dict (dict, optional) – Json representation of node data. Defaults to None.
  • parent (str, optional) – Parent of the node, if any (for compound nodes). Defaults to None.
  • label (str, optional) – Label of node. Defaults to None.
  • popup (str, optional) – A string that will be displayed in a popup window when the user clicks the node. This string can be HTML-formatted information, e.g., Gene Ontology annotations and database links for a protein; or types, mechanism, and database sources for an interaction.
  • k (int, optional) – An integer-valued attribute for the node, which denotes a rank. Through this attribute, GraphSpace allows the user to filter nodes and edges in a network visualization.
  • **attr – Arbitrary keyword arguments.

Example

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.add_node('a', popup='sample node popup text', label='A')
>>> G.add_node('b', popup='sample node popup text', label='B')
>>> G.nodes(data=True)
[('a', {'id': 'a', 'popup': 'sample node popup text', 'name': 'a',
'label': 'A'}), ('b', {'id': 'b', 'popup': 'sample node popup text',
'name': 'b', 'label': 'B'})]
add_node_style(node_name, attr_dict=None, content=None, shape='ellipse', color='#FFFFFF', height=None, width=None, bubble=None, valign='center', halign='center', style='solid', border_color='#000000', border_width=1)[source]

Add styling for a node belonging to the graph.

Parameters:
  • node_name (str) – Name of node.
  • attr_dict (dict, optional) – Json representation of style of node. Defaults to None.
  • shape (str, optional) – Shape of node. Defaults to ‘ellipse’. See ALLOWED_NODE_SHAPES for more details.
  • color (str, optional) – Hexadecimal representation of the color (e.g., #FFFFFF) or color name. Defaults to white.
  • height (int, optional) – Height of the node’s body, or None to determine height from the number of lines in the label. Defaults to None.
  • width (int, optional) – Width of the node’s body, or None to determine width from length of label. Defaults to None.
  • bubble (str, optional) – Color of the text outline. Using this option gives a “bubble” effect; see the bubbleeffect() function. Defaults to None.
  • valign (str, optional) – Vertical alignment. Defaults to ‘center’. See ALLOWED_TEXT_VALIGN for more details.
  • halign (str, optional) – Horizontal alignment. Defaults to ‘center’. See ALLOWED_TEXT_HALIGN for more details.
  • style (str, optional) – Style of border. Defaults to ‘solid’. If ‘bubble’ is specified, then style is overwritten. See ALLOWED_NODE_BORDER_STYLES for more details.
  • border_color (str, optional) – Color of border. Defaults to ‘#000000’. If ‘bubble’ is specified, then style is overwritten.
  • border_width (int, optional) – Width of border. Defaults to 1. If ‘bubble’ is specified, then style is overwritten.

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.add_node('a', popup='sample node popup text', label='A')
>>> G.add_node_style('a', shape='ellipse', color='red', width=90, height=90)
>>> G.add_node('b', popup='sample node popup text', label='B')
>>> G.add_node_style('b', color='blue', width=90, height=90, border_color='#4f4f4f')
>>> G.get_style_json()
{'style': [{'style': {'border-color': '#000000', 'border-width': 1, 'height': 90,
'width': 90, 'shape': 'ellipse', 'border-style': 'solid', 'text-wrap': 'wrap',
'text-halign': 'center', 'text-valign': 'center', 'background-color': 'red'},
'selector': 'node[name="a"]'}, {'style': {'border-color': '#4f4f4f', 'border-width': 1,
'height': 90, 'width': 90, 'shape': 'ellipse', 'border-style': 'solid', 'text-wrap':
'wrap', 'text-halign': 'center', 'text-valign': 'center', 'background-color': 'blue'},
'selector': 'node[name="b"]'}]}
add_style(selector, style_dict)[source]

Add styling for a given selector, for e.g., ‘nodes’, ‘edges’, etc.

Parameters:
  • selector (str) – A selector functions similar to a CSS selector on DOM elements, but here it works on collections of graph elements.
  • style_dict (dict) – Key-value pair of style attributes and their values.

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.add_style('node', {'background-color': '#bbb', 'opacity': 0.8})
>>> G.add_style('edge', {'line-color': 'green'})
>>> G.get_style_json()
{'style': [{'style': {'opacity': 0.8, 'background-color': '#bbb'}, 'selector':
'node'}, {'style': {'line-color': 'green'}, 'selector': 'edge'}]}
static check_color_hex(color_code)[source]

Check the validity of the hexadecimal code of various node and edge color related attributes.

This function returns an error if the hexadecimal code is not of the format ‘#XXX’ or ‘#XXXXXX’, i.e. hexadecimal color code is not valid.

Parameters:color_code (str) – Hex code of color or color name.
Returns:None, if color is valid; error message if color is invalid.
Return type:None or str
delete_legend(gslegend_obj)[source]

Set the json representation of legend for the graph to null.

Parameters:gslegend_obj (object) – GSLegend object having JSON representation of legend for the graph.

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> from graphspace_python.graphs.classes.gslegend import GSLegend
>>> L = GSLegend()
>>> legend_json = {
...         "legend":{
...             "nodes":{
...                 "Source Receptor": {
...                     "shape":"triangle",
...                     "background-color":"#ff1400"
...                  },
...                 "Receptor": {
...                     "shape":"circle",
...                     "background-color":"#1900ff"
...                 }
...             },
...             "edges":{
...                 "Phosphorylation":{
...                     "line-color":"#0fcf25",
...                     "line-style":"solid",
...                     "arrow-shape":"triangle"
...                 }
...             }
...         }
...     }
>>> L.set_legend_json(legend_json)
>>> G = GSGraph()
>>> G.set_name('My Sample Graph')
>>> G.set_tags(['sample'])
>>> G.set_legend(L)
>>> L = G.get_legend()
>>> G.delete_legend(L)
get_data()[source]

Computes the metadata of the graph and returns it.

Returns:Metadata of the graph.
Return type:dict

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.get_data()
{'name': 'Graph 12:10PM on July 20, 2017', 'tags': []}
>>> G.set_name('My sample graph')
>>> G.set_tags(['sample','tutorial'])
>>> G.get_data()
{'name': 'My sample graph', 'tags': ['sample', 'tutorial']}
get_graph_json()[source]

Computes the json representation for the graph structure from the graph nodes and edges and returns it.

Returns:Json representation of graph structure.
Return type:dict

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.get_graph_json()
{'elements': {'nodes': [], 'edges': []}, 'data': {'name':
'Graph 12:10PM on July 20, 2017', 'tags': []}}
>>> G.set_name('My sample graph')
>>> G.add_node('a', popup='sample node popup text', label='A')
>>> G.add_node('b', popup='sample node popup text', label='B')
>>> G.add_edge('a', 'b', directed=True, popup='sample edge popup')
>>> G.get_graph_json()
{'elements': {'nodes': [{'data': {'id': 'a', 'popup': 'sample node popup text',
'name': 'a', 'label': 'A'}}, {'data': {'id': 'b', 'popup': 'sample node popup text',
'name': 'b', 'label': 'B'}}], 'edges': [{'data': {'source': 'a', 'popup':
'sample edge popup', 'is_directed': True, 'target': 'b'}}]}, 'data': {'name':
'My sample graph', 'tags': []}}
get_is_public()[source]

Get visibility status of the graph.

Returns:Visibility status of graph. Either 0 or 1.
Return type:int

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.get_is_public()
0
>>> G.set_is_public(1)
>>> G.get_is_public()
1
get_legend()[source]

Get a GSLegend Object having JSON representation of legend for the graph.

Returns:GSLegend Object having JSON representation of legend for the graph.
Return type:object

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> from graphspace_python.graphs.classes.gslegend import GSLegend
>>> L = GSLegend()
>>> legend_json = {
...         "legend":{
...             "nodes":{
...                 "Source Receptor": {
...                     "shape":"triangle",
...                     "background-color":"#ff1400"
...                  },
...                 "Receptor": {
...                     "shape":"circle",
...                     "background-color":"#1900ff"
...                 }
...             },
...             "edges":{
...                 "Phosphorylation":{
...                     "line-color":"#0fcf25",
...                     "line-style":"solid",
...                     "arrow-shape":"triangle"
...                 }
...             }
...         }
...     }
>>> L.set_legend_json(legend_json)
>>> G = GSGraph()
>>> G.set_name('My Sample Graph')
>>> G.set_tags(['sample'])
>>> G.set_legend(L)
>>> G.get_legend()
<graphspace_python.graphs.classes.gslegend.GSLegend at 0x7f6ae5997e10>
get_name()[source]

Get the name of graph.

Returns:Name of graph.
Return type:str

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.get_name()
'Graph 01:22PM on July 20, 2017'
>>> G.set_name('My sample graph')
>>> G.get_name()
'My sample graph'
get_node_position(node_name)[source]

Get the x,y position of a node.

Parameters:node_name (str) – Name of the node.
Returns:Dict of x,y co-ordinates of the node, if node position is defined; otherwise None.
Return type:dict or None
get_style_json()[source]

Get the json representation for the graph style.

Returns:Json representation of graph style.
Return type:dict

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.get_style_json()
{'style': []}
>>> G.add_node_style('a', shape='ellipse', color='red', width=90, height=90)
>>> G.get_style_json()
{'style': [{'style': {'border-color': '#000000', 'border-width': 1, 'height': 90,
'width': 90, 'shape': 'ellipse', 'border-style': 'solid', 'text-wrap': 'wrap',
'text-halign': 'center', 'text-valign': 'center', 'background-color': 'red'},
'selector': 'node[name="a"]'}]}
get_tags()[source]

Get the tags for the graph.

Returns:List of tags of graph.
Return type:List[str]

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.get_tags()
[]
>>> G.set_tags(['sample', 'tutorial'])
>>> G.get_tags()
['sample', 'tutorial']
json()[source]

Get the json representation of graph details.

Returns:Json representation of graph details.
Return type:dict

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.json()
{'is_public': 0, 'style_json': {'style': []}, 'tags': [], 'name':
'Graph 12:10PM on July 20, 2017', 'graph_json': {'elements': {'nodes': [],
'edges': []}, 'data': {'name': 'Graph 12:10PM on July 20, 2017', 'tags': []}}}
>>> G.set_name('My sample graph')
>>> G.add_node('a', popup='sample node popup text', label='A')
>>> G.add_node_style('a', shape='ellipse', color='red', width=90, height=90)
>>> G.json()
{'is_public': 0, 'style_json': {'style': [{'style': {'border-color': '#000000',
'border-width': 1, 'height': 90, 'width': 90, 'shape': 'ellipse', 'border-style':
'solid', 'text-wrap': 'wrap', 'text-halign': 'center', 'text-valign': 'center',
'background-color': 'red'}, 'selector': 'node[name="a"]'}]}, 'tags': [], 'name':
'My sample graph', 'graph_json': {'elements': {'nodes': [{'data': {'id': 'a',
'popup': 'sample node popup text', 'name': 'a', 'label': 'A'}}], 'edges': []},
'data': {'name': 'My sample graph', 'tags': []}}}
remove_node_position(node_name)[source]

Remove the x,y position of a node.

Parameters:node_name (str) – Name of the node.
Raises:Exception – If node positions are undefined.
set_data(data)[source]

Set the metadata of the graph.

Parameters:data (dict) – Key-value pairs describing the graph.

Example

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.set_name('My sample graph')
>>> G.set_tags(['sample'])
>>> G.set_data({'description': 'A sample graph for demonstration purpose.'})
>>> G.get_data()
{'description': 'A sample graph for demonstration purpose.', 'name':
'My sample graph', 'tags': ['sample']}
static set_edge_color_property(edge_properties, color)[source]

Add a edge color to the edge_properties.

Color both the line and the target arrow; if the edge is undirected, then the target arrow color doesn’t matter. If it’s directed, then the arrow color will match the line color.

Color can be a name (e.g., ‘black’) or an HTML string (e.g., #00000).

Parameters:
  • edge_properties (dict) – Dictionary of edge attributes. Key-value pairs will be used to set data associated with the edge.
  • color (str) – Hexadecimal representation of the color (e.g., #FFFFFF) or color name.
Returns:

Dictionary of edge attributes.

Return type:

dict

Raises:

Exception – If the color is improperly formatted.

static set_edge_directionality_property(edge_properties, directed, arrow_shape='triangle')[source]

Sets a target arrow shape.

Parameters:
  • edge_properties (dict) – Dictionary of edge attributes. Key-value pairs will be used to set data associated with the edge.
  • directed (bool) – If True, draw the edge as directed.
  • arrow_shape (str) – Shape of arrow. Defaults to ‘triangle’. See ALLOWED_ARROW_SHAPES.
Returns:

Dictionary of edge attributes.

Return type:

dict

static set_edge_line_style_property(edge_properties, style)[source]

Adds the edge line style to edge.

Parameters:
  • edge_properties (dict) – Dictionary of edge attributes. Key-value pairs will be used to set data associated with the edge.
  • style (str) – Style of line.
Returns:

Dictionary of edge attributes.

Return type:

dict

static set_edge_target_arrow_fill(edge_properties, fill)[source]

Adds the arrowhead fill to edge.

Parameters:
  • edge_properties (dict) – Dictionary of edge attributes. Key-value pairs will be used to set data associated with the edge.
  • fill (str) – Fill of arrowhead.
Returns:

Dictionary of edge attributes.

Return type:

dict

static set_edge_target_arrow_shape_property(edge_properties, arrow_shape)[source]

Assigns an arrow shape to edge.

Parameters:
  • edge_properties (dict) – Dictionary of edge attributes. Key-value pairs will be used to set data associated with the edge.
  • arrow_shape (str) – Shape of arrow. See ALLOWED_ARROW_SHAPES.
Returns:

Dictionary of edge attributes.

Return type:

dict

static set_edge_width_property(edge_properties, width)[source]

Sets the width property of the edge.

Parameters:
  • edge_properties (dict) – Dictionary of edge attributes. Key-value pairs will be used to set data associated with the edge.
  • width (float) – Width of the edge.
Returns:

Dictionary of edge attributes.

Return type:

dict

set_graph_json(graph_json)[source]

Set the json representation for the graph structure.

Parameters:graph_json (dict) – Json representation for the graph structure.

Example

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> graph_json = {
...     'elements': {
...             'nodes': [
...                     {
...                             'data': {
...                                     'id': 'a',
...                                     'popup': 'sample node popup text',
...                                     'name': 'a',
...                                     'label': 'A'
...                             }
...                     }
...             ],
...             'edges': []
...     },
...     'data': {
...             'name': 'My sample graph',
...             'tags': ['sample', 'tutorial']
...     }
... }
>>> G.set_graph_json(graph_json)
>>> G.get_graph_json()
{'elements': {'nodes': [{'data': {'id': 'a', 'popup': 'sample node popup text',
'name': 'a', 'label': 'A'}}], 'edges': []}, 'data': {'name': 'My sample graph',
'tags': ['sample', 'tutorial']}}
set_is_public(is_public=1)[source]

Set visibility status of the graph.

Parameters:is_public (int, optional) – Visibility status of graph. Defaults to 1.
Raises:Exception – If ‘is_public’ is neither 0 nor 1.

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.set_is_public() # By default takes param 'is_public' as 1.
>>> G.get_is_public()
1
>>> G.set_is_public(0)
>>> G.get_is_public()
0
set_legend(gslegend_obj)[source]

Set the json representation of legend for the graph.

Parameters:gslegend_obj (object) – GSLegend object having JSON representation of legend for the graph.

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> from graphspace_python.graphs.classes.gslegend import GSLegend
>>> L = GSLegend()
>>> legend_json = {
...         "legend":{
...             "nodes":{
...                 "Source Receptor": {
...                     "shape":"triangle",
...                     "background-color":"#ff1400"
...                  },
...                 "Receptor": {
...                     "shape":"circle",
...                     "background-color":"#1900ff"
...                 }
...             },
...             "edges":{
...                 "Phosphorylation":{
...                     "line-color":"#0fcf25",
...                     "line-style":"solid",
...                     "arrow-shape":"triangle"
...                 }
...             }
...         }
...     }
>>> L.set_legend_json(legend_json)
>>> G = GSGraph()
>>> G.set_name('My Sample Graph')
>>> G.set_tags(['sample'])
>>> G.set_legend(L)
set_name(name)[source]

Set the name of the graph.

Parameters:name (str) – Name of graph.

Example

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.set_name('My sample graph')
>>> G.get_name()
'My sample graph'
static set_node_border_color_property(node_properties, border_color)[source]

Set the border_color in node_properties.

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • border_color (str) – Hexadecimal representation of the border color (e.g., #FFFFFF) or a color name.
Returns:

Dictionary of node attributes.

Return type:

dict

Raises:

Exception – If the border_color is improperly formatted.

static set_node_border_style_property(node_properties, border_style)[source]

Set the border width in node_properties.

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • border_style (str) – Style of border.
Returns:

Dictionary of node attributes.

Return type:

dict

Raises:

Exception – If the border_style parameter is not one of the allowed border styles. See ALLOWED_NODE_BORDER_STYLES for more details.

static set_node_border_width_property(node_properties, border_width)[source]

Set the border width in node_properties.

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • border_width (int) – Width of border.
Returns:

Dictionary of node attributes.

Return type:

dict

static set_node_bubble_effect_property(node_properties, color, whitetext=False)[source]

Add a “bubble effect” to the node by making the border color the same as the text outline color.

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • color (str) – Hexadecimal representation of the text outline color (e.g., #FFFFFF) or a color name.
  • whitetext (bool, optional) – If True, text is colored white instead of black. Defaults to False.
Returns:

Dictionary of node attributes.

Return type:

dict

static set_node_color_property(node_properties, color)[source]

Add a background color to the node_properties. Color can be a name (e.g., ‘black’) or an HTML string (e.g., #00000).

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • color (str) – Hexadecimal representation of the color (e.g., #FFFFFF) or color name.
Returns:

Dictionary of node attributes.

Return type:

dict

Raises:

Exception – If the color is improperly formatted.

static set_node_height_property(node_properties, height)[source]

Add a node height property to the node_properties. If the height is ‘None’, then the height of the node is determined by the number of newlines in the label that will be displayed.

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • height (int or None) – Height of the node’s body, or None to determine height from the number of lines in the label.
Returns:

Dictionary of node attributes.

Return type:

dict

static set_node_horizontal_alignment_property(node_properties, halign)[source]

Set the horizontal alignment of label in node_properties.

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • halign (str) – Horizontal alignment of text.
Returns:

Dictionary of node attributes.

Return type:

dict

static set_node_label_property(node_properties, label)[source]

Set ‘label’ to ‘node_properties’ dict and return the ‘node_properties’ dict. The label is stored under ‘content’ in the node information. Also set wrap = ‘wrap’ so newlines are interpreted.

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • label (str) – Text to display on node. Newline sequence will be interpreted as a line break.
Returns:

Dictionary of node attributes.

Return type:

dict

set_node_position(node_name, y, x)[source]

Set the x,y position of a node.

Parameters:
  • node_name (str) – Name of the node.
  • y (float) – y co-ordinate of node.
  • x (float) – x co-ordinate of node.
static set_node_shape_property(node_properties, shape)[source]

Add a shape property “shape” to the node_properties.

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • shape (str) – Shape of node.
Returns:

Dictionary of node attributes.

Return type:

dict

Raises:

Exception – If the shape is not one of the allowed node shapes. See ALLOWED_NODE_SHAPES global variable.

static set_node_vertical_alignment_property(node_properties, valign)[source]

Set the vertical alignment of label in node_properties.

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • valign (str) – Vertical alignment of text.
Returns:

Dictionary of node attributes.

Return type:

dict

static set_node_width_property(node_properties, width)[source]

Add a node width property to the node_properties. If the width is ‘None’, then the width of the node is determined by the length of the label.

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • width (int or None) – Width of the node’s body, or None to determine width from length of label.
Returns:

Dictionary of node attributes.

Return type:

dict

static set_node_wrap_property(node_properties, wrap)[source]

Adding node wrap allows the newline sequence to be interpreted as a line break for the node.

Parameters:
  • node_properties (dict) – Dictionary of node attributes. Key-value pairs will be used to set data associated with the node.
  • wrap (str) – String denoting the type of wrap: one of “wrap” or “none”.
Returns:

Dictionary of node attributes.

Return type:

dict

Raises:

Exception – If the wrap parameter is not one of the allowed wrap styles. See ALLOWED_NODE_TEXT_WRAP for more details.

set_style_json(style_json)[source]

Set the json representation for the graph style.

Parameters:style_json (dict) – Json representation for the graph style.

Example

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> style_json = {
...     'style': [
...             {
...                     'style': {
...                             'border-color': '#000000',
...                             'border-width': 1,
...                             'height': 90,
...                             'width': 90,
...                             'shape': 'ellipse',
...                             'border-style': 'solid',
...                             'text-wrap': 'wrap',
...                             'text-halign': 'center',
...                             'text-valign': 'center',
...                             'background-color': 'red'
...                     },
...                     'selector': 'node[name="a"]'
...             }
...     ]
... }
>>> G.set_style_json(style_json)
>>> G.get_style_json()
{'style': [{'style': {'border-color': '#000000', 'border-width': 1, 'height': 90,
'width': 90, 'shape': 'ellipse', 'border-style': 'solid', 'text-wrap': 'wrap',
'text-halign': 'center', 'text-valign': 'center', 'background-color': 'red'},
'selector': 'node[name="a"]'}]}
set_tags(tags)[source]

Set the tags for the graph.

Parameters:tags (List[str]) – List of tags of graph.

Example

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.set_tags(['sample', 'tutorial'])
>>> G.get_tags()
['sample', 'tutorial']
static validate_edge_data_properties(data_properties, nodes_list)[source]

Validates the data properties.

Parameters:
  • data_properties (dict) – Dict of edge data properties.
  • nodes_list (List[str]) – List of nodes.
Raises:

Exception – If properties are invalid.

static validate_node_data_properties(data_properties, nodes_list)[source]

Validates the data properties.

Parameters:
  • data_properties (dict) – Dict of node data properties
  • nodes_list (List[str]) – List of nodes.
Raises:

Exception – If properties are invalid.

static validate_property(element, element_selector, property_name, valid_property_values)[source]

Goes through array to see if property is contained in the array.

Parameters:
  • element (dict) – Element to search for in network.
  • element_selector (str) – Selector for element in the network.
  • property_name (str) – Name of the property.
  • valid_property_values (List[str]) – List of valid properties.
Returns:

None, if the property is valid or does not exist; error message if property is invalid.

Return type:

None or str

static validate_style_json(style_json)[source]

Validates the json representation of style of graph.

Parameters:style_json (dict) – Json representation for graph style.
Raises:Exception – If properties are invalid.
static validate_style_properties(style_properties, selector)[source]

Validates the style properties.

Parameters:
  • style_properties (dict) – Dict of elements style properties.
  • selector (str) – Selector for the element.
Returns:

None, if properties are valid.

Return type:

None

Raises:

Exception – If properties are invalid.

Note

Refer to http://js.cytoscape.org/#selectors for selectors.

graphspace_python.graphs.classes.gsgroup module

class graphspace_python.graphs.classes.gsgroup.GSGroup(name=None, description=None)[source]

Bases: object

GSGroup class.

A GSGroup stores the details of a group that is understood by GraphSpace.

It holds the information about the group such as name and description.

It provides methods to define, modify and delete the details of the group.

name

Name of group.

Type:str
description

Description of group.

Type:str
get_description()[source]

Get description of the group.

Returns:Description of group.
Return type:str

Example

>>> from graphspace_python.graphs.classes.gsgroup import GSGroup
>>> group = GSGroup(name='My sample group', description='a sample group for demo')
>>> group.get_description()
'a sample group for demo'
get_name()[source]

Get the name of group.

Returns:Name of group.
Return type:str

Example

>>> from graphspace_python.graphs.classes.gsgroup import GSGroup
>>> group = GSGroup(name='My sample group', description='a sample group for demo')
>>> group.get_name()
'My sample group'
json()[source]

Get the json representation of group details.

Returns:Json representation of group details.
Return type:dict

Example

>>> from graphspace_python.graphs.classes.gsgroup import GSGroup
>>> group = GSGroup(name='My sample group', description='a sample group for demo')
>>> group.json()
{'name': 'My sample group', 'description': 'a sample group for demo'}
set_description(description)[source]

Set description of the group.

Parameters:description (str) – Description of group.

Example

>>> from graphspace_python.graphs.classes.gsgroup import GSGroup
>>> group = GSGroup()
>>> group.set_description('a sample group for demo')
>>> group.get_description()
'a sample group for demo'
set_name(name)[source]

Set the name of the group.

Parameters:name (str) – Name of group.

Example

>>> from graphspace_python.graphs.classes.gsgroup import GSGroup
>>> group = GSGroup()
>>> group.set_name('My sample group')
>>> group.get_name()
'My sample group'

graphspace_python.graphs.classes.gslayout module

class graphspace_python.graphs.classes.gslayout.GSLayout[source]

Bases: object

GSLayout class.

A GSLayout stores the details of a layout that is understood by GraphSpace.

It stores the X,Y positions of nodes of a graph in an organised json structure.

It also stores the style attributes of the respective nodes and edges in an organised json structure.

It holds the information about the layout such as name and sharing status.

It provides methods to define, modify and delete the details of the layout.

name

Name of layout.

Type:str
is_shared

Sharing status of layout. Has value 0 if layout is private, 1 if layout is shared.

Type:int
style_json

Json representation for layout style.

Type:dict
positions_json

Json representation for layout node positions.

Type:dict
add_edge_style(source, target, attr_dict=None, directed=False, color='#000000', width=1.0, arrow_shape='triangle', edge_style='solid', arrow_fill='filled')[source]

Add styling for an edge whose source and target nodes are provided.

Parameters:
  • source (str) – Unique ID of the source node.
  • target (str) – Unique ID of the target node.
  • attr_dict (dict, optional) – Json representation of style of edge. Defaults to None.
  • color (str, optional) – Hexadecimal representation of the color (e.g., #000000), or the color name. Defaults to black.
  • directed (bool, optional) – If True, draw the edge as directed. Defaults to False.
  • width (float, optional) – Width of the edge. Defaults to 1.0.
  • arrow_shape (str, optional) – Shape of arrow head. Defaults to ‘triangle’. See ALLOWED_ARROW_SHAPES for more details.
  • edge_style (str, optional) – Style of edge. Defaults to ‘solid’. See ALLOWED_EDGE_STYLES for more details.
  • arrow_fill (str, optional) – Fill of arrow. Defaults to ‘filled’. See ALLOWED_ARROW_FILL for more details.

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.add_edge_style('a', 'b', directed=True, edge_style='dotted')
>>> L.add_edge_style('b', 'c', arrow_shape='tee', arrow_fill='hollow')
>>> L.get_style_json()
{'style': [{'style': {'width': 1.0, 'line-color': '#000000', 'target-arrow-shape':
'triangle', 'line-style': 'dotted', 'target-arrow-fill': 'filled', 'target-arrow-color':
'#000000'}, 'selector': 'edge[source="a"][target="b"]'}, {'style': {'width': 1.0,
'line-color': '#000000', 'target-arrow-shape': 'none', 'line-style': 'solid',
'target-arrow-fill': 'hollow', 'target-arrow-color': '#000000'}, 'selector':
'edge[source="b"][target="c"]'}]}
add_node_style(node_name, attr_dict=None, content=None, shape='ellipse', color='#FFFFFF', height=None, width=None, bubble=None, valign='center', halign='center', style='solid', border_color='#000000', border_width=1)[source]

Add styling for a node belonging to the graph.

Parameters:
  • node_name (str) – Name of node.
  • attr_dict (dict, optional) – Json representation of style of node. Defaults to None.
  • shape (str, optional) – Shape of node. Defaults to ‘ellipse’. See ALLOWED_NODE_SHAPES for more details.
  • color (str, optional) – Hexadecimal representation of the color (e.g., #FFFFFF) or color name. Defaults to white.
  • height (int, optional) – Height of the node’s body, or None to determine height from the number of lines in the label. Defaults to None.
  • width (int, optional) – Width of the node’s body, or None to determine width from length of label. Defaults to None.
  • bubble (str, optional) – Color of the text outline. Using this option gives a “bubble” effect; see the bubbleeffect() function. Defaults to None.
  • valign (str, optional) – Vertical alignment. Defaults to ‘center’. See ALLOWED_TEXT_VALIGN for more details.
  • halign (str, optional) – Horizontal alignment. Defaults to ‘center’. See ALLOWED_TEXT_HALIGN for more details.
  • style (str, optional) – Style of border. Defaults to ‘solid’. If ‘bubble’ is specified, then style is overwritten. See ALLOWED_NODE_BORDER_STYLES for more details.
  • border_color (str, optional) – Color of border. Defaults to ‘#000000’. If ‘bubble’ is specified, then style is overwritten.
  • border_width (int, optional) – Width of border. Defaults to 1. If ‘bubble’ is specified, then style is overwritten.

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.add_node_style('a', shape='ellipse', color='red', width=90, height=90)
>>> L.add_node_style('b', color='blue', width=90, height=90, border_color='#4f4f4f')
>>> L.get_style_json()
{'style': [{'style': {'border-color': '#000000', 'border-width': 1, 'height': 90,
'width': 90, 'shape': 'ellipse', 'border-style': 'solid', 'text-wrap': 'wrap',
'text-halign': 'center', 'text-valign': 'center', 'background-color': 'red'},
'selector': 'node[name="a"]'}, {'style': {'border-color': '#4f4f4f', 'border-width': 1,
'height': 90, 'width': 90, 'shape': 'ellipse', 'border-style': 'solid', 'text-wrap':
'wrap', 'text-halign': 'center', 'text-valign': 'center', 'background-color': 'blue'},
'selector': 'node[name="b"]'}]}
add_style(selector, style_dict)[source]

Add styling for a given selector, for e.g., ‘nodes’, ‘edges’, etc.

Parameters:
  • selector (str) – A selector functions similar to a CSS selector on DOM elements, but here it works on collections of graph elements.
  • style_dict (dict) – Key-value pair of style attributes and their values.

Examples

>>> from graphspace_python.graphs.classes.gsgraph import GSGraph
>>> G = GSGraph()
>>> G.add_style('node', {'background-color': '#bbb', 'opacity': 0.8})
>>> G.add_style('edge', {'line-color': 'green'})
>>> G.get_style_json()
{'style': [{'style': {'opacity': 0.8, 'background-color': '#bbb'}, 'selector':
'node'}, {'style': {'line-color': 'green'}, 'selector': 'edge'}]}
delete_legend(gslegend_obj)[source]

Set the json representation of legend for the layout to null.

Parameters:gslegend_obj (object) – GSLegend object having JSON representation of legend.

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> from graphspace_python.graphs.classes.gslegend import GSLegend
>>> Ld = GSLegend()
>>> legend_json = {
...         "legend":{
...             "nodes":{
...                 "TF": {
...                     "shape":"ellipse",
...                     "background-color":"#ff1400"
...                 }
...             },
...             "edges":{
...                 "Enzymatic Reaction":{
...                     "line-color":"#0fcf25",
...                     "line-style":"solid",
...                     "arrow-shape":"triangle"
...                 }
...             }
...         }
...     }
>>> Ld.set_legend_json(legend_json)
>>> L = GSLayout()
>>> L.set_legend(Ld)
>>> Ld = L.get_legend()
>>> L.delete_legend(Ld)
>>> L.get_style_json()
{'legend': {}, 'style': []}
get_is_shared()[source]

Get sharing status of the layout.

Returns:Sharing status of layout. Either 0 or 1.
Return type:int

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.get_is_shared()
0
>>> L.set_is_shared(1)
>>> L.get_is_shared()
1
get_legend()[source]

Get a GSLegend Object having JSON representation of legend for a layout.

Returns:GSLegend Object having JSON representation of legend.
Return type:object

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> from graphspace_python.graphs.classes.gslegend import GSLegend
>>> Ld = GSLegend()
>>> legend_json = {
...         "legend":{
...             "nodes":{
...                 "Source Receptor": {
...                     "shape":"ellipse",
...                     "background-color":"#ff1400"
...                 }
...             },
...             "edges":{
...                 "Enzymatic Reaction":{
...                     "line-color":"#0fcf25",
...                     "line-style":"solid",
...                     "arrow-shape":"triangle"
...                 }
...             }
...         }
...     }
>>> Ld.set_legend_json(legend_json)
>>> L = GSLayout()
>>> L.set_legend(Ld)
>>> L.get_legend()
<graphspace_python.graphs.classes.gslegend.GSLegend at 0x7fdebc59d1d0>
get_name()[source]

Get the name of layout.

Returns:Name of layout.
Return type:str

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.get_name()
'Layout 03:42PM on July 20, 2017'
>>> L.set_name('My Sample Layout')
>>> L.get_name()
'My Sample Layout'
get_node_position(node_name)[source]

Get the x,y position of a node.

Parameters:node_name (str) – Name of the node.
Returns:Dict of x,y co-ordinates of the node, if node position is defined; otherwise None.
Return type:dict or None

Example

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.set_node_position('a', y=38.5, x=67.3)
>>> L.get_node_position('a')
{'y': 38.5, 'x': 67.3}
get_positions_json()[source]

Get the json representation for the layout node postitions.

Returns:Json representation of layout node postitions.
Return type:dict

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.get_positions_json()
{}
>>> L.set_node_position('a', y=38.5, x=67.3)
>>> L.get_positions_json()
{'a': {'y': 38.5, 'x': 67.3}}
get_style_json()[source]

Get the json representation for the layout style.

Returns:Json representation of layout style.
Return type:dict

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.get_style_json()
{'style': []}
>>> L.add_node_style('a', shape='ellipse', color='green', width=60, height=60)
>>> L.get_style_json()
{'style': [{'style': {'border-color': '#000000', 'border-width': 1, 'height': 60,
'width': 60, 'shape': 'ellipse', 'border-style': 'solid', 'text-wrap': 'wrap',
'text-halign': 'center', 'text-valign': 'center', 'background-color': 'green'},
'selector': 'node[name="a"]'}]}
json()[source]

Get the json representation of layout details.

Returns:Json representation of layout details.
Return type:dict

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.json()
{'style_json': {'style': []}, 'positions_json': {}, 'name':
'Layout 03:42PM on July 20, 2017', 'is_shared': 0}
>>> L.set_node_position('a', y=38.5, x=67.3)
>>> L.add_node_style('a', shape='ellipse', color='green', width=60, height=60)
>>> L.set_name('My Sample Layout')
>>> L.json()
{'style_json': {'style': [{'style': {'border-color': '#000000', 'border-width': 1,
'height': 60, 'width': 60, 'shape': 'ellipse', 'border-style': 'solid', 'text-wrap':
'wrap', 'text-halign': 'center', 'text-valign': 'center', 'background-color': 'green'},
'selector': 'node[name="a"]'}]}, 'positions_json': {'a': {'y': 38.5, 'x': 67.3}},
'name': 'My Sample Layout', 'is_shared': 0}
remove_node_position(node_name)[source]

Remove the x,y position of a node.

Parameters:node_name (str) – Name of the node.
Raises:Exception – If node positions are undefined.

Example

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.set_node_position('a', y=38.5, x=67.3)
>>> L.get_positions_json()
{'a': {'y': 38.5, 'x': 67.3}}
>>> L.remove_node_position('a')
>>> L.get_positions_json()
{}
set_is_shared(is_shared=1)[source]

Set sharing status of the layout.

Parameters:is_shared (int, optional) – Sharing status of layout. Defaults to 1.
Raises:Exception – If ‘is_shared’ is neither 0 nor 1.

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.set_is_shared() # By default takes param 'is_shared' as 1.
>>> L.get_is_shared()
1
>>> L.set_is_shared(0)
>>> L.get_is_shared()
0
set_legend(gslegend_obj)[source]

Set the json representation of legend for a layout.

Parameters:gslegend_obj (object) – GSLegend object having JSON representation of legend.

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> from graphspace_python.graphs.classes.gslegend import GSLegend
>>> Ld = GSLegend()
>>> legend_json = {
...         "legend":{
...             "nodes":{
...                 "TF": {
...                     "shape":"ellipse",
...                     "background-color":"#ff1400"
...                 }
...             },
...             "edges":{
...                 "Enzymatic Reaction":{
...                     "line-color":"#0fcf25",
...                     "line-style":"solid",
...                     "arrow-shape":"triangle"
...                 }
...             }
...         }
...     }
>>> Ld.set_legend_json(legend_json)
>>> L = GSLayout()
>>> L.set_legend(Ld)
>>> L.get_style_json()
{'legend': {'edges': {'Enzymatic Reaction': {'arrow-shape': 'triangle',
    'line-color': '#0fcf25',
    'line-style': 'solid'}},
  'nodes': {'TF': {'background-color': '#ff1400',
    'shape': 'ellipse'}}},
'style': []}
set_name(name)[source]

Set the name of the layout.

Parameters:name (str) – Name of layout.

Example

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.set_name('My Sample Layout')
>>> L.get_name()
'My Sample Layout'
set_node_position(node_name, y, x)[source]

Set the x,y position of a node.

Parameters:
  • node_name (str) – Name of the node.
  • y (float) – y co-ordinate of node.
  • x (float) – x co-ordinate of node.

Examples

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> L.set_node_position('a', y=38.5, x=67.3)
>>> L.get_positions_json()
{'a': {'y': 38.5, 'x': 67.3}}
>>> L.set_node_position('a', y=45, x=176) # Overwrites the position of 'a'.
>>> L.get_positions_json()
{'a': {'y': 45, 'x': 176}}
set_positions_json(positions_json)[source]

Set the json representation for the layout node postitions.

Parameters:positions_json (dict) – Json representation of layout node positions.

Example

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> positions_json = {
...     'a': {
...             'y': 38.5,
...             'x': 67.3
...     },
...     'b': {
...             'y': 124,
...             'x': 332.2
...     }
... }
>>> L.set_positions_json(positions_json)
>>> L.get_positions_json()
{'a': {'y': 38.5, 'x': 67.3}, 'b': {'y': 124, 'x': 332.2}}
set_style_json(style_json)[source]

Set the json representation for the layout style.

Parameters:style_json (dict) – Json representation of layout style.

Example

>>> from graphspace_python.graphs.classes.gslayout import GSLayout
>>> L = GSLayout()
>>> style_json = {
...     'style': [
...             {
...                     'style': {
...                             'border-color': '#000000',
...                             'border-width': 1,
...                             'height': 60,
...                             'width': 60,
...                             'shape': 'ellipse',
...                             'border-style': 'solid',
...                             'text-wrap': 'wrap',
...                             'text-halign': 'center',
...                             'text-valign': 'center',
...                             'background-color': 'green'
...                     },
...                     'selector': 'node[name="a"]'
...             }
...     ]
... }
>>> L.set_style_json(style_json)
>>> L.get_style_json()
{'style': [{'style': {'border-color': '#000000', 'border-width': 1, 'height': 60,
'width': 60, 'shape': 'ellipse', 'border-style': 'solid', 'text-wrap': 'wrap',
'text-halign': 'center', 'text-valign': 'center', 'background-color': 'green'},
'selector': 'node[name="a"]'}]}

graphspace_python.graphs.classes.gslegend module

class graphspace_python.graphs.classes.gslegend.GSLegend(*args, **kwargs)[source]

Bases: object

GSLegend class.

A GSLegend stores the details of legend.

It holds the information about the legend such as legend label and style of legend keys.

It provides methods to add, retrieve, modify and remove the detatils of the legend.

legend_json

JSON representation of the legend data.

Type:dict
add_legend_entries(element_type, label, style)[source]

Add an individual legend key to the legend data.

Parameters:
  • element_type (str) – Either nodes or edges.
  • label (str) – Label of legend key.Passing an already existing label as param will update that legend key.
  • style (dict) – Style dict of the legend key. Will contain attributes like node shape or edge type, color.

Examples

>>> from graphspace_python.graphs.classes.gslegend import GSLegend
>>> G = GSLegend()
>>> G.add_legend_entries(element_type='nodes', label='Receptor', style={'background-color': 'black', 'shape':'star'})
>>> G.get_legend_json()
{'legend': {'nodes': {'Receptor': {'background-color': 'black',
'shape': 'star'}}}}
delete_legend_json()[source]

Set legend_json to NULL.

Examples

>>> from graphspace_python.graphs.classes.gslegend import GSLegend
>>> G = GSLegend()
>>> G.add_legend_entries(element_type='nodes', label='Receptor', style={'background-color': 'black', 'shape':'star'})
>>> G.get_legend_json()
{'legend': {'nodes': {'Receptor': {'background-color': 'black',
'shape': 'star'}}}}
>>> G.delete_legend_json()
>>> G.get_legend_json()
{'legend': {}}
get_legend_json()[source]

Get the json representation of the legend.

Returns:JSON representation of legend data.
Return type:dict

Examples

>>> from graphspace_python.graphs.classes.gslegend import GSLegend
>>> G = GSLegend()
>>> G.get_legend_json()
{'legend': {}}
>>> G.add_legend_entries(element_type='nodes', label='Receptor', style={'background-color': 'black', 'shape':'star'})
>>> G.get_legend_json()
{'legend': {'nodes': {'Receptor': {'background-color': 'black',
'shape': 'star'}}}}
remove_legend_entries(element_type, label)[source]

Remove an individual legend key from the legend data.

Parameters:
  • element_type (str) – Either nodes or edges.
  • label (str) – Label of legend key to be deleted.

Examples

>>> from graphspace_python.graphs.classes.gslegend import GSLegend
>>> G = GSLegend()
>>> G.add_legend_entries(element_type='nodes', label='Receptor', style={'background-color': 'black', 'shape':'star'})
>>> G.get_legend_json()
{'legend': {'nodes': {'Receptor': {'background-color': 'black',
'shape': 'star'}}}}
>>> G.remove_legend_entries('nodes', 'Receptor')
>>> G.get_legend_json()
{'legend': {}}
set_legend_json(legend_json)[source]

Set the json representation of the legend.

Parameters:legend_json (dict) – JSON representation of the legend data.

Examples

>>> from graphspace_python.graphs.classes.gslegend import GSLegend
>>> G = GSLegend()
>>> legend_json = {
...         "legend":{
...             "nodes":{
...                 "Source Receptor": {
...                     "shape":"triangle",
...                     "background-color":"#ff1400"
...                  },
...                 "Receptor": {
...                     "shape":"circle",
...                     "background-color":"#1900ff"
...                 }
...             },
...             "edges":{
...                 "Phosphorylation":{
...                     "line-color":"#0fcf25",
...                     "line-style":"solid",
...                     "arrow-shape":"triangle"
...                 }
...             }
...         }
...     }
>>> G.set_legend_json(legend_json)
>>> G.get_legend_json()
{'legend': {'edges': {'Phosphorylation': {'arrow-shape': 'triangle', 'line-color': '#0fcf25', 'line-style': 'solid'}},
'nodes': {'Receptor': {'background-color': '#1900ff', 'shape': 'circle'},
'Source Receptor': {'background-color': '#ff1400', 'shape': 'triangle'}}}}
static validate_edge_legend_properties(data_properties)[source]
static validate_node_legend_properties(data_properties)[source]

Module contents