IRanges-class: IRanges and NormalIRanges objects

Description Constructor Coercion Concatenation Methods for NormalIRanges objects Author(s) See Also Examples

Description

The IRanges class is a simple implementation of the IntegerRanges container where 2 integer vectors of the same length are used to store the start and width values. See the IntegerRanges virtual class for a formal definition of IntegerRanges objects and for their methods (all of them should work for IRanges objects).

Some subclasses of the IRanges class are: NormalIRanges, Views, etc...

A NormalIRanges object is just an IRanges object that is guaranteed to be "normal". See the Normality section in the man page for IntegerRanges objects for the definition and properties of "normal" IntegerRanges objects.

Constructor

See ?`IRanges-constructor`.

Coercion

ranges(x, use.names=FALSE, use.mcols=FALSE): Squeeze the ranges out of IntegerRanges object x and return them in an IRanges object parallel to x (i.e. same length as x).

as(from, "IRanges"): Creates an IRanges instance from an IntegerRanges derivative, or from a logical or integer vector. When from is a logical vector, the resulting IRanges object contains the indices for the runs of TRUE values. When from is an integer vector, the elements are either singletons or "increase by 1" sequences.

as(from, "NormalIRanges"): Creates a NormalIRanges instance from a logical or integer vector. When from is an integer vector, the elements must be strictly increasing.

Concatenation

c(x, ..., ignore.mcols=FALSE): Concatenate IRanges object x and the IRanges objects in ... together. See ?c in the S4Vectors package for more information about concatenating Vector derivatives.

Methods for NormalIRanges objects

max(x): The maximum value in the finite set of integers represented by x.

min(x): The minimum value in the finite set of integers represented by x.

Author(s)

Hervé Pagès

See Also

Examples

 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
showClass("IRanges")  # shows the known subclasses

## ---------------------------------------------------------------------
## A. MANIPULATING IRanges OBJECTS
## ---------------------------------------------------------------------
## All the methods defined for IntegerRanges objects work on IRanges
## objects.
## See ?IntegerRanges for some examples.
## Also see ?`IRanges-utils` and ?`setops-methods` for additional
## operations on IRanges objects.
  
## Concatenating IRanges objects
ir1 <- IRanges(c(1, 10, 20), width=5)
mcols(ir1) <- DataFrame(score=runif(3))
ir2 <- IRanges(c(101, 110, 120), width=10)
mcols(ir2) <- DataFrame(score=runif(3))
ir3 <- IRanges(c(1001, 1010, 1020), width=20)
mcols(ir3) <- DataFrame(value=runif(3))
some.iranges <- c(ir1, ir2)
## all.iranges <- c(ir1, ir2, ir3) ## This will raise an error
all.iranges <- c(ir1, ir2, ir3, ignore.mcols=TRUE)
stopifnot(is.null(mcols(all.iranges)))

## ---------------------------------------------------------------------
## B. A NOTE ABOUT PERFORMANCE
## ---------------------------------------------------------------------
## Using an IRanges object for storing a big set of ranges is more
## efficient than using a standard R data frame:
N <- 2000000L  # nb of ranges
W <- 180L      # width of each range
start <- 1L
end <- 50000000L
set.seed(777)
range_starts <- sort(sample(end-W+1L, N))
range_widths <- rep.int(W, N)
## Instantiation is faster
system.time(x <- IRanges(start=range_starts, width=range_widths))
system.time(y <- data.frame(start=range_starts, width=range_widths))
## Subsetting is faster
system.time(x16 <- x[c(TRUE, rep.int(FALSE, 15))])
system.time(y16 <- y[c(TRUE, rep.int(FALSE, 15)), ])
## Internal representation is more compact
object.size(x16)
object.size(y16)

Example output

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, sd, var, xtabs

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

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, basename, cbind, colMeans, colSums, colnames,
    dirname, 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,
    rowMeans, rowSums, rownames, sapply, setdiff, sort, table, tapply,
    union, unique, unsplit, which, which.max, which.min

Loading required package: S4Vectors
Loading required package: stats4

Attaching package: 'S4Vectors'

The following object is masked from 'package:base':

    expand.grid

Class "IRanges" [package "IRanges"]

Slots:
                                                                              
Name:              start             width             NAMES       elementType
Class:           integer           integer character_OR_NULL         character
                                          
Name:    elementMetadata          metadata
Class: DataTable_OR_NULL              list

Extends: 
Class "IPosRanges", directly
Class "IntegerRanges", by class "IPosRanges", distance 2
Class "Ranges", by class "IPosRanges", distance 3
Class "IntegerRanges_OR_missing", by class "IntegerRanges", distance 3
Class "List", by class "IPosRanges", distance 4
Class "Vector", by class "IPosRanges", distance 5
Class "list_OR_List", by class "IPosRanges", distance 5
Class "Annotated", by class "IPosRanges", distance 6

Known Subclasses: "NormalIRanges", "GroupingIRanges"
   user  system elapsed 
  0.141   0.020   0.162 
   user  system elapsed 
  0.001   0.000   0.001 
   user  system elapsed 
  0.012   0.000   0.013 
   user  system elapsed 
  0.018   0.000   0.018 
1001472 bytes
1500768 bytes

IRanges documentation built on Dec. 14, 2020, 2 a.m.