筛选富集分析结果 groupgo 分组富集分析

  library(ggplot2)
    
    go <- xx@compareClusterResult
    head(go)
    go$term <- paste(go$ID, go$Description, sep = ': ')
    
  #  go <- go[order(go$ONTOLOGY, go$p.adjust, decreasing = c(TRUE, TRUE)), ]
    go <- go[order( go$p.adjust, decreasing = c( FALSE)  ), ]
    head(go)
    go$term <- factor(go$term, levels = unique(go$term))
    print(dim(go))
    
    #library(tidyr)
   # install.packages("BiocManager")
  #  library(BiocManager)
   # BiocManager::install("dplyr")
    head(go)
    go <-go %>%
      group_by(ONTOLOGY) %>%
      mutate(group_size = n()) %>%
      filter(row_number() <= ifelse(group_size > 10, 10, group_size)) %>%
      ungroup() %>%
      select(-group_size)   
  go
    
  p3=ggplot(go, aes(term, -log10(p.adjust))) +
      geom_col(aes(fill = ONTOLOGY), width = 0.5, show.legend = FALSE) +
      scale_fill_manual(values = c('#D06660', '#5AAD36', '#6C85F5')) +
      facet_grid(ONTOLOGY~., scale = 'free_y', space = 'free_y') +
      theme(panel.grid = element_blank(), panel.background = element_rect(color = 'black', fill = 'transparent')) +
      scale_y_continuous(expand = expansion(mult = c(0, 0.1))) + 
      coord_flip() +
      labs(x = '', y = '-Log10 P-Value\n')

 

 

 
  #https://mp.weixin.qq.com/s/WyT-7yKB9YKkZjjyraZdPg
  {
    library(clusterProfiler)
   # library(org.Hs.eg.db)
  # BiocManager::install("org.Rn.eg.db")
 #  install.packages("org.Rn.eg.db")
    library(org.Rn.eg.db)
    library(ggplot2)
    # degs_for_nlung_vs_tlung$gene=rownames(degs_for_nlung_vs_tlung)
    sce.markers=df
    head(sce.markers)
    ids=bitr(sce.markers$gene,'SYMBOL','ENTREZID','org.Rn.eg.db')
    head(ids)
    sce.markers=merge(sce.markers,ids,by.x='gene',by.y='SYMBOL')
    head(sce.markers)
    sce.markers=sce.markers[sce.markers$change!="NOT",]
    dim(sce.markers)
    head(sce.markers)
    sce.markers$cluster=sce.markers$mygroup
    
    gcSample=split(sce.markers$ENTREZID, sce.markers$cluster)
    gcSample # entrez id , compareCluster 
    #https://zhuanlan.zhihu.com/p/561522453
    xx <- compareCluster(gcSample, fun="enrichGO",OrgDb="org.Rn.eg.db",
                         readable=TRUE,
                         ont = 'ALL',  #GO Ontology,可选 BP、MF、CC,也可以指定 ALL 同时计算 3 者
                         pvalueCutoff=0.05) #organism="hsa", #'org.Hs.eg.db',
    p=dotplot(xx) 
    p2=p+ theme(axis.text.x = element_text(angle = 90, 
                                        vjust = 0.5, hjust=0.5))
    p2
    ggsave('degs_compareCluster-GO_enrichment-2.pdf',plot = p2,width = 6,height = 12,limitsize = F)
    xx
   openxlsx::write.xlsx(xx,file = "compareCluster-GO_enrichment.xlsx")
    
  }
  
  getwd()
  setwd("/home/data/t040413/wpx/wpx_transcriptomics_proteinomics_Metabolomics/transcriptomics/4_d28_vs_d14_treatment_effective/")
  

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

生信小博士

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值