cytoscape_graph#
- cytoscape_graph(data, attrs=None, name='name', ident='id')[source]#
Create a NetworkX graph from a dictionary in cytoscape JSON format.
- Parameters:
- datadict
A dictionary of data conforming to cytoscape JSON format.
- attrsdict or None (default=None)
A dictionary containing the keys ‘name’ and ‘ident’ which are mapped to the ‘name’ and ‘id’ node elements in cyjs format. All other keys are ignored. Default is
Nonewhich results in the default mappingdict(name="name", ident="id").Deprecated since version 2.6: The
attrskeyword argument will be replaced withnameandidentin networkx 3.0- namestring
A string which is mapped to the ‘name’ node element in cyjs format. Must not have the same value as
ident.- identstring
A string which is mapped to the ‘id’ node element in cyjs format. Must not have the same value as
name.
- Returns:
- grapha NetworkX graph instance
The
graphcan be an instance ofGraph,DiGraph,MultiGraph, orMultiDiGraphdepending on the input data.
- Raises:
- NetworkXError
If the
nameandidentattributes are identical.
See also
cytoscape_dataconvert a NetworkX graph to a dict in cyjs format
References
[1]Cytoscape user’s manual: http://manual.cytoscape.org/en/stable/index.html
Examples
>>> data_dict = { ... 'data': [], ... 'directed': False, ... 'multigraph': False, ... 'elements': {'nodes': [{'data': {'id': '0', 'value': 0, 'name': '0'}}, ... {'data': {'id': '1', 'value': 1, 'name': '1'}}], ... 'edges': [{'data': {'source': 0, 'target': 1}}]} ... } >>> G = nx.cytoscape_graph(data_dict) >>> G.name '' >>> G.nodes() NodeView((0, 1)) >>> G.nodes(data=True)[0] {'id': '0', 'value': 0, 'name': '0'} >>> G.edges(data=True) EdgeDataView([(0, 1, {'source': 0, 'target': 1})])