monkeybread.calc.shortest_distances

monkeybread.calc.shortest_distances(adata, groupby, group1, group2, basis='spatial')

Calculates the distance from each cell in one group to the nearest cell in another group.

Parameters
  • adata (AnnData) – Annotated data matrix.

  • groupby (str) – A categorical column in adata.obs to classify groups.

  • group1 (Union[str, List[str]]) – Either one value or a list of values from adata.obs[groupby].

  • group2 (Union[str, List[str]]) – Either one value or a list of values from adata.obs[groupby].

  • basis (Optional[str] (default: 'spatial')) – Coordinates in adata.obsm[X_{basis}] to use. Defaults to spatial.

Return type

DataFrame

Returns

A dataframe, indexed by cells in group1. The dataframe has two columns, distance and nearest_cell, corresponding to the distance to the nearest cell in group2 and the index of that cell respectively.