squidpy.tl.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[tuple[Any,...],dtype[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) – Name of annotation column in .obs where the observation used as anchor points are located.library_key (
str|None) – If multiple library_id, column inanndata.AnnData.obswhich stores mapping betweenlibrary_idand obs.library_id (
str|list[str] |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) – Name of the design matrix saved to .obsm.covariates (
str|list[str] |None) – Additional covariates from .obs to include in the design matrix.metric (
str) – Distance metric, defaults to “euclidean”.spatial_key (
str) – Key inanndata.AnnData.obsmwhere spatial coordinates are stored.copy (
bool) – IfTrue, return the result, otherwise save it to theadataobject.
- Return type:
- Returns:
If
copy = True, returns the design_matrix with the distances to an anchor point Otherwise, stores design_matrix in .obsm.