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, 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:
This implementation uses single-precision (float32) for calculations, which may result in decreased accuracy for weak correlations when compared to double-precision (float64) calculations. For strongly correlated data, the difference in p-values should be minimal. However, for weakly correlated data with I or C values close to their expected values, the lack of precision may lead to larger discrepancies in p-values.
- 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
Union
[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
vals
when it is a sparse matrix, by default True.- 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
copy
is False, the results are stored inadata.uns
and None is returned.