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_neighborsnearest cells (by centroid distance) are weighted byexp(-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 ofsdata. Defaults toFalse.celltype_key (str, optional) – Column in
adata.obswith 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
sdatawith a"target_score"table (per-transcript per-cell-type scores plusdistance,closest_cell, andclosest_cell_typecolumns in.obs) ifcopy=False; a copy of it ifcopy=True.