1 Introduction

SingleR is an automatic annotation method for single-cell RNA sequencing (scRNAseq) data (Aran et al. 2019). Given a reference dataset of samples (single-cell or bulk) with known labels, it labels new cells from a test dataset based on similarity to the reference. Thus, the burden of manually interpreting clusters and defining marker genes only has to be done once, for the reference dataset, and this biological knowledge can be propagated to new datasets in an automated manner.

To keep things brief, this vignette only provides a brief summary of the basic capabilities of SingleR. However, the package also provides more advanced functionality that includes the use of multiple references simultaneously, manipulating the cell ontology and improving performance on big datasets. Readers are referred to the book for more details.

2 Using built-in references

The easiest way to use SingleR is to annotate cells against built-in references. In particular, the celldex package provides access to several reference datasets (mostly derived from bulk RNA-seq or microarray data) through dedicated retrieval functions. Here, we will use the Human Primary Cell Atlas (Mabbott et al. 2013), represented as a SummarizedExperiment object containing a matrix of log-expression values with sample-level labels.

library(celldex)
hpca.se <- HumanPrimaryCellAtlasData()
hpca.se
## class: SummarizedExperiment 
## dim: 19363 713 
## metadata(0):
## assays(1): logcounts
## rownames(19363): A1BG A1BG-AS1 ... ZZEF1 ZZZ3
## rowData names(0):
## colnames(713): GSM112490 GSM112491 ... GSM92233 GSM92234
## colData names(3): label.main label.fine label.ont

Our test dataset consists of some human embryonic stem cells (La Manno et al. 2016) from the scRNAseq package. For the sake of speed, we will only label the first 100 cells from this dataset.

library(scRNAseq)
hESCs <- LaMannoBrainData('human-es')
hESCs <- hESCs[,1:100]

We use our hpca.se reference to annotate each cell in hESCs via the SingleR() function. This identifies marker genes from the reference and uses them to compute assignment scores (based on the Spearman correlation across markers) for each cell in the test dataset against each label in the reference. The label with the highest score is the assigned to the test cell, possibly with further fine-tuning to resolve closely related labels.

library(SingleR)
pred.hesc <- SingleR(test = hESCs, ref = hpca.se, assay.type.test=1,
    labels = hpca.se$label.main)

Each row of the output DataFrame contains prediction results for a single cell. Labels are shown before (labels) and after pruning (pruned.labels), along with the associated scores.

pred.hesc
## DataFrame with 100 rows and 4 columns
##                                         scores               labels delta.next
##                                       <matrix>          <character>  <numeric>
## 1772122_301_C02 0.347652:0.139036:0.109547:... Neuroepithelial_cell 0.08332864
## 1772122_180_E05 0.361187:0.155395:0.134934:...              Neurons 0.07283500
## 1772122_300_H02 0.446411:0.218052:0.190084:... Neuroepithelial_cell 0.13882912
## 1772122_180_B09 0.373512:0.172438:0.143537:... Neuroepithelial_cell 0.00317443
## 1772122_180_G04 0.357341:0.157275:0.126511:... Neuroepithelial_cell 0.09717938
## ...                                        ...                  ...        ...
## 1772122_299_E07 0.371989:0.202363:0.169379:... Neuroepithelial_cell  0.0837521
## 1772122_180_D02 0.353314:0.146049:0.115864:... Neuroepithelial_cell  0.0842804
## 1772122_300_D09 0.348789:0.129193:0.136732:... Neuroepithelial_cell  0.0595056
## 1772122_298_F09 0.332361:0.173357:0.141439:... Neuroepithelial_cell  0.1200606
## 1772122_302_A11 0.324928:0.127518:0.101609:...            Astrocyte  0.0509478
##                        pruned.labels
##                          <character>
## 1772122_301_C02 Neuroepithelial_cell
## 1772122_180_E05              Neurons
## 1772122_300_H02 Neuroepithelial_cell
## 1772122_180_B09 Neuroepithelial_cell
## 1772122_180_G04 Neuroepithelial_cell
## ...                              ...
## 1772122_299_E07 Neuroepithelial_cell
## 1772122_180_D02 Neuroepithelial_cell
## 1772122_300_D09 Neuroepithelial_cell
## 1772122_298_F09 Neuroepithelial_cell
## 1772122_302_A11            Astrocyte
# Summarizing the distribution:
table(pred.hesc$labels)
## 
##            Astrocyte Neuroepithelial_cell              Neurons 
##                   14                   81                    5

