cellpin.tl.label_transfer

Contents

cellpin.tl.label_transfer#

cellpin.tl.label_transfer(model, sc_adata, cell_type_col, sp_adata, conf_threshold=0.0, k=15, test_size=0.2, random_state=42, table_key='table')#

Transfer cell type labels from scRNA to spatial data via kNN in cellpin latent space.

If X_cellpin is absent from either adata, impute() is run automatically with default settings and the embedding is stored back into the adata.

Return type:

tuple[float, AnnData]

Args:

model: Trained CellPin instance. sc_adata: Single-cell AnnData with ground-truth cell type labels. cell_type_col: Column in sc_adata.obs containing the cell type labels. sp_adata: Spatial AnnData (or SpatialData) to annotate. Modified in-place:

sp_adata.obs["cellpin_annotation"] and sp_adata.obs["cellpin_annotation_certainty"] are written.

conf_threshold: Min max-class probability to assign a label (default 0.0 =

annotate all). Cells below this threshold receive the label "Unknown".

k: Number of nearest neighbours (default 15). test_size: Fraction of scRNA cells held out for evaluation (default 0.2). random_state: Random seed for the train/test split (default 42). table_key: Table key when sp_adata is a SpatialData object.

Returns:

Tuple of (test_accuracy, sp_adata).