spared.spot_features.get_spatial_neighbors

spared.spot_features.get_spatial_neighbors(adata: AnnData, n_hops: int, hex_geometry: bool) dict[source]

Compute neighbors dictionary for an AnnData object.

This function computes a neighbors dictionary for an AnnData object. The neighbors are computed according to topological distances over a graph defined by the hex_geometry connectivity. The neighbors dictionary is a dictionary where the keys are the indexes of the observations and the values are lists of the indexes of the neighbors of each observation. The neighbors include the observation itself as first element and are found inside an n_hops neighborhood (vicinity) of the observation.

Parameters:
  • adata (ad.AnnData) – The AnnData object to process. Importantly it is only from a single slide. Can not be a collection of slides.

  • n_hops (int) – The size of the neighborhood to take into account to compute the neighbors.

  • hex_geometry (bool) – Whether the graph is hexagonal or not. If True, then the graph is hexagonal. If False, then the graph is a grid. Only True for Visium datasets.

Returns:

The neighbors dictionary. The keys are the indexes of the observations and the values are lists of the indexes of the neighbors of each observation.

Return type:

dict