At this point, it is worth noting that SingleR is workflow/package agnostic. The above example uses SummarizedExperiment objects, but the same functions will accept any (log-)normalized expression matrix.

3 Using single-cell references

Here, we will use two human pancreas datasets from the scRNAseq package. The aim is to use one pre-labelled dataset to annotate the other unlabelled dataset. First, we set up the Muraro et al. (2016) dataset to be our reference.

library(scRNAseq)
sceM <- MuraroPancreasData()

# One should normally do cell-based quality control at this point, but for
# brevity's sake, we will just remove the unlabelled libraries here.
sceM <- sceM[,!is.na(sceM$label)]

# SingleR() expects reference datasets to be normalized and log-transformed.
library(scuttle)
sceM <- logNormCounts(sceM)

We then set up our test dataset from Grun et al. (2016). To speed up this demonstration, we will subset to the first 100 cells.

sceG <- GrunPancreasData()
sceG <- sceG[,colSums(counts(sceG)) > 0] # Remove libraries with no counts.
sceG <- logNormCounts(sceG) 

We then run SingleR() as described previously but with a marker detection mode that considers the variance of expression across cells. Here, we will use the Wilcoxon ranked sum test to identify the top markers for each pairwise comparison between labels. This is slower but more appropriate for single-cell data compared to the default marker detection algorithm (which may fail for low-coverage data where the median is frequently zero).

pred.grun <- SingleR(test=sceG, ref=sceM, labels=sceM$label, de.method="wilcox")
table(pred.grun$labels)
## 
##      acinar       alpha        beta       delta        duct endothelial 
##         657         245         276          57         367          34 
##     epsilon mesenchymal          pp     unclear 
##           1          41          35           5

4 Annotation diagnostics

plotScoreHeatmap() displays the scores for all cells across all reference labels, which allows users to inspect the confidence of the predicted labels across the dataset. Ideally, each cell (i.e., column of the heatmap) should have one score that is obviously larger than the rest, indicating that it is unambiguously assigned to a single label. A spread of similar scores for a given cell indicates that the assignment is uncertain, though this may be acceptable if the uncertainty is distributed across similar cell types that cannot be easily resolved.

plotScoreHeatmap(pred.grun)

Another diagnostic is based on the per-cell “deltas”, i.e., the difference between the score for the assigned label and the median across all labels for each cell. Low deltas indicate that the assignment is uncertain, which is especially relevant if the cell’s true label does not exist in the reference. We can inspect these deltas across cells for each label using the plotDeltaDistribution() function.

plotDeltaDistribution(pred.grun, ncol = 3)

The pruneScores() function will remove potentially poor-quality or ambiguous assignments based on the deltas. The minimum threshold on the deltas is defined using an outlier-based approach that accounts for differences in the scale of the correlations in various contexts - see ?pruneScores for more details. SingleR() will also report the pruned scores automatically in the pruned.labels field where low-quality assignments are replaced with NA.

summary(is.na(pred.grun$pruned.labels))
##    Mode   FALSE    TRUE 
## logical    1651      67

Finally, a simple yet effective diagnostic is to examine the expression of the marker genes for each label in the test dataset. We extract the identity of the markers from the metadata of the SingleR() results and use them in the plotHeatmap() function from scater, as shown below for beta cell markers. If a cell in the test dataset is confidently assigned to a particular label, we would expect it to have strong expression of that label’s markers. At the very least, it should exhibit upregulation of those markers relative to cells assigned to other labels.

all.markers <- metadata(pred.grun)$de.genes
sceG$labels <- pred.grun$labels

# Beta cell-related markers
library(scater)
plotHeatmap(sceG, order_columns_by="labels",
    features=unique(unlist(all.markers$beta))) 

5 FAQs

How can I use this with my Seurat, SingleCellExperiment, or cell_data_set object?

