ndex package¶
ndex.client module¶
-
class
ndex.client.
Ndex
(host='http://public.ndexbio.org', username=None, password=None)¶ A class to facilitate communication with an NDEx server.
-
get_neighborhood_as_cx_stream
(network_id, search_string, search_depth=1, edge_limit=2500)¶ Get a CX stream for a subnetwork of the network specified by UUID network_id and a traversal of search_depth steps around the nodes found by search_string.
Parameters: - network_id (str) – The UUID of the network.
- search_string (str) – The search string used to identify the network neighborhood.
- search_depth (int) – The depth of the neighborhood from the core nodes identified.
- edge_limit (int) – The maximum size of the neighborhood.
Returns: The response.
Return type:
-
get_network_as_cx_stream
(network_id)¶ Get the existing network with UUID network_id from the NDEx connection as a CX stream.
Parameters: network_id (str) – The UUID of the network. Returns: The response. Return type: response object
-
get_network_summary
(network_id)¶ Gets information about a network.
Parameters: network_id (str) – The UUID of the network. Returns: The response. Return type: response object
-
make_network_private
(network_id)¶ Makes the network specified by the network_id private.
Parameters: network_id (str) – The UUID of the network. Returns: The response. Return type: response object
-
make_network_public
(network_id)¶ Makes the network specified by the network_id public.
Parameters: network_id (str) – The UUID of the network. Returns: The response. Return type: response object
-
save_cx_stream_as_new_network
(cx_stream, provenance=None)¶ Create a new network from a CX stream, optionally providing a provenance history object to be included in the new network.
Parameters: - cx_stream – The network stream.
- provenance – The desired provenance history associated with the network.
Returns: The response.
Return type:
-
search_networks
(search_string='', account_name=None, skip_blocks=0, block_size=100)¶ Search for networks based on the search_text, optionally limited to networks owned by the specified account_name.
Parameters: - search_string (str) – The text to search for.
- account_name (str) – The account to search
- skip_blocks (int) – The number of blocks to skip. Usually zero, but may be used to page results.
- block_size (int) – The size of the block.
Returns: The response.
Return type:
-
update_cx_network
(cx_stream, network_id, provenance=None)¶ Update the network specified by UUID network_id using the CX stream cx_stream.
Parameters: - cx_stream – The network stream.
- network_id (str) – The UUID of the network.
- provenance – The desired provenance history associated with the network.
Returns: The response.
Return type:
-
ndex.networkn module¶
-
class
ndex.networkn.
NdexGraph
(cx=None, server=None, username=None, password=None, uuid=None, networkx_G=None, data=None, **attr)¶ Bases:
networkx.classes.multidigraph.MultiDiGraph
A graph compatible with NDEx
-
add_edge_between
(source_node_id, target_node_id, interaction='interacts_with', attr_dict=None, **attr)¶ Add an edge between two nodes in this network specified by source_node_id and target_node_id, optionally specifying the type of interaction.
Parameters: - source_node_id (int) – The node id of the source node.
- target_node_id (int) – The node id of the target node.
- interaction (str) – The type of interaction specified by the newly added edge.
- attr_dict (dict) – Dictionary of node attributes. Key/value pairs will update existing data associated with the node.
- attr – Set or change attributes using key=value.
-
add_new_node
(name=None, attr_dict=None, **attr)¶ Add a cx node, possibly with a particular name, to the graph.
Parameters: - name (str) – The name of the node. (Optional).
- attr_dict (dict) – Dictionary of node attributes. Key/value pairs will update existing data associated with the node.
- attr – Set or change attributes using key=value.
-
clear
()¶ Eliminate all graph data in this network. The network will then be empty and can be filled with data starting “from scratch”.
-
create_from_edge_list
(edge_list, interaction='interacts with')¶ Create a network from a list of tuples that represent edges. Each tuple consists of two nodes names that are to be connected. This operation will first clear ALL data already in the network.
Parameters: - edge_list (list) – A list of tuples containing node names that are connected.
- interaction (str or list) – Either a list of interactions that is the same length as the edge_list a single string with an interaction to be applied to all edges.
-
get_all_edge_attribute_keys
()¶ Get the unique list of all attribute keys used in at least one edge in the network.
Returns: A list of edge attribute keys. Return type: list
-
get_all_node_attribute_keys
()¶ Get the unique list of all attribute keys used in at least one node in the network.
Returns: A list of attribute keys. Return type: list
-
get_edge_attribute_value_by_id
(edge_id, query_key)¶ Get the value for attribute of the edge specified by edge_id.
Parameters: - edge_id – The id of the edge.
- query_key – The name of the attribute whose value should be retrieved.
Returns: The attribute value. If the value is a list, this returns the entire list.
Return type: any
-
get_edge_attribute_values_by_id_list
(edge_id_list, query_key)¶ Given a list of edge ids and particular attribute key, return a list of corresponding attribute values.’
Parameters: - edge_id_list – A list of edge ids whose attribute values we wish to retrieve
- query_key – The name of the attribute whose corresponding values should be retrieved.
Returns: A list of attribute values corresponding to the edge keys input.
Return type: list
-
get_edge_ids_by_node_attribute
(source_node_value, target_node_value, query_key='name')¶ Returns a list of edge ids of all edges where both the source node and target node have the specified values for query_key.
Parameters: - source_node_value – The value we want in the source node.
- target_node_value – The value we want in the target node.
- query_key – The name of the attribute where we should look for the value.
Returns: A list of edge ids.
Return type: list
-
get_name
()¶ Get the name of this graph
Returns: The descriptive name for this network. Return type: str
-
get_node_attribute_value_by_id
(node_id, query_key='name')¶ Get the value of a particular node attribute based on the id.
Parameters: - node_id (int) – A node id.
- query_key (str) – The name of the attribute whose value we desire.
Returns: The attribute value.
Return type: any
-
get_node_attribute_values_by_id_list
(id_list, query_key='name')¶ Returns a list of attribute values that correspond with the attribute key using the nodes in id_list.
Parameters: - id_list – A list of node ids whose attribute values we wish to retrieve.
- query_key – The name of the attribute whose corresponding values should be retrieved.
Returns: A list of attribute values.
Return type: list
-
get_node_ids
(value, query_key='name')¶ Returns a list of node ids of all nodes in which query_key has the specified value.
Parameters: - value – The value we want.
- query_key – The name of the attribute where we should look for the value.
Returns: A list of node ids.
Return type: list
-
get_node_name_by_id
(id)¶ Given a node id, return the name of the node.
Parameters: id (int) – The cx id of the node. Returns: The name of the node. Return type: str
-
get_node_names_by_id_list
(id_list)¶ Given a list of node ids, return a list of node names.
Parameters: id_list (list) – A list of node ids whose attribute values we wish to retrieve. Returns: A list of node names. Return type: list
-
remove_nodes_from
(nbunch)¶
-
set_edge_attribute
(id, attribute_key, attribute_value)¶ Set the value of a particular edge attribute.
Parameters: - id (int) – The edge id we wish to set an attribute on.
- attribute_key (string) – The name of the attribute we wish to set.
- attribute_value (any) – The value we wish to set the attribute to.
-
set_name
(name)¶ Set the name of this graph
Parameters: name (str) – A descriptive name for the network which will show up on NDEx.
-
show_stats
()¶ Show the number of nodes and edges.
-
to_cx
()¶ Convert this network to a CX dictionary
Returns: The cx dictionary that represents this network. Return type: dict
-
to_cx_stream
()¶ Convert this network to a CX stream
Returns: The CX stream representation of this network. Return type: io.BytesIO
-
upload_to
(server, username, password)¶ Upload this network to the specified server to the account specified by username and password.
Parameters: - server (str) – The NDEx server to upload the network to.
- username (str) – The username of the account to store the network.
- password (str) – The password for the account.
Returns: The UUID of the network on NDEx.
Return type: str
- Example:
- ndexGraph.upload_to(‘http://test.ndexbio.org‘, ‘myusername’, ‘mypassword’)
-
write_to
(filename)¶ Write this network as a CX file to the specified filename.
Parameters: filename (str) – The name of the file to write to.
-