troutpy.tl.compute_target_score

troutpy.tl.compute_target_score#

troutpy.tl.compute_target_score(sdata, layer='transcripts', gene_key='gene', coords_key=None, lambda_decay=0.1, copy=False, celltype_key='cell type', k_neighbors=50, batch_size=100000)#

Compute, for every extracellular transcript, a per-cell-type target score plus its closest cell.

For each transcript, the k_neighbors nearest cells (by centroid distance) are weighted by exp(-lambda_decay * distance) and summed per cell type to produce a target-score distribution, alongside the single closest cell and its type.

Parameters:
  • sdata (SpatialData) – SpatialData object containing transcript points and cell table.

  • layer (str, optional) – Transcript layer in sdata.points. Defaults to "transcripts".

  • gene_key (str, optional) – Column in the transcript table for gene names. Defaults to "gene".

  • coords_key (list of str, optional) – Coordinate column names, e.g. ["x", "y"]. Defaults to ["x", "y"].

  • lambda_decay (float, optional) – Exponential decay factor applied to neighbor distances. Defaults to 0.1.

  • copy (bool, optional) – If True, return a copy of sdata. Defaults to False.

  • celltype_key (str, optional) – Column in adata.obs with cell type labels. Defaults to "cell type".

  • k_neighbors (int, optional) – Number of nearest cells to consider per transcript. Defaults to 50.

  • batch_size (int, optional) – Number of transcripts to process per batch. Defaults to 100_000.

Returns:

SpatialData or None sdata with a "target_score" table (per-transcript per-cell-type scores plus distance, closest_cell, and closest_cell_type columns in .obs) if copy=False; a copy of it if copy=True.