SingleR is workflow agnostic - all it needs is normalized counts. An example showing how to map its results back to common single-cell data objects is available in the README.

Where can I find reference sets appropriate for my data?

celldex contains many built-in references that were previously in SingleR but have been migrated into a separate package for more general use by other Bioconductor packages. scRNAseq contains many single-cell datasets, many of which contain the authors’ manual annotations. ArrayExpress and GEOquery can be used to download any of the bulk or single-cell datasets in ArrayExpress or GEO, respectively.

Where can I get more help?

It is likely that your questions is already answered by the function documentation (e.g., ?SingleR). Further explanations on the reasoning behind certain functions can be found in the book. If this is not sufficient, we recommend posting an issue on the Bioconductor support site or the GitHub repository for this package. Be sure to include your session information and a minimal reproducible example.

6 Session information

sessionInfo()
## R version 4.4.0 beta (2024-04-15 r86425)
## Platform: x86_64-pc-linux-gnu
## Running under: Ubuntu 22.04.4 LTS
## 
## Matrix products: default
## BLAS:   /home/biocbuild/bbs-3.19-bioc/R/lib/libRblas.so 
## LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.10.0
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8    
##  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8   
##  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C                 
##  [9] LC_ADDRESS=C               LC_TELEPHONE=C            
## [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C       
## 
## time zone: America/New_York
## tzcode source: system (glibc)
## 
## attached base packages:
## [1] stats4    stats     graphics  grDevices utils     datasets  methods  
## [8] base     
## 
## other attached packages:
##  [1] scater_1.32.0               ggplot2_3.5.1              
##  [3] scuttle_1.14.0              SingleR_2.6.0              
##  [5] scRNAseq_2.17.10            SingleCellExperiment_1.26.0
##  [7] celldex_1.13.3              SummarizedExperiment_1.34.0
##  [9] Biobase_2.64.0              GenomicRanges_1.56.0       
## [11] GenomeInfoDb_1.40.0         IRanges_2.38.0             
## [13] S4Vectors_0.42.0            BiocGenerics_0.50.0        
## [15] MatrixGenerics_1.16.0       matrixStats_1.3.0          
## [17] BiocStyle_2.32.0           
## 
## loaded via a namespace (and not attached):
##   [1] RColorBrewer_1.1-3        jsonlite_1.8.8           
##   [3] magrittr_2.0.3            ggbeeswarm_0.7.2         
##   [5] magick_2.8.3              GenomicFeatures_1.56.0   
##   [7] gypsum_1.0.0              farver_2.1.1             
##   [9] rmarkdown_2.26            BiocIO_1.14.0            
##  [11] zlibbioc_1.50.0           vctrs_0.6.5              
##  [13] memoise_2.0.1             Rsamtools_2.20.0         
##  [15] DelayedMatrixStats_1.26.0 RCurl_1.98-1.14          
##  [17] tinytex_0.50              htmltools_0.5.8.1        
##  [19] S4Arrays_1.4.0            AnnotationHub_3.12.0     
##  [21] curl_5.2.1                BiocNeighbors_1.22.0     
##  [23] Rhdf5lib_1.26.0           SparseArray_1.4.0        
##  [25] rhdf5_2.48.0              sass_0.4.9               
##  [27] alabaster.base_1.4.0      bslib_0.7.0              
##  [29] alabaster.sce_1.4.0       httr2_1.0.1              
##  [31] cachem_1.0.8              GenomicAlignments_1.40.0 
##  [33] igraph_2.0.3              lifecycle_1.0.4          
##  [35] pkgconfig_2.0.3           rsvd_1.0.5               
##  [37] Matrix_1.7-0              R6_2.5.1                 
##  [39] fastmap_1.1.1             GenomeInfoDbData_1.2.12  
##  [41] digest_0.6.35             colorspace_2.1-0         
##  [43] AnnotationDbi_1.66.0      paws.storage_0.5.0       
##  [45] dqrng_0.3.2               irlba_2.3.5.1            
##  [47] ExperimentHub_2.12.0      RSQLite_2.3.6            
##  [49] beachmat_2.20.0           labeling_0.4.3           
##  [51] filelock_1.0.3            fansi_1.0.6              
##  [53] httr_1.4.7                abind_1.4-5              
##  [55] compiler_4.4.0            withr_3.0.0              
##  [57] bit64_4.0.5               BiocParallel_1.38.0      
##  [59] viridis_0.6.5             DBI_1.2.2                
##  [61] highr_0.10                HDF5Array_1.32.0         
##  [63] alabaster.ranges_1.4.0    alabaster.schemas_1.4.0  
##  [65] rappdirs_0.3.3            DelayedArray_0.30.0      
##  [67] rjson_0.2.21              bluster_1.14.0           
##  [69] tools_4.4.0               vipor_0.4.7              
##  [71] beeswarm_0.4.0            glue_1.7.0               
##  [73] restfulr_0.0.15           rhdf5filters_1.16.0      
##  [75] grid_4.4.0                cluster_2.1.6            
##  [77] generics_0.1.3            gtable_0.3.5             
##  [79] ensembldb_2.28.0          metapod_1.12.0           
##  [81] BiocSingular_1.20.0       ScaledMatrix_1.12.0      
##  [83] utf8_1.2.4                XVector_0.44.0           
##  [85] ggrepel_0.9.5             BiocVersion_3.19.1       
##  [87] pillar_1.9.0              limma_3.60.0             
##  [89] dplyr_1.1.4               BiocFileCache_2.12.0     
##  [91] lattice_0.22-6            rtracklayer_1.64.0       
##  [93] bit_4.0.5                 tidyselect_1.2.1         
##  [95] paws.common_0.7.2         locfit_1.5-9.9           
##  [97] Biostrings_2.72.0         knitr_1.46               
##  [99] gridExtra_2.3             bookdown_0.39            
## [101] ProtGenerics_1.36.0       edgeR_4.2.0              
## [103] xfun_0.43                 statmod_1.5.0            
## [105] pheatmap_1.0.12           UCSC.utils_1.0.0         
## [107] lazyeval_0.2.2            yaml_2.3.8               
## [109] evaluate_0.23             codetools_0.2-20         
## [111] tibble_3.2.1              alabaster.matrix_1.4.0   
## [113] BiocManager_1.30.22       cli_3.6.2                
## [115] munsell_0.5.1             jquerylib_0.1.4          
## [117] Rcpp_1.0.12               dbplyr_2.5.0             
## [119] png_0.1-8                 XML_3.99-0.16.1          
## [121] parallel_4.4.0            blob_1.2.4               
## [123] AnnotationFilter_1.28.0   scran_1.32.0             
## [125] sparseMatrixStats_1.16.0  bitops_1.0-7             
## [127] viridisLite_0.4.2         alabaster.se_1.4.0       
## [129] scales_1.3.0              crayon_1.5.2             
## [131] rlang_1.1.3               KEGGREST_1.44.0

