Chapter 1 Introduction
1.1 Motivation
The Bioconductor package SingleR implements an automatic annotation method for single-cell RNA sequencing (scRNA-seq) data (Aran et al. 2019). Given a reference dataset of samples (single-cell or bulk) with known labels, it assigns those labels to new cells from a test dataset based on similarities in their expression profiles. This provides a convenient way of transferring biological knowledge across datasets, allowing users to leverage the domain expertise implicit in the creation of each reference. The most common application of SingleR involves predicting cell type (or “state”, or “kind”) in a new dataset, a process that is facilitated by the availability of curated references and compatibility with user-supplied datasets. In this manner, the burden of manually interpreting clusters and defining marker genes only has to be done once, for the reference dataset, and this knowledge can be propagated to new datasets in an automated manner.
1.2 Method description
SingleR can be considered a robust variant of nearest-neighbors classification, with some tweaks to improve resolution for closely related labels. For each test cell:
- We compute the Spearman correlation between its expression profile and that of each reference sample. The use of Spearman’s correlation provides a measure of robustness to batch effects across datasets. The calculation only uses the union of marker genes identified by pairwise comparisons between labels in the reference data, so as to improve resolution of separation between labels.
- We define the per-label score as a fixed quantile (by default, 0.8) of the correlations across all samples with that label. This accounts for differences in the number of reference samples for each label, which interferes with simpler flavors of nearest neighbor classification; it also avoids penalizing classifications to heterogeneous labels by only requiring a good match to a minority of samples.
- We repeat the score calculation for all labels in the reference dataset. The label with the highest score is used as SingleR’s prediction for this cell.
- We optionally perform a fine-tuning step to improve resolution between closely related labels. The reference dataset is subsetted to only include labels with scores close to the maximum; scores are recomputed using only marker genes for the subset of labels, thus focusing on the most relevant features; and this process is iterated until only one label remains.
1.3 Quick start
We will demonstrate the use of SingleR()
on a well-known 10X Genomics dataset (Zheng et al. 2017)
with the Human Primary Cell Atlas dataset (Mabbott et al. 2013) as the reference.
# Loading test data.
library(TENxPBMCData)
new.data <- TENxPBMCData("pbmc4k")
# Loading reference data with Ensembl annotations.
library(celldex)
ref.data <- HumanPrimaryCellAtlasData(ensembl=TRUE)
# Performing predictions.
library(SingleR)
predictions <- SingleR(test=new.data, assay.type.test=1,
ref=ref.data, labels=ref.data$label.main)
table(predictions$labels)
##
## B_cell CMP DC GMP
## 606 8 1 2
## Monocyte NK_cell Platelets Pre-B_cell_CD34-
## 1164 217 3 46
## T_cells
## 2293
And that’s it, really.
1.4 Where to get help
Questions on the general use of SingleR should be posted to the Bioconductor support site. Please send requests for general assistance and advice to the support site rather than to the individual authors. Bug reports or feature requests should be made to the GitHub repository; well-considered suggestions for improvements are always welcome.
Session information
R Under development (unstable) (2024-10-21 r87258)
Platform: x86_64-pc-linux-gnu
Running under: Ubuntu 24.04.1 LTS
Matrix products: default
BLAS: /home/biocbuild/bbs-3.21-bioc/R/lib/libRblas.so
LAPACK: /usr/lib/x86_64-linux-gnu/lapack/liblapack.so.3.12.0
locale:
[1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
[3] LC_TIME=en_GB LC_COLLATE=C
[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] SingleR_2.9.1 ensembldb_2.31.0
[3] AnnotationFilter_1.31.0 GenomicFeatures_1.59.1
[5] AnnotationDbi_1.69.0 celldex_1.17.0
[7] TENxPBMCData_1.25.0 HDF5Array_1.35.1
[9] rhdf5_2.51.0 DelayedArray_0.33.2
[11] SparseArray_1.7.2 S4Arrays_1.7.1
[13] abind_1.4-8 Matrix_1.7-1
[15] SingleCellExperiment_1.29.1 SummarizedExperiment_1.37.0
[17] Biobase_2.67.0 GenomicRanges_1.59.1
[19] GenomeInfoDb_1.43.1 IRanges_2.41.1
[21] S4Vectors_0.45.2 BiocGenerics_0.53.3
[23] generics_0.1.3 MatrixGenerics_1.19.0
[25] matrixStats_1.4.1 BiocStyle_2.35.0
[27] rebook_1.17.0
loaded via a namespace (and not attached):
[1] bitops_1.0-9 DBI_1.2.3
[3] httr2_1.0.6 CodeDepends_0.6.6
[5] rlang_1.1.4 magrittr_2.0.3
[7] gypsum_1.3.0 compiler_4.5.0
[9] RSQLite_2.3.8 dir.expiry_1.15.0
[11] DelayedMatrixStats_1.29.0 png_0.1-8
[13] vctrs_0.6.5 ProtGenerics_1.39.0
[15] pkgconfig_2.0.3 crayon_1.5.3
[17] fastmap_1.2.0 dbplyr_2.5.0
[19] XVector_0.47.0 utf8_1.2.4
[21] Rsamtools_2.23.0 rmarkdown_2.29
[23] graph_1.85.0 UCSC.utils_1.3.0
[25] purrr_1.0.2 bit_4.5.0
[27] xfun_0.49 beachmat_2.23.1
[29] zlibbioc_1.53.0 cachem_1.1.0
[31] jsonlite_1.8.9 blob_1.2.4
[33] rhdf5filters_1.19.0 BiocParallel_1.41.0
[35] Rhdf5lib_1.29.0 parallel_4.5.0
[37] R6_2.5.1 bslib_0.8.0
[39] rtracklayer_1.67.0 jquerylib_0.1.4
[41] Rcpp_1.0.13-1 bookdown_0.41
[43] knitr_1.49 tidyselect_1.2.1
[45] yaml_2.3.10 codetools_0.2-20
[47] curl_6.0.1 lattice_0.22-6
[49] tibble_3.2.1 withr_3.0.2
[51] KEGGREST_1.47.0 evaluate_1.0.1
[53] BiocFileCache_2.15.0 alabaster.schemas_1.7.0
[55] ExperimentHub_2.15.0 Biostrings_2.75.1
[57] pillar_1.9.0 BiocManager_1.30.25
[59] filelock_1.0.3 RCurl_1.98-1.16
[61] BiocVersion_3.21.1 sparseMatrixStats_1.19.0
[63] alabaster.base_1.7.2 glue_1.8.0
[65] alabaster.ranges_1.7.0 lazyeval_0.2.2
[67] alabaster.matrix_1.7.0 tools_4.5.0
[69] beachmat.hdf5_1.5.1 BiocIO_1.17.0
[71] AnnotationHub_3.15.0 BiocNeighbors_2.1.0
[73] GenomicAlignments_1.43.0 XML_3.99-0.17
[75] grid_4.5.0 GenomeInfoDbData_1.2.13
[77] restfulr_0.0.15 cli_3.6.3
[79] rappdirs_0.3.3 fansi_1.0.6
[81] dplyr_1.1.4 alabaster.se_1.7.0
[83] sass_0.4.9 digest_0.6.37
[85] rjson_0.2.23 memoise_2.0.1
[87] htmltools_0.5.8.1 lifecycle_1.0.4
[89] httr_1.4.7 mime_0.12
[91] bit64_4.5.2