r - Loop saving output to matrix -


i'm trying access ncbi sra database, query list of ids , save output matrix.

i'm using sradb package bioconductor , can access , query database, slow , couldn't quite figure out how save loop output.

the file gpl11154_gsms.txt contains ids i'm interested in. , looks this:

gsm616127 gsm616128 gsm616129 gsm663427 gsm665037 

what have updates result on every iteration.

#source("https://bioconductor.org/bioclite.r") #bioclite("sradb") library(sradb)  #connect databasse sqlfile <- getsradbfile() sra_con <- dbconnect(sqlite(),sqlfile)   ## lists tables in sqlite database sra_tables <- dblisttables(sra_con) sra_tables   dbgetquery(sra_con,'pragma table_info(study)')  ## checking structure of tables #dblistfields(sra_con,"experiment") #dblistfields(sra_con,"run")    #read in file sample ids per platform x <- scan("gpl11154_gsms.txt", what="", sep="\n") gsm_list <- strsplit(x, "[[:space:]]+")  # separate elements 1 or more whitepace (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)   } 

using lapply instead of forloop, try:

res <- lapply(gsm_list, function(gsm){   getsra(search_terms = gsm,          out_types = c("submission", "study",                        "sample","experiment", "run"),          sra_con) }) 

from manuals, getsrashould return data.frame, res object have list of data.frames. if need convert list of data.frames 1 data.frame, this post on how it.


Comments

Popular posts from this blog

asynchronous - C# WinSCP .NET assembly: How to upload multiple files asynchronously -

aws api gateway - SerializationException in posting new Records via Dynamodb Proxy Service in API -

asp.net - Problems sending emails from forum -