monkeybread.stat.shortest_distances_pairwise

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

Performs the same statistical analyses implemented by monkeybread.stat.shortest_distances(), but in a pairwise fashion between every cell type in group1 and every cell type in group2. This stands in contrast to monkeybread.stat.shortest_distances() that considered the union of cells with cell type labels in group1 as the first group and union of cell type labels in group2 as the second group.

For every pair of cell types in group1 and group2, this function calculates an expected null distribution of shortest distances from cells in the group1 cell type to cells in the group2 cell type by permuting coordinates of cells that aren’t in the group1 cell type. The null hypothesis assumes no coherent spatial co-localization between cells of the group1 cell type and cells of the group2 cell type.

If observed and threshold are provided, p-values are computed on the following test statistics: the number of shortest distances from cells in each group1 cell type to cells in each group2 cell type that are less than threshold.

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

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

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

  • group2 (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[Dict[str, Dict[str, 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: 'spatial')) – Coordinates in adata.obsm[{basis}] to use. Defaults to spatial.

Return type:

Union[Dict[str, Dict[str, ndarray]], Tuple[Dict[str, Dict[str, ndarray]], Dict[str, Dict[str, float]]]]

Returns:

: If threshold is not provided, an dictonary of dictonaries is returned that maps each cell type of group1 to a cell type of group2 to a list containing the expected null distribution as described above. If threshold is provided, a length-3 tuple will be returned, where the first element is the dictionary mapping to the null distributions. The second is a dictionary mapping to the the p-values.