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 ingroup1and every cell type ingroup2. This stands in contrast tomonkeybread.stat.shortest_distances()that considered the union of cells with cell type labels ingroup1as the first group and union of cell type labels ingroup2as the second group.For every pair of cell types in
group1andgroup2, this function calculates an expected null distribution of shortest distances from cells in thegroup1cell type to cells in thegroup2cell type by permuting coordinates of cells that aren’t in thegroup1cell type. The null hypothesis assumes no coherent spatial co-localization between cells of thegroup1cell type and cells of thegroup2cell type.If
observedandthresholdare provided, p-values are computed on the following test statistics: the number of shortest distances from cells in eachgroup1cell type to cells in eachgroup2cell type that are less thanthreshold.- Parameters:
adata (
AnnData) – Annotated data matrix.groupby (
str) – A categorical column inadata.obsto use for grouping.group1 (
List[str]) – One or more levels fromadata.obs[groupby]to use as sources for shortest distance.group2 (
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[Dict[str,Dict[str,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:'spatial')) – Coordinates inadata.obsm[{basis}]to use. Defaults tospatial.
- Return type:
Union[Dict[str,Dict[str,ndarray]],Tuple[Dict[str,Dict[str,ndarray]],Dict[str,Dict[str,float]]]]- Returns:
: If
thresholdis not provided, an dictonary of dictonaries is returned that maps each cell type ofgroup1to a cell type ofgroup2to a list containing the expected null distribution as described above. Ifthresholdis 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.