troutpy.tl.spatial_variability#
- troutpy.tl.spatial_variability(sdata, coord_keys=None, gene_key='gene', n_neighbors=10, kde_resolution=1000, square_size=20, n_threads=1, method='moran', copy=False)#
Compute spatial variability of extracellular RNA using Moran’s I (or another autocorrelation statistic).
Extracellular transcripts are binned onto a spatial grid with
LazyKDE, and spatial autocorrelation is computed per gene on the resulting grid usingsquidpy. Results are stored insdata["xrna_metadata"].var.- Parameters:
sdata (spatialdata.SpatialData) – SpatialData object with a
"transcripts"points layer containingcoord_keys,"extracellular", andgene_keycolumns.coord_keys (list of str, optional) – Spatial coordinate column names. Defaults to
["x", "y"].gene_key (str, optional) – Column in the transcript layer with gene identifiers. Defaults to
"gene".n_neighbors (int, optional) – Number of neighbors used to build the spatial neighbor graph. Defaults to
10.kde_resolution (int, optional) – Grid resolution passed to
LazyKDE. Defaults to1000.square_size (int, optional) – Bin size (in coordinate units) for the KDE grid. Defaults to
20.n_threads (int, optional) – Number of threads for LazyKDE processing. Defaults to
1.method (str, optional) – Spatial autocorrelation statistic passed to
squidpy.gr.spatial_autocorr(). Defaults to"moran".copy (bool, optional) – If
True, return the updated SpatialData object; otherwise modify in place and returnNone. Defaults toFalse.
- Returns:
spatialdata.SpatialData or None Updated SpatialData with
f"{method}_*"columns added tosdata["xrna_metadata"].varifcopy=True; otherwiseNone.