clusterprofiler:gson格式初探.md 2.3 KB


title: clusterProfiler:gson格式初探 tags: [] id: '2126' categories:

  • - 通路富集 comments: false date: 2022-07-21 06:43:59 ---

更新包

保存gson到本地

  • library(clusterProfiler)
  • kk <- gson_KEGG('hsa')
  • gson::write.gson(kk, file = './KEGG.hsa.gson')

使用本地gson进行KEGG分析

  • library(clusterProfiler)
  • kk <- gson::read.gson('KEGG.hsa.gson')
  • rres <- readRDS('deg.rds')
  • rres <- rres[order(rres$log2FoldChange),]

    require(org.Hs.eg.db)
    f_id2name_kk <- function(lc_cgene, keytype="SYMBOL", columns="ENTREZID"){
    res=AnnotationDbi::select(org.Hs.eg.db::org.Hs.eg.db,keys=lc_cgene,columns=columns, keytype=keytype)
    res <- subset(res, !is.na(ENTREZID))
    res$ENTREZID
    }
    require(tidyverse)
    require(enrichplot)
    require(DOSE)
    f_kegg_p <- function(keggr2, n = 15){
    keggr <- subset(keggr2@result, p.adjust < 0.05)
    keggr[['-log(Padj)']] <- -log10(keggr[['p.adjust']])
    keggr[['geneRatio']] <- parse_ratio(keggr[['GeneRatio']])
    keggr$Description <- factor(keggr$Description, 
                                       levels=keggr[order(keggr$geneRatio),]$Description)
    ggplot(head(keggr,n),aes(x=geneRatio,y=Description))+
        geom_point(aes(color=`-log(Padj)`,
                 size=`Count`))+
        theme_bw()+
        scale_color_gradient(low="blue1",high="brown1")+
        labs(y=NULL) + 
        theme(axis.text.x=element_text(angle=90,hjust = 1,vjust=0.5, size = 12),
             axis.text.y=element_text(size = 15))
    }
    f_title <- function(gp,title){
    gp + labs(title = title) + theme(plot.title = element_text(hjust = 0.5))
    }
    kegg.d <- enrichKEGG(gene = f_id2name_kk(subset(rres, log2FoldChange < -0.1 & padj < 0.05)$symbol),
      organism = kk,
      universe = f_id2name_kk(rres$symbol),
      pAdjustMethod = "fdr",
      qvalueCutoff =0.05)
    f_kegg_p(kegg.d, n =15) %>% f_title("kegg.d")