我正在尝试访问NCBI SRA数据库,查询ID列表并将输出保存到矩阵中。
我正在使用Bioconductor的sradb包来做这件事,现在我可以访问和查询数据库了,但是它真的很慢,而且我不知道如何保存循环输出。
文件GPL11154_GSMs.txt包含我感兴趣的I。它看起来像这样:
GSM616127
GSM616128
GSM616129
GSM663427
GSM665037我现在所拥有的在每次迭代中都会更新结果。
#source("https://bioconductor.org/biocLite.R")
#biocLite("SRAdb")
library(SRAdb)
#connect to databasse
sqlfile <- getSRAdbFile()
sra_con <- dbConnect(SQLite(),sqlfile)
## lists all the tables in the SQLite database
sra_tables <- dbListTables(sra_con)
sra_tables
dbGetQuery(sra_con,'PRAGMA TABLE_INFO(study)')
## checking the structure of the tables
#dbListFields(sra_con,"experiment")
#dbListFields(sra_con,"run")
#read in file with sample IDs per platform
x <- scan("GPL11154_GSMs.txt", what="", sep="\n")
gsm_list <- strsplit(x, "[[:space:]]+") # Separate elements by one or more whitepace
for (gsm in gsm_list){
gsm_to_srr <- getSRA(search_terms = gsm, out_types = c("submission", "study", "sample","experiment", "run"), sra_con)
print(gsm_to_srr)
}发布于 2016-11-10 19:56:59
使用lapply而不是forloop,尝试:
res <- lapply(gsm_list, function(gsm){
getSRA(search_terms = gsm,
out_types = c("submission", "study",
"sample","experiment", "run"),
sra_con) })在手册中,getSRA应该返回一个data.frame,所以res对象将有data.frames的列表。如果我们需要将data.frames列表转换成一个data.frame,this post会告诉你怎么做。
https://stackoverflow.com/questions/40524025
复制相似问题