py4cytoscape.networks.get_first_neighbors

get_first_neighbors(node_names=None, as_nested_list=False, network=None, base_url='http://127.0.0.1:1234/v1')[source]

Returns a non-redundant list of first neighbors of the supplied list of nodes or current node selection.

Parameters
  • node_names (str or list or int or None) – List of nodes (as 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 name column of the node table. Default is currently selected nodes.

  • as_nested_list (bool) – Whether to return lists of neighbors per query node.

  • 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

deduped list of nodes neighboring specified nodes.

If as_nested_list parameter is True, a list of neighbor node lists, one per specified node

Return type

list

Raises
  • CyError – if network name or SUID doesn’t exist, if no nodes are selected, or if node doesn’t exist

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

Examples

>>> get_first_neighbors(node_names = None, as_nested_list=True)
[['YBR020W', ['YGL035C', 'YOL051W', 'YPL248C', 'YML051W']], ['YGL035C', ['YLR044C', 'YLR377C', ...]], ...]
>>> get_first_neighbors(['YBR020W', 'YGL035C'], as_nested_list=False)
['YGL035C', 'YOL051W', 'YPL248C', 'YML051W', 'YLR044C', 'YLR377C', 'YIL162W', ... ]
>>> get_first_neighbors('YBR020W, YGL035C'], as_nested_list=False)
['YGL035C', 'YOL051W', 'YPL248C', 'YML051W', 'YLR044C', 'YLR377C', 'YIL162W', ... ]
>>> get_first_neighbors('YBR020W', as_nested_list=False)
['YGL035C', 'YOL051W', 'YPL248C', 'YML051W']
>>> get_first_neighbors([515677, 515678], as_nested_list=False)
['YGL035C', 'YOL051W', 'YPL248C', 'YML051W', 'YLR044C', 'YLR377C', 'YIL162W', ... ]
>>> get_first_neighbors('515677, 515678', as_nested_list=False)
['YGL035C', 'YOL051W', 'YPL248C', 'YML051W', 'YLR044C', 'YLR377C', 'YIL162W', ... ]
>>> get_first_neighbors(515677, as_nested_list=False)
['YGL035C', 'YOL051W', 'YPL248C', 'YML051W']

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

See also

select_nodes(), select_first_neighbors()