spateo.tools.spatial_degs
#
Spatial DEGs
Module Contents#
Functions#
|
Identify genes with strong spatial autocorrelation with Moran's I test. |
|
Calculate Moran's I score for each celltype (in segmented cell adata). |
- spateo.tools.spatial_degs.moran_i(adata: anndata.AnnData, genes: Optional[List[str]] = None, layer: Optional[str] = None, spatial_key: str = 'spatial', model: Literal[2d, 3d] = '2d', x: Optional[List[int]] = None, y: Optional[List[int]] = None, z: Optional[List[int]] = None, k: int = 5, weighted: Optional[List[str]] = None, permutations: int = 199, n_jobs: int = 1) pandas.DataFrame [source]#
Identify genes with strong spatial autocorrelation with Moran’s I test. This can be used to identify genes that are potentially related to cluster.
- Parameters
- adata :
AnnData
an Annodata object
- genes : list or None (default: None)
The list of genes that will be used to subset the data for dimension reduction and clustering. If None, all genes will be used.
- layer : str or None (default: None)
The layer that will be used to retrieve data for dimension reduction and clustering. If None, .X is used.
- spatial_key : The key in
.obsm
that corresponds to the spatial coordinate of each cell. - x : ‘list’ or None(default: None)
x-coordinates of all buckets.
- y : ‘list’ or None(default: None)
y-coordinates of all buckets.
- z : ‘list’ or None(default: None)
z-coordinates of all buckets.
- k : 'int' (defult=20)
Number of neighbors to use by default for kneighbors queries.
- weighted : 'str'(defult='kernel')
Spatial weights, defult is None, ‘kernel’ is based on kernel functions.
- permutations : int (default=999)
Number of random permutations for calculation of pseudo-p_values.
- n_cores : int (default=30)
The maximum number of concurrently running jobs, If -1 all CPUs are used. If 1 is given, no parallel computing code is used at all.
- adata :
- Returns
A pandas DataFrame of the Moran’ I test results.
- spateo.tools.spatial_degs.cellbin_morani(adata_cellbin: anndata.AnnData, binsize: int, cluster_key: str = 'Celltype') pandas.DataFrame [source]#
Calculate Moran’s I score for each celltype (in segmented cell adata). Since the presentation of cells are boolean values, this function first summarizes the number of each celltype using a given binsize, creating a spatial 2D matrix with cell counts. Then calculates Moran’s I score on the matrix for spatial score for each celltype.
- Parameters
- Returns
A pandas DataFrame containing the Moran’ I score for celltypes.