Creating NiceCXNetwork objects

ndex2.create_nice_cx_from_raw_cx(cx)[source]

Create a NiceCXNetwork() from a as a list of dict objects in CX format

Example:

import json
import ndex2

# cx_as_str is a str containing JSON in CX format above
net_cx = ndex2.create_nice_cx_from_raw_cx(json.loads(cx_as_str))
Parameters:cx (list) – CX as a list of dict objects
Returns:NiceCXNetwork
Return type:NiceCXNetwork()
ndex2.create_nice_cx_from_file(path)[source]

Create a NiceCXNetwork() from a file that is in the CX format

Parameters:

path (str) – the path of the CX file

Raises:
  • Exception – if path is not a file
  • OSError – if there is an error opening the path file
  • JSONDecodeError – if there is an error parsing the path file with json.load()
Returns:

NiceCXNetwork

Return type:

NiceCXNetwork()

ndex2.create_nice_cx_from_networkx(G)[source]

Creates a NiceCXNetwork based on a networkx graph.

The resulting NiceCXNetwork contains the nodes, edges and their attributes from the networkx graph and also preserves the graph ‘pos’ attribute as a CX cartesian coordinates aspect.

The node name is taken from the networkx node id. Node ‘represents’ is taken from the networkx node attribute ‘represents’

Parameters:G (networkx graph) – networkx graph
Returns:NiceCXNetwork
Return type:NiceCXNetwork
ndex2.create_nice_cx_from_pandas(df, source_field=None, target_field=None, source_node_attr=[], target_node_attr=[], edge_attr=[], edge_interaction=None, source_represents=None, target_represents=None)[source]

Create a NiceCXNetwork() from a pandas dataframe in which each row specifies one edge in the network.

If only the df argument is provided the dataframe is treated as ‘SIF’ format, where the first two columns specify the source and target node ids of the edge and all other columns are ignored. The edge interaction is defaulted to “interacts-with”

If both the source_field and target_field arguments are provided, the those and any other arguments refer to headers in the dataframe, controlling the mapping of columns to the attributes of nodes, and edges in the resulting NiceCXNetwork(). If a header is not mapped the corresponding column is ignored. If the edge_interaction is not specified it defaults to “interacts-with”

Parameters:
  • df – pandas dataframe to process
  • source_field – header name specifying the name of the source node.
  • target_field – header name specifying the name of the target node.
  • source_node_attr – list of header names specifying attributes of the source node.
  • target_node_attr – list of header names specifying attributes of the target node.
  • edge_attr – list of header names specifying attributes of the edge.
  • edge_interaction – the relationship between the source node and the target node, defaulting to “interacts-with”
Returns:

NiceCXNetwork

Return type:

NiceCXNetwork()

ndex2.create_nice_cx_from_server(server, username=None, password=None, uuid=None)[source]

Create a NiceCXNetwork() based on a network retrieved from NDEx, specified by its UUID. If the network is not public, then username and password arguments for an account on the server with permission to access the network must be supplied.

Parameters:
  • server – the URL of the NDEx server hosting the network.
  • username – the user name of an account with permission to access the network.
  • password – the password of an account with permission to access the network.
  • uuid – the UUID of the network.
Returns:

NiceCXNetwork

Return type:

NiceCXNetwork()