IRanges (version 2.6.1)

IRanges-utils: IRanges utility functions


Utility functions for creating or modifying IRanges objects.


## Create an IRanges instance: successiveIRanges(width, gapwidth=0, from=1) breakInChunks(totalsize, chunksize, nchunk)
## Turn a logical vector into a set of ranges: whichAsIRanges(x)
## Coercion: asNormalIRanges(x, force=TRUE)


A vector of non-negative integers (with no NAs) specifying the widths of the ranges to create.
A single integer or an integer vector with one less element than the width vector specifying the widths of the gaps separating one range from the next one.
A single integer specifying the starting position of the first range.
A single non-negative integer. The total size of the object to break.
A single positive integer. The size of the chunks (last chunk might be smaller).
A single positive integer. The number of chunks.
A logical vector for whichAsIRanges. An IRanges object for asNormalIRanges.
TRUE or FALSE. Should x be turned into a NormalIRanges object even if isNormal(x) is FALSE?


successiveIRanges returns an IRanges instance containing the ranges that have the widths specified in the width vector and are separated by the gaps specified in gapwidth. The first range starts at position from. When gapwidth=0 and from=1 (the defaults), the returned IRanges can be seen as a partitioning of the 1:sum(width) interval. See ?Partitioning for more details on this.

whichAsIRanges returns an IRanges instance containing all of the ranges where x is TRUE.

If force=TRUE (the default), then asNormalIRanges will turn x into a NormalIRanges instance by reordering and reducing the set of ranges if necessary (i.e. only if isNormal(x) is FALSE, otherwise the set of ranges will be untouched). If force=FALSE, then asNormalIRanges will turn x into a NormalIRanges instance only if isNormal(x) is TRUE, otherwise it will raise an error. Note that when force=FALSE, the returned object is guaranteed to contain exactly the same set of ranges than x. as(x, "NormalIRanges") is equivalent to asNormalIRanges(x, force=TRUE).

See Also

Ranges-class, IRanges-class,

intra-range-methods for intra range transformations,

inter-range-methods for inter range transformations,

setops-methods, solveUserSEW, successiveViews


Run this code
  vec <- as.integer(c(19, 5, 0, 8, 5))


  breakInChunks(600999, 50000)  # 13 chunks of size 50000 (last chunk is
                                # smaller).

  whichAsIRanges(vec >= 5)

  x <- IRanges(start=c(-2L, 6L, 9L, -4L, 1L, 0L, -6L, 10L),
               width=c( 5L, 0L, 6L,  1L, 4L, 3L,  2L,  3L))
  asNormalIRanges(x)  # 3 non-empty ranges ordered from left to right and
                      # separated by gaps of width >= 1.

  ## More on normality:
  isNormal(x16)                        # FALSE
  if (interactive())
      x16 <- asNormalIRanges(x16)      # Error!
  whichFirstNotNormal(x16)             # 57
  isNormal(x16[1:56])                  # TRUE
  xx <- asNormalIRanges(x16[1:56])

Run the code above in your browser using DataCamp Workspace