Contents

1 Introduction

This document gives an introduction to and overview of the quality control functionality of the scater package. scater contains tools to help with the analysis of single-cell transcriptomic data, focusing on RNA-seq data. The package features:

2 Creating a SingleCellExperiment object

We assume that you have a matrix containing expression count data summarised at the level of some features (gene, exon, region, etc.). First, we create a SingleCellExperiment object containing the data, as demonstrated below with some example data ("sc_example_counts") and metadata ("sc_example_cell_info"): Rows of the object correspond to features, while columns correspond to samples, i.e., cells in the context of single-cell ’omics data.

library(scater)
data("sc_example_counts")
data("sc_example_cell_info")
example_sce <- SingleCellExperiment(
    assays = list(counts = sc_example_counts), 
    colData = sc_example_cell_info
)
example_sce
## class: SingleCellExperiment 
## dim: 2000 40 
## metadata(0):
## assays(1): counts
## rownames(2000): Gene_0001 Gene_0002 ... Gene_1999 Gene_2000
## rowData names(0):
## colnames(40): Cell_001 Cell_002 ... Cell_039 Cell_040
## colData names(4): Cell Mutation_Status Cell_Cycle Treatment
## reducedDimNames(0):
## spikeNames(0):

We usually expect (raw) count data to be labelled as "counts" in the assays, which can be easily retrieved with the counts accessor. Getters and setters are also provided for exprs, tpm, cpm, fpkm and versions of these with the prefix norm_.

str(counts(example_sce))

Row and column-level metadata are easily accessed (or modified) as shown below. There are also dedicated getters and setters for spike-in specifiers (isSpike); size factor values (sizeFactors); and reduced dimensionality results (reducedDim).

example_sce$whee <- sample(LETTERS, ncol(example_sce), replace=TRUE)
colData(example_sce)
## DataFrame with 40 rows and 5 columns
##                 Cell Mutation_Status  Cell_Cycle   Treatment        whee
##          <character>     <character> <character> <character> <character>
## Cell_001    Cell_001        positive           S      treat1           U
## Cell_002    Cell_002        positive          G0      treat1           W
## Cell_003    Cell_003        negative          G1      treat1           J
## Cell_004    Cell_004        negative           S      treat1           E
## Cell_005    Cell_005        negative          G1      treat2           Z
## ...              ...             ...         ...         ...         ...
## Cell_036    Cell_036        negative          G0      treat1           P
## Cell_037    Cell_037        negative          G0      treat1           I
## Cell_038    Cell_038        negative          G0      treat2           F
## Cell_039    Cell_039        negative          G1      treat1           P
## Cell_040    Cell_040        negative          G0      treat2           P
rowData(example_sce)$stuff <- runif(nrow(example_sce))
rowData(example_sce)
## DataFrame with 2000 rows and 1 column
##                        stuff
##                    <numeric>
## Gene_0001 0.0673663057386875
## Gene_0002  0.222470983397216
## Gene_0003  0.947641894221306
## Gene_0004  0.374451905954629
## Gene_0005  0.593446868704632
## ...                      ...
## Gene_1996  0.474242345895618
## Gene_1997  0.192777156364173
## Gene_1998  0.151339191012084
## Gene_1999  0.400677960831672
## Gene_2000  0.937458637170494

Subsetting is very convenient with this class, as both data and metadata are processed in a synchronized manner. For example, we can filter out features (genes) that are not expressed in any cells:

keep_feature <- rowSums(counts(example_sce) > 0) > 0
example_sce <- example_sce[keep_feature,]

More details about the SingleCellExperiment class can be found in the documentation for SingleCellExperiment package.

3 Calculating a variety of expression values

We calculate counts-per-million using the aptly-named calculateCPM function. The output is most appropriately stored as an assay named "cpm" in the assays of the SingleCellExperiment object.

cpm(example_sce) <- calculateCPM(example_sce)

Another option is to use the normalize function, which calculates log2-transformed normalized expression values. This is done by dividing each count by its size factor (or scaled library size, if no size factors are defined), adding a pseudo-count and log-transforming. The resulting values can be interpreted on the same scale as log-transformed counts, and are stored in "logcounts".

example_sce <- normalize(example_sce)
assayNames(example_sce)
## [1] "counts"    "cpm"       "logcounts"

Note that exprs is a synonym for logcounts when accessing or setting data. This is done for backwards compatibility with older verions of scater.

identical(exprs(example_sce), logcounts(example_sce))
## [1] TRUE

Of course, users can construct any arbitrary matrix of the same dimensions as the count matrix and store it as an assay.

assay(example_sce, "is_expr") <- counts(example_sce)>0

The calcAverage function will compute the average count for each gene after scaling each cell’s counts by its size factor. If size factors are not available, it will compute a size factor from the library size.

head(calcAverage(example_sce))
##  Gene_0001  Gene_0002  Gene_0003  Gene_0004  Gene_0005  Gene_0006 
## 305.551749 325.719897 183.090462 162.143201   1.231123 187.167913

4 Other methods of data import

Count matrices stored as CSV files or equivalent can be easily read into R session using read.table from utils or fread from the data.table package. It is advisable to coerce the resulting object into a matrix before storing it in a SingleCellExperiment object.

