| Views-class {IRanges} | R Documentation |
Views objects
Description
The Views virtual class is a general container for storing a set of views on an arbitrary Vector object, called the "subject".
Its primary purpose is to introduce concepts and provide some facilities that can be shared by the concrete classes that derive from it.
Some direct subclasses of the Views class are: RleViews, XIntegerViews (defined in the XVector package), XStringViews (defined in the Biostrings package), etc...
Constructor
Views(subject, start=NULL, end=NULL, width=NULL, names=NULL):-
This constructor is a generic function with dispatch on argument
subject. Specific methods must be defined for the subclasses of the Views class. For example a method for XString subjects is defined in the Biostrings package that returns an XStringViews object. There is no default method.The treatment of the
start,endandwidtharguments is the same as with theIRangesconstructor, except that, in addition,Viewsallowsstartto be an IntegerRanges object. With this feature,Views(subject, IRanges(my_starts, my_ends, my_widths, my_names))andViews(subject, my_starts, my_ends, my_widths, my_names)are equivalent (except whenmy_startsis itself a IntegerRanges object).
Coercion
In the code snippets below, from is a Views object:
as(from, "IRanges"):-
Creates an
IRangesobject containing the view locations infrom.
Accessor-like methods
All the accessor-like methods defined for IRanges objects
work on Views objects. In addition, the following accessors are defined
for Views objects:
subject(x):-
Return the subject of the views.
Subsetting
x[i]:-
Select the views specified by
i. x[[i]]:-
Extracts the view selected by
ias an object of the same class assubject(x). Subscriptican be a single integer or a character string. The result is the subsequence ofsubject(x)defined bywindow(subject(x), start=start(x)[i], end=end(x)[i])or an error if the view is "out of limits" (i.e.start(x)[i] < 1orend(x)[i] > length(subject(x))).
Concatenation
c(x, ..., ignore.mcols=FALSE):-
Concatenate
Viewsobjects. They must have the same subject.
Other methods
trim(x, use.names=TRUE):-
Equivalent to
restrict(x, start=1L, end=length(subject(x)), keep.all.ranges=TRUE, use.names=use.names). subviews(x, start=NA, end=NA, width=NA, use.names=TRUE):-
start,end, andwidtharguments must be vectors of integers, eventually with NAs, that contain coordinates relative to the current ranges. Equivalent totrim(narrow(x, start=start, end=end, width=width, use.names=use.names)). successiveViews(subject, width, gapwidth=0, from=1):-
Equivalent to
Views(subject, successiveIRanges(width, gapwidth, from))
See
?successiveIRangesfor a description of thewidth,gapwidthandfromarguments.
Author(s)
Hervé Pagès
See Also
IRanges-class, Vector-class, IRanges-utils, XVector.
Some direct subclasses of the Views class: RleViews-class, XIntegerViews-class, XDoubleViews-class, XStringViews-class.
Examples
showClass("Views") # shows (some of) the known subclasses
## Create a set of 4 views on an Rle subject of length 50:
subject <- Rle(LETTERS[1:10], 5)
v1 <- Views(subject, start=9:4, end=9:14)
v1
## Extract the 4th view:
v1[[4]]
## Some views can be "out of limits":
v2 <- Views(101:110, start=4:-1, end=6)
## Not run:
v2[[5]] # Error! view is out of limits
## End(Not run)
## Trimming the views so they're no longer out of limits:
trim(v2)
trim(v2)[[5]]
## Note that using subviews() with no additional arguments has
## the same effect as trimming:
subviews(v2)
## See ?`XIntegerViews-class` in the XVector package for more examples.