py4cytoscape.networks.create_network_from_data_frames

create_network_from_data_frames(nodes=None, edges=None, title='From dataframe', collection='My Dataframe Network Collection', base_url='http://127.0.0.1:1234/v1', *, node_id_list='id', source_id_list='source', target_id_list='target', interaction_type_list='interaction')[source]

Create a network from data frames.

Takes data frames for nodes and edges, as well as naming parameters to generate the JSON data format required by the “networks” POST operation via CyREST. Returns the network.suid and applies the preferred layout set in Cytoscape preferences.

Notes

nodes should contain a column of character strings named: id. This name can be overridden by the arg: node_id_list. Additional columns are loaded as node attributes. edges should contain columns of character strings named: source, target and interaction. These names can be overridden by args: source_id_list, target_id_list, interaction_type_list. Additional columns are loaded as edge attributes. The interaction list can contain a single value to apply to all rows; and if excluded altogether, the interaction type will be set to “interacts with”. NOTE: attribute values of types (num) will be imported as (Double); (int) as (Integer); (chr) as (String); and (logical) as (Boolean). (Lists) will be imported as (Lists) in CyREST v3.9+.

Note that the extra id column is created in the node table because the id column is mandatory in the cytoscape.js format, which is what is sent to Cytoscape.

Parameters
  • nodes (DataFrame) – see details and examples below; default NULL to derive nodes from edge sources and targets

  • edges (DataFrame) – see details and examples below; default NULL for disconnected set of nodes

  • title (str) – network name

  • collection (str) – network collection name

  • base_url (str) – Ignore unless you need to specify a custom domain, port or version to connect to the CyREST API. Default is http://127.0.0.1:1234 and the latest version of the CyREST API supported by this version of py4cytoscape.

  • *

  • node_id_list (str) – Name of column in nodes containing node id

  • source_id_list (str) – Name of column in edges containing source node name

  • target_id_list (str) – Name of column in edges containing target node name

  • interaction_type_list (str) – Name of column in edges containing interaction name

Returns

The SUID of the new network

Return type

int

Raises
  • ValueError – if server response has no JSON

  • CyError – if network name or SUID doesn’t exist

  • requests.exceptions.RequestException – if can’t connect to Cytoscape or Cytoscape returns an error

Examples

>>> node_data = {'id':["node 0","node 1","node 2","node 3"],
>>>              'group':["A","A","B","B"],
>>>              'score':[20,10,15,5]}
>>> nodes = df.DataFrame(data=node_data, columns=['id', 'group', 'score'])
>>> edge_data = {'source':["node 0","node 0","node 0","node 2"],
>>>              'target':["node 1","node 2","node 3","node 3"],
>>>              'interaction':["inhibits","interacts","activates","interacts"],
>>>              'weight':[5.1,3.0,5.2,9.9]}
>>> edges = df.DataFrame(data=edge_data, columns=['source', 'target', 'interaction', 'weight'])
>>>
>>> create_network_from_data_frames(nodes, edges, title='From node & edge dataframe')
1477