troutpy.pp.define_urna_probability

troutpy.pp.define_urna_probability#

troutpy.pp.define_urna_probability(sdata, p_threshold=0.5, copy=False)#

Classify transcripts as extracellular (uRNA) via a Bayesian probability from grid-interpolated KDEs.

Fits Gaussian KDEs of cosine_similarity for transcripts inside cells versus background transcripts outside cells, evaluates both on a shared grid to derive P(uRNA | cosine_similarity), and interpolates this probability back onto every transcript.

Parameters:
  • sdata (spatialdata.SpatialData) – SpatialData object with a "transcripts" points layer containing overlaps_cell, cosine_similarity, and enrichment_class columns.

  • p_threshold (float, optional) – Minimum prob_is_urna value for a transcript to be classified as extracellular. Defaults to 0.5.

  • copy (bool, optional) – If True, return the modified SpatialData object. Otherwise modify sdata in place and return None. Defaults to False.

Returns:

spatialdata.SpatialData or None SpatialData with prob_is_urna and extracellular columns added to the "transcripts" layer if copy=True; otherwise None. If fewer than 10 reference transcripts are available inside or outside cells, sdata is returned unchanged.