Information flow for layers
- connectome_interpreter.external_paths.compute_flow_hitting_time(conn_df: DataFrame | spmatrix, flow_seed_idx: ndarray[int], flow_steps: int, flow_thre: float)[source]
Compute hitting time for all cells in conn_df. Hitting time is the average number of hops required to reach a cell from a set of seed cells. The main algorithm is implemented in the ‘navis’ library (https://github.com/navis-org/navis).
- Parameters:
conn_df (pd.DataFrame) – DataFrame containing the connections with columns ‘pre’, ‘post’, and ‘weight’.
flow_seed_idx (np.ndarray) – Array of seed cell indices.
flow_steps (int) – Number of steps for flow calculation.
flow_thre (float) – Threshold for activation in flow calculation.
- Returns:
DataFrame with columns ‘idx’ and ‘hitting_time’, where ‘idx’ is the cell index and ‘hitting_time’ is the computed hitting time.
- Return type:
pd.DataFrame
- connectome_interpreter.external_paths.effective_conn_per_path_from_paths(paths_df: DataFrame) tuple[float, ndarray, ndarray][source]
Compute the total effective weight of each path of fixed length. Beware that this might be slow for long paths.
- Parameters:
paths_df (pd.DataFrame) – DataFrame containing the path data with columns ‘layer’, ‘pre’, ‘post’, and ‘weight’.
- Returns:
- total_effective_weight (float):
Total effective weight of all paths ending in target group.
- all_path_weights (np.array):
Array of weights for each individual path.
- min_path_weights (np.array):
Array of minimum edge weights for each individual path.
- Return type:
tuple
- connectome_interpreter.external_paths.find_instance_flow(inprop: spmatrix | DataFrame, idx_to_group: dict, flow_seed_groups: list[str] = ['L1', 'L2', 'L3', 'R7p', 'R8p', 'R7y', 'R8y', 'R7d', 'R8d', 'HBeyelet'], file_path: str | None = None, save_flow: bool | None = True, save_prefix: str | None = 'flow_', flow_steps: int = 20, flow_thre: float = 0.1) DataFrame[source]
Get the hitting time for all cell groups. The hitting time is computed using the information flow algorithm (navis:https://github.com/navis-org/navis) for each neuron, and then taking the median across neurons of each cell group.
- Parameters:
inprop (Union[spmatrix, pd.DataFrame]) – Input sparse matrix or DataFrame representing connections. If a DataFrame, it should have columns ‘pre’, ‘post’, and ‘weight’.
idx_to_group (dict) – Dictionary mapping cell indices to their respective cell groups.
flow_seed_groups (list) – List of cell groups to be used as seeds for flow calculation.
file_path (str) – Path to the directory containing the hitting time data.
save_flow (bool) – Whether to save the computed hitting time to a CSV file. Defaults to True.
save_prefix (str) – Prefix for the saved file names.
flow_seed_groups – List of cell group to be used as seeds for flow calculation.
flow_steps (int) – Number of steps for flow calculation.
flow_thre (float) – Threshold for flow calculation.
- Returns:
DataFrame with columns ‘cell_group’ and ‘hitting_time’, where ‘cell_group’ is the name of the cell group and ‘hitting_time’ is the median hitting time for that group.
- Return type:
pd.DataFrame
- connectome_interpreter.external_paths.layered_el(inprop: spmatrix, inidx: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], outidx: _Buffer | _SupportsArray[dtype[Any]] | _NestedSequence[_SupportsArray[dtype[Any]]] | bool | int | float | complex | str | bytes | _NestedSequence[bool | int | float | complex | str | bytes], n: int, idx_to_group: dict, thre_cumsum: float | None = None, thre_step_min: float = 0.0, combining_method: str = 'mean', flow_steps: int = 20, flow_thre: float = 0.1, flow: DataFrame | None = None)[source]
Similar to el_within_n_steps but using filter_paths_to_cumsum and layers based on the information flow hitting time (navis: https://github.com/navis-org/navis). If thre_cumsum is None, then paths are filtered based on direct weight thre_step_min; otherwise, paths are filtered such that the cumulative effective weight reaches thre_cumsum.
- Parameters:
inprop (spmatrix) – Input sparse matrix representing connections.
inidx (np.ndarray) – Array of input indices.
outidx (np.ndarray) – Array of output indices.
n (int) – The maximum number of hops. n=1 for direct connections.
idx_to_group (dict) – Dictionary mapping cell indices to their respective cell groups.
thre_cumsum (float) – The cumulative effective weight threshold to reach for filtered paths. Defaults to None, in which case paths are only filtered based on thre_step_min.
thre_step_min (float, optional) – The minimum threshold for the weight of the direct connection between pre and post. Defaults to 0.0.
combining_method (str, optional) – Method to combine inputs (outprop=False) or outputs (outprop=True). Can be ‘sum’, ‘mean’, or ‘median’. Defaults to ‘mean’.
flow_steps (int) – Number of steps for flow calculation. Defaults to 20.
flow_thre (float) – Threshold for flow calculation. Defaults to 0.1.
flow (pd.DataFrame, optional) – DataFrame containing the flow hitting time. If provided, it should have columns ‘cell_group’ and ‘hitting_time’. If None, the flow hitting time is computed from inprop and idx_to_group.
- Returns:
- pd.DataFrame:
DataFrame containing the edgelist with flow layers.
- float:
The total effective weight of the filtered paths.
- float:
The total effective weight of all paths before filtering.
- float:
The minimum edge weight threshold used to filter paths which is minimally thre_step_min.
- Return type:
tuple