For large data sets, the matrix can be read in chunk-by-chunk with progressive coercion into a sparse matrix from the Matrix package. This is performed using readSparseCounts and reduces memory usage by not explicitly storing zeroes in memory.

Data from 10X Genomics experiments can be read in using the read10xCounts function from the DropletUtils package. This will automatically generate a SingleCellExperiment with a sparse matrix, see the documentation for more details.

scater also provides wrapper functions readSalmonResults or readKallistoResults to import transcript abundances from the kallisto and Salmon pseudo-aligners. This is done using methods from the tximport package.

5 Transitioning from the SCESet class

As of July 2017, scater has switched from the SCESet class previously defined within the package to the more widely applicable SingleCellExperiment class. From Bioconductor 3.6 (October 2017), the release version of scater will use SingleCellExperiment. SingleCellExperiment is a more modern and robust class that provides a common data structure used by many single-cell Bioconductor packages. Advantages include support for sparse data matrices and the capability for on-disk storage of data to minimise memory usage for large single-cell datasets.

It should be straight-forward to convert existing scripts based on SCESet objects to SingleCellExperiment objects, with key changes outlined immediately below.

Users may need to be aware of the following when updating their own scripts:

Session information

sessionInfo()
## R version 3.5.1 Patched (2018-07-12 r74967)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 16.04.5 LTS
## 
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.8-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.8-bioc/R/lib/libRlapack.so
## 
## locale:
##  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C              
##  [3] LC_TIME=en_US.UTF-8        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       
## 
## attached base packages:
## [1] parallel  stats4    stats     graphics  grDevices utils     datasets 
## [8] methods   base     
## 
## other attached packages:
##  [1] scater_1.10.0               SingleCellExperiment_1.4.0 
##  [3] SummarizedExperiment_1.12.0 DelayedArray_0.8.0         
##  [5] BiocParallel_1.16.0         matrixStats_0.54.0         
##  [7] Biobase_2.42.0              GenomicRanges_1.34.0       
##  [9] GenomeInfoDb_1.18.0         IRanges_2.16.0             
## [11] S4Vectors_0.20.0            BiocGenerics_0.28.0        
## [13] ggplot2_3.1.0               knitr_1.20                 
## [15] BiocStyle_2.10.0           
## 
## loaded via a namespace (and not attached):
##  [1] bitops_1.0-6             destiny_2.12.0          
##  [3] xts_0.11-1               rprojroot_1.3-2         
##  [5] tools_3.5.1              backports_1.1.2         
##  [7] R6_2.3.0                 HDF5Array_1.10.0        
##  [9] vipor_0.4.5              lazyeval_0.2.1          
## [11] colorspace_1.3-2         nnet_7.3-12             
## [13] withr_2.1.2              sp_1.3-1                
## [15] smoother_1.1             tidyselect_0.2.5        
## [17] gridExtra_2.3            curl_3.2                
## [19] compiler_3.5.1           labeling_0.3            
## [21] bookdown_0.7             scales_1.0.0            
## [23] lmtest_0.9-36            DEoptimR_1.0-8          
## [25] robustbase_0.93-3        proxy_0.4-22            
## [27] stringr_1.3.1            digest_0.6.18           
## [29] foreign_0.8-71           rmarkdown_1.10          
## [31] rio_0.5.10               XVector_0.22.0          
## [33] pkgconfig_2.0.2          htmltools_0.3.6         
## [35] TTR_0.23-4               ggthemes_4.0.1          
## [37] rlang_0.3.0.1            readxl_1.1.0            
## [39] DelayedMatrixStats_1.4.0 bindr_0.1.1             
## [41] zoo_1.8-4                dplyr_0.7.7             
## [43] zip_1.0.0                car_3.0-2               
## [45] RCurl_1.95-4.11          magrittr_1.5            
## [47] GenomeInfoDbData_1.2.0   Matrix_1.2-14           
## [49] Rcpp_0.12.19             ggbeeswarm_0.6.0        
## [51] munsell_0.5.0            Rhdf5lib_1.4.0          
## [53] abind_1.4-5              viridis_0.5.1           
## [55] scatterplot3d_0.3-41     stringi_1.2.4           
## [57] yaml_2.2.0               carData_3.0-2           
## [59] MASS_7.3-51              zlibbioc_1.28.0         
## [61] rhdf5_2.26.0             Rtsne_0.13              
## [63] plyr_1.8.4               grid_3.5.1              
## [65] forcats_0.3.0            crayon_1.3.4            
## [67] lattice_0.20-35          haven_1.1.2             
## [69] cowplot_0.9.3            hms_0.4.2               
## [71] pillar_1.3.0             igraph_1.2.2            
## [73] boot_1.3-20              reshape2_1.4.3          
## [75] glue_1.3.0               evaluate_0.12           
## [77] laeken_0.4.6             data.table_1.11.8       
## [79] BiocManager_1.30.3       vcd_1.4-4               
## [81] cellranger_1.1.0         VIM_4.7.0               
## [83] gtable_0.2.0             purrr_0.2.5             
## [85] assertthat_0.2.0         xfun_0.4                
## [87] openxlsx_4.1.0           RcppEigen_0.3.3.4.0     
## [89] e1071_1.7-0              class_7.3-14            
## [91] viridisLite_0.3.0        tibble_1.4.2            
## [93] beeswarm_0.2.3           bindrcpp_0.2.2