rapids_singlecell.gr.spatial_autocorr#
- rapids_singlecell.gr.spatial_autocorr(adata, *, connectivity_key='spatial_connectivities', genes=None, mode='moran', transformation=True, n_perms=None, two_tailed=False, corr_method='fdr_bh', layer=None, use_raw=False, use_sparse=True, dtype=None, multi_gpu=None, copy=False)[source]#
Calculate spatial autocorrelation for genes in an AnnData object.
This function computes spatial autocorrelation scores (Moran’s I or Geary’s C) for each gene in an AnnData object. The function also calculates p-values and corrected p-values for multiple testing.
- Note:
The precision (float32 or float64) is determined by the input data dtype. For best numerical stability, especially with genes having low variance, use float64 input data.
- Parameters:
- adata
AnnData Annotated data matrix.
- connectivity_key
str(default:'spatial_connectivities') Key of the connectivity matrix in
adata.obsp, by default “spatial_connectivities”.- genes
str|Sequence[str] |None(default:None) Genes for which to compute the autocorrelation scores. If None, all genes or highly variable genes will be used.
- mode
Literal['moran','geary'] (default:'moran') Spatial autocorrelation method to use, either “moran” or “geary”, by default “moran”.
- transformation
bool(default:True) If True, row-normalize the connectivity matrix, by default True.
- n_perms
int|None(default:None) Number of permutations for calculating p-values, by default None.
- two_tailed
bool(default:False) If True, calculate two-tailed p-values, by default False.
- corr_method
str|None(default:'fdr_bh') Multiple testing correction method to use, by default “fdr_bh”.
- layer
str|None(default:None) Layer in the AnnData object to use, by default None.
- use_raw
bool(default:False) If True, use the raw data in the AnnData object, by default False.
- use_sparse
bool(default:True) If True, use a sparse representation for the input matrix
valswhen it is a sparse matrix, by default True.- dtype
dtype|None(default:None) Data type for computation. If None, uses input data dtype. For best numerical stability, especially with genes having low variance, use
np.float64.- multi_gpu
bool|list[int] |str|None(default:None) GPU selection for permutation tests: - None: Use all GPUs if available (default) - True: Use all available GPUs - False: Use only GPU 0 - list[int]: Use specific GPU IDs (e.g., [0, 2]) - str: Comma-separated GPU IDs (e.g., “0,2”)
- copy
bool(default:False) If True, return the results as a DataFrame instead of storing them in
adata.uns, by default False.
- adata
- Return type:
- Returns:
DataFrame containing the autocorrelation scores, p-values, and corrected p-values for each gene. If
copyis False, the results are stored inadata.unsand None is returned.