References

Aran, D., A. P. Looney, L. Liu, E. Wu, V. Fong, A. Hsu, S. Chak, et al. 2019. “Reference-based analysis of lung single-cell sequencing reveals a transitional profibrotic macrophage.” Nat. Immunol. 20 (2): 163–72.

Grun, D., M. J. Muraro, J. C. Boisset, K. Wiebrands, A. Lyubimova, G. Dharmadhikari, M. van den Born, et al. 2016. “De Novo Prediction of Stem Cell Identity using Single-Cell Transcriptome Data.” Cell Stem Cell 19 (2): 266–77.

La Manno, G., D. Gyllborg, S. Codeluppi, K. Nishimura, C. Salto, A. Zeisel, L. E. Borm, et al. 2016. “Molecular Diversity of Midbrain Development in Mouse, Human, and Stem Cells.” Cell 167 (2): 566–80.

Mabbott, Neil A., J. K. Baillie, Helen Brown, Tom C. Freeman, and David A. Hume. 2013. “An expression atlas of human primary cells: Inference of gene function from coexpression networks.” BMC Genomics 14. https://doi.org/10.1186/1471-2164-14-632.

Muraro, M. J., G. Dharmadhikari, D. Grun, N. Groen, T. Dielen, E. Jansen, L. van Gurp, et al. 2016. “A Single-Cell Transcriptome Atlas of the Human Pancreas.” Cell Syst 3 (4): 385–94.