Skip to contents

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,
  BPPARAM = BiocParallel::bpparam()
)

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

A character vector specifying the column name in the `srt_query` metadata that represents the cell grouping.

ref_group

A character vector specifying the column name in the `srt_ref` metadata that represents the cell grouping.

query_assay

A character vector specifying the assay to be used for the query data. Defaults to the default assay of the `srt_query` object.

ref_assay

A character vector specifying the assay to be used for the reference data. Defaults to the default assay of the `srt_ref` object.

genes

"genes" parameter in SingleR function.

de.method

"de.method" parameter in SingleR function.

sd.thresh

Deprecated and ignored.

de.n

An integer scalar specifying the number of DE genes to use when genes="de". If de.method="classic", defaults to 500 * (2/3) ^ log2(N) where N is the number of unique labels. Otherwise, defaults to 10.

aggr.ref, aggr.args

Arguments controlling the aggregation of the references prior to annotation, see trainSingleR.

quantile, fine.tune, tune.thresh, prune

Further arguments to pass to classifySingleR.

BPPARAM

A BiocParallelParam object specifying how parallelization should be performed in other steps, see ?trainSingleR and ?classifySingleR for more details.

Examples

data("panc8_sub")
# Simply convert genes from human to mouse and preprocess the data
genenames <- make.unique(capitalize(rownames(panc8_sub), force_tolower = TRUE))
panc8_sub <- RenameFeatures(panc8_sub, newnames = genenames)
#> Rename features for the assay: RNA
panc8_sub <- check_srtMerge(panc8_sub, batch = "tech")[["srtMerge"]]
#> [2023-11-21 07:51:19.069847] Spliting srtMerge into srtList by column tech... ...
#> [2023-11-21 07:51:19.233309] Checking srtList... ...
#> Data 1/5 of the srtList is raw_normalized_counts. Perform NormalizeData(LogNormalize) on the data ...
#> Perform FindVariableFeatures on the data 1/5 of the srtList...
#> Data 2/5 of the srtList is raw_normalized_counts. Perform NormalizeData(LogNormalize) on the data ...
#> Perform FindVariableFeatures on the data 2/5 of the srtList...
#> Data 3/5 of the srtList is raw_normalized_counts. Perform NormalizeData(LogNormalize) on the data ...
#> Perform FindVariableFeatures on the data 3/5 of the srtList...
#> Data 4/5 of the srtList is raw_counts. Perform NormalizeData(LogNormalize) on the data ...
#> Perform FindVariableFeatures on the data 4/5 of the srtList...
#> Data 5/5 of the srtList is raw_counts. Perform NormalizeData(LogNormalize) on the data ...
#> Perform FindVariableFeatures on the data 5/5 of the srtList...
#> Use the separate HVF from srtList...
#> Number of available HVF: 2000
#> [2023-11-21 07:51:21.056182] Finished checking.

# Annotation
data("pancreas_sub")
pancreas_sub <- Standard_SCP(pancreas_sub)
#> [2023-11-21 07:51:22.816783] Start Standard_SCP
#> [2023-11-21 07:51:22.817021] Checking srtList... ...
#> Data 1/1 of the srtList is raw_counts. Perform NormalizeData(LogNormalize) on the data ...
#> Perform FindVariableFeatures on the data 1/1 of the srtList...
#> Use the separate HVF from srtList...
#> Number of available HVF: 2000
#> [2023-11-21 07:51:23.426502] Finished checking.
#> [2023-11-21 07:51:23.426677] Perform ScaleData on the data...
#> [2023-11-21 07:51:23.499636] Perform linear dimension reduction (pca) on the data...
#> Warning: The following arguments are not used: force.recalc
#> Warning: The following arguments are not used: force.recalc
#> [2023-11-21 07:51:24.168432] Perform FindClusters (louvain) on the data...
#> [2023-11-21 07:51:24.242835] Reorder clusters...
#> [2023-11-21 07:51:24.303697] Perform nonlinear dimension reduction (umap) on the data...
#> Non-linear dimensionality reduction(umap) using Reduction(Standardpca, dims:1-13) as input
#> Found more than one class "dist" in cache; using the first, from namespace 'BiocGenerics'
#> Also defined by ‘spam’
#> Found more than one class "dist" in cache; using the first, from namespace 'BiocGenerics'
#> Also defined by ‘spam’
#> Non-linear dimensionality reduction(umap) using Reduction(Standardpca, dims:1-13) as input
#> Found more than one class "dist" in cache; using the first, from namespace 'BiocGenerics'
#> Also defined by ‘spam’
#> Found more than one class "dist" in cache; using the first, from namespace 'BiocGenerics'
#> Also defined by ‘spam’
#> [2023-11-21 07:51:32.530625] Standard_SCP done
#> Elapsed time: 9.71 secs 
pancreas_sub <- RunSingleR(
  srt_query = pancreas_sub, srt_ref = panc8_sub,
  query_group = "Standardclusters", ref_group = "celltype",
)
#> Detected srt_query data type: log_normalized_counts
#> Detected srt_ref data type: log_normalized_counts
#> Perform SingleRCluster on the data...
#> 
  |                                                                                                                    
  |                                                                                                              |   0%
  |                                                                                                                    
  |=======================================================                                                       |  50%
  |                                                                                                                    
  |==============================================================================================================| 100%
#> 
#> 
  |                                                                                                                    
  |                                                                                                              |   0%
  |                                                                                                                    
  |===========================================================                                                   |  54%
  |                                                                                                                    
  |==============================================================================================================| 100%
#> 
#> Warning: missing values for 'group'
#> 
  |                                                                                                                    
  |                                                                                                              |   0%
#> 
#> 
  |                                                                                                                    
  |=======================================================                                                       |  50%
#> 
#> 
  |                                                                                                                    
  |==============================================================================================================| 100%
#> 
#> Error in `rownames<-`(`*tmp*`, value = new_rownames): missing values not allowed in rownames
CellDimPlot(pancreas_sub, group.by = "singler_annotation")
#> Error in CellDimPlot(pancreas_sub, group.by = "singler_annotation"): singler_annotation is not in the meta.data of srt object.

pancreas_sub <- RunSingleR(
  srt_query = pancreas_sub, srt_ref = panc8_sub,
  query_group = NULL, ref_group = "celltype"
)
#> Detected srt_query data type: log_normalized_counts
#> Detected srt_ref data type: log_normalized_counts
#> Perform SingleRCell on the data...
#> 
  |                                                                                                                    
  |                                                                                                              |   0%
  |                                                                                                                    
  |=======================================================                                                       |  50%
  |                                                                                                                    
  |==============================================================================================================| 100%
#> 
#> 
  |                                                                                                                    
  |                                                                                                              |   0%
  |                                                                                                                    
  |===========================================================                                                   |  54%
  |                                                                                                                    
  |==============================================================================================================| 100%
#> 
#> Error: No cell overlap between new meta data and Seurat object
CellDimPlot(pancreas_sub, group.by = "singler_annotation")
#> Error in CellDimPlot(pancreas_sub, group.by = "singler_annotation"): singler_annotation is not in the meta.data of srt object.