error with a function to retrieve data from a database

前端 未结 2 1417
后悔当初
后悔当初 2021-01-13 11:42

I am trying to get a FASTA file form NCBI website, I use the following function

getncbiseq <- function(accession){
  dbs <- c()
  for (i in 1:numdbs){         


        
2条回答
  •  日久生厌
    2021-01-13 12:16

    Thanks for great help. I was stuck at this point for a full day. I finally got the following code worked under windows 10 with R3.4.0(32bits):-

    getncbiseq <- function(accession)
    {
    require("seqinr") # this function requires the SeqinR R package
    # first find which ACNUC database the accession is stored in:
    dbs <- c("genbank","refseq","refseqViruses","bacterial")
    numdbs <- length(dbs)
    for (i in 1:numdbs)
    {
    db <- dbs[i]
    choosebank(db)
    # check if the sequence is in ACNUC database 'db':
    resquery <- try(query(".tmpquery", paste("AC=", accession)), silent = TRUE)
    
    if (!(inherits(resquery, "try-error"))) {
      queryname <- "query2"
      thequery <- paste("AC=", accession, sep="")
      query2 <- query(queryname, thequery)
      # see if a sequence was retrieved:
      seq <- getSequence(query2$req[[1]])
      closebank()
      return(seq)
    }
    closebank()
    }
    print(paste("ERROR: accession",accession,"was not found"))
    }
    

提交回复
热议问题