Skip to main content
Bioinformatics logoLink to Bioinformatics
. 2023 Aug 10;39(8):btad479. doi: 10.1093/bioinformatics/btad479

BEENE: deep learning-based nonlinear embedding improves batch effect estimation

Md Ashiqur Rahman 1,2, Abdullah Aman Tutul 3,4, Mahfuza Sharmin 5,✉, Md Shamsuzzoha Bayzid 6,✉
Editor: Christina Kendziorski
PMCID: PMC10448987  PMID: 37561107

Abstract

Motivation

Analyzing large-scale single-cell transcriptomic datasets generated using different technologies is challenging due to the presence of batch-specific systematic variations known as batch effects. Since biological and technological differences are often interspersed, detecting and accounting for batch effects in RNA-seq datasets are critical for effective data integration and interpretation. Low-dimensional embeddings, such as principal component analysis (PCA) are widely used in visual inspection and estimation of batch effects. Linear dimensionality reduction methods like PCA are effective in assessing the presence of batch effects, especially when batch effects exhibit linear patterns. However, batch effects are inherently complex and existing linear dimensionality reduction methods could be inadequate and imprecise in the presence of sophisticated nonlinear batch effects.

Results

We present Batch Effect Estimation using Nonlinear Embedding (BEENE), a deep nonlinear auto-encoder network which is specially tailored to generate an alternative lower dimensional embedding suitable for both linear and nonlinear batch effects. BEENE simultaneously learns the batch and biological variables from RNA-seq data, resulting in an embedding that is more robust and sensitive than PCA embedding in terms of detecting and quantifying batch effects. BEENE was assessed on a collection of carefully controlled simulated datasets as well as biological datasets, including two technical replicates of mouse embryogenesis cells, peripheral blood mononuclear cells from three largely different experiments and five studies of pancreatic islet cells.

Availability and implementation

BEENE is freely available as an open source project at https://github.com/ashiq24/BEENE.

1 Introduction

Recent technological advancements have paved the way to generate large-scale single-cell RNA sequencing (scRNA-seq) data, leading to the establishment of large-scale projects such as the Human Cell Atlas (Regev et al. 2017). Due to logistical constraints in such large studies, scRNA-seq data is often generated and compiled from multiple experiments with differences in laboratory conditions, reagent lots, capturing times, and personnel differences (Leek et al. 2010, Haghverdi et al. 2018, Tran et al. 2020). As such, integrative analysis of several scRNA-seq datasets from different cohorts and studies is inevitable to acquire comprehensive and meaningful biological information (Rhodes and Chinnaiyan 2005, Korsunsky et al. 2019). However, meaningful biological variations are often confounded by the unwanted technical variations introduced by nonbiological factors of the experiments (Luo et al. 2010). This qualitatively different behavior across conditions that are unrelated to the biological or scientific variables is known as batch effects.

Batch effects are widespread and critical to address. As such, identification and removal of batch effects while preserving the biological variations have received considerable attention from the scientific community. ComBat (Johnson et al. 2007), CombBat-Seq (Zhang et al. 2020), limma (Ritchie et al. 2015), RUVseq (Risso et al. 2014), svaseq (Leek 2014), Seurat-CCA (Butler et al. 2018), MNN Correct (Haghverdi et al. 2018), BERMUDA (Wang et al. 2019), DESC (Li et al. 2020), and Harmony(Korsunsky et al. 2019) are among the well-known state-of-the-art batch correction methods. In addition to these batch correction techniques, methods for batch effect assessment are also of high interest to effectively detect and measure batch effects. The primary approach for batch effect detection involves visual inspection of low dimensional representation of data, such as PCA, t-SNE (Van der Maaten and Hinton 2008), and UMAP (McInnes et al. 2018). Batch evaluation methods, involving interactive visualizations and statistical analyses to evaluate batch effects and explore their impact on the data, have also been developed (Manimaran et al. 2016). However, visual inspections are subjective and do not provide any quantitative measurements to assess and compare the level of batch effects present in the data. As a result, several quantitative measures for assessing batch effects have been developed. Average Silhouette Width (Rousseeuw 1987, Lotfollahi et al. 2018) assesses batch effects by silhouette scores, which represents the similarity of data points in its own cluster compared to other clusters. The Adjusted Rand Index (Hubert and Arabie 1985), which computes the similarity between two clusters, can also be used for batch effect assessments. k-nearest neighbor batch-effect test (kBET) (Büttner et al. 2019) and Local Inverse Simpson’s Index (LISI) (Korsunsky et al. 2019) are two well-known “local” batch effect measurement metrics. The kBET metric measures batch mixing by considering the deviation between local and global distributions using a predetermined number of nearest neighbors. LISI measures the local batch mixing “integration LISI” (iLISI) by computing the inverse Simpson’s index on the local neighborhood based on a predefined perplexity. These assessment metrics mostly involve calculating distances between data points in lower dimensional embeddings generated by linear dimensionality reduction methods such as PCA.

Batch effects, on the other hand, are complex in nature and can be highly nonlinear (Tran et al. 2020), making it difficult for the embeddings generated by linear dimensionality reduction methods like PCA to correctly detect and assess the degree of batch effects present in the data. The application of nonlinear transformations to learn nonlinear mappings from the data domain to low-dimensional latent space may lead to improved clustering of data (Salakhutdinov and Hinton 2007, Ren et al. 2014, Yang et al. 2017). However, nonlinear transformations that are specially tailored to generate embeddings capable of capturing both biological and batch variability in the face of both linear and nonlinear batch effects are currently lacking.

