细胞类型自动化注释
# 数据来源:http://biocc.hrbmu.edu.cn/CellMarker/download.jsp
library(dplyr)
library(openxlsx)
#### 1. 加载marker数据库 ####
load("./Human_cell_markers.RData")
cellmarker.file <- "./multi/multi_total_marker_genes_tsne_20PC.txt"
sampleid <- "multi"
#读入单细胞分析中输出的cell marker 基因文件
marker.gene <- read.table(cellmarker.file,header = T,stringsAsFactors = F,sep = "\t")
marker.gene.sig <- marker.gene %>% filter(as.numeric(p_val_adj) <= 0.05)
cat("Totally marker genes:",length(unique(marker.gene.sig$gene)))
table(marker.gene.sig$cluster)
#### 2. 定位数据库中存在的基因 ####
marker.gene.sig %>% filter(gene %in% cell.markers.tb$geneSymbol) -> marker.gene.sel
marker.gene.sel$cellMarker <- apply(marker.gene.sel,1,function(x)paste(unique(cell.markers.tb[cell.markers.tb$geneSymbol == x["gene"],1]),collapse = ","))
cat("Totally find",length(unique(marker.gene.sel$gene)),"/",length(unique(marker.gene.sig$gene)),"genes in cellMarker db")
#### 3. 将marker基因与细胞类型结果写出到文件 ####
write.table(marker.gene.sel,file =paste0("./",sampleid,"/",sampleid,"_DEG_marker_cells_tsne.txt"),row.names = T,col.names = T,sep = "\t",quote = F)
#sub_analysis_scRNA
以下代码在sub_analysis_scRNA.R中
计算特定两组细胞之间的差异基因,决定要不要把两个亚群合并
# 计算特定两组细胞之间的差异基因
sub.markers <- FindMarkers(experiment.aggregate,
ident.1 = c("0","3"),
ident.2 = "1")
View(sub.markers)
修改具体类别名字
# 修改具体类别的名字(需要基于marker基因来定义)
experiment.merged <- RenameIdents(
object = experiment.aggregate,
"0" = "B cells type1",
"2" = "B cells type2",
"3" = "B cells type1"
)
pdf(paste0("./",sam.name,"/CellCluster-TSNEPlot_Rename_",max(dim.use),"PC.pdf"),width = 5,height = 4)
DimPlot(object = experiment.merged, pt.size=0.5,
reduction = "tsne",label = T) +
ggsci::scale_color_igv()
dev.off()