title: SingleR注释免疫细胞亚群 tags: [] id: '1554' categories:
library(celldex)
ref_HPCD <- HumanPrimaryCellAtlasData()
ref_BFD <- BlueprintEncodeData()
ref_MRD <- MouseRNAseqData()
ref_IGD <- ImmGenData()
ref_DICED <- DatabaseImmuneCellExpressionData()
ref_NHD <- NovershternHematopoieticData()
ref_MID <- MonacoImmuneData()
save(list = c('ref_HPCD', 'ref_BFD', 'ref_MRD', 'ref_IGD', 'ref_DICED', 'ref_NHD', 'ref_MID'), file = '~/upload/zl_liu/celldexData/celldex.rdata')
加载参考数据集
library(celldex)
load(file = '~/upload/zl_liu/celldexData/celldex.rdata')
读入待注释对象
library(SingleR)
library(Seurat)
sce <- readRDS('Myeloid.rds')
sce@meta.data <- readRDS('myeloid_metadata.rds')
DimPlot(sce, reduction = 'umap', label = T, repel = T)
进行分群
require(dplyr)
f_FindNeighbors_integrated_s <- function(scRNA){
DefaultAssay(scRNA) <- 'integrated'
scRNA <- ScaleData(scRNA)
scRNA <- RunPCA(scRNA)
scRNA <- RunUMAP(scRNA, dims = 1:30)
}
f_FindNeighbors_integrated <- function(scRNA, resolution = 0.5, reduction='pca'){
scRNA <- scRNA %>% FindNeighbors(reduction = reduction) %>% FindClusters(resolution = resolution)
scRNA[[paste0('h_resolution_', resolution)]] <- Idents(scRNA)
scRNA
}
sce <- f_FindNeighbors_integrated_s(sce)
sce <- f_FindNeighbors_integrated(sce, 1.5)
DimPlot(sce, reduction = 'umap', label = T, repel = T)
进行预测
sce_for_SingleR <- GetAssayData(sce, slot="data")
clusters <- sce[['h_resolution_1.5']][[1]]
pred_MID <- SingleR(test = sce_for_SingleR, ref = ref_MID, labels = ref_MID$label.main,
method = "cluster", clusters = clusters,
assay.type.test = "logcounts", assay.type.ref = "logcounts")
pred_NHD <- SingleR(test = sce_for_SingleR, ref = ref_NHD, labels = ref_NHD$label.main,
method = "cluster", clusters = clusters,
assay.type.test = "logcounts", assay.type.ref = "logcounts")
cellType=data.frame(ClusterID=levels(sce@meta.data$seurat_clusters),
pred_MID=pred_MID$labels,
pred_NHD=pred_NHD$labels )
head(cellType)
sce@meta.data$pred_MID <- cellType[match(clusters,cellType$ClusterID), 'pred_MID']
sce@meta.data$pred_NHD <- cellType[match(clusters,cellType$ClusterID), 'pred_NHD']
肉眼观察
DimPlot(sce, reduction = 'umap', group.by = 'pred_MID', label = T, repel = T)
DimPlot(sce, reduction = 'umap', group.by = 'pred_NHD', label = T, repel = T)
DimPlot(sce, reduction = 'umap', group.by = 'majority_voting', label = T, repel = T)
DimPlot(sce, reduction = 'umap', group.by = 'immune_annotion', label = T, repel = T)
plotScoreHeatmap(pred_MID, show.labels = T, show.pruned = T, show_colnames = T)
plotDeltaDistribution(pred_MID)