Here, we present Batch Effect Estimation using Nonlinear Embedding (BEENE) to correctly estimate linear as well as complex nonlinear batch effects in RNA-seq data. The advantage of nonlienar transformations, as used in BEENE, is its ability in modeling the higher-order correlations among the original data dimensions (Salakhutdinov and Hinton 2007). BEENE exploits the ability of a deep autoencoder to approximate nonlinear mappings, which is guided by two separate neural networks to capture batch-specific and biological variability in the data. Thus, BEENE embeds cells into a lower-dimensional space using nonlinear transformation, which can explain batch variability while retaining biological variables in the presence of both linear and complex nonlinear batch effects. As we will show in the following that the BEENE embeddings are, in fact, more robust and sensitive to the presence of batch effects than PCA regardless of whether the batch effects are linear or nonlinear. The performance of BEENE was assessed on a collection of simulated datasets covering a wide range of model conditions with both linear and nonlinear batch effects, as well as several single-cell RNA-seq datasets, including two technical replicates of mouse embryonic stem cells (mESCs), peripheral blood mononuclear cells (PBMC) from three different experiments, and five studies of pancreatic islet cells. The performance of BEENE was evaluated in comparison to both traditional PCA and existing batch assessment methods such as kBET and LISI. Furthermore, we evaluate its performance before and after batch correction using widely used batch correction approaches, namely ComBat (Johnson et al. 2007), ComBat-Seq (Zhang et al. 2020), MNN Correct (Haghverdi et al. 2018), and Harmony (Korsunsky et al. 2019).

2 Materials and methods

We start with an overview of the overall pipeline used in BEENE in Section 2.1 followed by the detailed descriptions of the architecture of BEENE in the subsequent section.

2.1 Overview of BEENE

We propose BEENE, a supervised and guided learning of nonlinear embedding to estimate batch effects in scRNA-seq data. The workflow of BEENE is illustrated in Fig. 1A–E. After preprocessing steps (e.g. normalization), BEENE uses an autoencoder model to learn the nonlinear embeddings of RNA-seq expression data, which is guided by two additional modules: (i) a network to predict batch variables (e.g. cohorts, protocols) that indicate the batches from which the RNA-seq data was generated, and (ii) a network to learn biological variables (e.g. cell types, disease status). The nonlinear embedding learned by the autoencoder is used by both batch and biological variable learner modules. The autoencoder and these two learning networks are trained in tandem to guide the embedding in such a way that biological heterogeneity in the data as well as variability across batches are preserved. The batch learner module learns to predict the known and unknown probable batches across datasets and the biological learner module learns to predict the cell types in single-cell data and/or any other phenotypic information available in the samples. Thus, these two learners guide the autoencoder to learn an embedding that best explains the data in terms of their biological properties and batches, even if the batches across samples are highly nonlinear. This representation of the data is then utilized to estimate batch effects. We train the entire model, which includes the autoencoder and two additional modules, using three loss functions that are jointly optimized using the mini batch gradient descent method (see Materials and Methods for details). We investigated the efficacy of the embedding produced by BEENE in detecting batch effects with alternative measures: the k-nearest-neighbor (KNN) based local distribution of batches (kBET) (Büttner et al. 2019) and the local inverse Simpson’s index (iLISI) (Korsunsky et al. 2019). We applied kBET and LISI in both PCA space and BEENE embeddings, and found that kBET and LISI with BEENE provide more robust and sensitive estimation of batch effects than those using the PCA space, regardless of the linear or nonlinear nature of batch effects.

Figure 1.

Figure 1.

(A–E) Workflow of BEENE. BEENE takes as input RNA-seq data (before or after batch correction) and produces an embedding Z, which can subsequently be used by batch estimation methods, such as kBET and LISI. (D) The auto-encoder model used in BEENE. The model consists of an encoder-decoder network (fϕ−fθ), one batch prediction network (fψ), and one biological factor prediction network (fω). These are jointly optimized by mini batch gradient descent.

2.2 Nonlinear dimensionality reduction

BEENE uses a deep autoencoder to project a high dimensional RNA-seq data to a lower dimensional space by nonlinear transformations. An autoencoder is a type of artificial neural network that learns to copy its input to its output. This is achieved by learning efficient data embedding in an unsupervised manner to recreate the input. A schematic diagram of the autoencoder-based architecture of BEENE is shown in Fig. 1D. It consists of an encoder network and a decoder networks. The encoder network can be defined as fϕ:X→Z, which maps the input space X∈RD to the embedding space Z∈Rd where d≪D. The decoder network can be defined as fθ:Z→X, which maps the embedding Z back to the input space X. This intermediate embedding Z can subsequently be used with batch estimation methods such as kBET or LISI to detect batch effects. Here, ϕ and θ are the parameters of encoder and decoder network, respectively. Both the encoder and decoder networks in BEENE are fully connected neural network and following the architecture proposed in (Li et al. 2020) with two hidden layers. The encoder network has 200 neurons in the first hidden layer and 100 neurons in the second hidden layer, while the decoder network has 100 and 200 neurons in the first and second hidden layers, respectively. The dimension d of the intermediate embedding space was set to 50 to make this study comparable with kBET (Büttner et al. 2019). However, it can be changed based on the need of a particular application. We used Scaled Exponential Linear Unit (SELU) as the activation function, which was found superior for a wide range of tasks (Klambauer et al. 2017).

BEENE uses two additional single-layer networks fψ and fω to guide the embedding Z learned by the encoder network fϕ such that the embedding preserves both biological and batch-specific variations. The batch prediction network fψ uses softmax or logistic regression (depending on the number of classes) to predict the batch variables associated with the input X from the embedding Z learned by encoder fϕ. Similarly, fω predicts the biological variables associated with input X. fψ guides the encoder network fϕ to learn an embedding Z such that the RNA-seq data will be grouped or clustered by their respective batches. fω does the same for the biological variables. As a result, the encoder network fω tries to learn an embedding Z that best explains the data with respect to their batches and biological variables. Moreover, this simultaneous multitask learning (i.e. predicting both batches and biological variables from the embedding Z) improves generalization by inductive transfer (Caruana 1997).

