monkeybread.stat.shortest_distances

monkeybread.stat.shortest_distances(adata, groupby, group1, group2, n_perms=100, observed=None, threshold=None, basis='X_spatial')

Calculates an expected null distribution of shortest distances from cells in group1 to cells in group2 by permuting coordinates of cells that aren’t in group1. The null hypothesis assumes no coherent spatial co-localization between cells of group1 and cells of group2. If group1 is a list, then this function will consider the union of all cells with a label in group1. Likewise if group2 is a list then this function will consider the union of all cells with a label in group2.

If observed and threshold are provided, a p-value is computed on the following test statistic: the number of shortest distances from cells in group1 to cells in group2 that are less than threshold.

Parameters:
  • adata (AnnData) – Annotated data matrix.

  • groupby (str) – A categorical column in adata.obs to use for grouping.

  • group1 (Union[str, List[str]]) – One or more levels from adata.obs[groupby] to use as sources for shortest distance.

  • group2 (Union[str, List[str]]) – One or more levels from adata.obs[groupby] to use as destinations for shortest distance.

  • n_perms (Optional[int] (default: 100)) – The number of permutations to run. Defaults to 100.

  • observed (Optional[DataFrame] (default: None)) – The observed distribution of shortest distances, as calculated by monkeybread.calc.shortest_distances().

  • threshold (Optional[float] (default: None)) – A distance threshold to use for significance calculation, in coordinate units.

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

Return type:

Union[ndarray, Tuple[ndarray, float]]

Returns:

: If threshold is not provided, an array containing the expected null distribution as described above. If threshold is provided, a length-2 tuple will be returned, where the first element is the array containing the expected null distribution. The second element corresponds to the the p-value calculated.