spateo.tools.cluster.find_clusters

Attributes

Functions

spagcn_pyg(→ Optional[anndata.AnnData])

Function to find clusters with spagcn.

scc(→ Optional[anndata.AnnData])

Spatially constrained clustering (scc) to identify continuous tissue domains.

Module Contents

spateo.tools.cluster.find_clusters.to_dense_matrix[source]
spateo.tools.cluster.find_clusters.spagcn_pyg(adata: anndata.AnnData, n_clusters: int, p: float = 0.5, s: int = 1, b: int = 49, refine_shape: str | None = None, his_img_path: str | None = None, total_umi: str | None = None, x_pixel: str = None, y_pixel: str = None, x_array: str = None, y_array: str = None, seed: int = 100, copy: bool = False) anndata.AnnData | None[source]

Function to find clusters with spagcn.

Reference:

Jian Hu, Xiangjie Li, Kyle Coleman, Amelia Schroeder, Nan Ma, David J. Irwin, Edward B. Lee, Russell T. Shinohara & Mingyao Li. SpaGCN: Integrating gene expression, spatial location and histology to identify spatial domains and spatially variable genes by graph convolutional network. Nature Methods volume 18, pages1342–1351 (2021)

Parameters:
adata

an Anndata object, after normalization.

n_clusters

Desired number of clusters.

p

parameter p in spagcn algorithm. See SpaGCN for details. Defaults to 0.5.

s

alpha to control the color scale in calculating adjacent matrix. Defaults to 1.

b

beta to control the range of neighbourhood when calculate grey value for one spot in calculating adjacent matrix. Defaults to 49.

refine_shape

Smooth the spatial domains with given spatial topology, “hexagon” for Visium data, “square” for ST data. Defaults to None.

his_img_path

The file path of histology image used to calculate adjacent matrix in spagcn algorithm. Defaults to None.

total_umi

By providing the key(colname) in adata.obs which contains total UMIs(counts) for each spot, the function use the total counts as a grayscale image when histology image is not provided. Ignored if his_img_path is not None. Defaults to “total_umi”.

x_pixel

The key(colname) in adata.obs which contains corresponding x-pixels in histology image. Defaults to None.

y_pixel

The key(colname) in adata.obs which contains corresponding y-pixels in histology image. Defaults to None.

x_array

The key(colname) in adata.obs which contains corresponding x-coordinates. Defaults to None.

y_array

The key(colname) in adata.obs which contains corresponding y-coordinates. Defaults to None.

seed

Global seed for random, torch, numpy. Defaults to 100.

copy

Whether to return a new deep copy of adata instead of updating adata object passed in arguments. Defaults to False.

Returns:

~anndata.AnnData: An ~anndata.AnnData object with cluster info in “spagcn_pred”, and in “spagcn_pred_refined” if refine_shape is set.

The adjacent matrix used in spagcn algorithm is saved in adata.uns[“adj_spagcn”].

Return type:

class

spateo.tools.cluster.find_clusters.scc(adata: anndata.AnnData, spatial_key: str = 'spatial', key_added: str | None = 'scc', pca_key: str = 'pca', e_neigh: int = 30, s_neigh: int = 6, resolution: float | None = None) anndata.AnnData | None[source]

Spatially constrained clustering (scc) to identify continuous tissue domains.

Reference:

Ao Chen, Sha Liao, Mengnan Cheng, Kailong Ma, Liang Wu, Yiwei Lai, Xiaojie Qiu, Jin Yang, Wenjiao Li, Jiangshan Xu, Shijie Hao, Xin Wang, Huifang Lu, Xi Chen, Xing Liu, Xin Huang, Feng Lin, Zhao Li, Yan Hong, Defeng Fu, Yujia Jiang, Jian Peng, Shuai Liu, Mengzhe Shen, Chuanyu Liu, Quanshui Li, Yue Yuan, Huiwen Zheng, Zhifeng Wang, H Xiang, L Han, B Qin, P Guo, PM Cánoves, JP Thiery, Q Wu, F Zhao, M Li, H Kuang, J Hui, O Wang, B Wang, M Ni, W Zhang, F Mu, Y Yin, H Yang, M Lisby, RJ Cornall, J Mulder, M Uhlen, MA Esteban, Y Li, L Liu, X Xu, J Wang. Spatiotemporal transcriptomic atlas of mouse organogenesis using DNA nanoball-patterned arrays. Cell, 2022.

Parameters:
adata

an Anndata object, after normalization.

spatial_key

the key in .obsm that corresponds to the spatial coordinate of each bucket.

key_added

adata.obs key under which to add the cluster labels.

pca_key

label for the .obsm key containing PCA information (without the potential prefix “X_”)

e_neigh

the number of nearest neighbor in gene expression space.

s_neigh

the number of nearest neighbor in physical space.

resolution

the resolution parameter of the louvain clustering algorithm.

Returns:

An ~anndata.AnnData object with cluster info in .obs.

Return type:

adata