Annotate single cells using SingleR
Usage
RunSingleR(
srt_query,
srt_ref,
query_group = NULL,
ref_group = NULL,
query_assay = "RNA",
ref_assay = "RNA",
genes = "de",
de.method = "wilcox",
sd.thresh = 1,
de.n = NULL,
aggr.ref = FALSE,
aggr.args = list(),
quantile = 0.8,
fine.tune = TRUE,
tune.thresh = 0.05,
prune = TRUE,
cores = 1,
verbose = TRUE
)Arguments
- srt_query
An object of class Seurat to be annotated with cell types.
- srt_ref
An object of class Seurat storing the reference cells.
- query_group
Column name in the
srt_querymetadata that represents the cell grouping.- ref_group
Column name in the
srt_refmetadata that represents the cell grouping.- query_assay
Assay to be used for the query data. Default is the default assay of the
srt_queryobject.- ref_assay
Assay to be used for the reference data. Default is the default assay of the
srt_refobject.- genes
A string containing
"de", indicating that markers should be calculated fromref. For back compatibility, other string values are allowed but will be ignored with a deprecation warning.Alternatively, if
refis not a list,genescan be either:A list of lists of character vectors containing DE genes between pairs of labels.
A list of character vectors containing marker genes for each label.
If
refis a list,genescan be a list of length equal toref. Each element of the list should be one of the two above choices described for non-listref, containing markers for labels in the corresponding entry ofref.- de.method
String specifying how DE genes should be detected between pairs of labels. Defaults to
"classic", which sorts genes by the log-fold changes and takes the topde.n. Other options are"wilcox"and"t", see Details. Ignored ifgenesis a list of markers/DE genes.- sd.thresh
Deprecated and ignored.
- de.n
An integer scalar specifying the number of DE genes to use when
genes="de". Ifde.method="classic", defaults to500 * (2/3) ^ log2(N)whereNis the number of unique labels. Otherwise, defaults to 10. Ignored ifgenesis a list of markers/DE genes.- aggr.ref, aggr.args
Arguments controlling the aggregation of the references prior to annotation, see
trainSingleR.- quantile
"quantile" parameter in SingleR::SingleR function.
- fine.tune
"fine.tune"parameter in SingleR::SingleR function.- tune.thresh
"tune.thresh"parameter in SingleR::SingleR function.- prune
"prune"parameter in SingleR::SingleR function.- cores
The number of worker processes to use for parallelization. Default is
1.- verbose
Whether to print the message. Default is
TRUE.
Value
An annotate Seurat object.
The annotation results are stored in the singler_annotation column of the meta data,
and the corresponding scores are stored in the singler_score column.
Examples
data(panc8_sub)
genenames <- make.unique(
thisutils::capitalize(
rownames(panc8_sub),
force_tolower = TRUE
)
)
names(genenames) <- rownames(panc8_sub)
panc8_sub <- RenameFeatures(
panc8_sub,
newnames = genenames
)
#> ℹ [2026-08-30 05:37:26] Rename features for the assay: RNA
panc8_sub <- RunStandardWorkflow(panc8_sub)
#> ℹ [2026-08-30 05:37:26] Start standard processing workflow...
#> ℹ [2026-08-30 05:37:26] Checking a list of <Seurat>...
#> ! [2026-08-30 05:37:27] Data 1/1 of the `srt_list` is "unknown"
#> Warning: Data 1/1 of the `srt_list` is "unknown"
#> ℹ [2026-08-30 05:37:27] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on 1/1 of `srt_list`...
#> ℹ [2026-08-30 05:37:27] Perform `FindVariableFeatures()` on 1/1 of `srt_list`...
#> ℹ [2026-08-30 05:37:27] Use the separate HVF from `srt_list`
#> ℹ [2026-08-30 05:37:27] Number of available HVF: 2000
#> ℹ [2026-08-30 05:37:27] Finished check
#> ℹ [2026-08-30 05:37:27] Perform `ScaleData()`
#> ℹ [2026-08-30 05:37:27] Perform pca linear dimension reduction
#> ℹ [2026-08-30 05:37:28] Use stored estimated dimensions 1:26 for Standardpca
#> ℹ [2026-08-30 05:37:28] Perform `Seurat::FindClusters()` with `cluster_algorithm = 'louvain'` and `cluster_resolution = 0.6`
#> ℹ [2026-08-30 05:37:28] Reorder clusters...
#> ℹ [2026-08-30 05:37:28] Skip `log1p()` because `layer = data` is not "counts"
#> ℹ [2026-08-30 05:37:29] Perform umap nonlinear dimension reduction
#> ✔ [2026-08-30 05:37:38] Standard processing workflow completed
data(pancreas_sub)
pancreas_sub <- RunStandardWorkflow(pancreas_sub)
#> ℹ [2026-08-30 05:37:38] Start standard processing workflow...
#> ℹ [2026-08-30 05:37:38] Checking a list of <Seurat>...
#> ! [2026-08-30 05:37:38] Data 1/1 of the `srt_list` is "unknown"
#> Warning: Data 1/1 of the `srt_list` is "unknown"
#> ℹ [2026-08-30 05:37:38] Perform `NormalizeData()` with `normalization.method = 'LogNormalize'` on 1/1 of `srt_list`...
#> ℹ [2026-08-30 05:37:38] Perform `FindVariableFeatures()` on 1/1 of `srt_list`...
#> ℹ [2026-08-30 05:37:38] Use the separate HVF from `srt_list`
#> ℹ [2026-08-30 05:37:39] Number of available HVF: 2000
#> ℹ [2026-08-30 05:37:39] Finished check
#> ℹ [2026-08-30 05:37:39] Perform `ScaleData()`
#> ℹ [2026-08-30 05:37:39] Perform pca linear dimension reduction
#> ℹ [2026-08-30 05:37:39] Use stored estimated dimensions 1:23 for Standardpca
#> ℹ [2026-08-30 05:37:39] Perform `Seurat::FindClusters()` with `cluster_algorithm = 'louvain'` and `cluster_resolution = 0.6`
#> ℹ [2026-08-30 05:37:40] Reorder clusters...
#> ℹ [2026-08-30 05:37:40] Skip `log1p()` because `layer = data` is not "counts"
#> ℹ [2026-08-30 05:37:40] Perform umap nonlinear dimension reduction
#> ✔ [2026-08-30 05:37:48] Standard processing workflow completed
pancreas_sub <- RunSingleR(
srt_query = pancreas_sub,
srt_ref = panc8_sub,
query_group = "Standardpca_SNN_res.0.6",
ref_group = "celltype"
)
#> ℹ [2026-08-30 05:37:48] Start SingleR annotation
#> ℹ [2026-08-30 05:37:49] Data type is log-normalized
#> ℹ [2026-08-30 05:37:49] Detected `srt_query` data type: "log_normalized_counts"
#> ℹ [2026-08-30 05:37:49] Data type is log-normalized
#> ℹ [2026-08-30 05:37:49] Detected `srt_ref` data type: "log_normalized_counts"
#> ℹ [2026-08-30 05:37:49] Perform "SingleRCluster"
#> Detected a large SingleCellExperiment as the reference dataset, consider
#> setting 'aggr.ref = TRUE' for speed in trainSingleR(). If you know better, this
#> hint can be disabled with 'hint.sce=FALSE'.
#> ✔ [2026-08-30 05:37:50] SingleR annotation completed
CellDimPlot(
pancreas_sub,
group.by = c("singler_annotation", "SubCellType")
)
pancreas_sub <- RunSingleR(
srt_query = pancreas_sub,
srt_ref = panc8_sub,
query_group = NULL,
ref_group = "celltype"
)
#> ℹ [2026-08-30 05:37:51] Start SingleR annotation
#> ℹ [2026-08-30 05:37:51] Data type is log-normalized
#> ℹ [2026-08-30 05:37:51] Detected `srt_query` data type: "log_normalized_counts"
#> ℹ [2026-08-30 05:37:51] Data type is log-normalized
#> ℹ [2026-08-30 05:37:51] Detected `srt_ref` data type: "log_normalized_counts"
#> ℹ [2026-08-30 05:37:52] Perform "SingleRCell"
#> Detected a large SingleCellExperiment as the reference dataset, consider
#> setting 'aggr.ref = TRUE' for speed in trainSingleR(). If you know better, this
#> hint can be disabled with 'hint.sce=FALSE'.
#> ✔ [2026-08-30 05:37:53] SingleR annotation completed
CellDimPlot(
pancreas_sub,
group.by = c("singler_annotation", "SubCellType"),
label = TRUE
)
FeatureStatPlot(
pancreas_sub,
stat.by = "singler_score",
group.by = "singler_annotation"
)
#> ! [2026-08-30 05:37:54] Removed 2 groups with < 2 observations for violin plot: "sp--gp-quiescent-stellate" and "sp--gp-mast"
#> Warning: Removed 2 groups with < 2 observations for violin plot: "sp--gp-quiescent-stellate" and "sp--gp-mast"
#> Warning: No shared levels found between `names(values)` of the manual scale and the
#> data's colour values.
ht1 <- CellCorHeatmap(
srt_query = pancreas_sub,
srt_ref = pancreas_sub,
query_group = "SubCellType",
cluster_rows = TRUE,
ref_group = "singler_annotation",
cluster_columns = TRUE,
width = 2,
height = 2
)
#> ℹ [2026-08-30 05:37:54] Drop [1] 10 cells with NA in the ref_group
#> ℹ [2026-08-30 05:37:55] Use the HVF to calculate distance metric
#> ℹ [2026-08-30 05:37:55] Use [1] 2000 features to calculate distance.
#> ℹ [2026-08-30 05:37:55] Detected query data type: "log_normalized_counts"
#> ℹ [2026-08-30 05:37:55] Detected reference data type: "log_normalized_counts"
#> ℹ [2026-08-30 05:37:55] Calculate similarity...
#> ℹ [2026-08-30 05:37:55] Use raw method to find neighbors
#> ℹ [2026-08-30 05:37:55] Predict cell type...
ht1$plot