2016-11-10 7 views
1

NCBI SRA 데이터베이스에 액세스하려고 시도하고 ID 목록을 쿼리하여 출력을 행렬에 저장하려고합니다.출력을 행렬에 저장

Bioconductor의 sradb 패키지를 사용하여 데이터베이스에 액세스하고 쿼리 할 수 ​​있지만 실제로는 느리고 나는 루프 출력을 저장하는 방법을 알 수 없습니다.

파일 GPL11154_GSMs.txt 내가 관심이있는 ID를 포함 그리고는 다음과 같습니다.

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) 
    } 

답변

0

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.frame의 목록을 하나의 data.frame으로 변환해야한다면, 어떻게 할 것인가에 대해서는 this post입니다.

+0

예, res.df = as.data.frame (do.call (rbind, res))을 변환 한 다음 저장했습니다. 그것은 완벽하게 작동했습니다. 감사 – MenieM