Biostrings character vector conversion
2
0
Entering edit mode
ribioinfo ▴ 100
@ribioinfo-9434
Last seen 3.7 years ago

Hi, I have a DNAStringSet list and I would like to convert it in a character vector but as.character does not work because it gives me a vector of "<S4 object of class \"DNAStringSet\">".

Could you help me?

Thank you.

 

Riccardo

biostrings • 4.7k views
ADD COMMENT
0
Entering edit mode
@martin-morgan-1513
Last seen 5 days ago
United States

I guess you have something like

a = DNAStringSet(c("AAA", "TTT"))
b = DNAStringSet(c("GGG", "CCC"))
dsl = DNAStringSetList(a, b)

which displays as

> dsl
DNAStringSetList of length 2
[[1]] AAA TTT
[[2]] GGG CCC

You could unlist this and coerce

> as.character(unlist(dsl))
[1] "AAA" "TTT" "GGG" "CCC"

but that removes the grouping of DNA strings. Another option is to coerce to a CharacterList, which behaves like a plain-old-list where each element is a character vector.

> cl = as(dsl, "CharacterList")
> cl
CharacterList of length 2
[[1]] AAA TTT
[[2]] GGG CCC

Or make this into a plain-old-list

> as.list(cl)
[[1]]
[1] "AAA" "TTT"

[[2]]
[1] "GGG" "CCC"

But I guess the question is, why do you want to do this? Maybe the step is unnecessary.

ADD COMMENT
0
Entering edit mode
ribioinfo ▴ 100
@ribioinfo-9434
Last seen 3.7 years ago

Thank you! I want to do this because I have to do a merge between two data frame, in one of them there is a column with character values and in the other table there is another column with DNAStringSet values.

Riccardo

ADD COMMENT
0
Entering edit mode

Provide a short example, maybe using the DNAStringSetList I created, to illustrate what you want to do. Add the example by editing your original question.

In the future, use 'ADD COMMENT' if you are commenting on an answer someone has provided.

ADD REPLY

Login before adding your answer.

Traffic: 1078 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