Entering edit mode
I have a file with DNA sequence of length 900 characters. I use Biostrings package to read the sequence from the file into R.
library(Biostrings) ref <- readDNAStringSet(filepath)
I get something like
A DNAStringSet instance of length 1 width seq names [1] 900 AACTGGTTACCTGCCGTGAGTAAATTAAAATT...GACGCAACGGTTCCGACTACTCTGCTGCGGTG AGCTTTTCATTCTGACT...
I would like to know, how to get the full DNA sequence into other variable. How to access the full sequence.
It is there, only some of the letters are showing. What do you want to do with your sequence now that you have read it in?
I want to have the full sequence as a character string and do some operation on that. Suppose I want to display the first 500 characters or do some string operation on that.
On the one hand you could display them with
as.character(ref)
but if you wanted to do something you'd typically use a function, e.g.,reverseComplement(ref
) ornarrow(ref, 500)
. This would return another DNAStringSet, which you could then coerce to character if you wanted, but really there's not much to be gained by looking at 500 letters (or 3 billion, or 10 million 100-mers) with the naked eye. Check out the help page?DNAStringSet
including the examples to get some ideas; the infrastructure is very flexible.Looking at your DNAStringSet, I wonder what the file that you are reading from looks like? readDNAStringSet is expecting a FASTA file
and the identifier is used as the 'name'; it seems like you have a 'name' that is a sequence. If you have a plain text file with 1 DNA sequence per line, you could do something like
When I try to find the number of characters
It returns 0. What is going wrong??.
Do you mean
nchar(ref)
? Please cut-and-paste from your R session into the support site, because it is very important to be precise. I haveusing the current version of software. What is the output of your
sessionInfo()
?Thanks a lot for writing . Its my bad that I could not notice the error early in my FASTA file. Everything looks fine now.
will this only work with a FATSA file or can I do this with a txt file?
Please don't add comments to a 6 year old post. If you have a question, please submit a new question.