20 Cell Identity and Reference Mapping chapter.
Label transfer from a reference is cheap enough to demonstrate: a KNN mapping of pbmc against a held-out subset of itself gives a mapping record with a real transferred-label column and a real score column, which is exactly what the two functions read.
The KNN path is deliberate. SingleR/celldex mapping is already demonstrated in the reference mapping chapter, but it downloads a reference atlas and is conditional on those packages; for a visualization example the requirement is a record, not a specific backend.
set.seed(11)
ref_index <- sample(seq_len(ncol(pbmc)), 500)
ref_sce <- pbmc[, ref_index]
query_sce <- pbmc[, -ref_index]
ref_sce$label <- as.character(SingleCellExperiment::colLabels(ref_sce))
query_sce <- RunReferenceMapping(
object = query_sce,
ref = ref_sce,
labels = "label",
method = "KNN",
layer = "logcounts",
k = 5,
name = "knn_viz"
)
# Both columns the two plots resolve from the mapping record.
get_mapping(query_sce, id = "knn_viz")$artifacts[c("labels_col", "score_col")]## $labels_col
## [1] "knn_viz_labels"
##
## $score_col
## [1] "knn_viz_score"
# Label transfer summary heatmap: query groups x transferred labels.
plot_reference_label_transfer_heatmap(query_sce, group.by = "colLabels",
id = "knn_viz")
