Skip to article frontmatterSkip to article content
Site not loading correctly?

This may be due to an incorrect BASE_URL configuration. See the MyST Documentation for reference.

SCTransform workflow

Introduction

Normalization and preprocessing are the key challenges affecting directly to downstream scRNA-seq results, in which technically sequencing bias is cut down while biological variation is reserved. An effective workflow would eliminate technical bias among cells/samples and keep genewise heterogeneity without being overwhelmed by dominant genes Hafemeister & Satija, 2019Choudhary & Satija, 2022.

Based on that, SCTransform is introduced as a probabilistic approach stabilizing variation in the count matrix Hafemeister & Satija, 2019. When there is a significant difference in cell expression originally, the SCTransform method is able to replace Seurat standard preprocessing workflow (normalization, feature selection, and scaling), mentioned in pbmc3k_tutorial.

Workflow

Overall, the raw count matrix is utilized for Negative Binomial (NB) model estimate to determine the expected mean and overdispersion parameters for each gene. After the estimating, the raw likelihood parameters are highly variable across genes, a regulation step is applied to stabilize variance and reduce the sampling noise.

Next, the contribution of each element in the count matrix to the Chi-square dependence between genes and samples is quantified via Pearson residuals. Subsequently, the count matrix is corrected by eliminating technical noise across samples, and reconstructing normalized expression counts from the stabilized residuals.

Finally, the Pearson residuals undergo post-processing, where highly variable features are identified, and confounding biological or technical covariates (such as cell viability indicated by the percentage of mitochondrial reads) can be regressed out, yielding a polished residual matrix ready for downstream analysis (e.g., PCA and clustering).

Fitting model

At the beginning, only genes obtaining an overdispersion factor (σ2>μ\sigma^2 > \mu) are used to train. A number of genes is randomly selected (default is 2,000) across their expression levels, and the total count of selected genes must be greater than 5 by default. Subsequently, their raw count matrix are modeled by Gamma-Poisson general linear model (Gamma-Poisson GLM), i.e Negative Binomial (NB) model, to properly obtain overdispersion. See Gamma-Poisson GLM for more detail about the model-fitting process.

Briefly, it uses the Maximum Likelihood Estimates (MLE) method to estimate coefficients of the model according to the count values of each gene. The coefficients include relative log-scaled count mean β\beta, and overdispersion θ\theta. Note that the definition of overdispersion between sctransform and Gamma-Poisson GLM are reciprocal.

