In this vignette, we will combine two 10X PBMC datasets: one containing 4K cells and one containing 8k cells. The datasets can be found here.
To start, we read in the data and create two Seurat objects.
library(Seurat)
pbmc4k.data <- Read10X(data.dir = "~/Projects/datasets/10X/pbmc4k/filtered_gene_bc_matrices/GRCh38/")
pbmc4k <- CreateSeuratObject(raw.data = pbmc4k.data, project = "PBMC4K")
pbmc8k.data <- Read10X(data.dir = "~/Projects/datasets/10X/pbmc8k/filtered_gene_bc_matrices/GRCh38/")
pbmc8k <- CreateSeuratObject(raw.data = pbmc8k.data, project = "PBMC8K")
MergeSeurat
merges the raw.data matrices of two Seurat objects and creates a new Seurat object with the resulting combined raw.data matrix. To easily tell which original object any particular cell came from, you can set the add.cell.id1(2)
parameters which will append the given identifier to the beginning of each cell name. The original project ID will remain stored in object@meta.data$orig.ident
pbmc.combined <- MergeSeurat(object1 = pbmc4k, object2 = pbmc8k, add.cell.id1 = "4K",
add.cell.id2 = "8K", project = "PBMC12K")
# notice the cell names now have an added identifier
head(x = pbmc.combined@cell.names)
## [1] "4K_AAACCTGAGAAGGCCT" "4K_AAACCTGAGACAGACC" "4K_AAACCTGAGATAGTCA"
## [4] "4K_AAACCTGAGCGCCTCA" "4K_AAACCTGAGGCATGGT" "4K_AAACCTGCAAGGTTCT"
table(pbmc.combined@meta.data$orig.ident)
##
## PBMC4K PBMC8K
## 4340 8381
AddSamples
takes an existing Seurat object, and adds samples based on an additional raw.data matrix from a new dataset. This is essentially a shortcut compared to MergeSeurat
, so that you don’t need to create a Seurat object for the new data. The add.cell.id field is added to objectmeta.data$orig.ident
for the new cells.
pbmc.combined <- AddSamples(object = pbmc4k, new.data = pbmc8k.data, add.cell.id = "8K")
tail(pbmc.combined@cell.names)
## [1] "8K_TTTGTCAGTTACCGAT" "8K_TTTGTCATCATGTCCC" "8K_TTTGTCATCCGATATG"
## [4] "8K_TTTGTCATCGTCTGAA" "8K_TTTGTCATCTCGAGTA" "8K_TTTGTCATCTGCTTGC"
table(pbmc.combined@meta.data$orig.ident)
##
## PBMC4K 8K
## 4340 8381