squidpy.tl.var_by_distance

squidpy.tl.var_by_distance(adata, groups, cluster_key, library_key=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, dtype[Any]]) – Anchor points to calculate distances from, can be a single gene, a list of genes or a set of coordinates.

  • cluster_key (str) – Annotation column in .obs that is used as anchor.

  • library_key (Optional[str]) – If multiple library_id, column in anndata.AnnData.obs which stores mapping between library_id and obs.

  • design_matrix_key (str) – Name of the design matrix saved to .obsm.

  • covariates (Union[list[str], str, None]) – Additional covariates from .obs to include in the design matrix.

  • metric (str) – Distance metric, defaults to “euclidean”.

  • spatial_key (str) – Key in anndata.AnnData.obsm where spatial coordinates are stored.

  • copy (bool) – If True, return the result, otherwise save it to the adata object.

Return type:

AnnData

Returns:

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