clusterProfiler:gson格式初探

更新包

保存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),]
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
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")

clusterProfiler:gson格式初探
https://occdn.limour.top/2126.html
Author
Limour
Posted on
July 21, 2022
Licensed under