pyucell.smooth_knn_scores#
- pyucell.smooth_knn_scores(adata, obs_columns, k=10, use_rep='X_pca', decay=0.1, up_only=False, graph_key=None, suffix='_kNN', device=None)#
Smooth per-cell signature scores by weight-averaging over k nearest neighbors.
- Parameters:
adata (AnnData) – AnnData with .obs columns containing signature scores.
obs_columns (list of str) – Names of columns in adata.obs with the scores to smooth.
k (int) – Number of neighbors (ignored if graph_key provided).
use_rep (str) – Representation to compute neighbors (e.g., ‘X_pca’, ‘X’).
decay (float) – Decay parameter (0<decay<1) for weighting nearest neighbors: weight = (1 - decay)^i for i-th neighbor.
up_only (bool) – If True, ensures smoothed scores are at least as high as the original.
graph_key (str or None) – If provided, the name of a precomputed graph in adata.obsp to use (e.g. ‘connectivities’ or ‘my_graph’). If None, compute neighbors with scanpy.
suffix (str) – Optional suffix for smoothed scores. By default ‘_kNN’ is appended.
device (str | None, optional) –
None(default) → CPU sparse matmul."cpu"/"cuda"/"mps"/"auto"→ torch sparse matmul on that device. Requires thepyucell[gpu]extra.
- Returns:
None. Adds smoothed scores to adata.obs.