troutpy.tl.spatial_colocalization#
- troutpy.tl.spatial_colocalization(sdata, coord_keys=None, gene_key='gene', resolution=1000, square_size=20, n_threads=1, threshold_colocalized=1, copy=False)#
Compute the proportion of spatially colocalized extracellular transcripts per gene.
Uses kernel density estimation (LazyKDE) to bin transcripts into a spatial grid, then calculates for each gene the fraction of bins whose count exceeds
threshold_colocalized. Results are stored insdata["xrna_metadata"].var["proportion_of_colocalized"].- Parameters:
sdata (spatialdata.SpatialData) – SpatialData object with a
"transcripts"points layer containing"extracellular"andgene_keycolumns, and an"xrna_metadata"table (created automatically if absent).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".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.threshold_colocalized (int, optional) – Minimum per-bin count for a bin to be considered colocalized. Defaults to
1.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
"proportion_of_colocalized"added tosdata["xrna_metadata"].varifcopy=True; otherwiseNone.