setwd("C:/Users/86156/Desktop/gogogogo/fun/pro")
#先看一下例子
go <- fread("pancre.t.n.go.result (1).csv",data.table = F)#go的富集结果

go <- go[,c(3,9)]
item<-c("response to oxidative stress",
"fatty acid metabolic process",
)
go <- go[go$Description %in% item,]
for(i in go$Description){
# i<-"fatty acid metabolic process"
data<-go[go$Description %in% i,]$geneID
#按/分割
a <- strsplit(data,split = "/") %>% as.data.frame()
gset <- c(i,"NA",a[,1])
gset <- gset%>%
as.data.frame() %>%
t()
#将i中" "替换为"."
i<-gsub(" ",".",i,fixed = T)
#输出文件名
outFile=paste0(i, ".gmt")
#输出
write.table(gset,file = outFile,sep = "\t",row.names = F,col.names = F,quote = F)
}

##########################################循环体应用算GSVA----
name<-c(
"/data/ff/ref/list/Lipid and atherosclerosis.gmt",
"/data/ff/ref/list/fatty acid metabolic process.gmt")
gsva.exp=data.frame()
library(GSEABase)
for(i in name){
#i="/data/ff/ref/list/Cuproptosis.gmt"
geneset <- GSEABase::getGmt(i)
data <- gsva(pro, geneset)
gsva.exp=rbind(gsva.exp,data)
}
write.csv(gsva.exp,"pro.gsva.exp.csv",row.names = TRUE)
网友评论