Extract sequences from Class DNAbin
1
0
Entering edit mode
9.4 years ago
l.roca ▴ 10

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)
sequence r • 8.1k views
ADD COMMENT
0
Entering edit mode

Try lapply(cotton, as.character)

ADD REPLY
0
Entering edit mode

this could help. cotton <- read.GenBank(cotton_acc, species.names = T, as.character=T)

ADD REPLY
1
Entering edit mode
9.4 years ago
David W 4.9k

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=""))
ADD COMMENT
0
Entering edit mode

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.

ADD REPLY
0
Entering edit mode

What do you need?

ADD REPLY
0
Entering edit mode

Hi,

I wish to save the accession number, species name and the sequence in a data.frame.

Thanks

ADD REPLY
0
Entering edit mode

Ok, answer edited.

ADD REPLY
0
Entering edit mode

Thanks a lot

ADD REPLY

Login before adding your answer.

Traffic: 3020 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6