I do not know how to access the sequence as it is in the DNAbin object. the typeoff and the [] does not provide what I need.
Extract sequences from Class DNAbin
Hi,
In the script below, based on this, how can I extract the sequences from the Class DNAbin?
Thanks
require(ape)
cotton_acc <- c("U56806", "U12712", "U56810",
"U12732", "U12725", "U56786", "U12715",
"AF057758", "U56790", "U12716", "U12729",
"U56798", "U12727", "U12713", "U12719",
"U56811", "U12728", "U12730", "U12731",
"U12722", "U56796", "U12714", "U56789",
"U56797", "U56801", "U56802", "U12718",
"U12710", "U56804", "U12734", "U56809",
"U56812", "AF057753", "U12711", "U12717",
"U12723", "U12726")
cotton <- read.GenBank(cotton_acc, species.names = T)
• 9,846 views
•
link
1 answer
I'm not quite sure what you mean by "extract" here. The DNAbin object contains the sequences, which in this case behaves rather like a list:
typeof(cotton)
To extract elements from the object you can use either of the normal methods: $NAME, [[iINDEX]] or [INDEX]. If you are new to R you might want to check out? Extract to see how those methods differ.
EDIT
To answer the new question you could make your dataframe like this:
df <- data.frame(ID=labels(cotton),
sp=attr(cotton, "species"),
seq=sapply(cotton, paste, collapse=""))
• 1 views
•
link
Log in to answer this question.
Try
lapply(cotton, as.character)this could help. cotton <- read.GenBank(cotton_acc, species.names = T, as.character=T)