TL;DR

We recently introduced sctransform to perform normalization and variance stabilization of scRNA-seq datasets. We now release an updated version (‘v2’), based on our broad analysis of 59 scRNA-seq datasets spanning a range of technologies, systems, and sequencing depths. This update improves speed and memory consumption, the stability of parameter estimates, the identification of variable features, and the the ability to perform downstream differential expression analyses.

Users can install sctransform v2 from Github (CRAN update coming soon), and invoke the use of the updated method via the vst.flavor argument.

# install Seurat from Github (automatically updates sctransform)
devtools::install_github("satijalab/seurat", ref = "develop")
# invoke sctransform
object <- SCTransform(object, vst.flavor = "v2")

Introduction

Heterogeneity in single-cell RNA-seq (scRNA-seq) data is driven by multiple sources, including biological variation in cellular state as well as technical variation introduced during experimental processing. In Choudhary and Satija, 2021 we provide a set of recommendations for modeling variation in scRNA-seq data, particularly when using generalized linear models or likelihood-based approaches for preprocessing and downstream analysis.

In this vignette, we use sctransform v2 based workflow to perform a comparative analysis of human immune cells (PBMC) in either a resting or interferon-stimulated state. In this vignette we apply sctransform-v2 based normalization to perform the following tasks:

  • Create an ‘integrated’ data assay for downstream analysis
  • Compare the datasets to find cell-type specific responses to stimulation
  • Obtain cell type markers that are conserved in both control and stimulated cells

Install sctransform

We will install sctransform v2 from Github. We will also install the glmGamPoi package which substantially improves the speed of the learning procedure.

# install glmGamPoi
if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager")
BiocManager::install("glmGamPoi")
# install sctransform from Github
devtools::install_github("satijalab/sctransform", ref = "develop")

Setup the Seurat objects

The dataset is available through our SeuratData package.

# install dataset
InstallData("ifnb")
# load dataset
LoadData("ifnb")

# split the dataset into a list of two seurat objects (stim and CTRL)
ifnb.list <- SplitObject(ifnb, split.by = "stim")

ctrl <- ifnb.list[["CTRL"]]
stim <- ifnb.list[["STIM"]]

Perform normalization and dimensionality reduction

To perform normalization, we invoke SCTransform with an additional flag vst.flavor="v2" to invoke the v2 regularization. This provides some improvements over our original approach first introduced in Hafemeister and Satija, 2019.

  • We fix the slope parameter of the GLM to \(\ln(10)\) with \(\log_{10}(\text{total UMI})\) used as the predictor as proposed by Lause et al.
  • We utilize an improved parameter estimation procedure that alleviates uncertainty and bias that result from fitting GLM models for very lowly expressed genes.
  • We place a lower bound on gene-level standard deviation when calculating Pearson residuals. This prevents genes with extremely low expression (only 1-2 detected UMIs) from having a high pearson residual.
# normalize and run dimensionality reduction on control dataset
ctrl <- SCTransform(ctrl, vst.flavor = "v2", verbose = FALSE) %>%
    RunPCA(npcs = 30, verbose = FALSE) %>%
    RunUMAP(reduction = "pca", dims = 1:30, verbose = FALSE) %>%
    FindNeighbors(reduction = "pca", dims = 1:30, verbose = FALSE) %>%
    FindClusters(resolution = 0.7, verbose = FALSE)

p1 <- DimPlot(ctrl, label = T, repel = T) + ggtitle("Unsupervised clustering")
p2 <- DimPlot(ctrl, label = T, repel = T, group.by = "seurat_annotations") + ggtitle("Annotated celltypes")

p1 | p2

Perform integration using pearson residuals

To perform integration using the pearson residuals calculated above, we use the PrepSCTIntegration() function after selecting a list of informative features using SelectIntegrationFeatures():

stim <- SCTransform(stim, vst.flavor = "v2", verbose = FALSE) %>%
    RunPCA(npcs = 30, verbose = FALSE)
ifnb.list <- list(ctrl = ctrl, stim = stim)
features <- SelectIntegrationFeatures(object.list = ifnb.list, nfeatures = 3000)
ifnb.list <- PrepSCTIntegration(object.list = ifnb.list, anchor.features = features)

To integrate the two datasets, we use the FindIntegrationAnchors() function, which takes a list of Seurat objects as input, and use these anchors to integrate the two datasets together with IntegrateData().

immune.anchors <- FindIntegrationAnchors(object.list = ifnb.list, normalization.method = "SCT",
    anchor.features = features)
immune.combined.sct <- IntegrateData(anchorset = immune.anchors, normalization.method = "SCT")

Perform an integrated analysis

Now we can run a single integrated analysis on all cells:

immune.combined.sct <- RunPCA(immune.combined.sct, verbose = FALSE)
immune.combined.sct <- RunUMAP(immune.combined.sct, reduction = "pca", dims = 1:30, verbose = FALSE)
immune.combined.sct <- FindNeighbors(immune.combined.sct, reduction = "pca", dims = 1:30)
immune.combined.sct <- FindClusters(immune.combined.sct, resolution = 0.3)

To visualize the two conditions side-by-side, we can use the split.by argument to show each condition colored by cluster.

DimPlot(immune.combined.sct, reduction = "umap", split.by = "stim")

We can also visualize the distribution of annotated celltypes across control and stimulated datasets:

p1 <- DimPlot(immune.combined.sct, reduction = "umap", group.by = "stim")
p2 <- DimPlot(immune.combined.sct, reduction = "umap", group.by = "seurat_clusters", label = TRUE,
    repel = TRUE)
p3 <- DimPlot(immune.combined.sct, reduction = "umap", group.by = "seurat_annotations", label = TRUE,
    repel = TRUE)
p1 | p2 | p3

Identify differential expressed genes across conditions

Using the normalized datasets with known celltype annotation, we can ask what genes change in different conditions for cells of the same type. First, we create a column in the meta.data slot to hold both the cell type and stimulation information and switch the current ident to that column.

immune.combined.sct$celltype.stim <- paste(immune.combined.sct$seurat_annotations, immune.combined.sct$stim,
    sep = "_")
Idents(immune.combined.sct) <- "celltype.stim"

To run differential expression, we make use of ‘corrected counts’ that are stored in the data slot of the the SCT assay. Corrected counts are obtained by setting the sequencing depth for all the cells to a fixed value and reversing the learned regularized negative-binomial regression model. Prior to performing differential expression, we first run PrepSCTFindMarkers, which ensures that the fixed value is set properly. Then we use FindMarkers(assay="SCT") to find differentially expressed genes. Here, we aim to identify genes that are differently expressed between stimulated and control B cells.

immune.combined.sct <- PrepSCTFindMarkers(immune.combined.sct)

b.interferon.response <- FindMarkers(immune.combined.sct, assay = "SCT", ident.1 = "B_STIM", ident.2 = "B_CTRL",
    verbose = FALSE)
head(b.interferon.response, n = 15)
##                 p_val avg_log2FC pct.1 pct.2     p_val_adj
## ISG15   1.505693e-159  3.5088882 0.998 0.229 2.003475e-155
## IFIT3   4.128835e-154  2.5684404 0.961 0.052 5.493827e-150
## IFI6    2.479476e-153  2.4602058 0.965 0.076 3.299190e-149
## ISG20   9.385626e-152  2.5618077 1.000 0.666 1.248851e-147
## IFIT1   2.447118e-139  2.1328142 0.904 0.029 3.256136e-135
## MX1     2.111944e-124  1.9311875 0.900 0.115 2.810153e-120
## LY6E    2.930414e-122  1.8496310 0.898 0.150 3.899209e-118
## TNFSF10 1.104024e-112  1.7817968 0.785 0.020 1.469014e-108
## IFIT2   3.491368e-108  1.7594656 0.783 0.037 4.645615e-104
## B2M      3.405403e-98  0.5980104 1.000 1.000  4.531229e-94
## IRF7     1.114291e-96  1.4721297 0.834 0.187  1.482675e-92
## PLSCR1   3.364901e-96  1.4495896 0.783 0.111  4.477338e-92
## UBE2L6   1.155610e-85  1.3221839 0.849 0.295  1.537655e-81
## CXCL10   5.689834e-84  3.0310329 0.639 0.010  7.570893e-80
## PSMB9    2.304426e-81  1.2355834 0.937 0.568  3.066269e-77

If running on a subset of the original object after running PrepSCTFindMarkers(), FindMarkers() should be invoked with recorrect_umi = FALSE to use the existing corrected counts:

immune.combined.sct.subset <- subset(immune.combined.sct, idents = c("B_STIM", "B_CTRL"))
b.interferon.response.subset <- FindMarkers(immune.combined.sct.subset, assay = "SCT", ident.1 = "B_STIM",
    ident.2 = "B_CTRL", verbose = FALSE, recorrect_umi = FALSE)

We can also use the corrected counts for visualization:

Idents(immune.combined.sct) <- "seurat_annotations"
DefaultAssay(immune.combined.sct) <- "SCT"
FeaturePlot(immune.combined.sct, features = c("CD3D", "GNLY", "IFI6"), split.by = "stim", max.cutoff = 3,
    cols = c("grey", "red"))

plots <- VlnPlot(immune.combined.sct, features = c("LYZ", "ISG15", "CXCL10"), split.by = "stim",
    group.by = "seurat_annotations", pt.size = 0, combine = FALSE)
wrap_plots(plots = plots, ncol = 1)

Identify conserved cell type markers

To identify canonical cell type marker genes that are conserved across conditions, we provide the FindConservedMarkers() function. This function performs differential gene expression testing for each dataset/group and combines the p-values using meta-analysis methods from the MetaDE R package. For example, we can identify genes that are conserved markers irrespective of stimulation condition in NK cells. Note that the PrepSCTFindMarkers command does not to be rerun here.

nk.markers <- FindConservedMarkers(immune.combined.sct, assay = "SCT", ident.1 = "NK", grouping.var = "stim",
    verbose = FALSE)
head(nk.markers)
##        CTRL_p_val CTRL_avg_log2FC CTRL_pct.1 CTRL_pct.2 CTRL_p_val_adj
## GNLY            0       4.2126974      0.943      0.045              0
## FGFBP2          0       1.2675614      0.500      0.020              0
## CLIC3           0       1.3891367      0.601      0.024              0
## CTSW            0       1.0842918      0.537      0.029              0
## KLRD1           0       0.9382079      0.507      0.019              0
## KLRC1           0       0.7310252      0.379      0.004              0
##           STIM_p_val STIM_avg_log2FC STIM_pct.1 STIM_pct.2 STIM_p_val_adj
## GNLY    0.000000e+00       4.3429777      0.956      0.056   0.000000e+00
## FGFBP2 3.703265e-160       0.6174405      0.259      0.015  4.927564e-156
## CLIC3   0.000000e+00       1.5325425      0.623      0.030   0.000000e+00
## CTSW    0.000000e+00       1.2323017      0.592      0.035   0.000000e+00
## KLRD1   0.000000e+00       1.0502928      0.555      0.026   0.000000e+00
## KLRC1   0.000000e+00       0.7401034      0.374      0.005   0.000000e+00
##             max_pval minimump_p_val
## GNLY    0.000000e+00              0
## FGFBP2 3.703265e-160              0
## CLIC3   0.000000e+00              0
## CTSW    0.000000e+00              0
## KLRD1   0.000000e+00              0
## KLRC1   0.000000e+00              0

Session Info

## R version 4.1.0 (2021-05-18)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.2 LTS
## 
## Matrix products: default
## BLAS/LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.8.so
## 
## 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=C             
##  [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] stats     graphics  grDevices utils     datasets  methods   base     
## 
## other attached packages:
##  [1] ggplot2_3.3.5                 dplyr_1.0.7                  
##  [3] patchwork_1.1.1               thp1.eccite.SeuratData_3.1.5 
##  [5] stxBrain.SeuratData_0.1.1     ssHippo.SeuratData_3.1.4     
##  [7] pbmcsca.SeuratData_3.0.0      pbmcMultiome.SeuratData_0.1.1
##  [9] pbmc3k.SeuratData_3.1.4       panc8.SeuratData_3.0.2       
## [11] ifnb.SeuratData_3.1.0         hcabm40k.SeuratData_3.0.0    
## [13] bmcite.SeuratData_0.3.0       SeuratData_0.2.1             
## [15] SeuratObject_4.0.4            Seurat_4.0.6                 
## 
## loaded via a namespace (and not attached):
##   [1] utf8_1.2.2                  reticulate_1.22            
##   [3] tidyselect_1.1.1            htmlwidgets_1.5.4          
##   [5] grid_4.1.0                  Rtsne_0.15                 
##   [7] devtools_2.4.3              munsell_0.5.0              
##   [9] mutoss_0.1-12               codetools_0.2-18           
##  [11] ragg_1.1.3                  ica_1.0-2                  
##  [13] future_1.23.0               miniUI_0.1.1.1             
##  [15] withr_2.4.3                 colorspace_2.0-2           
##  [17] Biobase_2.52.0              highr_0.9                  
##  [19] knitr_1.33                  stats4_4.1.0               
##  [21] ROCR_1.0-11                 tensor_1.5                 
##  [23] listenv_0.8.0               Rdpack_2.1.2               
##  [25] labeling_0.4.2              MatrixGenerics_1.4.2       
##  [27] GenomeInfoDbData_1.2.6      mnormt_2.0.2               
##  [29] polyclip_1.10-0             farver_2.1.0               
##  [31] rprojroot_2.0.2             TH.data_1.0-10             
##  [33] parallelly_1.30.0           vctrs_0.3.8                
##  [35] generics_0.1.1              xfun_0.25                  
##  [37] R6_2.5.1                    GenomeInfoDb_1.28.1        
##  [39] bitops_1.0-7                spatstat.utils_2.3-0       
##  [41] cachem_1.0.6                DelayedArray_0.18.0        
##  [43] assertthat_0.2.1            promises_1.2.0.1           
##  [45] scales_1.1.1                multcomp_1.4-17            
##  [47] gtable_0.3.0                globals_0.14.0             
##  [49] processx_3.5.2              goftest_1.2-3              
##  [51] sandwich_3.0-1              rlang_0.4.12               
##  [53] systemfonts_1.0.2           splines_4.1.0              
##  [55] lazyeval_0.2.2              spatstat.geom_2.3-1        
##  [57] BiocManager_1.30.15         yaml_2.2.1                 
##  [59] reshape2_1.4.4              abind_1.4-5                
##  [61] httpuv_1.6.5                tools_4.1.0                
##  [63] usethis_2.1.5               ellipsis_0.3.2             
##  [65] spatstat.core_2.3-2         jquerylib_0.1.4            
##  [67] RColorBrewer_1.1-2          BiocGenerics_0.38.0        
##  [69] sessioninfo_1.2.2           ggridges_0.5.3             
##  [71] TFisher_0.2.0               Rcpp_1.0.7                 
##  [73] plyr_1.8.6                  sparseMatrixStats_1.4.2    
##  [75] zlibbioc_1.38.0             purrr_0.3.4                
##  [77] RCurl_1.98-1.3              ps_1.6.0                   
##  [79] prettyunits_1.1.1           rpart_4.1-15               
##  [81] deldir_1.0-6                pbapply_1.5-0              
##  [83] cowplot_1.1.1               S4Vectors_0.30.0           
##  [85] zoo_1.8-9                   SummarizedExperiment_1.22.0
##  [87] ggrepel_0.9.1               cluster_2.1.2              
##  [89] fs_1.5.2                    magrittr_2.0.1             
##  [91] RSpectra_0.16-0             data.table_1.14.2          
##  [93] glmGamPoi_1.4.0             scattermore_0.7            
##  [95] lmtest_0.9-39               RANN_2.6.1                 
##  [97] tmvnsim_1.0-2               mvtnorm_1.1-2              
##  [99] fitdistrplus_1.1-6          matrixStats_0.61.0         
## [101] pkgload_1.2.1               mime_0.12                  
## [103] evaluate_0.14               xtable_1.8-4               
## [105] IRanges_2.26.0              gridExtra_2.3              
## [107] testthat_3.0.4              compiler_4.1.0             
## [109] tibble_3.1.6                KernSmooth_2.23-20         
## [111] crayon_1.4.2                htmltools_0.5.2            
## [113] mgcv_1.8-35                 later_1.3.0                
## [115] tidyr_1.1.4                 DBI_1.1.1                  
## [117] formatR_1.11                MASS_7.3-54                
## [119] rappdirs_0.3.3              Matrix_1.3-3               
## [121] cli_3.1.0                   rbibutils_2.2              
## [123] metap_1.4                   parallel_4.1.0             
## [125] igraph_1.2.11               GenomicRanges_1.44.0       
## [127] pkgconfig_2.0.3             sn_2.0.0                   
## [129] pkgdown_1.6.1               numDeriv_2016.8-1.1        
## [131] plotly_4.10.0               spatstat.sparse_2.1-0      
## [133] bslib_0.3.1                 multtest_2.48.0            
## [135] XVector_0.32.0              stringr_1.4.0              
## [137] callr_3.7.0                 digest_0.6.29              
## [139] sctransform_0.3.2.9011      RcppAnnoy_0.0.19           
## [141] spatstat.data_2.1-2         rmarkdown_2.10             
## [143] leiden_0.3.9                uwot_0.1.11                
## [145] DelayedMatrixStats_1.14.2   curl_4.3.2                 
## [147] shiny_1.7.1                 lifecycle_1.0.1            
## [149] nlme_3.1-152                jsonlite_1.7.2             
## [151] limma_3.48.0                desc_1.4.0                 
## [153] viridisLite_0.4.0           fansi_1.0.0                
## [155] pillar_1.6.4                lattice_0.20-44            
## [157] plotrix_3.8-1               fastmap_1.1.0              
## [159] httr_1.4.2                  pkgbuild_1.3.1             
## [161] survival_3.2-11             glue_1.6.0                 
## [163] remotes_2.4.0               png_0.1-7                  
## [165] stringi_1.7.6               sass_0.4.0                 
## [167] textshaping_0.3.5           memoise_2.0.0              
## [169] mathjaxr_1.4-0              irlba_2.3.5                
## [171] future.apply_1.8.1