API Reference

This page contains the API reference for the Neko package.

Network Class

The main class in NeKo is the Network class. You can import it as follows:

from neko.core.network import Network

Below is a summary of the methods available in the Network class:

class neko.core.network.Network(initial_nodes: list[str] | None = None, sif_file=None, resources=None)

Bases: object

A molecular interaction network.

The Network object is the central organizing component of the neko module. It is the subject of all operations implemented here, including topological algorithms, graph analysis, network visualization and integration of database knowledge.

Args:

initial_nodes: A list of initial nodes to be added to the network. sif_file: A SIF (Simple Interaction Format) file to load the network from. resources: A pandas DataFrame containing the resources database.

Methods:

add_edge(edge: DataFrame, provenance: dict | None = None) None

This method adds an interaction to the list of interactions while converting it to the NeKo-network format. It checks if the edge represents inhibition or stimulation and sets the effect accordingly. It also checks if the nodes involved in the interaction are already present in the network, if not, it adds them. Optionally, provenance information can be attached to the edge.

Args:
  • edge: A pandas DataFrame representing the interaction. The DataFrame should contain columns for

‘source’, ‘target’, ‘type’, and ‘references’. The ‘source’ and ‘target’ columns represent the nodes involved in the interaction. The ‘type’ column represents the type of interaction. The ‘references’ column contains the references for the interaction. - provenance: Optional dict with provenance info (strategy, parameters, timestamp, etc.)

Returns:
  • None

add_node(node: str, from_sif: bool = False) bool

Adds a node to the network. The node is added to the nodes DataFrame of the network. The function checks the syntax for the genesymbol to ensure it is correct. If the node is a complex, it is added with the ‘Genesymbol’ as the complex string and ‘Uniprot’ as the node. Otherwise, it is added with the ‘Genesymbol’ as the genesymbol and ‘Uniprot’ as the uniprot. The ‘Type’ is set as ‘NaN’ for all new nodes.

Args:
  • node: A string representing the node to be added. The node can be represented by either its

    Genesymbol or Uniprot identifier.

Returns:
  • None.

bfs_algorithm(node1: str, node2: str, maxlen: int, only_signed: bool, consensus: bool, connect_with_bias: bool) None

Delegates to graph_traversal.bfs_algorithm.

check_gene_list_format(genes)
check_node(node: str) bool

This function checks if a node exists in the resources’ database.

Args:
  • node: A string representing the node to be checked.

Returns:
  • A boolean indicating whether the node exists in the resources’ database.

check_nodes(nodes: list[str]) list[str]

This function checks if the nodes exist in the resources database and returns the nodes that are present.

Args:
  • nodes: A list of node identifiers (strings). These are the nodes to be checked.

Returns:
  • A list[str] of node identifiers that are present in the resources database.

check_sign(edge, consensus_only=False)
compare_states(idx1: int, idx2: int) dict

Compare two saved network states by index. Returns a dict with added/removed nodes/edges and provenance diffs. Node comparison is now based only on unique Uniprot identifiers to avoid dtype issues and ensure robust diffing.

complete_connection(maxlen: int | None = 2, algorithm: Literal['bfs', 'dfs'] = 'dfs', minimal: bool = True, only_signed: bool = False, consensus: bool = False, connect_with_bias: bool = False) None

Delegates to strategies.complete_connection.

connect_as_atopo(strategy: Literal['radial', 'complete', None] | None = None, max_len: int = 1, loops: bool = False, outputs=None, only_signed: bool = True, consensus: bool = False) None

Delegates to strategies.connect_as_atopo.

connect_component(comp_A, comp_B, maxlen: int = 2, mode: Literal['OUT', 'IN', 'ALL'] = 'OUT', only_signed: bool = False, consensus: bool = False) None

Delegates to strategies.connect_component.

connect_genes_to_phenotype(phenotype: str | None = None, id_accession: str | None = None, sub_genes: list | None = None, maxlen: int = 2, only_signed: bool = False, compress: bool = False) None

Delegates to strategies.connect_genes_to_phenotype.

connect_network_radially(max_len: int = 1, direction: Literal['OUT', 'IN', None] | None = None, loops: bool = False, consensus: bool = False, only_signed: bool = True) None

Delegates to strategies.connect_network_radially.

connect_nodes(only_signed: bool = False, consensus_only: bool = False) None

Delegates to strategies.connect_nodes.

connect_subgroup(group, maxlen: int = 1, only_signed: bool = False, consensus: bool = False) None

Delegates to strategies.connect_subgroup.

connect_to_upstream_nodes(nodes_to_connect=None, depth: int = 1, rank: int = 1, only_signed: bool = True, consensus: bool = False) None

Delegates to strategies.connect_to_upstream_nodes.

convert_edgelist_into_genesymbol() DataFrame

This function generates a new edges dataframe with the source and target identifiers translated (if possible) in Genesymbol format.

Args:
  • None

Returns:
  • A pandas DataFrame containing the edges with the source and target identifiers translated into Genesymbol

    format.

copy()
describe_states() None

Print a summary of all saved states.

dfs_algorithm(node1: str, node2: str, maxlen: int, only_signed: bool, consensus: bool, connect_with_bias: bool) None

