Last data update: 2014.03.03

R: List of Ranges
RangesList-classR Documentation

List of Ranges

Description

An extension of List that holds only Ranges objects. Useful for storing ranges over a set of spaces (e.g. chromosomes), each of which requires a separate Ranges object. As a Vector, RangesList may be annotated with its universe identifier (e.g. a genome) in which all of its spaces exist.

Accessors

In the code snippets below, x is a RangesList object.

All of these accessors collapse over the spaces:

start(x), start(x) <- value: Get or set the starts of the ranges. When setting the starts, value can be an integer vector of length sum(elementNROWS(x)) or an IntegerList object of length length(x) and names names(x).

end(x), end(x) <- value: Get or set the ends of the ranges. When setting the ends, value can be an integer vector of length sum(elementNROWS(x)) or an IntegerList object of length length(x) and names names(x).

width(x), width(x) <- value: Get or set the widths of the ranges. When setting the widths, value can be an integer vector of length sum(elementNROWS(x)) or an IntegerList object of length length(x) and names names(x).

space(x): Gets the spaces of the ranges as a character vector. This is equivalent to names(x), except each name is repeated according to the length of its element.

These accessors are for the universe identifier:

universe(x): gets the name of the universe as a single string, if one has been specified, NULL otherwise.

universe(x) <- value: sets the name of the universe to value, a single string or NULL.

Constructor

RangesList(..., universe = NULL): Each Ranges in ... becomes an element in the new RangesList, in the same order. This is analogous to the list constructor, except every argument in ... must be derived from Ranges. The universe is specified by the universe parameter, which should be a single string or NULL, to leave unspecified.

Coercion

In the code snippets below, x and from are a RangesList object.

as.data.frame(x, row.names = NULL, optional = FALSE, ..., value.name = "value", use.outer.mcols = FALSE, group_name.as.factor = FALSE): Coerces x to a data.frame. See as.data.frame on the List man page for details (?List).

as(from, "SimpleIRangesList"): Coerces from, to a SimpleIRangesList, requiring that all Ranges elements are coerced to internal IRanges elements. This is a convenient way to ensure that all Ranges have been imported into R (and that there is no unwanted overhead when accessing them).

as(from, "CompressedIRangesList"): Coerces from, to a CompressedIRangesList, requiring that all Ranges elements are coerced to internal IRanges elements. This is a convenient way to ensure that all Ranges have been imported into R (and that there is no unwanted overhead when accessing them).

as(from, "SimpleNormalIRangesList"): Coerces from, to a SimpleNormalIRangesList, requiring that all Ranges elements are coerced to internal NormalIRanges elements.

as(from, "CompressedNormalIRangesList"): Coerces from, to a CompressedNormalIRangesList, requiring that all Ranges elements are coerced to internal NormalIRanges elements.

Arithmetic Operations

Any arithmetic operation, such as x + y, x * y, etc, where x is a RangesList, is performed identically on each element. Currently, Ranges supports only the * operator, which zooms the ranges by a numeric factor.

Author(s)

Michael Lawrence

See Also

List, the parent of this class, for more functionality.

Examples

## ---------------------------------------------------------------------
## Basic manipulation
## ---------------------------------------------------------------------

range1 <- IRanges(start=c(1, 2, 3), end=c(5, 2, 8))
range2 <- IRanges(start=c(15, 45, 20, 1), end=c(15, 100, 80, 5))
named <- RangesList(one = range1, two = range2)
length(named) # 2
start(named) # same as start(c(range1, range2))
names(named) # "one" and "two"
named[[1]] # range1
unnamed <- RangesList(range1, range2)
names(unnamed) # NULL

# edit the width of the ranges in the list
edited <- named
width(edited) <- rep(c(3,2), elementNROWS(named))
edited

# same as list(range1, range2)
as.list(RangesList(range1, range2))

# coerce to data.frame
as.data.frame(named)

# set the universe
universe(named) <- "hg18"
universe(named)
RangesList(range1, range2, universe = "hg18")

