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
group1to cells ingroup2by permuting coordinates of cells that aren’t in group1. The null hypothesis assumes no coherent spatial co-localization between cells ofgroup1and cells ofgroup2. Ifgroup1is a list, then this function will consider the union of all cells with a label ingroup1. Likewise ifgroup2is a list then this function will consider the union of all cells with a label ingroup2.If
observedandthresholdare provided, a p-value is computed on the following test statistic: the number of shortest distances from cells ingroup1to cells ingroup2that are less thanthreshold.- Parameters:
adata (
AnnData) – Annotated data matrix.groupby (
str) – A categorical column inadata.obsto use for grouping.group1 (
Union[str,List[str]]) – One or more levels fromadata.obs[groupby]to use as sources for shortest distance.group2 (
Union[str,List[str]]) – One or more levels fromadata.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 bymonkeybread.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 inadata.obsm[{basis}]to use. Defaults tospatial.
- Return type:
- Returns:
: If
thresholdis not provided, an array containing the expected null distribution as described above. Ifthresholdis 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.