Last data update: 2014.03.03

R: The XIntegerViews class
XIntegerViews-classR Documentation

The XIntegerViews class

Description

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

Details

An XIntegerViews object contains a set of views (start/end locations) on the same XInteger object called "the subject integer vector" or simply "the subject". Each view is defined by its start and end locations: both are integers such that start <= end. An XIntegerViews object is in fact a particular case of a Views object (the XIntegerViews 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 XIntegerViews objects, and i can be a numeric or logical vector.

x[[i]]: Extract a view as an XInteger 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 XInteger 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 XIntegerViews object being compared are recycled as necessary.

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

Author(s)

P. Aboyoun

See Also

view-summarization-methods, Views-class, XInteger-class, XDoubleViews-class

Examples

## One standard way to create an XIntegerViews object is to use
## the Views() constructor:
subject <- as(c(45, 67, 84, 67, 45, 78), "XInteger")
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 XInteger 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), "XInteger")
Views(subject, start=-3:4, end=-3:4 + c(3:6, 6:3))

## Views on a big XInteger subject:
subject <- XInteger(99999, sample(99, 99999, replace=TRUE) - 50)
v5 <- Views(subject, start=1:99*1000, end=1:99*1001)
v5
v5[-1]
v5[[5]]

## 31 adjacent views:
successiveViews(subject, 40:10)

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/XIntegerViews-class.Rd_%03d_medium.png", width=480, height=480)
> ### Name: XIntegerViews-class
> ### Title: The XIntegerViews class
> ### Aliases: class:XIntegerViews XIntegerViews-class XIntegerViews
> ###   Views,XInteger-method Views,integer-method show,XIntegerViews-method
> ###   ==,XIntegerViews,XIntegerViews-method
> ###   ==,XIntegerViews,XInteger-method ==,XIntegerViews,integer-method
> ###   ==,XInteger,XIntegerViews-method ==,integer,XIntegerViews-method
> ### Keywords: methods classes
> 
> ### ** Examples
> 
> ## One standard way to create an XIntegerViews object is to use
> ## the Views() constructor:
> subject <- as(c(45, 67, 84, 67, 45, 78), "XInteger")
> v4 <- Views(subject, start=3:0, end=5:8)
> v4
Views on a 6-integer XInteger subject
subject: 45 67 84 67 45 78
views:
    start end width
[1]     3   5     3 [84 67 45]
[2]     2   6     5 [67 84 67 45 78]
[3]     1   7     7 [45 67 84 67 45 78]
[4]     0   8     9 [45 67 84 67 45 78]
> subject(v4)
XInteger of length 6
 [1] 45 67 84 67 45 78
> 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 XInteger object:
> v4[[2]]
XInteger of length 5
 [1] 67 84 67 45 78
> 
> ## 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), "XInteger")
> Views(subject, start=-3:4, end=-3:4 + c(3:6, 6:3))
Views on a 6-integer XInteger 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]
> 
> ## Views on a big XInteger subject:
> subject <- XInteger(99999, sample(99, 99999, replace=TRUE) - 50)
> v5 <- Views(subject, start=1:99*1000, end=1:99*1001)
> v5
Views on a 99999-integer XInteger subject
subject: -21 -44  30 -49  19  10  26 -14 ...   0 -19  25  32 -20 -24  -3  24   3
views:
     start   end width
 [1]  1000  1001     2 [ 21 -27]
 [2]  2000  2002     3 [-36  41 -18]
 [3]  3000  3003     4 [ 49 -38 -35   2]
 [4]  4000  4004     5 [ 32  28  -3 -45  20]
 [5]  5000  5005     6 [ 11   8   2 -33  18  -1]
 [6]  6000  6006     7 [-17 -49 -15 -18 -21  28  18]
 [7]  7000  7007     8 [ 25  34 -26  45 -48 -38  32  38]
 [8]  8000  8008     9 [ -7  42 -39  18 -33  27  35  20 -14]
 [9]  9000  9009    10 [ -1  46 -36 -32  28  40   7  48  18  36]
 ...   ...   ...   ... ...
