py4cytoscape.networks.create_subnetwork

create_subnetwork(nodes=None, nodes_by_col='SUID', edges=None, edges_by_col='SUID', exclude_edges=False, subnetwork_name=None, network=None, base_url='http://127.0.0.1:1234/v1')[source]

Copies a subset of nodes and edges into a newly created subnetwork.

Parameters
  • nodes (str or list or int or None) – List of nodes or keyword: selected, unselected or all. If node list: list of node names or SUIDs, comma-separated string of node names or SUIDs, or scalar node name or SUID. Node names should be found in the SUID column of the node table unless specified in nodes_by_col. If list is None, default is currently selected nodes.

  • nodes_by_col (str) – name of node table column corresponding to provided nodes list; default is ‘SUID’

  • edges (str or list or int or None) – List of edges or keyword: selected, unselected or all. If edge list: list of edge names or SUIDs, comma-separated string of edge names or SUIDs, or scalar edge name or SUID. Edge names should be found in the SUID column of the edge table unless specified in edges_by_col. If list is None, default is currently selected edges.

  • edges_by_col (str) – name of edge table column corresponding to provided edges list; default is ‘SUID’

  • exclude_edges (bool) – whether to exclude connecting edges; default is FALSE

  • subnetwork_name (str) – name of new subnetwork to be created; default is to add a numbered suffix to source network name

  • network (SUID or str or None) – Name or SUID of a network or view. Default is the “current” network active in Cytoscape.

  • 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.

Returns

The SUID of the new subnetwork

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

>>> create_subnetwork(nodes='all') # choose all selected and unselected nodes
1477
>>> create_subnetwork(edges='selected') # choose only nodes whose edges are selected, and include those edges
1477
>>> create_subnetwork(nodes=['RAP1', 'HIS4', 'PDC1', 'RPL18A'], nodes_by_col='COMMON', subnetwork_name=base_name+'xx')
1477
>>> create_subnetwork(nodes='RAP1, HIS4, PDC1, RPL18A', nodes_by_col='COMMON', subnetwork_name=base_name+'xx')
1477
>>> create_subnetwork(nodes=[1502, 1555, 1560, 1701], subnetwork_name=base_name+'xx')
1477

Note

To identify a node whose name contains a comma, use ‘\’ to escape the comma. For example, ‘node1, node\,2’ identifies ‘node1’ and ‘node,2’.