Delegates to graph_traversal.dfs_algorithm.

edges_as_objects()
filter_edges_by_provenance(keyword: str) DataFrame

Return all edges whose provenance contains the given keyword.

get_edge_provenance(source: str, target: str) str

Return the provenance information for a given edge.

list_states() list

List all saved states (returns their metadata).

mapping_node_identifier(node)
modify_node_name(old_name: str, new_name: str, type: Literal['Genesymbol', 'Uniprot', 'both'] = 'Genesymbol') None

This function modifies the name of a node in the network. It takes the old name of the node and the new name as input and modifies the name of the node in the nodes and in the edges DataFrame. If type is set to ‘Genesymbol’, it modifies the genesymbol name of the node in the nodes DataFrame. If type is set to ‘Uniprot’, it modifies the uniprot name of the node in the edges DataFrame. If type is set to ‘both’, it modifies both the genesymbol and uniprot names of the node in the nodes and edges DataFrame.

Args:
  • old_name: A string representing the old name of the node. - new_name: A string representing the new

name of the node. - type: A string indicating the type of name to be modified. It can be ‘Genesymbol’, ‘Uniprot’, or ‘both’. Default is ‘Genesymbol’.

Returns:

-None

nodes_as_objects()
print_my_paths(node1: str, node2: str, maxlen: int = 2, genesymbol: bool = True) None

This function prints all the paths between two nodes in the network. It uses the find_paths method from the Connections class to find all the paths between the two nodes in the Network object. If no paths are found, it prints a warning message. If one of the selected nodes is not present in the network, it prints an error message.

Args:
  • node1: A string representing the source node.

  • node2: A string representing the target node.

  • maxlen: An integer representing the maximum length of the paths to be searched for. Default is 2.

  • genesymbol: A boolean flag indicating whether to print the paths in genesymbol format. Default is True.

Returns:
  • None

redo() None

Redo is not supported unless branching is implemented. Placeholder for future extension.

remove_bimodal_interactions()

Removes all bimodal interactions from the network.

remove_disconnected_nodes() None

This function removes nodes from the network that are not connected to any other nodes.

Returns: None. The function modifies the network object in-place by removing the disconnected nodes from the nodes DataFrame.

remove_edge(node1: str, node2: str) None

This function removes an edge from the network. It takes the source node and target node as input and removes the edge from the edges DataFrame.

Args:
  • node1: A string representing the source node of the edge.

  • node2: A string representing the target node of the edge.

Returns:
  • None

remove_node(node: str) None

Removes a node from the network. The node is removed from both the list of nodes and the list of edges.

Args:
  • node: A string representing the node to be removed. The node can be represented by either its

    Genesymbol or Uniprot identifier.

Returns:
  • None

remove_path(path: list[str]) None

This function removes a path from the network. It takes a list of nodes representing the path and removes all the edges between the nodes in the path.

Args:
  • path: A list of nodes representing the path to be removed. The nodes can be represented as strings or tuples.

Returns:
  • None

remove_undefined_interactions()

This function removes all undefined interactions from the network.

Args:
  • None

Returns:
  • None

restore_state(index: int = -1) None

Restore the network to a previous state by index (default: last state).

save_state(metadata: dict | None = None) None

Save the current state of the network (nodes, edges, and optional metadata) to the history.

sync_edges_from_df()
sync_edges_to_df()
sync_nodes_from_df()
sync_nodes_to_df()
undo() None

Undo the last change by restoring the previous state in history.

Method Details

neko.core.network.Network.add_edge(edge[, ...])

This method adds an interaction to the list of interactions while converting it to the NeKo-network format.

neko.core.network.Network.remove_node(node)

Removes a node from the network.

neko.core.network.Network.add_node(node[, ...])

Adds a node to the network.

neko.core.network.Network.complete_connection([...])

Delegates to strategies.complete_connection.

neko.core.network.Network.connect_component(...)

Delegates to strategies.connect_component.

neko.core.network.Network.connect_genes_to_phenotype([...])

Delegates to strategies.connect_genes_to_phenotype.

neko.core.network.Network.connect_nodes([...])

Delegates to strategies.connect_nodes.

neko.core.network.Network.connect_subgroup(group)

Delegates to strategies.connect_subgroup.

neko.core.network.Network.connect_to_upstream_nodes([...])

Delegates to strategies.connect_to_upstream_nodes.

neko.core.network.Network.convert_edgelist_into_genesymbol()

This function generates a new edges dataframe with the source and target identifiers translated (if possible) in Genesymbol format.

NetworkVisualizer Class Methods

neko._visual.visualize_network.NetworkVisualizer.set_custom_edge_colors(...)

neko._visual.visualize_network.NetworkVisualizer.set_node_colors(...)

neko._visual.visualize_network.NetworkVisualizer.tissue_mapping(...)

Color the nodes based on their expression in the tissue of interest (based on data from The Human Protein Atlas).

neko._visual.visualize_network.NetworkVisualizer.render([...])

Render the graph.

neko._visual.visualize_network.NetworkVisualizer.yfiles_visual(...)

neko._visual.visualize_network.NetworkVisualizer.vis_comparison(...)

Other Modules