troutpy.tl.adaptative_source_score#
- troutpy.tl.adaptative_source_score(sdata, max_dist=200, lmbda=0.1, max_k=15, ambient_floor=1.5, signal_threshold=3.0, residual=0.1, cell_type_col='leiden', copy=False)#
Score extracellular transcripts against nearby cells using an adaptive neighborhood size.
For each extracellular transcript, a context gene set is built from its
k_adaptivenearest extracellular neighbors (wherek_adaptivegrows with the transcript’s"enrichment_over_random"), then candidate parent cells withinmax_distare weighted by how well their expression matches that context and by exponential distance decay.- Parameters:
sdata (
SpatialData) – SpatialData object containing a"table"AnnData and a"transcripts"points layer with"overlaps_cell","enrichment_over_random","gene","x", and"y"columns.max_dist (
float(default:200)) – Maximum distance (in coordinate units) to search for candidate parent cells.lmbda (
float(default:0.1)) – Decay rate for the exponential distance weighting.max_k (
int(default:15)) – Maximum number of extracellular neighbors used to build the context gene set.ambient_floor (
float(default:1.5)) –"enrichment_over_random"value at or below whichk_adaptiveis 1.signal_threshold (
float(default:3.0)) –"enrichment_over_random"value at or above whichk_adaptiveismax_k.residual (
float(default:0.1)) – Constant added to the denominator when normalizing candidate weights, preventing division by zero and capping the maximum normalized score.cell_type_col (
str(default:'leiden')) – Column insdata["table"].obscontaining cell-type annotations.copy (
bool(default:False)) – IfTrue, returnsdata. Otherwise modify in place and returnNone.
- Return type:
- Returns:
If
copy=True,sdata. OtherwiseNone, modifyingsdatain place.
Notes
Adds a
"source_score"table tosdata;"urna_source_score"/"normalized_urna_source_score"columns tosdata["table"].obs; and"aggregated_source_score"/"mean_assignment_score"columns tosdata["xrna_metadata"].var. This is one of two overlapping source-scoring implementations in this module, alongsideadaptative_source_score_optimized().