Let the input RNA-seq dataset X={x1,x2,…,xn} with K batches and M biological classes {(x1,b1,y1), (x2,b2,y2), …,(xn,bn,yn)}, where xi∈RD is an RNA-seq, bi∈{0,1,…,K−1} is the corresponding batch variable, and yi∈{0,1,…M−1} is the biological variable associated with RNA-seq xi. Let Z={z1,z2,…,zn} be the embeddings learned by the autoencoder network, where zi∈R50. For K≥2, the batch predictor network fψ performs a softmax regression and estimates the probability P(bi=j|zi) (j∈{0,1,…K−1}) from zi=fϕ(xi) using Equation 2.

fψ(zi)=[P(bi=0|zi;ψ)P(bi=1|zi;ψ)⋮P(bi=K−1|zi;ψ)] (1)
=1∑j=0K−1 exp(ψ(j)⊤zi)[ exp(ψ(0)⊤zi) exp(ψ(1)⊤zi)⋮ exp(ψ(K−1)⊤zi)] (2)

Here, ψ=[ψ(0),ψ(0),…ψ(K−1)] are the learnable parameters (weights) of the single layer neural network fψ. For K=2, i.e. when there are only two batches in the dataset, fψ performs logistic regression to estimate P(bi=j|zi) for j∈{0,1} using Equation 3, where σ represents the sigmoid function.

P(bi=1|zi;ψ)=fψ(zi)=11+exp(−ψ⊤zi)≡σ(ψ⊤zi)P(bi=0|zi;ψ)=1−P(bi=1|zi;ψ)=1−fψ(zi). (3)

Biological variable predictor network fω follows the same architecture to predict the biological variables from embedding Z. In order to prevent overfitting, we used Dropout (at a rate of 15%–20%) (Srivastava et al. 2014) and l2-regularization. The parameters of the four networks in BEENE, {ϕ,θ,ψ, and ω}, are simultaneously optimized by minimizing the loss function J(ϕ,θ,ψ,ω) using mini batch gradient descent. Bk,i and Yk,i are computed using Equation 3 when K=2 and logistic regression is performed instead of softmax regression. λ1,λ2, and λ3 are the weights for reconstruction loss, cross-entropy loss for batch prediction, and cross-entropy loss for biological factor prediction, respectively. These are hyper-parameters of BEENE that may affect the embedding Z learned by the autoencoder (see Supplementary Material). Note that λ1 and λ3 are related to the inherent biological properties of the RNA-seq data, while λ2 is related to nonbiological factors (batch effects). If not explicitly stated otherwise, in our simulation study, we have set λ1=1,λ2=2,λ3=1, and for datasets with no biological variables, we used λ1=1, λ2=1 and λ3=0 (i.e. when there are no biological variables associated with the RNA-seq data Xi, fω is scraped from the model). For the mouse embryonic stem cell data, which is very high dimensional with almost 11 thousand genes per cell, we have used an extra dropout regularization (with a 70% dropout rate) at the input layer of the model to reduce the risk of overfitting. Moreover, as the mean square error increases with increasing dimensions, we have used λ1=0.001,λ2=5.0 for this particular dataset to ensure a reasonable balance between the mean square reconstruction error of the autoencoder and the cross-entropy loss for batch detection. Further discussion including a clear guideline on setting these parameters are provided in Supplementary Section 2.6 in the Supplementary Material.

J(ϕ,θ,ψ,ω)=∑i=0s(λ1*||xi−fθ(fϕ(xi))||22−λ2*∑k=0K−11{bi=k} log Bk,i−λ3*∑k=0M−11{yi=k} log Yk,i+10−4*∑w∈{ϕ,θ,ψ,ω}||w||22)Here,Bk,i=P(bi=k|fϕ(xi);ψ)= exp(ψ(k)⊤fϕ(xi))∑j=0K−1 exp (ψ(j)⊤fϕ(xi))Yk,i=P(yi=k|fϕ(xi);ω)= exp(ω(k)⊤fϕ(xi))∑j=0M−1 exp (ω(j)⊤fϕ(xi))1{.} is an indicator function.s is the batch size (4)

2.3 k-Nearest neighbor batch-effect test (kBET)

