spcoral.pp.calculate_global_moran#
- spcoral.pp.calculate_global_moran(adata, spatial_coords_key='spatial', weight_method='knn', k=6, distance_threshold=None, use_layer=None, permutations=0, multiple_testing_correction='fdr_bh', alpha=0.05, I_cut=None, n_jobs=-1, batch_size=None, verbose=True)#
Compute global Moran’s I for each gene and return a new AnnData object containing only genes with significant spatial autocorrelation (p-value < alpha).
Supports parallel computation for faster processing on large datasets.
- Parameters:
adata (AnnData) – Input AnnData object containing gene expression data and spatial coordinates.
spatial_coords_key (str, optional (default: 'spatial')) – Key in
.obsmwhere spatial coordinates are stored.weight_method ({'knn', 'distance'}, optional (default: 'knn')) – Method to construct the spatial weights matrix: - ‘knn’: K-nearest neighbors. - ‘distance’: Distance threshold (inverse distance weighting within threshold).
k (int, optional (default: 6)) – Number of nearest neighbors when
weight_method='knn'.distance_threshold (float, optional) – Distance threshold when
weight_method='distance'. If None, automatically set to 1.5 × median pairwise distance.use_layer (str, optional) – Key in
.layersto use for expression data. If None, uses.X.permutations (int, optional (default: 0)) – Number of permutations for permutation test. If 0, uses normal approximation for p-values; if >0, uses permutation test.
multiple_testing_correction ({'fdr_bh', 'bonferroni'}, optional (default: 'fdr_bh')) – Multiple testing correction method. If None, no correction is applied.
alpha (float, optional (default: 0.05)) – Significance level threshold.
I_cut (float, optional) – Optional lower threshold for Moran’s I value. Only genes with I >
I_cutare considered significant (in addition to p-value < alpha).n_jobs (int, optional (default: -1)) – Number of parallel jobs. -1 uses all available CPU cores; 1 disables parallelism.
batch_size (int, optional) – Number of genes processed per worker batch. If None, automatically determined.
verbose (bool, optional (default: True)) – Whether to display progress and information messages.
- Returns:
New AnnData object containing only genes with significant spatial autocorrelation. The
.vardataframe includes columns: - ‘moran_i’: Moran’s I statistic. - ‘moran_pval’: raw p-value. - ‘moran_pval_<method>’ (if correction applied): corrected p-value.- Return type:
AnnData