【单细胞】合并多个seurat数据对象

藏宝库编辑 2024-10-11 14:35:22 3772 0 来自 中国
在实际中,经常存在多个样本一起团结分析的环境:
1.png
比如我们既可以按照样本泉源表现聚类,也可以按照范例来表现聚类效果。
以是,我们测试利用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 = "BMC4K")
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 = "BMC8K")
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 = "BMC12K")
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 = "BMC15K")
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 = "BMC12K",merge.data = TRUE)
GetAssayData(pbmc.combined)[1:10, 1:15]
GetAssayData(pbmc.normalized)[1:10, 1:15]

本文利用  同步
您需要登录后才可以回帖 登录 | 立即注册

Powered by CangBaoKu v1.0 小黑屋藏宝库It社区( 冀ICP备14008649号 )

GMT+8, 2024-12-4 01:46, Processed in 0.166817 second(s), 36 queries.© 2003-2025 cbk Team.

快速回复 返回顶部 返回列表