单细胞分析R生信相关单细胞测序

SingleR单细胞类型自动注释与celldex参考数据包

2021-08-27  本文已影响0人  小贝学生信

SingleR包可基于参考数据集,实现对单细胞数据细胞类型的自动注释。celldex包提供若干常用的人/老鼠的注释细胞类型的Bulk RNA-seq/microarray参考数据。

一、SingleR自动注释流程

1、准备输入数据

#例如从 Seurat对象中提取
library(scRNAseq)
hESCs <- LaMannoBrainData('human-es') #SingleCellExperiment对象
assays(hESCs) #only counts
hESCs <- scuttle::logNormCounts(hESCs) 
# add logcounts slot
hESCs
library(Seurat)
scRNA = as.Seurat(hESCs)
scRNA
head(scRNA@meta.data)
scRNA <- NormalizeData(scRNA, normalization.method = "LogNormalize", scale.factor = 10000)
scRNA <- FindVariableFeatures(scRNA, selection.method = "vst", nfeatures = 2000) 
scRNA <- ScaleData(scRNA, features = VariableFeatures(scRNA))
scRNA <- RunPCA(scRNA, features = VariableFeatures(scRNA)) 
pc.num=1:20
scRNA <- FindNeighbors(scRNA, dims = pc.num) 
scRNA <- FindClusters(scRNA, resolution = c(0.01,0.05,0.1,0.2,0.5,0.7,0.9),
                      verbose = F)
table(scRNA$originalexp_snn_res.0.2)

norm_count = GetAssayData(scRNA, slot="data") #稀疏矩阵
dim(norm_count)
#[1] 18538  1715
norm_count[1:4,1:4]
# 4 x 4 sparse Matrix of class "dgCMatrix"
# 1772122_301_C02 1772122_180_E05 1772122_300_H02 1772122_180_B09
# WASH7P-p1               1.1275620       .                0.485604               .
# LINC01002-loc4          .               .                .                      .
# LOC100133331-loc1       0.7149377       0.5823631        .                      .
# LOC100132287-loc2       .               .                .                      .
library(celldex)
ref = HumanPrimaryCellAtlasData()
#ref = readRDS("C:/Users/xiaoxin/Desktop/生信数据/celldex/HumanPrimaryCellAtlasDatar.rds")

2、SingleR注释

根据注释方法以及参考数据集可分为如下几种情况

pred<- SingleR(test = norm_count, 
               ref = ref, 
               labels = ref$label.main)
head(pred)
table(pred$labels)
# Astrocyte         Chondrocytes Embryonic_stem_cells            iPS_cells 
# 32                    1                  127                  195 
# Neuroepithelial_cell              Neurons  Smooth_muscle_cells 
# 1030                  325                    5 


#identical(rownames(pred),colnames(norm_count))
#TRUE

#将注释结果添加到seurat对象里
scRNA$singleR_cell = pred$labels
table(scRNA$singleR_cell)
pred<- SingleR(test = norm_count, 
               ref = ref, 
               clusters = scRNA$originalexp_snn_res.0.2,
               labels = ref$label.main)
head(pred)
table(pred$labels)
scRNA$singleR_cluster = pred$labels[match(scRNA$originalexp_snn_res.0.2,
                                          rownames(pred))]
table(scRNA$singleR_cluster)
# 表达矩阵: 行名为基因名,列名为细胞类型注释

# if start from "counts"
# ref <-  SummarizedExperiment(assays=list(counts=ref))
# ref <- scuttle::logNormCounts(ref) 
# ref_logcount<- assay(ref, "logcounts")

ref_logcount[1:4,1:4]
pred<- SingleR(test = norm_count, 
               ref = ref_logcount, 
               labels = colnames(ref_logcount))
head(pred)
table(pred$labels)
pred<- SingleR(test = test, 
               ref = ref, 
               labels = ref$label.main,
               de.method="wilcox")
plotScoreHeatmap(pred)
plotDeltaDistribution(pred.grun, ncol = 3)

二、celldex参考数据包

Mouse reference dataset
library(celldex)
ref = HumanPrimaryCellAtlasData()
ref = readRDS("C:/Users/xiaoxin/Desktop/生信数据/celldex/HumanPrimaryCellAtlasDatar.rds")
assay(ref, "logcounts")[1:4,1:4]
unique(ref$label.main)
unique(ref$label.fine)
unique(ref$label.ont)
上一篇 下一篇

猜你喜欢

热点阅读