How to convert a DnaStringSet object to list of seq?
2
0
Entering edit mode
vinod.acear ▴ 50
@vinodacear-8884
Last seen 4.2 years ago
India

Hi

Please help me to convert the DNA sequences of a "DNAStrinset" object to the list of DNA sequences.

Here is the description below:

Input:

> s1
  A DNAStringSet instance of length 5
    width seq
[1]     7 AGGCTCT
[2]     6 AGGTCT
[3]     7 AGGGTGT
[4]     7 AGGCTCT
[5]     7 TTCGGTA

 

I need following output in the form of list of sequences:

[[1]]
[1] "AGGCTCT"

[[2]]
[1] "AGGTCT"

[[3]]
[1] "AGGGTGT"

[[4]]
[1] "AGGCTCT"

[[5]]
[1] "TTCGGTA"

 

Thanks

dnastringset list stringset • 4.0k views
ADD COMMENT
2
Entering edit mode
@martin-morgan-1513
Last seen 3 months ago
United States

as.list(as.character(s1)), but a very important question is why would you want to move from an efficient and compact representation to an inefficient one?

ADD COMMENT
0
Entering edit mode

Thanks Martin.  I know  its inefficient way, but this was required as an input  for a already written function. I will try to modify it further.
 

ADD REPLY
0
Entering edit mode
Haiying.Kong ▴ 110
@haiyingkong-9254
Last seen 5.6 years ago
Germany

Try:

lapply(1:length(s1), function(i) data.frame(s1)[i,1] )

ADD COMMENT
1
Entering edit mode

FWIW, this is not very efficient R code, calling data.frame() for each element of DNAStringSet, and failing when s1 = DNAStringSet(). Can you make it more efficient (call data.frame(s1) only once) and robust (use seq_along(s1) instead of 1:length(s1))?

ADD REPLY

Login before adding your answer.

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