## zoom in 2X
collection <- RangesList(one = range1, range2)
collection * 2

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(IRanges)
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

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/IRanges/RangesList-class.Rd_%03d_medium.png", width=480, height=480)
> ### Name: RangesList-class
> ### Title: List of Ranges
> ### Aliases: class:RangesList-class class:SimpleRangesList-class
> ###   RangesList-class SimpleRangesList-class RangesList SimpleRangesList
> ###   end,RangesList-method end<-,RangesList-method width,RangesList-method
> ###   width<-,RangesList-method start,RangesList-method
> ###   start<-,RangesList-method space space,RangesList-method
> ###   universe,RangesList-method universe<-,RangesList-method universe
> ###   universe<- isNormal,RangesList-method
> ###   whichFirstNotNormal,RangesList-method
> ###   coerce,RangesList,IRangesList-method
> ###   coerce,RangesList,CompressedIRangesList-method
> ###   coerce,RangesList,SimpleIRangesList-method
> ###   coerce,SimpleRangesList,SimpleIRangesList-method
> ###   coerce,RangesList,SimpleRangesList-method
> ###   coerce,RangesList,SimpleNormalIRangesList-method
> ###   coerce,SimpleIRangesList,SimpleNormalIRangesList-method
> ###   coerce,NormalIRangesList,CompressedNormalIRangesList-method
> ###   coerce,CompressedIRangesList,CompressedNormalIRangesList-method
> ###   coerce,RangesList,CompressedNormalIRangesList-method
> ###   coerce,RangesList,NormalIRangesList-method
> ###   coerce,LogicalList,IRangesList-method
> ###   coerce,LogicalList,CompressedIRangesList-method
> ###   coerce,LogicalList,SimpleIRangesList-method
> ###   coerce,LogicalList,NormalIRangesList-method
> ###   coerce,LogicalList,CompressedNormalIRangesList-method
> ###   coerce,LogicalList,SimpleNormalIRangesList-method
> ###   coerce,RleList,IRangesList-method
> ###   coerce,RleList,CompressedIRangesList-method
> ###   coerce,RleList,SimpleIRangesList-method
> ###   coerce,RleList,NormalIRangesList-method
> ###   coerce,RleList,CompressedNormalIRangesList-method
> ###   coerce,RleList,SimpleNormalIRangesList-method
> ###   coerce,list,RangesList-method merge,RangesList,missing-method
> ###   merge,missing,RangesList-method merge,RangesList,RangesList-method
> ###   show,RangesList-method showAsCell,RangesList-method
> ### Keywords: methods classes
> 
> ### ** Examples
> 
> ## ---------------------------------------------------------------------
> ## Basic manipulation
> ## ---------------------------------------------------------------------
> 
> range1 <- IRanges(start=c(1, 2, 3), end=c(5, 2, 8))
> range2 <- IRanges(start=c(15, 45, 20, 1), end=c(15, 100, 80, 5))
> named <- RangesList(one = range1, two = range2)
> length(named) # 2
[1] 2
> start(named) # same as start(c(range1, range2))
IntegerList of length 2
[["one"]] 1 2 3
[["two"]] 15 45 20 1
> names(named) # "one" and "two"
[1] "one" "two"
> named[[1]] # range1
IRanges object with 3 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         1         5         5
  [2]         2         2         1
  [3]         3         8         6
> unnamed <- RangesList(range1, range2)
> names(unnamed) # NULL
NULL
> 
> # edit the width of the ranges in the list
> edited <- named
> width(edited) <- rep(c(3,2), elementNROWS(named))
> edited
RangesList of length 2
$one
IRanges object with 3 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         1         3         3
  [2]         2         4         3
  [3]         3         5         3

$two
IRanges object with 4 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]        15        16         2
  [2]        45        46         2
  [3]        20        21         2
  [4]         1         2         2

> 
> # same as list(range1, range2)
> as.list(RangesList(range1, range2))
[[1]]
IRanges object with 3 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         1         5         5
  [2]         2         2         1
  [3]         3         8         6

[[2]]
IRanges object with 4 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]        15        15         1
  [2]        45       100        56
  [3]        20        80        61
  [4]         1         5         5

> 
> # coerce to data.frame
> as.data.frame(named)
  group group_name start end width
1     1        one     1   5     5
2     1        one     2   2     1
3     1        one     3   8     6
4     2        two    15  15     1
5     2        two    45 100    56
6     2        two    20  80    61
7     2        two     1   5     5
> 
> # set the universe
> universe(named) <- "hg18"
> universe(named)
[1] "hg18"
> RangesList(range1, range2, universe = "hg18")
RangesList of length 2
[[1]]
IRanges object with 3 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         1         5         5
  [2]         2         2         1
  [3]         3         8         6

[[2]]
IRanges object with 4 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]        15        15         1
  [2]        45       100        56
  [3]        20        80        61
  [4]         1         5         5

> 
> ## zoom in 2X
> collection <- RangesList(one = range1, range2)
> collection * 2
RangesList of length 2
$one
IRanges object with 3 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]         2         3         2
  [2]         2         1         0
  [3]         4         6         3

[[2]]
IRanges object with 4 ranges and 0 metadata columns:
          start       end     width
      <integer> <integer> <integer>
  [1]        15        14         0
  [2]        59        86        28
  [3]        35        64        30
  [4]         2         3         2

> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>