troutpy.tl.identify_density_k_neighbors#
- troutpy.tl.identify_density_k_neighbors(sdata, k_range=range(3, 61, 2), crop_size=400, d_threshold=0.8, segmentation_key='overlaps_cell')#
Find and visualize the smallest neighbor count
kthat separates cell from extracellular transcript density.Crops a square region around the median transcript position, computes a k-nearest-neighbor density (
k / (pi * r_k^2)) for everykink_range, and measures the Cohen’s d effect size between the densities of transcripts inside vs. outside cells. A plot of effect size vs.kis shown.- Parameters:
sdata (spatialdata.SpatialData) – SpatialData object with a
"transcripts"points layer containingx,y, andsegmentation_keycolumns.k_range (range or iterable of int, optional) – Candidate neighbor counts to evaluate. Defaults to
range(3, 61, 2).crop_size (float, optional) – Side length of the square region (centered on the median transcript position) used for the analysis. Defaults to
400.d_threshold (float, optional) – Minimum Cohen’s d effect size for
kto be considered separating. Defaults to0.8.segmentation_key (str, optional) – Boolean column identifying transcripts that overlap a segmented cell. Defaults to
"overlaps_cell".
- Returns:
int The smallest
kink_rangewhose Cohen’s d reachesd_threshold, or the largest value ink_rangeif none does.