Lamentation
What you are getting is a character vector, one entry per row, with the fasta header always in the first entry. Did I mention that this is an odd representation?
I think, the first thing to do is to complain to the authors of efetch to integrate better with the Bioconductor infrastructure. Imho, the method efetch should
already return a DNAStingSet object by default or at least have an option to convert, e.g. by
as(handle, DNAStringSet)
Their excuse might be historical reasons or dependencies, but I wouldn't buy it ;) The main reason is possibly, that efetch can return very different data types and not all are sequences.
Why is this annoying? Look at this:
efetch(c("NM_009790",'NM_009790'), db="nucleotide", rettype="fasta")
[1] ">gi|118130270:1-700 Mus musculus calmodulin 1 (Calm1), mRNA"
[2] "GGGAGTCTCGTGTCCGTGGTGCCGTTACTCGAAGTCGGGCGGCGGCTGAGGCTCAGCGCACAACGCAGGT"
[3] "AGCGCGTTAGCAGCAGCAGAAGCGGAGGCACCTCGGCGGTCACAGCCCCTGCGCTGGTGCAGCCACCCTC"
[12] ""
[13] ">gi|118130270:1-700 Mus musculus calmodulin 1 (Calm1), mRNA"
[14] "GGGAGTCTCGTGTCCGTGGTGCCGTTACTCGAAGTCGGGCGGCGGCTGAGGCTCAGCGCACAACGCAGGT"
[15] "AGCGCGTTAGCAGCAGCAGAAGCGGAGGCACCTCGGCGGTCACAGCCCCTGCGCTGGTGCAGCCACCCTC"
[16] "GCCTGCTCCGTTCTTCCTTCCTTCGCTCGCACCATGGCTGATCAGCTGACTGAAGAGCAGATTGCTGAAT"
Unfortunately, this is still a character vector, while it definitely should be a list type for multiple entries. So your only options are either to parse the vector yourself or to write it to a temporary file and read it with readRNAStringSet, because
readDNAStringSet(stdin())
Error in .normargInputFilepath(filepath) :
'filepath' must be a character vector with no NAs
Solution
In conclusion, the easiest and mostly safe way is possibly the following. Also, this doesn't create more overhead, because efetch will write its downloaded data to a temporary file anyway.
tmp = tempfile()
efetch(c("NM_009790",'NM_009790'), db="nucleotide", retmode="text", rettype="fasta", destfile=tmp)
readDNAStringSet(tmp)
A DNAStringSet instance of length 2
width seq names
[1] 700 GGGAGTCTCGTGTCCGTGGTGCCGTTACTCGAAGTC...ATTGAAATCTTTTACTTACCTCTTACAAAAAAAAGA gi|118130270:1-70...
[2] 700 GGGAGTCTCGTGTCCGTGGTGCCGTTACTCGAAGTC...ATTGAAATCTTTTACTTACCTCTTACAAAAAAAAGA gi|118130270:1-70...
+1 for finding that efetch return types are annoying.