#多个单细胞亚群各自标记基因联合进行GO和KEGG注释rm(list=ls())options(stringsAsFactors = F)library(Seurat)library(gplots)library(ggplot2)library(clusterProfiler)pro='all'#加载差异基因load('sce.markers.all_10_celltype.Rdata')table(sce.markers$cluster) #每个单细胞亚群都有自己的marker基因library(org.Hs.eg.db)ids=bitr(sce.markers$gene,'SYMBOL','ENTREZID','org.Hs.eg.db')sce.markers=merge(sce.markers,ids,by.x='gene',by.y='SYMBOL')gcSample=split(sce.markers$ENTREZID,sce.markers$cluster)gcSample #entrez id , compareCluster
##KEGG
xx <- compareCluster(gcSample,
fun="enrichKEGG",
organism="hsa",
pvalueCutoff=0.05)
dotplot(xx)
ggsave(paste0(pro,'_kegg.pdf'))

图 KEGG
##BP
formula_res <- compareCluster(
gcSample,
fun="enrichGO",
OrgDb="org.Hs.eg.db",
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.01,
qvalueCutoff = 0.05)
#Run GO enrichment test and merge terms
# that are close to each other to remove result redundancy
lineage1_ego <- simplify(
formula_res,
cutoff=0.5,
by="p.adjust",
select_fun=min)
pdf(paste0(pro,'_GO_BP_cluster_simplified.pdf'),
width = 15,
height = 6)
print(dotplot(lineage1_ego,
showCategory=5))
dev.off()
write.csv(lineage1_ego@compareClusterResult,
file=paste0(pro,'_GO_BP_cluster_simplified.csv'))

图 BP
##CC
formula_res <- compareCluster(
gcSample,
fun="enrichGO",
OrgDb="org.Hs.eg.db",
ont = "CC",
pAdjustMethod = "BH",
pvalueCutoff = 0.01,
qvalueCutoff = 0.05)
# Run GO enrichment test and merge terms
# that are close to each other to remove result redundancy
lineage1_ego <- simplify(
formula_res,
cutoff=0.5,
by="p.adjust",
select_fun=min)
pdf(paste0(pro,'_GO_CC_cluster_simplified.pdf'),
width = 15,
height = 6)
print(dotplot(lineage1_ego,
showCategory=5))
dev.off()
write.csv(lineage1_ego@compareClusterResult,
file=paste0(pro,'_GO_CC_cluster_simplified.csv'))

图 CC
##MF
formula_res <- compareCluster(
gcSample,
fun="enrichGO",
OrgDb="org.Hs.eg.db",
ont = "MF",
pAdjustMethod = "BH",
pvalueCutoff = 0.01,
qvalueCutoff = 0.05)
# Run GO enrichment test and merge terms
# that are close to each other to remove result redundancy
lineage1_ego <- simplify(
formula_res,
cutoff=0.5,
by="p.adjust",
select_fun=min
)
pdf(paste0(pro,'_GO_MF_cluster_simplified.pdf'),
width = 15,
height = 6)
print(dotplot(lineage1_ego,
showCategory=5))
dev.off()
write.csv(lineage1_ego@compareClusterResult,
file=paste0(pro,'_GO_MF_cluster_simplified.csv'))

图 MF
