Pairs objects

Description

Pairs is a Vector that stores two parallel vectors (any object that can be a column in a DataFrame). It provides conveniences for performing binary operations on the vectors, as well as for converting between an equivalent list representation. Virtually all of the typical R vector operations should behave as expected.

A typical use case is representing the pairing from a findOverlaps call, for which findOverlapPairs is a shortcut.

Constructor

Pairs(first, second, ..., names = NULL, hits = NULL): Constructs a Pairs object by aligning the vectors first and second. The vectors must have the same length, unless hits is specified. Arguments in ... are combined as columns in the mcols of the result. The names argument specifies the names on the result. If hits is not NULL, it should be a Hits object that collates the elements in first and second to produce the corresponding pairs.

Accessors

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

names(x), names(x) <- value: get or set the names

first(x), first(x) <- value: get or set the first member of each pair

second(x), second(x) <- value: get or set the second member of each pair

Coercion

zipup(x): Interleaves the Pairs object x into a list, where each element is composed of a pair. The type of list depends on the type of the elements.

zipdown(x): The inverse of zipup(). Converts x, a list where every element is of length 2, to a Pairs object, by assuming that each element of the list represents a pair.

Subsetting

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

x[i]: Subset the Pairs object.

Author(s)

Michael Lawrence

See Also

  • Hits-class, a typical way to define a pairing.

  • findOverlapPairs in the IRanges package, which generates an instance of this class based on overlaps.

  • setops-methods in the IRanges package, for set operations on Pairs objects.

Examples

1
2
3
4
5
6
7
8
p <- Pairs(1:10, Rle(1L, 10), score=rnorm(10), names=letters[1:10])
identical(first(p), 1:10)
mcols(p)$score
p 
as.data.frame(p)
z <- zipup(p)
first(p) <- Rle(1:10)
identical(zipdown(z), p)