The XStringViews class
The XStringViews class is the basic container for storing a set of views (start/end locations) on the same sequence (an XString object).
An XStringViews object contains a set of views (start/end locations) on the
same XString object called "the subject string"
or "the subject sequence" or simply "the subject".
Each view is defined by its start and end locations: both are
integers such that start <= end.
An XStringViews object is in fact a particular case of an
object (the XStringViews class contains the
Views class) so it
can be manipulated in a similar manner: see
Note that two views can overlap and that a view can be "out of limits"
i.e. it can start before the first letter of the subject or/and end
after its last letter.
Views(subject, start=NULL, end=NULL, width=NULL, names=NULL): See
?Viewsin the IRanges package for the details.
All the accessor-like methods defined for
work on XStringViews objects. In addition, the following accessors are defined
for XStringViews objects:
nchar(x): A vector of non-negative integers containing the number of letters in each view. Values in
nchar(x)coincide with values in
width(x)except for "out of limits" views where they are lower.
In the code snippets below,
e2 are XStringViews objects,
i can be a numeric or logical vector.
e1 == e2: A vector of logicals indicating the result of the view by view comparison. The views in the shorter of the two XStringViews object being compared are recycled as necessary.
Like for comparison between XString objects, comparison between two XStringViews objects with subjects of different classes is not supported with one exception: when the subjects are DNAString and RNAString instances.
Also, like with XString objects, comparison between an XStringViews object with a BString subject and a character vector is supported (see examples below).
e1 != e2: Equivalent to
!(e1 == e2).
as.character(x, use.names=TRUE, check.limits=TRUE): Converts
xto a character vector of the same length as
use.namesargument controls whether or not
names(x)should be propagated to the names of the returned vector. The
check.limitsargument controls whether or not an error should be raised if
xhas "out of limit" views. If
FALSEthen "out of limit" views are trimmed with a warning.
as.data.frame(x, row.names = NULL, optional = FALSE, ...)
as.matrix(x, use.names=TRUE): Returns a character matrix containing the "exploded" representation of the views. Can only be used on an XStringViews object with equal-width views. The
use.namesargument controls whether or not
names(x)should be propagated to the row names of the returned matrix.
toString(x): Equivalent to
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53
## One standard way to create an XStringViews object is to use ## the Views() constructor. ## Views on a DNAString object: s <- DNAString("-CTC-N") v4 <- Views(s, start=3:0, end=5:8) v4 subject(v4) length(v4) start(v4) end(v4) width(v4) ## Attach a comment to views #3 and #4: names(v4)[3:4] <- "out of limits" names(v4) ## A more programatical way to "tag" the "out of limits" views: names(v4)[start(v4) < 1 | nchar(subject(v4)) < end(v4)] <- "out of limits" ## or just: names(v4)[nchar(v4) < width(v4)] <- "out of limits" ## Two equivalent ways to extract a view as an XString object: s2a <- v4[] s2b <- subseq(subject(v4), start=start(v4), end=end(v4)) identical(s2a, s2b) # TRUE ## It is an error to try to extract an "out of limits" view: #v4[] # Error! v12 <- Views(DNAString("TAATAATG"), start=-2:9, end=0:11) v12 == DNAString("TAA") v12[v12 == v12] v12[v12 == v12] v12 == Views(RNAString("AU"), start=0, end=2) ## Here the first view doesn't even overlap with the subject: Views(BString("aaa--b"), start=-3:4, end=-3:4 + c(3:6, 6:3)) ## 'start' and 'end' are recycled: subject <- "abcdefghij" Views(subject, start=2:1, end=4) Views(subject, start=5:7, end=nchar(subject)) Views(subject, start=1, end=5:7) ## Applying gaps() to an XStringViews object: v2 <- Views("abCDefgHIJK", start=c(8, 3), end=c(14, 4)) gaps(v2) ## Coercion: as(v12, "XStringSet") # same as 'as(v12, "DNAStringSet")' rna <- as(v12, "RNAStringSet") as(rna, "Views")