SingleR包注释单细胞数据

SingleR包通过利用纯细胞类型的参考转录组数据集独立推断每个单细胞的起源细胞,从单细胞RNA测序数据执行无偏细胞类型识别。

1. 载入单细胞数据

# if (!requireNamespace("BiocManager", quietly = TRUE))
#   install.packages("BiocManager")
# 
# BiocManager::install("scRNAseq")

library(scRNAseq) # Collection of Public Single-Cell RNA-Seq Datasets
ls("package:scRNAseq")
hESCs <- LaMannoBrainData('human-es')
# 取前100个单细胞的表达谱做演示
hESCs <- hESCs[,1:100]
assays(hESCs)
assay(hESCs)[1:4,1:4]

#assay(x, i) 
#is simply a convenience function which is equivalent to 
#assays(x)[[i]]
#assays(se)[[1]][1:5, 1:5] 
#assay(se)[1:5, 1:5]

2. 载入细胞类型注释数据集

celldex包提供一组参考表达数据集,这些数据集带有精确的细胞类型标签,用于单细胞数据的自动注释或批量RNA序列的反卷积等过程。

library(celldex)

hpca.se <- HumanPrimaryCellAtlasData()
hpca.se

3. 注释细胞类型

library(SingleR)
ls("package:SingleR")

# library(BiocStyle)
# browseVignettes("BiocStyle")

# SingleR Returns the best annotation for each cell in a test dataset, 
# given a labelled reference dataset in the same feature space.
# • scores, a numeric matrix of correlations at the specified quantile for each label (column) in
# each cell (row). This will contain NAs if multiple references were supplied to trainSingleR
# with recompute=TRUE. 
# • first.labels, a character vector containing the predicted label before fine-tuning. Only
# added if fine.tune=TRUE. 
# • tuned.scores, a DataFrame containing first and second. 
# These are numeric vectors containing the best and next-best scores 
# at the final round of fine-tuning for each cell. Only added if fine.tune=TRUE. 
# • labels, a character vector containing the predicted label based on the maximum entry in
# scores. 
# • pruned.labels, a character vector containing the pruned labels where “low-quality”. els are
# replaced with NAs. Only added if prune=TRUE.

## SingleR() expects reference datasets to be normalized and log-transformed.
library(scuttle)
hESCs <- logNormCounts(hESCs)
hpca.se <- logNormCounts(hpca.se)

pred.hesc <- SingleR(test = hESCs, ref = hpca.se, assay.type.test="logcounts",
                     labels = hpca.se$label.main)
class(pred.hesc) # "DFrame" 
dim(pred.hesc) # 行为单细胞名,列为特征,其中label是细胞类型
colnames(pred.hesc)
head(pred.hesc)
table(pred.hesc$labels)
#Create a heatmap of the SingleR assignment scores across all cell-label combinations.
plotScoreHeatmap(pred.hesc)
#Plot the distribution of deltas (i.e., the gap between the assignment score 
#for the assigned label and those of the remaining labels) across cells assigned to each reference label.
plotDeltaDistribution(pred.hesc, ncol = 3)

summary(is.na(pred.hesc$pruned.labels))

4. 用一个SingleCellExperiment对象的细胞类型label去注释另一个SingleCellExperiment

library(scRNAseq)
sceM <- MuraroPancreasData()

# One should normally do cell-based quality control at this point, but for
# brevity's sake, we will just remove the unlabelled libraries here.
sceM <- sceM[,!is.na(sceM$label)]

# SingleR() expects reference datasets to be normalized and log-transformed.
# scuttle包:Provides basic utility functions for performing single-cell analyses, 
#focusing on simple normalization, quality control and data transformations. 
#Also provides some helper functions to assist development of other packages.

library(scuttle)
sceM <- logNormCounts(sceM)

## -----------------------------------------------------------------------------
sceG <- GrunPancreasData()
sceG <- sceG[,colSums(counts(sceG)) > 0] # Remove libraries with no counts.
sceG <- logNormCounts(sceG) 
sceG <- sceG[,1:100]

## -----------------------------------------------------------------------------
pred.grun <- SingleR(test=sceG, ref=sceM, labels=sceM$label, de.method="wilcox")
table(pred.grun$labels)

5. 可视化

## -----------------------------------------------------------------------------
plotScoreHeatmap(pred.grun)

## -----------------------------------------------------------------------------
plotDeltaDistribution(pred.grun, ncol = 3)

## -----------------------------------------------------------------------------
summary(is.na(pred.grun$pruned.labels))

## -----------------------------------------------------------------------------
## 不同细胞类型的marker基因
all.markers <- metadata(pred.grun)$de.genes
sceG$labels <- pred.grun$labels

# Beta cell-related markers
library(scater)
plotHeatmap(sceG, order_columns_by="labels",
            features=unique(unlist(all.markers$beta))) 

  • 0
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
R语言中,对单细胞数据进行注释可以使用许多不同的和方法。以下是一些常用的注释方法: 1. 使用SingleRSingleR是一个用于单细胞RNA测序数据注释的软件。它通过将单细胞数据与基准参考数据进行比较,来预测每个单细胞样本的细胞类型。你可以使用SingleR中的`SingleR`函数来进行注释。首先,你需要准备一个基准参考数据集,然后使用`SingleR`函数将单细胞数据与该参考数据集进行比较。 2. 使用scmap:scmap是另一个用于单细胞数据注释的软件。它也是通过将单细胞数据与参考数据进行比较来预测每个单细胞样本的细胞类型。你可以使用scmap中的`scmapCluster`函数来进行注释。首先,你需要准备一个参考数据集,然后使用`scmapCluster`函数将单细胞数据映射到参考数据集上。 3. 使用SingleCellExperimentSingleCellExperiment是一个用于存储和分析单细胞RNA测序数据的通用框架。你可以使用该中提供的方法来进行单细胞数据注释。例如,你可以使用`reducedDims`函数对单细胞数据进行降维,然后使用`cluster`函数对降维后的数据进行聚类,最后使用`annotate`函数将聚类结果注释为细胞类型。 这些是一些常用的单细胞数据注释方法,你可以根据具体的需求选择合适的方法进行注释。当然,还有其他的和方法可供选择,具体选择哪个方法取决于你的数据和研究问题。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值