Combining and harmonizing samples or datasets from different batches such as experiments or conditions to enable meaningful cross-sample comparisons.
Authors
Åsa Björklund
Paulo Czarnewski
Susanne Reinsbach
Roy Francis
Published
09-Feb-2024
Note
Code chunks run R commands unless otherwise specified.
In this tutorial we will look at different ways of integrating multiple single cell RNA-seq datasets. We will explore a few different methods to correct for batch effects across datasets. Seurat uses the data integration method presented in Comprehensive Integration of Single Cell Data, while Scran and Scanpy use a mutual Nearest neighbour method (MNN). Below you can find a list of some methods for single data integration:
# download pre-computed data if missing or long computefetch_data <-TRUE# url for source and intermediate datapath_data <-"https://export.uppmax.uu.se/naiss2023-23-3/workshops/workshop-scrnaseq"path_file <-"data/covid/results/bioc_covid_qc_dr.rds"if (!dir.exists(dirname(path_file))) dir.create(dirname(path_file), recursive =TRUE)if (fetch_data &&!file.exists(path_file)) download.file(url =file.path(path_data, "covid/results/bioc_covid_qc_dr.rds"), destfile = path_file)sce <-readRDS(path_file)print(reducedDims(sce))
List of length 8
names(8): PCA UMAP tSNE_on_PCA ... UMAP_on_ScaleData KNN UMAP_on_Graph
We split the combined object into a list, with each dataset as an element. We perform standard preprocessing (log-normalization), and identify variable features individually for each dataset based on a variance stabilizing transformation (vst).
pheatmap::pheatmap(t(overlap *1), cluster_rows = F, color =c("grey90", "grey20")) ## MNN
The mutual nearest neighbors (MNN) approach within the scran package utilizes a novel approach to adjust for batch effects. The fastMNN() function returns a representation of the data with reduced dimensionality, which can be used in a similar fashion to other lower-dimensional representations such as PCA. In particular, this representation can be used for downstream methods such as clustering. The BNPARAM can be used to specify the specific nearest neighbors method to use from the BiocNeighbors package. Here we make use of the Annoy library via the BiocNeighbors::AnnoyParam() argument. We save the reduced-dimension MNN representation into the reducedDims slot of our sce object.
mnn_out <- batchelor::fastMNN(sce, subset.row =unique(unlist(hvgs_per_dataset)), batch =factor(sce$sample), k =20, d =50)
Caution
fastMNN() does not produce a batch-corrected expression matrix.
We can observe that a new assay slot is now created under the name MNN.
reducedDims(sce)
List of length 9
names(9): PCA UMAP tSNE_on_PCA UMAP_on_PCA ... KNN UMAP_on_Graph MNN
Thus, the result from fastMNN() should solely be treated as a reduced dimensionality representation, suitable for direct plotting, TSNE/UMAP, clustering, and trajectory analysis that relies on such results.
set.seed(42)sce <-runTSNE(sce, dimred ="MNN", n_dimred =50, perplexity =30, name ="tSNE_on_MNN")sce <-runUMAP(sce, dimred ="MNN", n_dimred =50, ncomponents =2, name ="UMAP_on_MNN")
We can now plot the unintegrated and the integrated space reduced dimensions.
An alternative method for integration is Harmony, for more details on the method, please se their paper Nat. Methods. This method runs the integration on a dimensionality reduction, in most applications the PCA. So first, we will rerun scaling and PCA with the same set of genes that were used for the CCA integration.
sce <-RunHarmony( sce,group.by.vars ="sample",reduction.save ="harmony",reduction ="PCA",dims.use =1:50)# Here we use all PCs computed from Harmony for UMAP calculationsce <-runUMAP(sce, dimred ="harmony", n_dimred =50, ncomponents =2, name ="UMAP_on_Harmony")
3 Scanorama
Important
If you are running locally using Docker and you have a Mac with ARM chip, the Scanorama reticulate module is known to crash. In this case, you might want to skip this section.
Another integration method is Scanorama (see Nat. Biotech.). This method is implemented in python, but we can run it through the Reticulate package.
We will run it with the same set of variable genes, but first we have to create a list of all the objects per sample.