这样做的原因是我的RStudio坏了,一直报库的错。就尝试了直接用r跑,发现还是很方便的。
windows上装r很简单,到官网上下载符合系统版本的r安装包就好,点击安装包按照提示步骤就可以安装好。以下代码在r软件里直接用就好,亲测好用。
代码
#GO富集分析
# 加载必要的库
library(tidyverse)
library(clusterProfiler)
go <- read.table("D:/课题/go/newgo/TG_GOterm_anno3.txt",sep="\t",quote="",header=FALSE)
gene_list <- read.table("D:/课题/go/positiveid2.txt")
go_term2gene <- data.frame(go$V2,go$V1)#go$GO:表名为go的GO列
go_term2name <- data.frame(go$V2,go$V3)
gene_list <- as.vector(gene_list$V1)
go_enrich <- enricher(gene=gene_list,pvalueCutoff = 0.01,pAdjustMethod = "BH",minGSSize= 1,maxGSSize= 500,TERM2GENE = go_term2gene,TERM2NAME = go_term2name)
write.csv(as.data.frame(go_enrich),"D:/课题/go/newgo/positiveid_go.csv",row.names = F)
# 绘制条形图
#barplot(go_enrich)
# 绘制气泡图
dotplot(go_enrich)
#KEGG
gene_list <- read.table("D:/课题/go/newgo/CHR7,7.txt")
data <- read.table("D:/课题/go/newgo/TG_KEGGpathway_anno.txt",sep="\t",quote="",header=TRUE)
gene_list <- as.vector(gene_list$V1)
kegg_term2gene <- data[, c(2, 1)]#2指KO号那一列,1指GeneID那一列
kegg_term2name <- data[, c(2, 3)]#2指KO号那一列,4指Name(description)那一列
kegg_enrich <- enricher(gene=gene_list, pvalueCutoff = 0.01,pAdjustMethod = "BH",TERM2GENE = kegg_term2gene,TERM2NAME = kegg_term2name)
write.csv(as.data.frame(kegg_enrich),"D:/课题/go/newgo/kegg/CHR7midu7_kegg.csv",row.names = F)
png("D:/课题/go/newgo/kegg/CHR7midu7_kegg_dotplot.png", width = 1000, height = 800)
dotplot(kegg_enrich, showCategory = 20)
dev.off()
画图代码
source("D:/课题/go/newgo/plot_kegg_dotplot.R")
plot_kegg_dotplot(
enrich_result = kegg_enrich,
out_file = "D:/课题/go/newgo/kegg/CHR6_7_kegg_dotplot.png",
show_num = 20,
font_size = 18
)
直接在window,r软件里面运行这些命令就可以