scRNAscRNA-seq单细胞学习

scRNA基础分析-3:鉴定细胞类型

2020-08-26  本文已影响0人  小贝学生信

scRNA基础分析-1:安装包、导入数据、过滤质控 - 简书
scRNA基础分析-2:降维与聚类 - 简书
scRNA基础分析-3:鉴定细胞类型 - 简书
scRNA基础分析-4:细胞亚类再聚类、注释 - 简书
scRNA基础分析-5:伪时间分析 - 简书
scRNA基础分析-6:富集分析 - 简书

之前已将1222个细胞分成10个cluster,这一步我们鉴定下每个cluster为什么类型细胞。

library(Seurat)
library(tidyverse)
library(patchwork)
rm(list=ls())
scRNA <- readRDS("scRNA.rds")

法1:mark基因鉴定

wilcox(default)

diff.wilcox = FindAllMarkers(scRNA)
#大概1-2min
all.markers = diff.wilcox %>% select(gene, everything()) %>% subset(p_val<0.05)
#先把基因这一列放在第一列,然后选取p值小于0.05的行(结果行数不变,说明都挺好的)
top10 = all.markers %>% group_by(cluster) %>% top_n(n = 10, wt = avg_logFC)
#0-9共10个cluster,每个cluster选取top10高变基因
1-1

MAST

diff.mast = FindAllMarkers(scRNA, test.use = 'MAST')
# 较慢,4-5min左右
all.markers = diff.mast %>% select(gene, everything()) %>% subset(p_val<0.05)
top10 = all.markers %>% group_by(cluster) %>% top_n(n = 10, wt = avg_logFC)

DESeq2

diff.deseq2 = FindAllMarkers(scRNA, test.use = 'DESeq2', slot = 'counts')
#选用 "DESeq2",还需要将slot参数设为"counts"
# 太慢,放弃了
all.markers = diff.deseq2 %>% select(gene, everything()) %>% subset(p_val<0.05)
top10 = all.markers %>% group_by(cluster) %>% top_n(n = 10, wt = avg_logFC)

top10基因热图可视化

top10 = CaseMatch(search = as.vector(top10$gene), match = rownames(scRNA)) 
#这里选取的是wilcox方法挑选的差异基因
plot1 = DoHeatmap(scRNA, features = top10, group.by = "seurat_clusters", group.bar = T, size = 4)
#结果可以看出cluster间差异还是挺明显的
1-2

挑选部分感兴趣基因可视化

select_genes <- c('LYZ','CD79A','CD8A','CD8B','GZMB','FCGR3A')  
#t挑选基因,最好分布在几个cluster里
 VlnPlot(scRNA, features = select_genes, pt.size=0, ncol=2)
# 图1-3
FeaturePlot(scRNA, features = select_genes, reduction = "tsne", label=T, ncol=2)
# 图1-4
1-3
1-4

人工注释

在上述工作的基础上,就可以进行人工注释cluster细胞类型了。

法2:SingleR包注释

library(SingleR)
refdata <- HumanPrimaryCellAtlasData()
#参考数据库,等待时间较长。建议下载成功后,储存为Rdata,以后方便使用。
testdata <- GetAssayData(scRNA, slot="data")
clusters <- scRNA@meta.data$seurat_clusters
cellpred <- SingleR(test = testdata, ref = refdata, labels = refdata$label.main, 
                    # 注意此时labels参数为 refdata$label.main,与下一节亚类再注释时的设置不同
                    method = "cluster", clusters = clusters, 
                    assay.type.test = "logcounts", assay.type.ref = "logcounts")
celltype = data.frame(ClusterID=rownames(cellpred), celltype=cellpred$labels, stringsAsFactors = F)
#如下为singleR的细胞cluster鉴定结果。
2-1
#结合上述结果,给scRNA增添celltype注释信息
scRNA@meta.data$celltype = "NA"
#先新增列celltype,值均为NA,然后利用下一行代码循环填充
for(i in 1:nrow(celltype)){
  scRNA@meta.data[which(scRNA@meta.data$seurat_clusters == celltype$ClusterID[i]),'celltype'] <- celltype$celltype[i]}

可视化1

p1 = DimPlot(scRNA, group.by="celltype", label=T, label.size=5, reduction='tsne')
p2 = DimPlot(scRNA, group.by="celltype", label=T, label.size=5, reduction='umap')
p3 = plotc <- p1+p2+ plot_layout(guides = 'collect')
2-2

可视化2

select_genes <- c('LYZ','CD79A','GZMB','FCGR3A')
#vlnplot展示
p1 <- VlnPlot(scRNA, features = select_genes, pt.size=0, group.by="celltype", ncol=2)
#featureplot展示
p2 <- FeaturePlot(scRNA, features = select_genes, reduction = "tsne", label=T, ncol=2)
p3=p1|p2
2-3
#最后保存分析结果,以供后续的分析
saveRDS(scRNA, file="scRNA.rds")
上一篇下一篇

猜你喜欢

热点阅读