ixxmu / mp_duty

抓取网络文章到github issues保存
https://archives.duty-machine.now.sh/
115 stars 30 forks source link

hypeR包:多种富集分析的额外选择 #5364

Closed ixxmu closed 2 months ago

ixxmu commented 2 months ago

https://mp.weixin.qq.com/s/bfDhWsACdX7RVej0OA67Xw

ixxmu commented 2 months ago

hypeR包:多种富集分析的额外选择 by 生信碱移

老铁们快点击蓝字 关注起来

生信碱移

hypeR富集工具

基因集富集是一种流行的注释高通量测序数据的方法。Anthony Federico为基因集丰富工作流程提供了一个全面的 R 包,内置结果报告并提供多种富集、可视化和共享方法。hypeR 是一个一站式解决方案,可以为广泛的受众执行基因集富集。

示例文件与代码的获取:afhype

项目地址:https://github.com/montilab/hypeR


软件包与参数设置

①引用R包(没有安装的需要安装):

#devtools::install_github("montilab/hypeR")
library(hypeR)
library(dplyr)
②设置参数
###参数设置
hyperdb_available() #参看目前内置的基因集数据集
# source gsets
#1 KEGG KEGG_v92.0.rds
#2 METABOANALYST METABOANALYST_DISEASE_CSF_v5.0.rds
#3 METABOANALYST METABOANALYST_DISEASE_FECAL_v5.0.rds
#4 METABOANALYST METABOANALYST_DISEASE_URINE_v5.0.rds
#5 METABOANALYST METABOANALYST_DRUG_v5.0.rds
#6 METABOANALYST METABOANALYST_KEGG_v5.0.rds
#7 METABOANALYST METABOANALYST_SMPDB_v5.0.rds
#8 METABOANALYST METABOANALYST_WITH_HMDB
#9 METABOANALYST METABOANALYST_WITH_HMDB
#10 METABOANALYST METABOANALYST_WITH_HMDB
#11 METABOANALYST METABOANALYST_WITH_HMDB
#12 METABOANALYST METABOANALYST_WITH_HMDB
#13 METABOANALYST METABOANALYST_WITH_HMDB
#14 METABOANALYST METABOANALYST_WITH_HMDB
#15 METABOANALYST README.md
#16 REACTOME REACTOME_v70.0.rds
#17 REFMET README.Rmd
#18 REFMET README.md
#19 REFMET RMSETS_RefMet_2022_05_11.rds
#20 SMPDB SMPDB_v2.75.rds
#选择KEGG数据集
genesets <- msigdb_gsets("Homo sapiens", "C2", "CP:KEGG")
logFCfil=1 #设置logFc过滤标准,绝对值
Pfil=0.05 #设置P值过滤标准
adjPfil=0.05 #设置矫正后的P值过滤标准

文件读入

①输入文件,"diff.txt"表头如下(分别对应有三列)

#读入差异分析结果
limma=read.table("diff.txt",sep = "\t",header = T,check.names = F)
limma=limma[,c(1,2,5,6)]
colnames(limma)=c("symbol","logFC","PValue","adj.Pval")
#添加高低表达分组分组
limma$group=ifelse(limma$logFC==0,"Stable",ifelse(limma$logFC>0,"UP","Down"))

①无权重基因的分析

(即单纯的基因列表)
signature <- limma %>% 
dplyr::filter(abs(logFC) > logFCfil & PValue<Pfil & adj.Pval < adjPfil) %>%
magrittr::use_series(symbol)
head(signature)
#开始富集,生成hyp_obj对象
hyp_obj <- hypeR(signature, genesets, test="hypergeometric", background=50000, fdr=0.01, plotting=TRUE)
#保存文件
hyp_to_excel(hyp_obj,"kegg.xls")
#查看一下显著的结果数目
length(hyp_obj$plots)

#绘制第一个具体信号的交集基因数目
hyp_obj$plots[[1]]
#展示结果表格,可以拖出保存
hyp_show(hyp_obj)

#展示点图
hyp_dots(hyp_obj)

#展示富集网络
ots)hyp_emap(hyp_obj)

#保存文件
hyp_to_excel(hyp_obj,"kegg.xls")

②有权重基因的分析

(logFC排序列表)

signature <- limma %>% 
dplyr::arrange(desc(logFC)) %>%
dplyr::select(symbol, logFC) %>%
tibble::deframe()
#开始富集
hyp_obj <- hypeR(signature, genesets, test="kstest", fdr=0.05, plotting=TRUE)
# 保存结果表格
hyp_to_excel(hyp_obj,"Weighted.xls")
#可视化第一个通路结果
hyp_obj$plots[[1]]


③有分组的富集
signature <- limma %>% 
dplyr::filter(abs(logFC) > logFCfil & PValue<Pfil & adj.Pval < adjPfil)
head(signature)
dn=signature$symbol[which(signature$group=="Down")]
up=signature$symbol[which(signature$group=="UP")]
signatures=list(Down=dn,UP=up)
mhyp <- hypeR(signatures, genesets, test="hypergeometric", background=50000)
# 保存结果表格
hyp_to_excel(mhyp,"group.xls")
#绘制点图
hyp_dots(mhyp, merge=TRUE, fdr=0.05, title="Differential gene enrichment")

END~