Last data update: 2014.03.03

R: The XDoubleViews class
XDoubleViews-classR Documentation

The XDoubleViews class

Description

The XDoubleViews class is the basic container for storing a set of views (start/end locations) on the same XDouble object.

Details

An XDoubleViews object contains a set of views (start/end locations) on the same XDouble object called "the subject numeric vector" or simply "the subject". Each view is defined by its start and end locations: both are integers such that start <= end. An XDoubleViews object is in fact a particular case of a Views object (the XDoubleViews class contains the Views class) so it can be manipulated in a similar manner: see ?Views for more information. Note that two views can overlap and that a view can be "out of limits" i.e. it can start before the first element of the subject or/and end after its last element.

Other methods

In the code snippets below, x, object, e1 and e2 are XDoubleViews objects, and i can be a numeric or logical vector.

x[[i]]: Extract a view as an XDouble object. i must be a single numeric value (a numeric vector of length 1). Can't be used for extracting a view that is "out of limits" (raise an error). The returned object has the same XDouble subtype as subject(x).

e1 == e2: A vector of logicals indicating the result of the view by view comparison. The views in the shorter of the two XDoubleViews object being compared are recycled as necessary.

e1 != e2: Equivalent to !(e1 == e2).

Author(s)

P. Aboyoun for the XIntegerViews* code, which was adapted to work over XDouble's by S. Lianoglou

See Also

view-summarization-methods, Views-class, XDouble-class, XIntegerViews-class

Examples

  ## One standard way to create an XDoubleViews object is to use
  ## the Views() constructor:
  subject <- as(rnorm(6), "XDouble")
  v4 <- Views(subject, 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:
  idx <- start(v4) < 1 | end(v4) > length(subject(v4))
  names(v4)[idx] <- "out of limits"

  ## Extract a view as an XDouble object:
  v4[[2]]

  ## It is an error to try to extract an "out of limits" view:
## Not run: 
  v4[[3]] # Error!

## End(Not run)

  ## Here the first view doesn't even overlap with the subject:
  subject <- as(c(97, 97, 97, 45, 45, 98), "XDouble")
  Views(subject, start=-3:4, end=-3:4 + c(3:6, 6:3))

  ## Some fast view* functionalities:
  x <- rnorm(55)
  bounds <- IRanges(c(1, 11, 35, 20), width=c(5, 10, 15, 28))
  v <- Views(x, bounds)
  val <- viewMins(v)
  expect <- sapply(1:length(bounds), function(i) {
    min(x[start(bounds)[i]:end(bounds[i])])
  })
  stopifnot(all(val == expect))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(XVector)
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: S4Vectors
Loading required package: stats4

Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

Loading required package: IRanges
> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/XVector/XDoubleViews-class.Rd_%03d_medium.png", width=480, height=480)
> ### Name: XDoubleViews-class
> ### Title: The XDoubleViews class
> ### Aliases: class:XDoubleViews XDoubleViews-class XDoubleViews
> ###   Views,XDouble-method Views,numeric-method show,XDoubleViews-method
> ###   ==,XDoubleViews,XDoubleViews-method ==,XDoubleViews,XDouble-method
> ###   ==,XDoubleViews,numeric-method ==,XDouble,XDoubleViews-method
> ###   ==,numeric,XDoubleViews-method
> ### Keywords: methods classes
> 
> ### ** Examples
> 
>   ## One standard way to create an XDoubleViews object is to use
>   ## the Views() constructor:
>   subject <- as(rnorm(6), "XDouble")
>   v4 <- Views(subject, start=3:0, end=5:8)
>   v4
Views on a 6-double XDouble subject
subject: -1.02686364  0.27566949  0.02375723 -0.31818310 -0.10372619 -0.60497875
views:
    start end width
[1]     3   5     3 [ 0.02375723 -0.31818310 -0.10372619]
[2]     2   6     5 [ 0.27566949  0.02375723 ...  -0.1037262  -0.6049788]
[3]     1   7     7 [ -1.0268636   0.2756695 ...  -0.1037262  -0.6049788]
[4]     0   8     9 [ -1.0268636   0.2756695 ...  -0.1037262  -0.6049788]
>   subject(v4)
XDouble of length 6
 [1] -1.02686364  0.27566949  0.02375723 -0.31818310 -0.10372619 -0.60497875
>   length(v4)
[1] 4
>   start(v4)
[1] 3 2 1 0
>   end(v4)
[1] 5 6 7 8
>   width(v4)
[1] 3 5 7 9
> 
>   ## Attach a comment to views #3 and #4:
>   names(v4)[3:4] <- "out of limits"
>   names(v4)
[1] NA              NA              "out of limits" "out of limits"
> 
>   ## A more programatical way to "tag" the "out of limits" views:
>   idx <- start(v4) < 1 | end(v4) > length(subject(v4))
>   names(v4)[idx] <- "out of limits"
> 
>   ## Extract a view as an XDouble object:
>   v4[[2]]
XDouble of length 5
 [1]  0.27566949  0.02375723 -0.31818310 -0.10372619 -0.60497875
> 
>   ## It is an error to try to extract an "out of limits" view:
> ## Not run: 
> ##D   v4[[3]] # Error!
> ## End(Not run)
> 
>   ## Here the first view doesn't even overlap with the subject:
>   subject <- as(c(97, 97, 97, 45, 45, 98), "XDouble")
>   Views(subject, start=-3:4, end=-3:4 + c(3:6, 6:3))
Views on a 6-double XDouble subject
subject: 97 97 97 45 45 98
views:
    start end width
[1]    -3   0     4 [ ]
[2]    -2   2     5 [97 97]
[3]    -1   4     6 [97 97 97 45]
[4]     0   6     7 [97 97 97 45 45 98]
[5]     1   7     7 [97 97 97 45 45 98]
[6]     2   7     6 [97 97 45 45 98]
[7]     3   7     5 [97 45 45 98]
[8]     4   7     4 [45 45 98]
> 
>   ## Some fast view* functionalities:
>   x <- rnorm(55)
>   bounds <- IRanges(c(1, 11, 35, 20), width=c(5, 10, 15, 28))
>   v <- Views(x, bounds)
>   val <- viewMins(v)
>   expect <- sapply(1:length(bounds), function(i) {
+     min(x[start(bounds)[i]:end(bounds[i])])
+   })
>   stopifnot(all(val == expect))
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>