美文网首页
学习SingleR(1):先把官网的代码干一遍!!!

学习SingleR(1):先把官网的代码干一遍!!!

作者: MYS_bio_man | 来源:发表于2023-01-03 16:38 被阅读0次

part1: Using built-in references

1.最简单就是用内建(收集)的参考信息来注释
2.Human Primary Cell Atlas (Mabbott et al. 2013),这是举例用到的内建参考
3.注意边跑边debug,了解过程中依赖的包关系

# https://www.bioconductor.org/packages/release/bioc/vignettes/SingleR/inst/doc/SingleR.html
################################################################################
# Using built-in references
library(celldex)
hpca.se <- HumanPrimaryCellAtlasData() # celldex内建注释信息
hpca.se
## class: SummarizedExperiment 
## dim: 19363 713 
## metadata(0):
## assays(1): logcounts
## rownames(19363): A1BG A1BG-AS1 ... ZZEF1 ZZZ3
## rowData names(0):
## colnames(713): GSM112490 GSM112491 ... GSM92233 GSM92234
## colData names(3): label.main label.fine label.ont
library(scRNAseq)
hESCs <- LaMannoBrainData('human-es') # 测试数据集human embryonic stem cells (La Manno et al. 2016)
hESCs <- hESCs[,1:100]

library(SingleR)
pred.hesc <- SingleR(test = hESCs, ref = hpca.se, assay.type.test=1,
                     labels = hpca.se$label.main)
pred.hesc
## DataFrame with 100 rows and 4 columns
##                                          scores               labels delta.next
##                                        <matrix>          <character>  <numeric>
## 1772122_301_C02  0.347652:0.109547:0.123901:... Neuroepithelial_cell 0.08332864
## 1772122_180_E05  0.361187:0.134934:0.148672:...              Neurons 0.07283500
## 1772122_300_H02  0.446411:0.190084:0.222594:... Neuroepithelial_cell 0.13882912
## 1772122_180_B09  0.373512:0.143537:0.164743:... Neuroepithelial_cell 0.00317443
## 1772122_180_G04  0.357341:0.126511:0.141987:... Neuroepithelial_cell 0.09717938
## ...                                         ...                  ...        ...
## 1772122_299_E07 0.371989:0.169379:0.1986877:... Neuroepithelial_cell  0.0837521
## 1772122_180_D02 0.353314:0.115864:0.1374981:... Neuroepithelial_cell  0.0842804
## 1772122_300_D09 0.348789:0.136732:0.1303042:... Neuroepithelial_cell  0.0595056
## 1772122_298_F09 0.332361:0.141439:0.1437860:... Neuroepithelial_cell  0.1200606
## 1772122_302_A11 0.324928:0.101609:0.0949826:...            Astrocyte  0.0509478
##                        pruned.labels
##                          <character>
## 1772122_301_C02 Neuroepithelial_cell
## 1772122_180_E05              Neurons
## 1772122_300_H02 Neuroepithelial_cell
## 1772122_180_B09 Neuroepithelial_cell
## 1772122_180_G04 Neuroepithelial_cell
## ...                              ...
## 1772122_299_E07 Neuroepithelial_cell
## 1772122_180_D02 Neuroepithelial_cell
## 1772122_300_D09 Neuroepithelial_cell
## 1772122_298_F09 Neuroepithelial_cell
## 1772122_302_A11            Astrocyte
table(pred.hesc$labels)
## 
##            Astrocyte Neuroepithelial_cell              Neurons 
##                   14                   81                    5

part2:Using single-cell references

1.用已经注释的单细胞数据作为参考注释新(或其他)数据
2.参考集合可自由定义,灵活性大,有经验可操

################################################################################
# Using single-cell references
library(scRNAseq)
c <- MuraroPancreasData() # 已经注释,作为参考:Muraro et al. (2016) dataset to be our reference

# 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.
library(scuttle)
sceM <- logNormCounts(sceM)

sceG <- GrunPancreasData() # 被注释数据
sceG <- sceG[,colSums(counts(sceG)) > 0] # Remove libraries with no counts.
sceG <- logNormCounts(sceG)

pred.grun <- SingleR(test=sceG, ref=sceM, labels=sceM$label, de.method="wilcox")
table(pred.grun$labels)
## 
##      acinar       alpha        beta       delta        duct endothelial 
##         657         245         276          57         367          34 
##     epsilon mesenchymal          pp     unclear 
##           1          41          35           5
pdf("test_plotScoreHeatmap.pdf",height = 7,width = 7) # 官网没有保存图片的代码,这里补上
plotScoreHeatmap(pred.grun) 
dev.off()

pdf("test_plotDeltaDistribution.pdf",height = 7,width = 7)
plotDeltaDistribution(pred.grun, ncol = 3)
dev.off()

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


all.markers <- metadata(pred.grun)$de.genes
sceG$labels <- pred.grun$labels

# Beta cell-related markers
library(scater)
pdf("test_plotHeatmap-all.markers.pdf",height = 7,width = 7)
plotHeatmap(sceG, order_columns_by="labels",
            features=unique(unlist(all.markers$beta)))
dev.off()

最后生成的图就不放了,与官网一致,这里首先是了解它,知道它的原理以及结果情况。后续再深入学习!!!

相关文章

网友评论

      本文标题:学习SingleR(1):先把官网的代码干一遍!!!

      本文链接:https://www.haomeiwen.com/subject/meelcdtx.html