[91] 91000 91091    92 [-12 -13  20 -49  14  18 ...  45  16 -36  45   8  -1  -7]
[92] 92000 92092    93 [-42 -11  30   4   9  37 ... -26  27   7  17 -19 -31  -1]
[93] 93000 93093    94 [-21  -3  27 -39  -4  33 ...  27 -13   7  -3  38 -35 -24]
[94] 94000 94094    95 [ 48 -25  35  16 -18  16 ...  39 -40   4   1  20  -5  48]
[95] 95000 95095    96 [ -5  43   8  11  29 -41 ...   0  46  36  31   3 -35  46]
[96] 96000 96096    97 [-10 -33  -2  44 -22  10 ...  -7  43  -3 -46  46  42  11]
[97] 97000 97097    98 [ 11  44 -36 -49   7 -22 ...  -3 -32  40  36  36 -28  -1]
[98] 98000 98098    99 [ 21  -3 -41  25 -48  18 ... -34  27  13 -49 -28  37 -36]
[99] 99000 99099   100 [ -5  10  27  33  40  47 ... -45 -23   2  26  36  44 -39]
> v5[-1]
Views on a 99999-integer XInteger subject
subject: -21 -44  30 -49  19  10  26 -14 ...   0 -19  25  32 -20 -24  -3  24   3
views:
     start   end width
 [1]  2000  2002     3 [-36  41 -18]
 [2]  3000  3003     4 [ 49 -38 -35   2]
 [3]  4000  4004     5 [ 32  28  -3 -45  20]
 [4]  5000  5005     6 [ 11   8   2 -33  18  -1]
 [5]  6000  6006     7 [-17 -49 -15 -18 -21  28  18]
 [6]  7000  7007     8 [ 25  34 -26  45 -48 -38  32  38]
 [7]  8000  8008     9 [ -7  42 -39  18 -33  27  35  20 -14]
 [8]  9000  9009    10 [ -1  46 -36 -32  28  40   7  48  18  36]
 [9] 10000 10010    11 [  1   7   8  42 -37 -29 -35  -6   7 -39 -40]
 ...   ...   ...   ... ...
[90] 91000 91091    92 [-12 -13  20 -49  14  18 ...  45  16 -36  45   8  -1  -7]
[91] 92000 92092    93 [-42 -11  30   4   9  37 ... -26  27   7  17 -19 -31  -1]
[92] 93000 93093    94 [-21  -3  27 -39  -4  33 ...  27 -13   7  -3  38 -35 -24]
[93] 94000 94094    95 [ 48 -25  35  16 -18  16 ...  39 -40   4   1  20  -5  48]
[94] 95000 95095    96 [ -5  43   8  11  29 -41 ...   0  46  36  31   3 -35  46]
[95] 96000 96096    97 [-10 -33  -2  44 -22  10 ...  -7  43  -3 -46  46  42  11]
[96] 97000 97097    98 [ 11  44 -36 -49   7 -22 ...  -3 -32  40  36  36 -28  -1]
[97] 98000 98098    99 [ 21  -3 -41  25 -48  18 ... -34  27  13 -49 -28  37 -36]
[98] 99000 99099   100 [ -5  10  27  33  40  47 ... -45 -23   2  26  36  44 -39]
> v5[[5]]
XInteger of length 6
 [1]  11   8   2 -33  18  -1
> 
> ## 31 adjacent views:
> successiveViews(subject, 40:10)
Views on a 99999-integer XInteger subject
subject: -21 -44  30 -49  19  10  26 -14 ...   0 -19  25  32 -20 -24  -3  24   3
views:
     start end width
 [1]     1  40    40 [-21 -44  30 -49  19  10 ...  -3 -15 -18  34 -22 -29  36]
 [2]    41  79    39 [ 10 -36 -21  29  45  15 ... -39 -46   5  41 -23  17  43]
 [3]    80 117    38 [ -2 -29  47   6   7 -49 ... -40 -14 -11   5 -49 -33 -11]
 [4]   118 154    37 [ 34 -30  34 -22 -22  31 ...  27  34 -24 -20 -48 -10   7]
 [5]   155 190    36 [ 12  43  43  45  27  39 ...  34  44  27  -3  43 -21  48]
 [6]   191 225    35 [-15  35 -49  31 -37  30 ...  39 -49   7   2 -23 -15  -1]
 [7]   226 259    34 [  4  25  46   0 -15 -40 ... -42  46 -27 -37 -42 -46 -45]
 [8]   260 292    33 [-10  10 -44  10 -28  -4 ...  41 -11 -21  35  -6 -47  12]
 [9]   293 324    32 [-20 -16   9  31  11  42 ...  39  -1  47  23   7  14 -20]
 ...   ... ...   ... ...
[23]   650 667    18 [-32   7   0 -47 -21 -28 ... -29 -42 -20  44   0 -39  13]
[24]   668 684    17 [ -9  28 -23 -44 -35  -7 ... -38 -23 -14  46  47 -38  10]
[25]   685 700    16 [ -9 -13 -26  -8 -20 -46 ...   9 -27  47  36  -1 -37 -40]
[26]   701 715    15 [ 21 -43 -20  43  -4 -21 ... -27 -46  33   6   6  45  21]
[27]   716 729    14 [-48  47  18  -4 -45  17 -31  14 -37  40  29  -7  17 -42]
[28]   730 742    13 [  6   3 -36 -44   1 -37 -48  43  28  31 -30 -42   3]
[29]   743 754    12 [-34 -40 -13  -6  38 -33 -44  38  15  40 -42 -10]
[30]   755 765    11 [-28  44   8 -43 -35 -49  47  32 -41  11 -41]
[31]   766 775    10 [ 24  -8 -35  25  33 -23 -49   8  46 -32]
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>