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
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
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.
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).
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
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.
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.
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.
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
Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Have sent a report to the Bioconductor mailing list.
Thanks a lot !