In R bioconductor, how to combine DNAString views please ?
2
3
Entering edit mode
10.4 years ago
Aurelie MLB ▴ 360

Hello,

I have some Views of DNAStrings in a list. I would like to combine them. I have tried c(), unlist(), append(), rbind() ...none of this works. Would someone know how to do please?

Many thanks

sequence R • 6.1k views
ADD COMMENT
1
Entering edit mode

Have sent a report to the Bioconductor mailing list.

ADD REPLY
0
Entering edit mode

Thanks a lot !

ADD REPLY
1
Entering edit mode
10.4 years ago
Michael 55k

I think that this is a missing feature in the Views-class implementation or alternatively a mistake in the documentation. In fact it doesn't feel natural that Views should not support concatenation or appending of some sort as all other vector classes do.

Workaround:

v = Views(1:10,1,2)
c(v, v) ## doesn't work
Error in c(v, v) : missing 'c' method for Vector class XIntegerViews
ir = as(v, "IRanges")
Views(subject(v), c(ir, ir))

Views on a 10-integer XInteger subject
subject:  1  2  3  4  5  6  7  8  9 10
views:
    start end width
[1]     1   2     2 [1 2]
[2]     1   2     2 [1 2]

From ?Views:

Subsetting and appending

"[", c and "[[" work on a Views object. The first two operations are just inherited from the IRanges class but now they return a Views object. However, the "[[" method for Views objects has a different semantic than the method for IRanges objects.

ADD COMMENT
2
Entering edit mode

Agreed. Views objects should support concatenation and appending. And most of them do. However there is an issue when the subject is an XVector or XVectorList object. I will address that. Note Michael that the man page excerpt you're showing above is from an old man page. The Views class used to derive from IRanges but not anymore: these days it derives directly from List (this was changed a couple of years ago).

ADD REPLY
0
Entering edit mode

My IRanges documentation is [Package IRanges version 1.18.4 Index], that is shown to be the most recent, but definitely not a few years old, maybe a regression? My R is 3.0, maybe the documentation changed for bioc 2?

ADD REPLY
0
Entering edit mode

The current version of IRanges is 1.20.7 (part of BioC 2.14). The change for Views happened at least 2 years ago. Looks like its man page was only modified last year.

ADD REPLY
0
Entering edit mode

Trying again: The current version of IRanges is 1.22.9 (part of BioC 2.14). I got things mixed up sorry.

So yes, 1.18.4 is pretty old (part of BioC 2.12, relased in spring 2013).

ADD REPLY
0
Entering edit mode

Then the solution is to update to the latest version of R 3.1.0 and BioC 2.22.9 where c() is implemented for views, right? - (Sorry for lagging behind but R release updates are quite tedious for me).

Seemingly not, after update to R 3.1 and IRanges 1.22.9 I get:

 c(v,v)
Error in unclass(target) : cannot unclass an external pointer
ADD REPLY
0
Entering edit mode

... which brings us back to my initial comment (DNAString and XInteger objects are XVector objects)

ADD REPLY
0
Entering edit mode

Good to know!

I had difficulties to find a documentation in depth / tutorial about Views. Their manipulation was not easy to understand for me. Is there any good documentation that you would advice please?

ADD REPLY
0
Entering edit mode

Thanks a lot for your solution Michael ! It helps a lot !

ADD REPLY
0
Entering edit mode
10.4 years ago
Martin Morgan ★ 1.6k

Not really clear what 'combine' means, but here are some ideas

> library(Biostrings)
> dna = DNAString("ACTGCA")
> v = Views(dna, IRanges(1, 2:5))
> v
  Views on a 6-letter DNAString subject
subject: ACTGCA
views:
    start end width
[1]     1   2     2 [AC]
[2]     1   3     3 [ACT]
[3]     1   4     4 [ACTG]
[4]     1   5     5 [ACTGC]
> DNAStringSet(v)
  A DNAStringSet instance of length 4
    width seq
[1]     2 AC
[2]     3 ACT
[3]     4 ACTG
[4]     5 ACTGC
> paste(v, collapse="")
[1] "ACACTACTGACTGC"

If you mean something like c(v, v) then I think you might be out of luck, at least in general; the notion of a view is that the view is on to a single underlying string, and the two views you'd be trying to combine would be on two different underlying strings. A work-around might be

c(DNAStringSet(v), DNAStringSet(v))

It might be better to ask these types of questions on the Bioconductor mailing list (no subscription required), where you'll get the attention of the experts.

ADD COMMENT
0
Entering edit mode

Note that a Views object is a List object where the list elements are the individual views. So if you want to achieve what Martin does with "coercion to DNAStringSet + collapse", you can just use unlist():

> unlist(v)
  14-letter "DNAString" instance
seq: ACACTACTGACTGC

If you have thousands of views, that will also be more efficient (because the result is a DNAString object instead of an ordinary character string).

Otherwise, you'll need to clarify what you mean by "combine". I will second Martin and encourage you to ask again on the Bioconductor mailing list, with more details on what you want to achieve.

ADD REPLY
0
Entering edit mode

In R context, it is quite well defined what 'combine' means: a method that works like 'c' on vectors, e.g. one could expect to find an implementation of method 'c' on Views that has the same semantics as 'c' has for IRanges objects.

c {base}

Combine Values into a Vector or List

Description

This is a generic function which combines its arguments.

ADD REPLY
0
Entering edit mode

Right. But we've seen people using "combine" for so many different things that I thought some clarification wouldn't hurt ;-) After all unlist(x) is also a way to "combine" things. It's actually equivalent to do.call("c", as.list(x)):

> do.call("c", as.list(v))

  14-letter "DNAString" instance
seq: ACACTACTGACTGC
ADD REPLY
0
Entering edit mode

Hello,

Thanks a lot for your answers. Yes what I would like to do is c(v,v) as Martin is proposing. Sorry if it was not clear enough!

ADD REPLY

Login before adding your answer.

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