cellina.spatial_neighbors#
- cellina.spatial_neighbors(adata, bandwidth=None, cutoff=0.1, max_neighbours=100, kernel='gaussian', set_diag=False, zoi=0, standardize=False, reference=None, spatial_key='spatial', key_added='spatial', library_key=None, test_indices=None, inplace=True)#
Generate spatial connectivity weights using Euclidean distance.
- Parameters:
%(adata)s
bandwidth (default:
None) – Denotes signaling length (l) and controls the maximum distance at which two spots are considered. Corresponds to the units in which spatial coordinates are expressed.cutoff (default:
0.1) – Values below this cutoff will be set to 0.max_neighbours (default:
100) – Maximum nearest neighbours to be considered when generating spatial connectivity weights. Essentially, the maximum number of edges in the spatial connectivity graph.kernel (default:
'gaussian') – Kernel function used to generate connectivity weights. It controls the shape of the connectivity weights. The following options are available: [‘gaussian’, ‘exponential’, ‘linear’]set_diag (default:
False) – Logical, sets connectivity diagonal to 0 ifFalse. Default isFalse.zoi (default:
0) – Zone of indifference. Values below this cutoff will be set tonp.inf.standardize (default:
False) – Whether to (l1) standardize spatial proximities (connectivities) so that they sum to 1. This plays a role when weighing border regions prior to downstream methods, as the number of spots in the border region (and hence the sum of proximities) is smaller than the number of spots in the center. Relevant for methods with unstandardized scores (e.g. product). Default isFalse.reference (default:
None) – Reference coordinates to use when generating spatial connectivity weights. IfNone, uses the spatial coordinates inadata.obsm[spatial_key]. This is only relevant if you want to use a different set of coordinates to generate spatial connectivity weights.%(spatial_key)s
key_added (default:
'spatial') – Key to add toadata.obspifinplace = True. If reference is notNone, key will be added toadata.obsm.library_key (default:
None) – Key in adata.obs for grouping samples. If provided, builds separate graphs per sample and concatenates them.test_indices (default:
None) – Integer indices (intoadata) of cells to exclude from being selected as neighbors. Each test cell’s coordinates are displaced to a unique far-away position so it cannot appear in any kNN result — resulting in all-zero rows and columns for those cells.%(inplace)s
Notes
This function is adapted from mistyR, and is set to be consistent with the
squidpy.gr.spatial_neighborsfunction in thesquidpypackage.- Returns:
: If
inplace = False, returns annp.arraywith spatial connectivity weights. Otherwise, modifies theadataobject with the following key:anndata.AnnData.obsp['{key_added}_connectivities']with the aforementioned array