【单细胞】合并多个seurat数据对象
在实际中,经常存在多个样本一起联合分析的情况:
比如我们既可以按照样本来源显示聚类,也可以按照类型来显示聚类结果。
所以,我们测试利用seurat如何进行多个样本的合并分析。
下载官网的2组测试数据。
pbmc4k:
https://support.10xgenomics.com/single-cell-gene-expression/datasets/2.1.0/pbmc4k
pbmc8k:
https://support.10xgenomics.com/single-cell-gene-expression/datasets/2.1.0/pbmc8k
====创建seurat对象===
library(Seurat)
pbmc4k.data <- Read10X(data.dir = "pbmc4k/filtered_gene_bc_matrices/GRCh38/")
pbmc4k <- CreateSeuratObject(counts = pbmc4k.data, project = "PBMC4K")
pbmc4k
> pbmc4k
An object of class Seurat
33694 features across 4340 samples within 1 assay
Active assay: RNA (33694 features, 0 variable features)
pbmc8k.data <- Read10X(data.dir = "pbmc8k/filtered_gene_bc_matrices/GRCh38/")
pbmc8k <- CreateSeuratObject(counts = pbmc8k.data, project = "PBMC8K")
pbmc8k
> pbmc8k
An object of class Seurat
33694 features across 8381 samples within 1 assay
Active assay: RNA (33694 features, 0 variable features)
===合并2个seurat对象====
利用merge()合并两个对象的原始计数矩阵,并创建一个新的对象。
pbmc.combined <- merge(pbmc4k, y = pbmc8k, add.cell.ids = c("4K", "8K"), project = "PBMC12K")
pbmc.combined
> pbmc.combined
An object of class Seurat
33694 features across 12721 samples within 1 assay
Active assay: RNA (33694 features, 0 variable features)
//从中可以看出合并了2个对象的4340和8381之后,获得12721个samples的信息。
head(colnames(pbmc.combined))
table(pbmc.combined$orig.ident)
====合并2个以上的seurat对象=====
要合并两个以上的对象,只需将多个对象的矢量传递到merge的y参数中即可:我们将使用 4K 和 8K PBMC 数据集以及pbmc3k进行合并:
pbmc.big <- merge(pbmc3k, y = c(pbmc4k, pbmc8k), add.cell.ids = c("3K", "4K", "8K"), project = "PBMC15K")
pbmc.big
统计各个样品中cell的数目:
unique(sapply(X = strsplit(colnames(pbmc.big), split = "_"), FUN = "[", 1))
table(pbmc.big$orig.ident)
===合并标准化后的数据====
pbmc4k <- NormalizeData(pbmc4k) //标准化
pbmc8k <- NormalizeData(pbmc8k) //标准化
pbmc.normalized <- merge(pbmc4k, y = pbmc8k, add.cell.ids = c("4K", "8K"), project = "PBMC12K",merge.data = TRUE)
GetAssayData(pbmc.combined)[1:10, 1:15]
GetAssayData(pbmc.normalized)[1:10, 1:15]
本文使用 文章同步助手 同步