Connections¶
Connections provides the search-and-connect algorithms that underlie Network expansion methods. It is initialised with an interaction database DataFrame and pre-processes lookup tables for fast neighbour queries.
You rarely need to instantiate Connections directly — it is used internally by Network. The documentation here is aimed at developers who want to extend NeKo with custom connection strategies.
Import¶
Quick example¶
import pandas as pd
from neko._methods.enrichment_methods import Connections
db = pd.read_csv("my_interactions.csv") # source, target, effect, ...
conn = Connections(db)
# Check if a direct path exists between two proteins
paths = conn.find_paths("EGFR", "AKT1", maxlen=3)
Class reference¶
Connections ¶
Class that stores many utility functions to enrich an object Network. Each utility functions should take as input the nodes dataframe, which is used as base for each algorithm, and a database from the inputs modules, which will be used to extend the initial network.
Source code in neko/_methods/enrichment_methods.py
Functions¶
find_target_neighbours ¶
Optimized helper function that finds the neighbors of the target node.
find_source_neighbours ¶
Optimized helper function that finds the neighbors of the target node.
find_all_neighbours ¶
Optimized helper function that finds all neighbors (both source and target) of the target node.
Source code in neko/_methods/enrichment_methods.py
is_signed_edge ¶
Returns True if the edge from source to target is signed (not undefined), False otherwise. Uses precomputed cache for speed.
Source code in neko/_methods/enrichment_methods.py
bfs ¶
bfs(start: str, end: str, maxlen: Optional[int], only_signed: bool = False, consensus: bool = False, force: bool = False) -> List[List[str]]
Returns the shortest path between two nodes (as a list of nodes) using BFS,
but stops searching if the path length exceeds maxlen edges (if provided).
If only_signed is True, only considers signed edges (not undefined).
If force is False and maxlen is None, uses a default upper bound of 10.
Source code in neko/_methods/enrichment_methods.py
find_paths ¶
find_paths(start: Union[str, DataFrame, List[str]], end: Union[str, DataFrame, List[str], None] = None, maxlen: int = 2, minlen: int = 1, loops: bool = False, only_signed: bool = False, consensus: bool = False) -> List[List[str]]
Find all paths or motifs in a network, with optional sign/consensus filtering. Uses an iterative DFS with an explicit stack for better performance and memory efficiency. Args: start: Node(s) to start from (str, list of str, or DataFrame with 'name_of_node'). end: Node(s) to end at (str, list of str, DataFrame, or None for motif search). maxlen: Maximum path length (number of edges). minlen: Minimum path length (number of edges). loops: Allow cycles/loops if True. only_signed: If True, only consider signed edges (not undefined). consensus: If True, use consensus sign filtering. Returns: List of paths (each path is a list of node names).
Source code in neko/_methods/enrichment_methods.py
find_upstream_cascades ¶
find_upstream_cascades(target_genes: List[str], max_depth: int = 1, selected_rank: int = 1) -> List[Tuple[str, str]]
Find cascades of interactions in the network. Parameters: - target_genes: List of target genes to start the cascade. - max_depth: Maximum depth of the cascade. - selected_rank: Number of top regulators to select for each iteration. Returns: - interactions: List of interactions in the cascade.