Skip to content

Instantly share code, notes, and snippets.

@Ruhshan
Created February 6, 2018 16:55
Show Gist options
  • Save Ruhshan/25865ad4ab22663c36026d1ab02d034a to your computer and use it in GitHub Desktop.
Save Ruhshan/25865ad4ab22663c36026d1ab02d034a to your computer and use it in GitHub Desktop.
library("seqinr")
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"))
}
dengueseq <- getncbiseq("NC_001477")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment