R语言:KEGG基因富集分析,一直报错。
1、报错如下:
“ cannot open the connection to 'https://rest.kegg.jp/link/hsa/pathway'”,但是浏览器可以打开这个网址。
2、尝试了网络各种方法:
①升级R、升级clusterProfiler包;
②设置了“R.utils::setOption("clusterProfiler.download.method","auto")”;
③按网络教程,尝试将KEGG数据库下载至本地再分析。
都没有解决,仍然报上面的错误。
甚至尝试将KEGG数据库下载至本地那条代码,也提示“ cannot open the connection to 'https://rest.kegg.jp/link/hsa/pathway'%E2%80%9D%E3%80%82
3、报错图片:

4、代码:
```r
> setwd("D:/R/KEGG")
> library(DOSE)
DOSE v4.0.0 Learn more at https://yulab-smu.top/contribution-knowledge-mining/
Please cite:
Guangchuang Yu, Li-Gen Wang, Guang-Rong Yan, Qing-Yu He. DOSE: an R/Bioconductor package for Disease Ontology Semantic and
Enrichment analysis. Bioinformatics. 2015, 31(4):608-609
> library(clusterProfiler)
clusterProfiler v4.14.4 Learn more at https://yulab-smu.top/contribution-knowledge-mining/
Please cite:
Guangchuang Yu, Li-Gen Wang, Yanyan Han and Qing-Yu He. clusterProfiler: an R package for comparing biological themes among gene
clusters. OMICS: A Journal of Integrative Biology. 2012, 16(5):284-287
载入程序包:‘clusterProfiler’
The following object is masked from ‘package:stats’:
filter
> packageVersion("clusterProfiler")
[1] ‘4.14.4’
> R.version$version.string
[1] "R version 4.4.2 (2024-10-31 ucrt)"
> # 1.读入的是ensembl gene ID ####
> ensembl_gene_ID=read.table("ensembl_gene_ID.txt",sep="\t",stringsAsFactors = F)[[1]]
> ensembl_gene_ID
[1] "ENSG00000081181" "ENSG00000130770" "ENSG00000204842" "ENSG00000188761" "ENSG00000089234" "ENSG00000133466" "ENSG00000204539"
[8] "ENSG00000213066" "ENSG00000224051" "ENSG00000163599" "ENSG00000136943" "ENSG00000065357" "ENSG00000089248" "ENSG00000180210"
[15] "ENSG00000267673" "ENSG00000162576" "ENSG00000117115" "ENSG00000159339" "ENSG00000019144" "ENSG00000186298" "ENSG00000095261"
[22] "ENSG00000117748" "ENSG00000115902" "ENSG00000092969" "ENSG00000232810" "ENSG00000157873" "ENSG00000234127" "ENSG00000138777"
[29] "ENSG00000130522" "ENSG00000204305" "ENSG00000172724"
> #做ID转换,KEGG富集分析要求输入的是entrez gene id
> eg = bitr(ensembl_gene_ID, fromType="ENSEMBL", toType="ENTREZID", OrgDb="org.Hs.eg.db")
'select()' returned 1:1 mapping between keys and columns
> gene_list=eg[[2]]
> gene_list
[1] "384" "93974" "6311" "440603" "8315" "114904" "1041" "11116" "80772" "1493" "1515" "1606" "10961" "2147" "112812"
[16] "54587" "11240" "23569" "23187" "5501" "5711" "6118" "6509" "7042" "7124" "8764" "7726" "27068" "3727" "177"
[31] "6363"
> kk <- enrichKEGG(gene = gene_list, #这里需要输入一串gene,ID只能为ENTREZID
+ organism = "hsa", #富集分析的物种,物种缩写可以参考https://www.genome.jp/kegg/catalog/org_list.html
+ pAdjustMethod = "BH", #FDR校正p值
+ pvalueCutoff = 0.05, #p值阈值<0.05
+ qvalueCutoff = 0.2, #q值阈值<0.2
+ minGSSize = 10, #富集的GO条目至少包含10个基因
+ keyType = "kegg"
+ )
Reading KEGG annotation online: "https://rest.kegg.jp/link/hsa/pathway"...
错误于file(con, "r"):
cannot open the connection to 'https://rest.kegg.jp/link/hsa/pathway'
此外: 警告信息:
In file(con, "r") :
URL 'https://rest.kegg.jp/link/hsa/pathway': status was 'Could not resolve hostname'
>
```