Hits-class {IRanges}R Documentation

Set of hits between 2 vector-like objects

Description

The Hits class stores a set of "hits" between the elements in one vector-like object (called the "query") and the elements in another (called the "subject"). Currently, Hits are used to represent the result of a call to findOverlaps, though other operations producing "hits" are imaginable.

Details

The as.matrix and as.data.frame methods coerce a Hits object to a two column matrix or data.frame with one row for each hit, where the value in the first column is the index of an element in the query and the value in the second column is the index of an element in the subject.

The as.table method counts the number of hits for each query element and outputs the counts as a table.

To transpose a Hits x, so that the subject and query are interchanged, call t(x). This allows, for example, counting the number of hits for each subject element using as.table.

When the Hits object is the result of a call to findOverlaps, the actual regions of intersection between the overlapping ranges can be obtained with the ranges accessor.

Coercion

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

as.matrix(x): Coerces x to a two column integer matrix, with each row representing a hit between a query index (first column) and subject index (second column).

as(from, "DataFrame"): Creates a DataFrame by combining the the result of as.matrix(from) with elementMetadata(from).

as.data.frame(x): Attempts to coerce the result of as(from, "DataFrame") to a data.frame.

as.table(x): counts the number of hits for each query element in x and outputs the counts as a table.

t(x): Interchange the query and subject in x, returns a transposed Hits.

as.list(x): Returns a list with an element for each query, where each element contains the indices of the subjects that have a hit with the corresponding query.

as(x, "List"): Like as.list, above.

Extraction

x[i]: Extracts a subset of the hits. The index argument i may be logical or numeric. If numeric, be sure that i does not contain any duplicates, which would violate the set property of Hits.

Accessors

queryHits(x): Equivalent to as.data.frame(x)[[1]].

subjectHits(x): Equivalent to as.data.frame(x)[[2]].

ranges(x, query, subject): returns a Ranges holding the intersection of the ranges in the Ranges objects query and subject, which should be the same subject and query used in the call to findOverlaps that generated x. Eventually, we might store the query and subject inside x, in which case the arguments would be redundant.

length(x): get the number of hits

queryLength(x), nrow(x): get the number of elements in the query

subjectLength(x), ncol(x): get the number of elements in the subject

dim(x): get a two-element integer vector, essentially c(nrow(x), ncol(x)).

Set Operations

A Hits object is a set of matchings, each from a query index to a subject index. The basic set operation API has been implemented to treat Hits in this manner. This includes %in%, intersect, union, and setdiff.

Author(s)

Michael Lawrence

See Also

findOverlaps, which generates an instance of this class.

Examples

  query <- IRanges(c(1, 4, 9), c(5, 7, 10))
  subject <- IRanges(c(2, 2, 10), c(2, 3, 12))
  tree <- IntervalTree(subject)
  matchings <- findOverlaps(query, tree)

  as.matrix(matchings)
  as.data.frame(matchings)

  as.table(matchings) # hits per query
  as.table(t(matchings)) # hits per subject

[Package IRanges version 1.14.4 Index]