其他分享
首页 > 其他分享> > R语言-Bioconductor依赖管理&&KEGG富集分析&&通路图&&pathview报错解决

R语言-Bioconductor依赖管理&&KEGG富集分析&&通路图&&pathview报错解决

作者:互联网

win10-R语言3.6.2-Bioconductor依赖管理&&KEGG富集分析&&通路图&&pathview报错解决

一、环境准备

下载安装包(64位),(如果没有翻墙,选择国内的源进行下载)链接如下:

https://mirrors.tuna.tsinghua.edu.cn/CRAN/bin/windows/base/R-3.6.2-win.exe

其他版本可以打开https://mirrors.tuna.tsinghua.edu.cn/CRAN,再根据自己物理机的配置自行选择,如下图所示:
在这里插入图片描述

或者选择本人的百度云链接进行下载,链接如下:

链接:https://pan.baidu.com/s/1_FEnaqRfSY1HpoQW9nfWbA 
提取码:727u

安装

配置环境变量,在系统环境变量的Path中写入安装的R路径F:\R\R-3.6.2\bin
在这里插入图片描述
在这里插入图片描述
点击快捷方式即可运行程序
在这里插入图片描述

二、运行程序

代码:

#install.packages("colorspace")
#install.packages("stringi")
#options(BioC_mirror=”https://mirrors.tuna.tsinghua.edu.cn/bioc/“)
#if (!requireNamespace("BiocManager", quietly = TRUE))
#   install.packages("BiocManager")
#BiocManager::install(version = "3.10")
#BiocManager::install(c("DOSE", "clusterProfiler","pathview"))

# setwd设置工作路径,文件的读入和写出都是相对与该路径
setwd("C:\\Users\\urmsone\\Desktop\\Li")
library("clusterProfiler")
rt=read.table("id.txt",sep="\t",header=T,check.names=F)
rt=rt[is.na(rt[,"entrezID"])==F,]

geneFC=rt$logFC
gene=rt$entrezID
names(geneFC)=gene

#kegg富集分析
kk <- enrichKEGG(gene = gene, organism = "hsa", pvalueCutoff =0.05, qvalueCutoff =0.05)
write.table(kk,file="KEGG.txt",sep="\t",quote=F,row.names = F)

#柱状图
tiff(file="barplot.tiff",width = 30,height = 20,units ="cm",compression="lzw",bg="white",res=600)
barplot(kk, drop = TRUE, showCategory = 20)
dev.off()

#点图
tiff(file="dotplot.tiff",width = 30,height = 20,units ="cm",compression="lzw",bg="white",res=600)
dotplot(kk, showCategory = 20)
dev.off()

#通路图
library("pathview")
source("./pathview-u.R")
keggxls=read.table("KEGG.txt",sep="\t",header=T)
for(i in keggxls$ID){
  pv.out <- pathview(gene.data = geneFC, pathway.id = i, species = "hsa", out.suffix = "pathview")
}

PS:首次运行时才需要安装依赖
安装依赖:

# 该程序需要手动安装的依赖有colorspace,stringi,DOSE,clusterProfiler,pathview
install.packages("colorspace")
install.packages("stringi")
# 换源
options(BioC_mirror=”https://mirrors.tuna.tsinghua.edu.cn/bioc/“)
if (!requireNamespace("BiocManager", quietly = TRUE))
    install.packages("BiocManager")
BiocManager::install(version = "3.10")
BiocManager::install(c("DOSE", "clusterProfiler","pathview"))

三、运行程序

打开R客户端
在这里插入图片描述
将代码复制进去执行

setwd("C:\\Users\\urmsone\\Desktop\\Li")
library("clusterProfiler")
rt=read.table("id.txt",sep="\t",header=T,check.names=F)
rt=rt[is.na(rt[,"entrezID"])==F,]

geneFC=rt$logFC
gene=rt$entrezID
names(geneFC)=gene

#kegg富集分析
kk <- enrichKEGG(gene = gene, organism = "hsa", pvalueCutoff =0.05, qvalueCutoff =0.05)
write.table(kk,file="KEGG.txt",sep="\t",quote=F,row.names = F)

#通路图
library("pathview")
#source("./pathview-u.R")
keggxls=read.table("KEGG.txt",sep="\t",header=T)
for(i in keggxls$ID){
  pv.out <- pathview(gene.data = geneFC, pathway.id = i, species = "hsa", out.suffix = "pathview")
}

PS: 如果输出的KEGG.txt文件中含有ID为hsa04251的数据,可能会报错。报错在下节讲解如何解决

四、报错解决

报错: With R version 3.5 or greater, install Bioconductor packages using BiocManager

报错:只有负下标里才能有零

报错:Error in readPNG(paste(kegg.dir, "/", pathway.name, ".png", sep = "")) : libpng error: Read Error

五、Demo获取链接

完整Demo和使用说明请参考https://github.com/UrmsOne/KEGG-demo

Urmsone 发布了31 篇原创文章 · 获赞 16 · 访问量 2万+ 私信 关注

标签:rt,KEGG,&&,pathview,报错,install,BiocManager,gene
来源: https://blog.csdn.net/Urms_handsomeyu/article/details/103962949