{σ2=μ+1θ^μ2α=θ^/θ\begin{cases} \begin{aligned} \sigma^2 &= \mu + \frac{1}{\hat{\theta}}\mu^2 \\ \alpha &= \hat{\theta} / \theta \end{aligned} \end{cases}

Next, theoretical overdispersion θ^\hat{\theta}, which is derived from mean-variance relationship of NB model, shown as Equation (1). α\alpha is the ratio of expected overdispersion (θ^\hat{\theta}) over observed overdispersion (θ\theta), which originates from estimation above. If α<0.001\alpha < 0.001, the model for that gene is assumed to follow the Poisson distribution (σ2=μ\sigma^2 = \mu, and θ\theta \rightarrow -\infty).

Regularizing model

Geometric mean

μg=exp[1Nj=1Nln(Cj+ϵ)]ϵ\mu_{\text{g}} = \exp\left[ \frac{1}{N} \sum_{j=1}^{N}{\ln(C_j + \epsilon)} \right] - \epsilon

For each gene, logarithmic geometric mean (μg\mu_{\text{g}}) computed by Equation (2), represents as a centric count without affected by outlier samples. With CjC_j is the count value of sample jj in total NN samples, and ϵ\epsilon (default is 1) is a small fixed number to avoid ln(0)\ln(0) Hafemeister & Satija, 2019.

Local outlier detection

Local outlier genes along the μg\mu_{g}-axis are detected based on the matrices of the log-scaled overdispersion factor (F=1+μg/θF = 1+\mu_g/\theta) and β\beta estimated from Gamma-Poisson GLM. These parameters serve for variance and mean outlier indicators, respectively.

Initially, the genes are assigned to bins according to their μg\mu_{g} value. The binwidth is determined using a heuristic rescale from the optimal bandwidth featured by Sheather & Jones (1991) to ensure data is fairly distributed across bins (satijalab/sctransform#214).

S=Ymedian(Y)MAD(Y)+ϵS = \frac{Y - \text{median}(Y)}{\text{MAD}(Y) + \epsilon}

For each evaluated matrix (YY representing either FF or β\beta), the outlier scores (SS) are computed for the points within each bin following Equation (3), which measures the distance to the median and eliminates deviation by Median Absolute Deviation (MAD) to enable comparability. For enhancing reliability, the measurement is processed on two overlapping grids, offset by half a binwidth. A gene is flagged as an outlier within a specific matrix when its absolute score on both grids exceeds a threshold, which defaults to 10.

Ultimately, a gene is marked as an outlier if it is flagged by either of the evaluated matrices (variance or mean).

Kernel smoothing

The estimated parameters (FF and β\beta) are sequentially smoothed across gene expression levels (log geometric mean) using the Nadaraya-Watson kernel regression estimator Nadaraya, 1964. To avoid overfitting, this smoothing is anchored by the subset comprising overdispersion genes which exclude the previously flagged outliers and Poisson-like genes.

{wij=K(μg(i)μg(j)σ)yj=i=iminmyiwiji=iminmwij\begin{cases} \begin{aligned} \large w_{ij} &= K\left(\frac{|\mu_{g}(i) - \mu_{g}(j)|}{\overline{\sigma}}\right) \\ \large \overline{y}_j &= \frac{\sum_{i=i_{\text{min}}}^m y_i \cdot w_{ij} }{\sum_{i=i_{\text{min}}}^m w_{ij}} \end{aligned} \end{cases}

The smoothed value yj\overline{y}_j (in FF or β\beta matrix) of any gene jj is computed by weighted average of anchored genes, as defined in Equation (4). Particularly, the weight (wijw_{ij}) is the density determined by the Gaussian kernel function KK at the distance between the current gene jj and anchored gene ii in the μg\mu_g level. In mm overdispersion genes, the employed subset starts from anchored gene imini_{\text{min}}, which is nearest to the boundary, four times the bandwidth h, from the targeted μg\mu_g range.

The interquartile of the distance distribution is assumed to be the range [0.25h,+0.25h][-0.25h, +0.25h], where hh is the optimal bandwidth of overdispersion genes by the method of Sheather & Jones (1991), see SJ bandwidth estimation for details. Noticeably, the optimized hh is tripled by default. All together, this ensures that anchor genes lying closer to the expected range obtained higher weight.

σ=0.25Φ1(0.75)h0.3707h\overline{\sigma} = \frac{0.25}{\Phi^{-1}(0.75)}h \approx 0.3707 \cdot h

Based on the assumption, standard deviation of the distance distribution (σ\overline{\sigma}) used in Equation (4) computed by Equation (5) with Φ1(0.75)\Phi^{-1}(0.75) being the inverse cumulative distribution function of 75th percentile.

By the end, smoothed β\beta and θ\theta, which is recoverd from smoothed FF, are utilized for the next process.

Pearson residuals

While Chi-square test evaluates the global association between two categorical variables in a contingency table, Pearson residuals isolate the explicit contribution of each individual component (here, each gene-cell pair) to that overall dependence. The computation of specific Pearson residual (zijz_{ij}) for gene ii in cell jj is outlined in Equation (6).

{E[cij]=exp(βi+ln(Cj))σij2=E[cij]+1θiE[cij]2zij=cijE[cij]σij\begin{cases} \begin{aligned} \mathbb{E}[c_{ij}] &= \exp(\beta_{i} + \ln(C_{j})) \\ \sigma_{ij}^2 &= \mathbb{E}[c_{ij}] + \frac{1}{\theta_{i}}\mathbb{E}[c_{ij}]^2 \\ z_{ij} &= \frac{c_{ij} - \mathbb{E}[c_{ij}]}{\sigma_{ij}} \end{aligned} \end{cases}

First, the expected count (E[cij]\mathbb{E}[c_{ij}]) is calculated analogously to the expected frequency in Chi-square test with the gene-specific log-scaled mean βi\beta_i estimated in the smoothing step and the total count CjC_{j} for each cell.

Hence count data assumably follows NB distribution, the variance (σij2\sigma_{ij}^2) for residuals is derived from E[cij]\mathbb{E}[c_{ij}] as the mean, and smoothed overdispersion θi\theta_i.

Finally, the specific Pearson residual is measured from the deviation between the observe (cijc_{ij}, the actual count) and the expected value (E[cij]\mathbb{E}[c_{ij}]), and scaled by standard deviation σij\sigma_{ij} to ensure comparability.

σmin2=(median(cij)5)2\sigma_{\text{min}}^2 = \left( \frac{\text{median}(c_{ij})}{5} \right)^2

In practice, the variance σij2\sigma_{ij}^2 is bound by a lower threshold σmin2\sigma_{\text{min}}^2 defined in Equation (7), where the deviation is expected to be always greater than the general median, and the maximum of residual is 5.

Count correction

Using the stabilized Pearson residuals, the raw count matrix is corrected following Equation (8).

{μc(i)=exp(βi+median(ln(Cj)))σc2(i)=μc(i)+1θiμc(i)2C[cij]=μc(i)+zijσc(i)\begin{cases} \begin{aligned} \mu_c(i) &= \exp\left( \beta_i + \text{median}(\ln(C_j)) \right) \\ \sigma_{c}^2(i) &= \mu_c(i) + \frac{1}{\theta_i} \mu_c(i)^2 \\ \mathbb{C}[c_{ij}] &= \mu_c(i) + z_{ij} \sigma_{c}(i) \end{aligned} \end{cases}

The gene-specific baseline mean μc(i)\mu_c(i) and variance σc2(i)\sigma_{c}^2(i) used for this correction step are calculated similarly to E[cij]\mathbb{E}[c_{ij}] and σij2\sigma_{ij}^2 in Equation (6), excepting that specifying the median of log-scaled total count of samples.

Ultimately, the corrected count value (C[cij]\mathbb{C}[c_{ij}]) is computed by the combination of the baseline mean count across samples, and the specific expectation deviation derived from the specific residual. Finally, the corrected values are polished by rounding, and the minimum floor set at 0.

Post-processing

Feature selection

The top variable features (genes) are determined by ranking the variance of Pearson residuals across cells.

In detail, after computing the raw residuals, they are practically clipped by the range [M/30,M/30][-\sqrt{M/30}, \sqrt{M/30}] (where MM is the total number of cells) to mitigate the distorting impact of extreme outliers. Next, genewise variance of these clipped residuals is calculated and the genes are sorted to select the top variable features (capped at 3,000 features by default).

Residualization

Subsequently, based on the parameter vars.to.regress, Pearson residuals are residualized against the percentage of mitochondrial genes, which reflects cell survival status. This step eliminates additional unwanted variance arising from technical errors or cell damage.

{zi=Ax+riA=[1pmt]\begin{cases} \begin{aligned} \mathbf{z}_i &= A\mathbf{x} + \mathbf{r}_i \\ A &= \begin{bmatrix} {\scriptstyle \vert} & {\scriptstyle \vert} \\ 1 & p_{mt} \\ {\scriptstyle \vert} & {\scriptstyle \vert} \end{bmatrix} \end{aligned} \end{cases}

This dependency is modeled linearly, as shown in Equation (9), where the Pearson residual vector of gene ii (zi\mathbf{z}_i) depends on a linear model of the mitochondrial gene percentage (pmtp_{mt}) and an independent residual vector (ri\mathbf{r}_i).

Finally, the resulting residuals are mean-centered within each gene.

Summary

To reduce technical noise without losing statistical variance, sctransform fits and regularizes a negative binomial model to stabilize variance across genes. Technical bias across cells is removed via Pearson residualization while preserving true biological variation. Furthermore, top variable features are selected, and dependence on confounding covariates is regressed out.

Notably, the corrected count matrix is reconstructed directly from the initial Pearson residuals before post-processing. Consequently, the corrected counts remain independent of additional covariate regressions, thereby preserving the baseline biological variance of the raw counts.

References
  1. Hafemeister, C., & Satija, R. (2019). Normalization and Variance Stabilization of Single-Cell RNA-seq Data Using Regularized Negative Binomial Regression. Genome Biology, 20(1), 296. 10.1186/s13059-019-1874-1
  2. Choudhary, S., & Satija, R. (2022). Comparison and Evaluation of Statistical Error Models for scRNA-seq. Genome Biology, 23(1), 27. 10.1186/s13059-021-02584-9
  3. Sheather, S. J., & Jones, M. C. (1991). A Reliable Data-Based Bandwidth Selection Method for Kernel Density Estimation. Journal of the Royal Statistical Society Series B: Statistical Methodology, 53(3), 683–690. 10.1111/j.2517-6161.1991.tb01857.x
  4. Nadaraya, E. A. (1964). On Estimating Regression. Theory of Probability & Its Applications, 9(1), 141–142. 10.1137/1109020