Clusterprofiler多分組富集分析及可視化

一般富集分析都是單個(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ù)

?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請(qǐng)聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時(shí)請(qǐng)結(jié)合常識(shí)與多方信息審慎甄別。
平臺(tái)聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡(jiǎn)書系信息發(fā)布平臺(tái),僅提供信息存儲(chǔ)服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容