spateo.tools.spatial_correlation ================================ .. py:module:: spateo.tools.spatial_correlation Functions --------- .. autoapisummary:: spateo.tools.spatial_correlation.spatial_bv_moran_obs_genes spateo.tools.spatial_correlation.spatial_bv_local_moran Module Contents --------------- .. py:function:: spatial_bv_moran_obs_genes(adata: anndata.AnnData, obs_key: str, connectivity_key: str = 'spatial_connectivities', genes: Union[str, int, Sequence[str], Sequence[int], None] = None, n_neighbors: int = 10, mode: str = 'moran', transformation: str = 'r', permutations: Optional[int] = 999, copy: bool = False) -> Optional[pandas.DataFrame] Calculate global bivariate Moran's I between a spatial variable and gene expression :param adata: AnnData object containing spatial data :param obs_key: Key in `adata.obs` for the variable :param connectivity_key: Key in `adata.obsp` for spatial connectivity matrix (default: 'spatial_connectivities') :param genes: Genes to calculate (names or indices). If None, use all genes. :param mode: Spatial correlation mode (only 'moran' supported) :param transformation: Weight transformation method ('r' for row-standardization) :param permutations: Number of permutations for significance testing :param copy: Return a DataFrame instead of storing in AnnData :returns: * If ``copy = True``, returns a :class:`pandas.DataFrame` with the following keys -- I : float value of bivariate Moran's I sim : array (if permutations>0) vector of I values for permuted samples p_sim : float (if permutations>0) p-value based on permutations (one-sided) null: spatial randomness alternative: the observed I is extreme it is either extremely high or extremely low z_sim : array (if permutations>0) standardized I based on permutations p_z_sim : float (if permutations>0) p-value based on standard normal approximation from permutations * Otherwise, modifies the ``adata`` with the following key -- - :attr:`anndata.AnnData.uns` ``['{obs_key}_gene_bv_moranI']`` - the above mentioned dataframe``. .. py:function:: spatial_bv_local_moran(adata: anndata.AnnData, feature1_key: str, feature2_key: str, connectivity_key: str = 'spatial_connectivities', n_neighbors: int = 10, mode: str = 'moran', transformation: str = 'r', permutations: Optional[int] = 999, copy: bool = False) -> Optional[pandas.DataFrame] Calculate global bivariate Moran's I between a spatial variable and gene expression :param adata: AnnData object containing spatial data :param feature1_key: Key in `adata.obs` for the first variable or gene_name :param feature2_key: Key in `adata.obs` for the seconda variable or gene_name :param connectivity_key: Key in `adata.obsp` for spatial connectivity matrix (default: 'spatial_connectivities') :param mode: Spatial correlation mode (only 'moran' supported) :param transformation: Weight transformation method ('r' for row-standardization) :param permutations: Number of permutations for significance testing :param copy: Return a DataFrame instead of storing in AnnData :returns: * If ``copy = True``, returns a :class:`pandas.DataFrame` with the following keys -- I : float value of bivariate Moran's I q : array (if permutations>0) values indicate quandrant location 1 HH, 2 LH, 3 LL, 4 HL sim : array (if permutations>0) vector of I values for permuted samples p_sim : float (if permutations>0) p-value based on permutations (one-sided) null: spatial randomness alternative: the observed I is extreme it is either extremely high or extremely low z_sim : array (if permutations>0) standardized I based on permutations p_z_sim : float (if permutations>0) p-value based on standard normal approximation from permutations * Otherwise, modifies the ``adata`` with the following key -- - :attr:`anndata.AnnData.uns` ``['{feature1_key}_{feature2_key}_bv_local_moranI']`` - the above mentioned dataframe``.