Windows系统下用R的biomartr包FTP下载基因组数据超时问题求助
问题
昨日咨询过代码相关问题,今日确认问题不在代码本身。使用R语言biomartr包从NCBI数据库下载基因组数据,执行代码如下:
install.packages("devtools") library(devtools) devtools::install_github("hadley/devtools") devtools::install_github("HajkD/biomartr", build_vignettes = TRUE, dependencies = TRUE) library(biomartr) options(timeout = 300000) is.genome.available(db = "refseq", organism = "Homo sapiens") MtbCDC1551 <- getGenome(db = "refseq", organism = "GCF_000008585.1", path = "~/Rdir/_ncbi_downloads/genomes", reference = FALSE)
在Windows 10系统运行时出现如下错误:
>MtbCDC1551 <- getGenome(db = "refseq", + organism = "GCF_000008585.1", + path = "~/Rdir/_ncbi_downloads/genomes", + reference = FALSE) Starting genome retrieval of 'GCF_000008585.1' from refseq ... The download session seems to have timed out at the FTP site 'https://ftp.ncbi.nlm.nih.gov/genomes/all/GCF/000/008/585/GCF_000008585.1_ASM858v1/GCF_000008585.1_ASM858v1_genomic.fna.gz'. This could be due to an overload of queries to the databases. Please restart this function to continue the data retrieval process or wait for a while before restarting this function in case your IP address was logged due to an query overload on the server side. Error: Please provide a valid file path to your genome assembly file.
该代码在Mac系统可正常运行,已为R可执行文件和RStudio开放所有防火墙权限,求问Windows系统下还需调整哪些设置解决问题?
解决方案
- 修正路径格式:Windows不识别
~作为用户目录缩写,把路径换成Windows原生格式,比如"C:/Users/你的用户名/Rdir/_ncbi_downloads/genomes",或者用file.path(Sys.getenv("USERPROFILE"), "Rdir", "_ncbi_downloads", "genomes")自动适配系统路径,避免路径解析错误。 - 排查代理配置:Windows默认代理可能影响R的网络请求,先运行
Sys.getenv("http_proxy")和Sys.getenv("https_proxy")查看代理状态。如果存在代理但无法访问NCBI,临时清空代理:Sys.setenv(http_proxy="", https_proxy="") - 更换下载方法:
biomartr底层依赖download.file,Windows下默认方法可能存在兼容性问题,手动指定下载方法:# 尝试wininet方法 options(download.file.method = "wininet") # 或libcurl方法 options(download.file.method = "libcurl") - 检查Windows Defender拦截:即使开放了防火墙权限,实时保护可能仍会拦截R的网络请求。临时关闭实时保护测试下载,若可行,将R和RStudio添加到Defender的排除列表中。
- 进一步延长超时时间:虽然已设置
timeout=300000,但Windows网络环境可能更不稳定,尝试增大超时值:options(timeout = 600000)
内容的提问来源于stack exchange,提问作者raydioactive
相关产品推荐
相关产品推荐

