一般富集分析都是單個(gè)組基因集,但是當(dāng)有多個(gè)數(shù)據(jù)集的時(shí)候,一個(gè)一個(gè)分析比較麻煩,clusterprofile包可以實(shí)現(xiàn)多組分析,這里演示一下。我們使用單細(xì)胞數(shù)據(jù)構(gòu)建一個(gè)例子。
setwd("D:/KS項(xiàng)目/公眾號(hào)文章/多組富集分析")
library(Seurat)
library(SeuratData)
#找一個(gè)單細(xì)胞數(shù)據(jù)集
# data("pbmc3k")
# PBMC <- pbmc3k.final
# PBMC = UpdateSeuratObject(object = PBMC)
#找一下各組的差異基因,構(gòu)建一下數(shù)據(jù)
# DefaultAssay(PBMC) <- "RNA"
# df <- FindAllMarkers(PBMC, only.pos = TRUE,
# min.pct = 0.25,
# logfc.threshold = 0.75)
# df_sig <- df[df$p_val_adj < 0.05, ]
# write.csv(df_sig, file = "df_sig.csv")
這里利用單細(xì)胞構(gòu)建了一個(gè)數(shù)據(jù),其他數(shù)據(jù)構(gòu)建成如此即可!
library(clusterProfiler)
library(ggplot2)
df_sig <- read.csv("df.csv", header = T)
構(gòu)建分組,轉(zhuǎn)化genesymbol-gene ID。
group <- data.frame(gene=df_sig$gene,
group=df_sig$cluster)
Gene_ID <- bitr(df_sig$gene, fromType="SYMBOL",
toType="ENTREZID",
OrgDb="org.Hs.eg.db")
#構(gòu)建文件并分析
data <- merge(Gene_ID,group,by.x='SYMBOL',by.y='gene')
富集分析,去除冗雜terms!
data_GO <- compareCluster(
ENTREZID~group,
data=data,
fun="enrichGO",
OrgDb="org.Hs.eg.db",
ont = "BP",
pAdjustMethod = "BH",
pvalueCutoff = 0.05,
qvalueCutoff = 0.05
)
data_GO_sim <- simplify(data_GO,
cutoff=0.7,
by="p.adjust",
select_fun=min)
dotplot(data_GO_sim, showCategory=5,font.size = 8)
data_GO_sim_fil <- data_GO_sim@compareClusterResult
clusterprofile中自帶可視化函數(shù)---dotplot,這里我們選擇可視化5個(gè)term,當(dāng)然了,默認(rèn)的圖可能不太好修改,我們可以導(dǎo)出數(shù)據(jù),在ggplot2中可視化!

image.png
每組中挑選需要可視化的terms進(jìn)行可視化;
df_GO <- read.csv("df_GO.csv", header = T)
library(forcats)
df_GO$Description <- as.factor(df_GO$Description)
df_GO$Description <- fct_inorder(df_GO$Description)
ggplot(df_GO, aes(Cluster, Description)) +
geom_point(aes(fill=p.adjust, size=Count), shape=21)+
theme_bw()+
theme(axis.text.x=element_text(angle=90,hjust = 1,vjust=0.5),
axis.text = element_text(color = 'black', size = 10))+
scale_fill_gradient(low="purple",high="yellow")+
labs(x=NULL,y=NULL)+
coord_flip()

image.png
所有數(shù)據(jù)及代碼已上傳QQ群,如果有幫助幫忙點(diǎn)贊分享一下!更多精彩內(nèi)容請(qǐng)至我的公眾號(hào)---KS科研分享與服務(wù)