rm(list = ls())
options(stringsAsFactors = F)
#读取excel
#install.packages("readxl")
library(readxl)
mRNA = read_excel("VDR target genes.xlsx",sheet = 1)
##制作gmt文档
gset <- c("VDR_target_geneset","NA",mRNA$gene)
gset <- gset%>%
as.data.frame() %>%
t()
write.table(gset,file = "VDR_Target_geneset.gmt",sep = "\t",row.names = F,col.names = F,quote = F)
kegmt<-read.gmt("VDR_Target_geneset.gmt")
##制作差异表达谱genelist
library(msigdbr)
library(fgsea)
library(org.Hs.eg.db)
library(dplyr)
library(clusterProfiler)
###此处加载你的差异表达谱
## 1.按照logFC进行排序
geneList1 <- DEG$logFC
## 2.命名
names(geneList1) = DEG$Gene.Symbol
## 3.排序很重要
geneList1 = sort(geneList1, decreasing = TRUE)
head(geneList1)
##4读取gmt基因集下载于https://www.gsea-msigdb.org/gsea/downloads.jsp
#kegmt<-read.gmt("HALLMARK_WNT_BETA_CATENIN_SIGNALING.v2023.1.Hs.gmt") #读gmt文件
##GSEA
KEGG<-GSEA(geneList1,TERM2GENE = kegmt,minGSSize = 1,
maxGSSize = 500,
pvalueCutoff =1) #GSEA分析
##画图 base size是字体大小
library(enrichplot)
gseaplot2(KEGG,1,color="red", base_size = 30,pvalue_table = T)
clusterProfiler包老版本已经不能使用,会报错
a5cd8f343c585038d59f37cfe511b9e.png
80bf904d1425aeb41aedd28fdff76ca.png
此时运行以下代码进行安装,更新“clusterProfiler”,里面有很多依赖包也同时需要更新。
devtools::install_github('YuLab-SMU/clusterProfiler')