var_by_distance#

squidpy.tl.var_by_distance(adata, *, groups, cluster_key=None, library_key=None, library_id=None, design_matrix_key='design_matrix', covariates=None, metric='euclidean', spatial_key='spatial', copy=False)[source]#

Build a design matrix consisting of distance measurements to selected anchor point(s) for each observation.

Parameters:
adata AnnData

Annotated data object.

groups str | list[str] | NDArray[Any]

Anchor point(s) to calculate distances to. Can be a single or multiple observations as long as they are annotated in an .obs column with name given by cluster_key. Alternatively, a numpy array of coordinates can be passed.

cluster_key str | None (default: None)

Name of annotation column in .obs where the observation used as anchor points are located.

library_key str | None (default: None)

If multiple library_id, column in anndata.AnnData.obs which stores mapping between library_id and obs.

library_id str | list[str] | None (default: None)

Name of the Z-dimension(s) that this function should be applied to. For not specified Z-dimensions, the identity function is applied.

design_matrix_key str (default: 'design_matrix')

Name of the design matrix saved to .obsm.

covariates str | list[str] | None (default: None)

Additional covariates from .obs to include in the design matrix.

metric str (default: 'euclidean')

Distance metric, defaults to “euclidean”.

spatial_key str (default: 'spatial')

Key in anndata.AnnData.obsm where spatial coordinates are stored.

copy bool (default: False)

If True, return the result, otherwise save it to the adata object.

Returns:

AnnData – If copy = True, returns the design_matrix with the distances to an anchor point Otherwise, stores design_matrix in .obsm.