The batch effect assessment metric kBET (Büttner et al. 2019) compares the local batch distribution with the global distribution to measure the extent of batch effect in the dataset. After reducing dimensionality by PCA (top 50 PCs by default), it selects the k nearest neighbors around each point and calculates the local batch distribution. Next, it selects 10% of the points to test their local distributions with the global distribution. It performs a χ2 test to check whether the null hypothesis, that all the batches are well mixed, can be rejected. Low rejection rates imply well-mixing of the data while higher rejection rates, i.e. rejection rates close to 1.00 indicate the presence of a significant amount of batch effects in the data. In the default settings of kBET (https://github.com/theislab/kBET), 100 rejection rates are calculated on 100 different sub-samples of the dataset.

2.4 Local inverse Simpson’s index (LISI)

LISI (Korsunsky et al. 2019) is another local method for batch estimation. But unlike kBET, it does not use any fixed value for k to determine the number of neighbors. It selects neighbors based on a local distance distribution with a fixed perplexity (by default 30), and uses inverse Simpson index of diversity (Korsunsky et al. 2019) to determine the effective number of batches present in the locality [known as “integration LISI”(iLISI)]. An iLISI score close to 1 indicates the worst score (i.e. no-mixing of batches) and increased iLISI (close to the expected number of batches) reflects increasingly improved mixing of batches.

2.5 Data simulation model

Please see Supplementary Section 1 in the Supplementary Material.

2.6 Biological datasets

We have evaluated BEENE on a collection of biological datasets, including three scRNA-seq datasets. We used the mESCs from Klein et al. (2015), where the authors demonstrated the droplet-based sequencing technique. The authors of kBET used two technical replicates of this mESCs dataset that consisted of 5952 cells from 2 batches and 11 308 genes with at least 2 cells having more than 4 unique molecular identifier (UMI) reads per cell. We obtained these two technical replicates from the authors of kBET and considered these two replicates as two batches. Thus, this dataset represents a model condition with two batches where all the cells are from a single cell type (embryonic stem cell). We have used three human PBMC datasets from Korsunsky et al. (2019), that were assayed on the Chromium 10X platform but prepared with different protocols: 3ʹ end v1 (3pV1), 3ʹ end v2 (3pV2), and 5ʹ end (5p). These different protocols were considered as different batches and there were seven cell types considered as biological variables. We used another scRNA-seq dataset from Korsunsky et al. (2019) that consisted of 14 746 human pancreatic islet cells from 36 donors, assayed on 5 independent studies: inDrop (4 donors, 8569 cells), Fluidigm C1 (13 donors, 638 cells), Smart-Seq2 (10 donors, 2355 cells), CEL-seq (5 donors, 946 cells), and CEL-seq2 (4 donors, 2238 cells). Thus, we have used datasets from both human and mouse with varying conditions (e.g. number of cells, cell-types, technological platforms).

3 Results

3.1 BEENE effectively captures batch effects

To test the efficacy of BEENE, we used simulated scRNA-seq data generated by Splatter R package (Zappia et al. 2017). We have simulated expression data in 2 different settings: (i) scRNA-seq data for two different cell types where 1000 cells (with 2500 genes each) were sampled from each of these two cell types and, for each of these two cell types, two batches were generated (each with 500 cells); and (ii) scRNA-seq for a single cell-type, where 1500 cells with 2500 genes each were sampled and two batches were generated (each with 750 cells). In both settings, expression data of these two batches have been generated with additive linear noise. Next, to train (and test) the model of BEENE, we divide the expression data randomly into training, validation, and testing sets with a 60:20:20 ratio. We estimated batch effects by measuring kBET and iLISI metrics in the embedding space given by BEENE on the test sets and compared them with kBET and iLISI values in the PCA space. Figure 2A–H (top panel) summarizes the assessment and the effectiveness of BEENE compared to the PCA space. For the dataset with two cell types, the batches are not clearly separated in the PCA space (Fig. 2A; top panel). The cells from different batches are closer than the cells from different cell types indicating that the dataset is either batch free or has small batch effects if we consider the shift of cells from the two batches. In case of the data with a single cell type, the expression data shows a clear separation by their respective batches, which was captured by the second PC (Fig. 2E). In contrast, the expression data in both cases shows much clearer separation by batches and cell types in the embedding space provided by BEENE, where the first PC of the embedding space captured the batch variation and the second PC captured different cell types (Fig. 2B and F). This indicates the presence of batch effects which was not effectively captured by the PCA space. We also investigated the performance of BEENE embeddings in comparison to t-SNE and UMAP embeddings—two widely used embeddings for the visual inspection of batch effects. Similar to PCA embeddings and unlike BEENE embeddings, t-SNE failed to capture the batch- and cell-specific variations (see Section 2.1 in Supplementary Material). As a result, kBET and LISI employing the BEENE embeddings achieved higher rejection rates and lower iLISI values respectively, compared to the values obtained using the PCA embeddings (Fig. 2C, D, G, and H)—indicating that BEENE has a higher sensitivity to the presence of batch effects than the PCA space.

Figure 2.

Figure 2.

Performance of BEENE on simulated scRNA-seq data with linear and nonlinear batch effects (shown in top and bottom panels respectively). (A) scRNA-seq data from two cell types in the PCA space. (B) scRNA-seq data from two cell types in the embedding space produced by BEENE. We used the first two PCs to visualize the data embeddings. (C) Rejection rates provided by kBET in the BEENE embedding (on the testset) and in the PCA space (on both the testset and the entire dataset). In each case, we show the distribution of 100 rejection rates provided by kBET. (D) iLISI values obtained using BEENE and PCA embeddings. (E–H) Similar to A–D using one cell type.

We conducted additional experiments to evaluate the performance of BEENE in situations where biological factors, such as cell types, were not provided (see Supplementary Fig. S3). The results indicate that BEENE was still able to accurately detect batch effects even without biological information. However, it should be noted that the embeddings generated by BEENE without biological information were unable to properly distinguish data based on cell types, as shown in Supplementary Fig. S2B. This behavior was expected, given that biological factors were not provided to the method. Nevertheless, this did not adversely impact BEENE’s ability to estimate batch effects, as demonstrated by the kBET rejection rate and the iLISI value obtained by BEENE.

3.2 BEENE effectively captures nonlinear batch effects

We next investigated the performance of BEENE on simulated scRNA-seq data with nonlinear batch effects. We modeled the nonlinear batch effect as an additive term to the simulated scRNA-seq data generated using Splatter (see Section 2 for details) and trained our model in a similar way as described in Section 3.1. Similar to Section 3.1, we have used two settings for simulating data, one with a single cell type and the other with two cell types. In both cases, batch effects were modeled considering data from two batches. The bottom panel in Fig. 2A–H demonstrates the effectiveness of BEENE in detecting and assessing nonlinear batch effects in comparison to the PCA space. Nonlinear batch effects are not visually separable when it is inspected in the PCA space (Fig. 2A and E; bottom panel). For data with one cell-type, one batch is more concentrated at the center without any clear separation between two batches and thus kBET gives lower rejection rates and LISI gives higher iLISI values in general, despite the presence of batch effects that was carefully introduced in our simulation study (Fig. 2C, D, G, and H; bottom panel). In contrast, the presence of batch effects is clearer in the embedding space generated by BEENE. For data with two types of cells from two batches, the BEENE embedding space effectively separates the data by both batches and cell types, where the batch variation is captured by the second principal component of the embedding space (Fig. 2B). Similarly, for the data with a single cell type, the first principal component of the embedding space captures the batch variation while the second one focuses on the biological variability of cells (Fig. 2F). In both cases, kBET in the embedding space gives higher rejection rates (Fig. 2C and G) and LISI gives lower iLISI values (Fig. 2D and H) compared to those obtained using the PCA space, indicating that BEENE has a higher sensitivity than the PCA space for detecting nonlinear batch effects.

3.3 BEENE does not overestimate batch effects

We have demonstrated in Sections 3.1 and 3.2 that the embedding produced by BEENE can capture batch variations more effectively than the PCA space. As a result, BEENE is more sensitive to the presence of batch effects and kBET and LISI measured on BEENE embedding resulted in higher rejection rates and lower iLISI values than those computed using the PCA space in the presence of batch effects. To investigate whether this is an indication of overestimation of batch effects, we tested our framework on two carefully controlled simulated datasets, using identical settings as Sections 3.1 and 3.2 but without introducing any batch effects. These datasets represent model conditions where data has been sequenced using two different technologies but no technical variation has been introduced into the data. In both cases, BEENE embeddings lead to rejection rates close to 0.0 and iLISI values close to 2.0, indicating no potential batch effects. kBET and LISI using the PCA space, achieved comparable yet higher rejection rates and lower iLISI values (see Supplementary Fig. S5). For data with two cell types, rejection rate drops from 0.85 to 0.0 and iLISI value increases from 1.36 to 1.95 when data is changed from batch-affected (nonlinear) to batch-free model conditions. In case of data with a single cell type, the rejection rate drops from 0.87 to 0.0 and the iLISI value increases from 1.32 to 1.95. Therefore, BEENE estimates the batch effects with necessary specificity. To show the robustness of batch assessment scores obtained from BEENE embeddings, we have also performed 5-fold cross-validatio (Kohavi et al. 1995) for nonlinear batch affected and batch free model conditions (see Supplementary Material). Furthermore, these results indicate that the batch estimations of BEENE described in Sections 3.1 and 3.2 are not overestimations, but instead represent appropriate sensitivity to batch effects. In sum, BEENE embedding outperforms PCA space in terms of sensitivity and specificity for detecting batch effects.

3.4 Sensitivity of BEENE to different levels of batch effects

We have assessed the performance of BEENE on simulated data with different levels of batch effects. Levels of batch effects were controlled by confining the components of the vector representing batch effects within a certain range [0, b] by choosing suitable values of A in Equation 2 in the Supplementary Material (see Supplementary Section 1 in Supplementary Material for details). Denoting the batch effect in the ith batch by a D dimensional vector B(i)∈RD (D is the number of genes), we choose suitable values for A in Equation 2 in the Supplementary Material so that every component of B(i), Bj(i)∈[0,b],∀i∈{0,1,…K−1},∀j∈{0,1,…,D−1}. Here [0, b] is a predefined range in which higher values of b indicate higher levels of batch effects.

The performance of BEENE on different ranges of batch effects ([0, b], b∈{0.1,0.2,0.3,0.4,0.5}) is shown in Supplementary Fig. S6. As expected, the rejection rates obtained using the embedding space produced by BEENE increase with increasing levels of batch effects. With a substantial level of batch effects ([0, 0.5]), the clustering based on the biological factor (cell-type) is not observed. Moreover, due to the nonlinear nature of the batch effects, the batches are not distinguishable in the PCA space but the BEENE embedding effectively separates the data by batches. Furthermore, the rejections rates of kBET using PCA space do not change appropriately with varying levels of batch effects. Even with a very high level of batch effects ([0, 0.5]), the rejection rate was around 0.4, and it did not vary significantly across a wide range of batch strengths (e.g. from [0, 0.2] to [0, 0.5]). In contrast, kBET with BEENE produced more meaningful rejection rates and it varied from 0 to 0.86 on different levels of batch effects, indicating appropriate sensitivity to varying levels of batch effects. Similar trends were observed for iLISI values, which gradually decreased from 1.90 to 1.65 with PCA space, but varied across a wider range (1.26–1.95) when BEENE embedding was used (see Table 1).

Table 1.

Performance of BEENE on varying levels of batch effects.a

Amplitude range LISI BEENE + LISI BEENE + kBET kBET
[0.0, 0.5] 1.65 1.26 0.86 0.45
[0.0, 0.4] 1.72 1.36 0.85 0.45
[0.0, 0.3] 1.78 1.59 0.65 0.19
[0.0, 0.2] 1.83 1.71 0.30 0.03
[0.0, 0.1] 1.88 1.90 0.05 0.03
[0.0, 0.0] 1.90 1.95 0.00 0.04
a

We show the kBET metric (rejection rate) and iLISI values obtained by kBET and LISI using default setting (i.e. PCA embedding) and BEENE embedding.

3.5 Sensitivity of BEENE to the proportion of genes having batch effects

We have investigated the performance of BEENE with varying proportions (10%–100%) of genes having batch effects (see Supplementary Fig. S7). The lower the proportion of affected genes, the less tightly clustered the data based on their batches. As we increase the proportion of genes having batch effects, the clustering of the data by batches becomes evident in the BEENE embedding space. However, due to the nonlinearity of the batch effects, no segregation with respect to batches was observed in the PCA space. The rejection rates of kBET with PCA embedding varies from 0.03 to 0.45 as we increase the proportion of genes having batch effects from 10% to 100%. However, kBET with BEENE embedding demonstrated improved sensitivity, as the rejection varied across a much wider range 0.05–0.85 (see Table 2). Similar trends were observed for iLISI values.

Table 2.

Rejection rates and iLISI values obtained by kBET and LISI using default settings (i.e. PCA embeddings) and BEENE embeddings for different percentages of genes having batch effects.

Proportion (%) LISI BEENE + LISI kBET BEENE + kBET
100 1.72 1.36 0.45 0.85
80 1.77 1.50 0.40 0.79
60 1.81 1.58 0.38 0.76
40 1.87 1.79 0.28 0.73
20 1.88 1.88 0.10 0.40
10 1.89 1.94 0.03 0.05

3.6 BEENE performs well on single-cell RNA-seq data

We evaluated the performance of BEENE on a collection of scRNA-seq data used in previous studies (Klein et al. 2015, Korsunsky et al. 2019) for batch effect estimation and correction including (i) two technical replicates of mouse embryonic stem cell (mESC), (ii) three human PBMC datasets assayed on the same platform with three different protocols indicating three batches, and (iii) human pancreatic islet cells from five independent studies with different technologies indicating five batches (see Section 2 for more details). These datasets were selected to cover a wide range of model conditions for batch effects of different levels and complexities.

Figure 3 presents the comparative analysis of kBET in the PCA space and BEENE embedding on mESC data of day 0 culture generated via inDrop protocol. This represents a model condition of data from different batches with no biological variables. Before any batch correction, the batch effect is more understood in the embedding space (Fig. 3B) than in the PCA space. As a result, kBET with BEENE embedding achieved a higher rejection rate (1.00) than kBET using PCA space which obtained rejection rates of 0.80 and 0.48 on the full and test data, respectively (see Fig. 3C). Similar trends were observed for the iLISI values (Fig. 3D), suggesting that before any batch correction, batch effects are detected in both the PCA and embedding spaces, although in the embedding space it is more pronounced than the PCA space. Next, we used ComBat (Johnson et al. 2007), a state-of-the-art method for batch correction, to remove batch effects from the data and subsequently applied batch effect estimation methods on the corrected data. As expected, the corrected data shows reduced levels of batch effects both in the PCA space (Fig. 3E) and the embedding space (Fig. 3F). However, the embedding generated by BEENE shows a shift along the second principal component, capturing the uncorrected leftover batch effects. Consequently, BEENE achieved a higher rejection rate (0.58) than the PCA space (0.33 and 0.20 on the full test dataset respectively) (Fig. 3G) and the iLISI values for the embedding space (1.57) is closer to 1 than that for the PCA space (∼1.76). Based on our results presented in Sections 3.3 and 3.4 that BEENE embedding is sensitive to batch effects and appropriately varies with varying levels of batch effect strengths, we believe that the higher rejection rates and lower iLISI values than those using the PCA space appropriately reflect the level of the batch effects that might have persisted in the data even after the batch correction by ComBat. Thus, BEENE embedding detected batch effects with appropriate sensitivity and more clearly than the PCA space before and after batch correction.

Figure 3.

Figure 3.

Performance of BEENE on mESC inDrop technical replicates. Results are shown for both before and after the data is batch corrected by ComBat. (A) PCA plot of the data colored by batches (technical replicates). (B) PCA plot of the embeddings learned by BEENE colored by batches. (C) Rejection rates provided by kBET using BEENE and PCA embeddings, (D) iLISI values obtained using BEENE and PCA embeddings. (E–H) Similar to A–D after batch correction by ComBat.

Next, we have demonstrated the performance of BEENE on three human PBMC datasets, each prepared on the Chromium 10X platform but with three different protocols. These three different protocols are considered as different batches, each with six types of cells as biological variables. In the PCA space, the cells appear to be clustered based on the biological variable, and the presence of batch-specific variations is also evident from the PCA plots (Fig. 4A and B). After applying batch correction using ComBat, the clustering remained almost similar, suggesting that ComBat may have failed to correct batch effects (Fig. 4A, B, G, and H). BEENE embedding demonstrates more clearly than the PCA embedding that the cells group by cell types and batches (Fig. 4B and C). It is also evident that the batch-specific variations remained even after batch correction (Fig. 4I and J). This is reflected in the high rejection rates before and after batch correction. Before batch correction, both BEENE and PCA embedding obtained rejection rates of close to 1.00 and after batch correction by ComBat, BEENE still gives a rejection rate of ∼1, and PCA embedding also lead to a very high rejection rate (0.96). This observation about ComBat’s failure to mix the batches well on this dataset was also demonstrated in previous studies [see Fig. 5 in Tran et al. (2020)]. As such, we have corrected the data by Harmony (Korsunsky et al. 2019) as well and investigated the performance of BEENE on Harmony- corrected human PBMC dataset. Harmony takes as input a low dimensional embedding, generally principal components, of gene expressions and returns a batch corrected embedding of the same dimension. On the other hand, BEENE takes gene expression as its input. So, in order to include Harmony, we used the first 100 principal components of PBMC data as BEENE’s input. Because the input dimension is significantly lower than that of gene expression data, we made a few changes to our model (e.g. we used only one hidden layer with 50 neurons and a 20 dimensional latent embedding for the autoencoder). Harmony-corrected data shows better mixing of batches while retaining biological variability (no mixing of cell types) both in the PC space and in the embedding space (Fig. 4M–P). This is also reflected in the rejection rate using BEENE embedding which drops to 0.80 after correction by Harmony, which was close to 1.00 for uncorrected and ComBat-corrected data. Similar trend was also noticed for iLISI values on BEENE embedding which increased from 1 to ∼2.5, indicating better mixing of the batches. This observation that Harmony performed significantly better than ComBat on this dataset is also supported by previous studies (Korsunsky et al. 2019, Tran et al. 2020). kBET and LISI using PC space, on the other hand, show contradictory trends—the iLISI values increased from 1 to 2.5 indicating mixing between batches, whereas the rejection rate of kBET remained the same even after correction by Harmony (Fig. 4Q). Thus, BEENE embedding was found to be more robust than the PCA embedding in capturing the extent of batch effects present in the data before and after batch correction. We further evaluated the performance of BEENE emabeddings on the data corrected by Combat-Seq and MNN correct. The results, presented in Section 2.3 in the Supplementary Material, show that BEENE performs well on the data corrected by these methods as well. Additionally, we ran Combat-seq with and without biological information to assess the performance of BEENE on different model conditions. These results suggest that the rejection rate drops and the iLISI value increases more prominently on Harmony-corrected data than the data corrected by ComBat, ComBat-Seq, and MNN—indicating that Harmony was more effective in removing batch effects than other methods on this dataset. Furthermore, ComBat-Seq, when run without biological information, appears to be more effective in removing batch effects than when it is run with biological information. We hypothesize that the extra constraint of retaining the biological factors negatively affected the performance of ComBat-Seq.

Figure 4.

Figure 4.

Performance of BEENE on human PBMC datasets. Results are shown before and after the data is batch corrected by ComBat and Harmony. (A) PC plot of the data colored by cell types. (B) PC plot of the data colored by batches. (C) PC plot of the embeddings learned by BEENE colored by cell types. (D) PC plot of the embeddings learned by BEENE colored by batches. (E) Rejection rates provided by kBET using BEENE and PCA embeddings, (F) iLISI values obtained using BEENE and PCA embeddings. (G–L) Similar to A–F after batch correction by ComBat. (M–R) Similar to A–F after batch correction by Harmony with the first 100 principal components of the data.

Finally, we have tested the performance of BEENE on scRNA-seq data of human pancreatic islet cells from five independent studies, generated by five different technological platforms (Cel-seq, Cel-seq2, SMART-Seq2, Fluidigm C1, and inDrop) that represent five batches. Each of these 5 datasets have 10 different cell types as biological variables. The results on this dataset are presented in Section 2.6 in Supplementary Material.

4 Discussion

Batch effects are inherently complex and difficult to estimate. While linear adjustments of batch effects may be adequate for many applications, it is important to consider various downstream analyses that involve more sophisticated methods such as machine learning models. These downstream analyses can be affected by the nonlinear remnant of batch effects. Therefore, even if linear adjustments appear to be sufficient, it is crucial for users to carefully evaluate the necessity of nonlinear adjustments depending on the specific application of the corrected data. Most of the existing approaches for batch effect detection and estimation rely on a lower-dimensional embedding of the data generated by PCA. In this study, we have proposed BEENE, which utilizes a deep autoencoder network to learn a latent embedding of the data using nonlinear transformation. Furthermore, we used two separate networks to learn batch and biological variations. We train these three networks in tandem with appropriate loss functions so that the embedding learned by the autoencoder is capable of explaining both batch and biological variations. BEENE is the first known study to consider and model the nonlinearity of batch effects in batch effect detection and estimation. Experimental results on various carefully controlled simulated datasets with both linear and nonlinear batch effects of different levels show that BEENE embeddings are more robust and sensitive than PCA embeddings. BEENE makes methods like kBET and LISI perform better in the face of complex batch effects. See Section 3 in Supplementary Material for additional discussion.

Supplementary Material

btad479_Supplementary_Data

Acknowledgements

This study was based on the undergraduate thesis of M.A.R. and A.A.T. conducted at the Department of Computer Science and Engineering (CSE), Bangladesh University of Engineering and Technology (BUET).

Contributor Information

Md Ashiqur Rahman, Department of Computer Science and Engineering, Bangladesh University of Engineering and Technology, Dhaka 1205, Bangladesh; Department of Computer Science, Purdue University, West Lafayette, IN 47907, United States.

Abdullah Aman Tutul, Department of Computer Science and Engineering, Bangladesh University of Engineering and Technology, Dhaka 1205, Bangladesh; Department of Computer Science and Engineering, Texas A&M University, College Station, TX 77843, United States.

Mahfuza Sharmin, Department of Genetics, Stanford University, Stanford, CA 94305, United States.

Md Shamsuzzoha Bayzid, Department of Computer Science and Engineering, Bangladesh University of Engineering and Technology, Dhaka 1205, Bangladesh.

Supplementary data

Supplementary data are available at Bioinformatics online.

Conflict of interest

None declared.

Funding

This work was partially supported by the Research and Innovation Centre for Science and Engineering at BUET (RISE-BUET) Internal Research Grant (ID: 2021-01-016).

Data availability

The data underlying this article are available at https://github.com/ashiq24/BEENE.

References

  1. Butler A, Hoffman P, Smibert P. et al. Integrating single-cell transcriptomic data across different conditions, technologies, and species. Nat Biotechnol 2018;36:411–20. [DOI] [PMC free article] [PubMed] [Google Scholar]
  2. Büttner M, Miao Z, Wolf FA. et al. A test metric for assessing single-cell RNA-seq batch correction. Nat Methods 2019;16:43–9. [DOI] [PubMed] [Google Scholar]
  3. Caruana R. Multitask learning. Mach Learn 1997;28:41–75. [Google Scholar]
  4. Haghverdi L, Lun AT, Morgan MD. et al. Batch effects in single-cell RNA-sequencing data are corrected by matching mutual nearest neighbors. Nat Biotechnol 2018;36:421–7. [DOI] [PMC free article] [PubMed] [Google Scholar]
  5. Hubert L, Arabie P.. Comparing partitions. J Classif 1985;2:193–218. [Google Scholar]
  6. Johnson WE, Li C, Rabinovic A.. Adjusting batch effects in microarray expression data using empirical bayes methods. Biostatistics 2007;8:118–27. [DOI] [PubMed] [Google Scholar]
  7. Klambauer G, Unterthiner T., Mayr A. et al. Self-normalizing neural networks. In: International Conference on Neural Information Processing Systems, pp. 971-981, Curran Associates Inc., 2017.
  8. Klein AM, Mazutis L, Akartuna I. et al. Droplet barcoding for single-cell transcriptomics applied to embryonic stem cells. Cell 2015;161:1187–201. [DOI] [PMC free article] [PubMed] [Google Scholar]
  9. Kohavi R. et al. A study of cross-validation and bootstrap for accuracy estimation and model selection. In: International Joint Conference on Artificial Intelligence, Vol. 14, pp. 1137–45. Montreal, Canada, 1995. [Google Scholar]
  10. Korsunsky I, Millard N, Fan J. et al. Fast, sensitive and accurate integration of single-cell data with harmony. Nat Methods 2019;16:1289–96. [DOI] [PMC free article] [PubMed] [Google Scholar]
  11. Leek JT. Svaseq: removing batch effects and other unwanted noise from sequencing data. Nucleic Acids Res 2014;42:e161. [DOI] [PMC free article] [PubMed] [Google Scholar]
  12. Leek JT, Scharpf RB, Bravo HC. et al. Tackling the widespread and critical impact of batch effects in high-throughput data. Nat Rev Genet 2010;11:733–9. [DOI] [PMC free article] [PubMed] [Google Scholar]
  13. Li X, Wang K, Lyu Y. et al. Deep learning enables accurate clustering with batch effect removal in single-cell rna-seq analysis. Nat Commun 2020;11:2338. [DOI] [PMC free article] [PubMed] [Google Scholar]
  14. Lotfollahi M, Wolf FA, Theis FJ.. Generative modeling and latent space arithmetics predict single-cell perturbation response across cell types, studies and species. bioRxiv, 2018, 478503, preprint: not peer reviewed. [Google Scholar]
  15. Luo J, Schumacher M, Scherer A. et al. A comparison of batch effect removal methods for enhancement of prediction performance using MAQC-II microarray gene expression data. Pharmacogenomics J 2010;10:278–91. [DOI] [PMC free article] [PubMed] [Google Scholar]
  16. Manimaran S, Selby HM, Okrah K. et al. BatchQC: interactive software for evaluating sample and batch effects in genomic data. Bioinformatics 2016;32:3836–8. [DOI] [PMC free article] [PubMed] [Google Scholar]
  17. McInnes L, Healy J, Melville J. UMAP: uniform manifold approximation and projection for dimension reduction. J Open Source Softw 2018; 3(29): 861. [Google Scholar]
  18. Regev A, Teichmann SA, Lander ES. et al. ; Human Cell Atlas Meeting Participants. The human cell atlas. eLife 2017;6:e27041. [DOI] [PMC free article] [PubMed] [Google Scholar]
  19. Ren W, Yu Y, Zhang J. et al. Learning convolutional nonlinear features for k nearest neighbor image classification. In: 2014 22nd International Conference on Pattern Recognition, pp. 4358–63. Stockholm, Sweden: IEEE, 2014.
  20. Rhodes DR, Chinnaiyan AM.. Integrative analysis of the cancer transcriptome. Nat Genet 2005;37:S31–7. [DOI] [PubMed] [Google Scholar]
  21. Risso D, Ngai J, Speed TP. et al. Normalization of RNA-seq data using factor analysis of control genes or samples. Nat Biotechnol 2014;32:896–902. [DOI] [PMC free article] [PubMed] [Google Scholar]
  22. Ritchie ME, Phipson B, Wu D. et al. limma powers differential expression analyses for rna-sequencing and microarray studies. Nucleic Acids Res 2015;43:e47. [DOI] [PMC free article] [PubMed] [Google Scholar]
  23. Rousseeuw PJ. Silhouettes: a graphical aid to the interpretation and validation of cluster analysis. J Comput Appl Math 1987;20:53–65. [Google Scholar]
  24. Salakhutdinov R, Hinton G.. Learning a nonlinear embedding by preserving class neighbourhood structure. In: Artificial Intelligence and Statistics, pp. 412–19. San Juan, Puerto Rico: PMLR, 2007. [Google Scholar]
  25. Srivastava N, Hinton G, Krizhevsky A. et al. Dropout: a simple way to prevent neural networks from overfitting. J Mach Learn Res 2014;15:1929–58. [Google Scholar]
  26. Tran HTN, Ang KS, Chevrier M. et al. A benchmark of batch-effect correction methods for single-cell RNA sequencing data. Genome Biol 2020;21:12–32. [DOI] [PMC free article] [PubMed] [Google Scholar]
  27. Van der Maaten L, Hinton G.. Visualizing data using t-sne. J Mach Learn Res 2008;9:2579–605. [Google Scholar]
  28. Wang T, Johnson TS, Shao W. et al. Bermuda: a novel deep transfer learning method for single-cell RNA sequencing batch correction reveals hidden high-resolution cellular subtypes. Genome Biol 2019;20:165–15. [DOI] [PMC free article] [PubMed] [Google Scholar]
  29. Yang B, Fu X, Sidiropoulos ND. et al. Towards k-means-friendly spaces: simultaneous deep learning and clustering. In: International Conference on Machine Learning, pp. 3861–70. Sydney, Australia: PMLR, 2017.
  30. Zappia L, Phipson B, Oshlack A.. Splatter: simulation of single-cell RNA sequencing data. Genome Biol 2017;18:174–15. [DOI] [PMC free article] [PubMed] [Google Scholar]
  31. Zhang Y, Parmigiani G, Johnson WE.. Combat-seq: batch effect adjustment for rna-seq count data. NAR Genom Bioinform 2020;2:lqaa078. [DOI] [PMC free article] [PubMed] [Google Scholar]

Associated Data

This section collects any data citations, data availability statements, or supplementary materials included in this article.

Supplementary Materials

btad479_Supplementary_Data

Data Availability Statement

The data underlying this article are available at https://github.com/ashiq24/BEENE.


Articles from Bioinformatics are provided here courtesy of Oxford University Press

RESOURCES