troutpy.tl.adaptative_source_score_optimized

troutpy.tl.adaptative_source_score_optimized#

troutpy.tl.adaptative_source_score_optimized(sdata, chunk_size=100000, max_dist=100, lmbda=0.1, max_k=10, ambient_floor=1.0, signal_threshold=10, residual=0.1, cell_type_col='leiden', copy=False)#

Score extracellular transcripts against nearby cells using a chunked, numba-accelerated kernel.

A faster, chunked reimplementation of adaptative_source_score(). Cells are represented by a “shell” of their outermost assigned transcripts, and each extracellular transcript is scored against shell points within max_dist using _core_scoring_engine_chunk, processing chunk_size transcripts at a time.

Parameters:
  • sdata (SpatialData) – SpatialData object containing a "table" AnnData (with "cell_id" in .obs) and a "transcripts" points layer with "cell_id", "enrichment_over_random", "gene", "x", and "y" columns.

  • chunk_size (int (default: 100000)) – Number of extracellular transcripts processed per chunk.

  • max_dist (float (default: 100)) – 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: 10)) – Maximum number of extracellular neighbors used to build the context gene set.

  • ambient_floor (float (default: 1.0)) – "enrichment_over_random" value at or below which k_adaptive is 1.

  • signal_threshold (float (default: 10)) – "enrichment_over_random" value at or above which k_adaptive is max_k.

  • residual (float (default: 0.1)) – Constant added to the denominator when normalizing candidate weights.

  • cell_type_col (str (default: 'leiden')) – Column in sdata["table"].obs containing cell-type annotations.

  • copy (bool (default: False)) – If True, return sdata. Otherwise modify in place and return None.

Return type:

SpatialData | None

Returns:

If copy=True, sdata. Otherwise None, modifying sdata in place.

Notes

Adds a "source_score" table to sdata; an "urna_source_score" column to sdata["table"].obs; and "aggregated_source_score" / "mean_assignment_score" columns to sdata["xrna_metadata"].var. This is one of two overlapping source-scoring implementations in this module, alongside adaptative_source_score().