問題
學(xué)員遇到一個(gè)報(bào)錯(cuò):

第一個(gè)buff:timeout設(shè)置
我一瞅,time out 啊。迅速發(fā)了一個(gè)鏈接,并告訴他要主動(dòng)搜索。。。
核心解決方案是一句代碼
options(timeout=100000)
getOption("timeout")
## [1] 1e+05
就是把下載時(shí)間60s的限制解除。之前用來解決一個(gè)類似的報(bào)錯(cuò):
Timeout of 60 seconds was reached
反饋沒用,報(bào)錯(cuò)不變。
第二個(gè)buff:加速
options( 'download.file.method.GEOquery' = 'libcurl' )
這個(gè)是設(shè)置用libcurl加快訪問速度。加速完了還是慢,那有啥辦法,憋著吧。
反饋沒用,報(bào)錯(cuò)還是不變。
第三個(gè)buff:geoChina
既然是geo的芯片數(shù)據(jù),那么曾老板的鏡像怎么可以沒有鏡頭。
#install.packages("AnnoProbe")
library(AnnoProbe)
a = geoChina("GSE148601",destdir = ".")
## Error in geoChina("GSE148601", destdir = "."): Your GSE may not be expression by array, or even not a GSE
反饋報(bào)錯(cuò),說這不是一個(gè)芯片。
其實(shí)是因?yàn)檫@個(gè)數(shù)據(jù)太新,2022年9月的,比我兒子還小。
所以沒有被AnnoProbe收錄?。e急別急,你看,他在搞了。
如果是一個(gè)被收錄了的數(shù)據(jù),他的打開方式是這樣的:
b = geoChina("GSE42872",destdir = ".")
class(b[[1]])
## [1] "ExpressionSet"
## attr(,"package")
## [1] "Biobase"
然后就可以對接提取矩陣和臨床信息的代碼啦。
或者也可以使用tinyarray進(jìn)一步簡化
#install.packages("tinyarray")
library(tinyarray)
geo = geo_download("GSE42872",by_annopbrobe = T)
names(geo)
## [1] "exp" "pd" "gpl"
一步到位拿到表達(dá)矩陣 臨床信息 GPL編號(hào)哦。
第四個(gè)buff:改包!
既然前三個(gè)buff都不能解決,只能讓神奇的小潔老師自己上手了。
一番搜索,發(fā)現(xiàn)是GEOquery更新過后,downloadFile這個(gè)函數(shù)做了改動(dòng)。
2.62版本,它是這樣
function (url, destfile, mode, quiet = TRUE)
{
h <- curl::new_handle()
curl::handle_setheaders(h, `accept-encoding` = "gzip")
result = tryCatch({
curl::curl_download(url, destfile, mode = mode, quiet = quiet,
handle = h)
return(TRUE)
}, error = function(e) {
message(e)
return(FALSE)
})
message("File stored at:")
message(destfile)
if (!result) {
if (file.exists(destfile)) {
file.remove(destfile)
}
stop(sprintf("Failed to download %s!", destfile))
}
return(0)
}
2.66版本 它成了這樣:
function (url, destfile, mode, quiet = TRUE)
{
h <- curl::new_handle()
curl::handle_setheaders(h, `accept-encoding` = "gzip")
timeout_seconds <- 120
curl::handle_setopt(h, timeout_ms = timeout_seconds * 1000)
result = tryCatch({
curl::curl_download(url, destfile, mode = mode, quiet = quiet,
handle = h)
return(TRUE)
}, error = function(e) {
message(e)
return(FALSE)
})
message("File stored at:")
message(destfile)
if (!result) {
if (file.exists(destfile)) {
file.remove(destfile)
}
stop(sprintf("Failed to download %s!", destfile))
}
return(0)
}
簡單來說就是timeout變成固定的120s了,這也就是為什么學(xué)員一開始的報(bào)錯(cuò)里出現(xiàn)了120000毫秒,換算過來就是120s。
so,解決辦法是編輯R包。github上面已經(jīng)有人提交了解決辦法,但還沒有被作者團(tuán)隊(duì)接納。
從github下載這個(gè)包的zip,解壓,找到R/getGEOfile.R,downloadFile函數(shù),把第三句代碼改掉
timeout_seconds <- max(getOption("timeout"), 120)
這樣,timeout的設(shè)置就可以用起來了,。
devtools::install_local("GEOquery-master.zip")
library(GEOquery)
options(timeout=100000)
getOption("timeout")
options( 'download.file.method.GEOquery' = 'libcurl' )
a = getGEO("GSE148601",destdir = ".")
不報(bào)錯(cuò)啦!
第五個(gè)buff:想辦法外部下載。
無非是網(wǎng)絡(luò)限制而已,你可以想辦法的。或者,把表達(dá)矩陣的鏈接復(fù)制下來,求助也是很快的。

點(diǎn)進(jìn)去,右鍵復(fù)制鏈接

https://ftp.ncbi.nlm.nih.gov/geo/series/GSE148nnn/GSE148601/matrix/GSE148601_series_matrix.txt.gz
自己去瀏覽器下載,或者發(fā)出來求助,拿到文件后,放在工作目錄下,代碼就可以調(diào)用本地文件,而不去網(wǎng)頁下載,這樣就可以正常運(yùn)行啦!
請注意,降低別人幫助你的門檻是很重要的,發(fā)鏈接別人可以直接下載,發(fā)編號(hào)別人卻需要一下下搜索和點(diǎn)開哦?!稙榛卮鹉愕娜酥胍幌隆?/p>