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)