spateo.segmentation.moran ========================= .. py:module:: spateo.segmentation.moran .. autoapi-nested-parse:: Cell masking using Moran's I metric. Adapted from code written by @HailinPan. Functions --------- .. autoapisummary:: spateo.segmentation.moran.moranI spateo.segmentation.moran.run_moran spateo.segmentation.moran.run_moran_and_mask_pixels spateo.segmentation.moran.binary_morani_result Module Contents --------------- .. py:function:: moranI(X: numpy.ndarray, kernel: numpy.ndarray, mask: Optional[numpy.ndarray] = None) -> Tuple[numpy.ndarray, numpy.ndarray, numpy.ndarray, numpy.ndarray] Compute Moran's I for cell masking. :param X: Numpy array containing (possibly smoothed) UMI counts or binarized values. :param kernel: 2D kernel containing weights :param mask: If provided, only consider pixels within the mask :returns: A 4-element tuple containing (z, c, i, pvalue). .. py:function:: run_moran(X: numpy.ndarray, k: int = 7, p_threshold: float = 0.05, mask: Optional[numpy.ndarray] = None) -> numpy.ndarray Compute scores using Moran's I method. :param X: Numpy array containing (possibly smoothed) UMI counts or binarized values. :param k: Kernel size :param p_threshold: P-value threshold. Test. Test Test :param mask: If provided, only consider pixels within the mask :returns: A 2D Numpy array indicating pixel scores .. py:function:: run_moran_and_mask_pixels(adata: anndata.AnnData, layer: str, k: int = 7, method: str = 'edge-watershed', mk: int = 3, mask: Optional[numpy.ndarray] = None, mask_layer: Optional[str] = None) -> numpy.ndarray Compute scores using Moran's I method. :param adata: Input Anndata :param layer: Layer that contains UMI counts to use :param k: Kernel size :param method: Method used for generating cell mask based on p value of Moran's I. 'edge-watershed' or 'otsu' :param mk: Kernel size of morphological open and close operations to reduce noise in the mask. :param mask: If provided, only consider pixels within the mask :param mask_layer: Layer to save the final mask. Defaults to `{layer}_mask`. :returns: A boolean mask. .. py:function:: binary_morani_result(c: numpy.ndarray, p: numpy.ndarray, pvalue_cutoff: float = None, method: str = 'edge-watershed', c_cutoff: float = None, tissue_mask: Optional[numpy.ndarray] = None) -> numpy.ndarray Generate cell mask based on Moran's I.