以前跑过很多次的单细胞整合分析,很多时候都因为没有很好的总结就得重新写浪费时间
现如今整理了一个到手就能直接用的脚本,根据Seurat官方最新流程总结
- 可直接调用的代码,需要修改的参数已标记,详解在后面
两个单细胞样本的整合举例
library(Seurat)
library(sctransform)
library(glmGamPoi)
mat1 <- Read10X(dir1)#任意一个seurat识别的矩阵数据框
data1 <- CreateSeuratObject(counts = mat1, project = 'sample1')
mat2 <- read.table(dir2)#同理任意一个
data2 <- CreateSeuratObject(counts = mat2, project = 'sample2')
dataset_list <- list(data1,data2)
dataset_list <- lapply(dataset_list,function(object) {
object <- PercentageFeatureSet(object, pattern = "^MT-", col.name = "percent.mt")
object <- subset(object,subset = nCount_RNA >* &nCount_RNA <* & percent.mt < *)#参数过滤细胞
object <- SCTransform(object,verbose = FALSE,vst.flavor="v2",method = "glmGamPoi",vars.to.regress = "percent.mt")
})
integration_features <- SelectIntegrationFeatures(object.list = dataset_list,nfeatures = 3000)
dataset_list <- PrepSCTIntegration(object.list = dataset_list, anchor.features = integration_features)
integration_anchors <- FindIntegrationAnchors(object.list = dataset_list, normalization.method = "SCT", anchor.features = integration_features)
integrated <- IntegrateData(anchorset = integration_anchors,normalization.method = "SCT")
integrated <- RunPCA(object = integrated, npcs = 30, verbose = FALSE)
integrated <- RunUMAP(object = integrated, reduction = "pca", dims = 1:30)
integrated <- FindNeighbors(object = integrated, reduction = "pca", dims = 1:30)
#DefaultAssay(integrated) <- "integrated"
integrated <- FindClusters(integrated,resolution = 1)#调分辨率
有两个包建议先安装了,这是seurat在SCTransform中附加的插件,能更快的处理数据
if (!requireNamespace("BiocManager", quietly = TRUE)) install.packages("BiocManager")
BiocManager::install("glmGamPoi")
install.packages("sctransform")