Hits objects
Description
The Hits class is a container for representing a set of hits between a set of left nodes and a set of right nodes. Note that only the hits are stored in the object. No information about the left or right nodes is stored, except their number.
For example, the findOverlaps
function, defined
and documented in the IRanges package, returns the hits between
the query
and subject
arguments in a Hits
object.
Usage
1 2 3 4 5 6 7 
Arguments
from, to 
2 integer vectors of the same length.
The values in 
nLnode, nRnode 
Number of left and right nodes. 
... 
Metadata columns to set on the Hits object. All the metadata columns must
be vectorlike objects of the same length as 
sort.by.query 
Should the hits in the returned object be sorted by query? If yes, then a SortedByQueryHits object is returned (SortedByQueryHits is a subclass of Hits). 
nnode 
Number of nodes. 
Accessors
In the code snippets below, x
is a Hits
object.
length(x)
: get the number of hitsfrom(x)
: Equivalent toas.data.frame(x)[[1]]
.to(x)
: Equivalent toas.data.frame(x)[[2]]
.nLnode(x)
,nrow(x)
: get the number of left nodesnRnode(x)
,ncol(x)
: get the number of right nodescountLnodeHits(x)
: Counts the number of hits for each left node, returning an integer vector.countRnodeHits(x)
: Counts the number of hits for each right node, returning an integer vector.
The following accessors are just aliases for the above accessors:
queryHits(x)
: alias forfrom(x)
.subjectHits(x)
: alias forto(x)
.queryLength(x)
: alias fornLnode(x)
.subjectLength(x)
: alias fornRnode(x)
.countQueryHits(x)
: alias forcountLnodeHits(x)
.countSubjectHits(x)
: alias forcountRnodeHits(x)
.
Coercion
In the code snippets below, x
is a Hits
object.
as.matrix(x)
: Coercesx
to a two column integer matrix, with each row representing a hit between a left node (first column) and a right node (second column).as.table(x)
: Counts the number of hits for each left node inx
and outputs the counts as atable
.
Subsetting
In the code snippets below, x
is a Hits
object.
x[i]
: Subset the Hits object.
Other transformations
In the code snippets below, x
is a Hits
object.
t(x)
: Transposex
by interchanging the left and right nodes. This allows, for example, counting the number of hits for each right node usingas.table
.remapHits(x, Lnodes.remapping=NULL, new.nLnode=NA, Rnodes.remapping=NULL, new.nRnode=NA)
: Only supports SortedByQueryHits objects at the moment.Remaps the left and/or right nodes in
x
. The left nodes are remapped thru the map specified via theLnodes.remapping
andnew.nLnode
arguments. The right nodes are remapped thru the map specified via theRnodes.remapping
andnew.nRnode
arguments.Lnodes.remapping
must represent a function defined on the 1..M interval that takes values in the 1..N interval, where N isnLnode(x)
and M is the value specified by the user via thenew.nLnode
argument. Note that this mapping function doesn't need to be injective or surjective. Also it is not represented by an R function but by an integer vector of length M with no NAs. More preciselyLnodes.remapping
can be NULL (identity map), or a vector ofnLnode(x)
nonNA integers that are >= 1 and <=new.nLnode
, or a factor of lengthnLnode(x)
with no NAs (a factor is treated as an integer vector, and, if missing,new.nLnode
is taken to be its number of levels). Note that a factor will typically be used to represent a mapping function that is not injective.The same applies to the
Rnodes.remapping
.remapHits
returns a Hits object wherefrom(x)
andto(x)
have been remapped thru the 2 specified maps. This remapping is actually only the 1st step of the transformation, and is followed by 2 additional steps: (2) the removal of duplicated hits, and (3) the reordering of the hits (first by query hits, then by subject hits). Note that if the 2 maps are injective then the remapping won't introduce duplicated hits, so, in that case, step (2) is a noop (but is still performed). Also if the "query map" is strictly ascending and the "subject map" ascending then the remapping will preserve the order of the hits, so, in that case, step (3) is also a noop (but is still performed).breakTies(x, method=c("first", "last"))
: Restrict the hits so that every left node maps to at most one right node. Ifmethod
is “first”, for each left node, select the edge with the first (lowest rank) right node, if any. Ifmethod
is “last”, select the edge with the last (highest rank) right node.
SelfHits
A SelfHits object is a Hits object where the left and right nodes are
identical. For a SelfHits object x
, nLnode(x)
is equal to
nRnode(x)
. The object can be seen as an oriented graph where
nLnode
is the nb of nodes and the hits are the (oriented) edges.
SelfHits objects support the same set of accessors as Hits objects
plus the nnode()
accessor that is equivalent to nLnode()
and nRnode()
.
We also provide two little utilities to operate on a SelfHits object
x
:
isSelfHit(x)
: A self hit is an edge from a node to itself.isSelfHit(x)
returns a logical vector parallel tox
indicating which elements inx
are self hits.isRedundantHit(x)
: When there is more than 1 edge between 2 given nodes (regardless of orientation), the extra edges are considered to be redundant hits.isRedundantHit(x)
returns a logical vector parallel tox
indicating which elements inx
are redundant hits.
Author(s)
Michael Lawrence and Hervé Pagès
See Also

Hitscomparison for comparing and ordering hits.
The
findOverlaps
function in the IRanges package which returns SortedByQueryHits object.
Hitsexamples in the IRanges package, for some examples of Hits object basic manipulation.

setopsmethods in the IRanges package, for set operations on Hits objects.
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 45 46  from < c(5, 2, 3, 3, 3, 2)
to < c(11, 15, 5, 4, 5, 11)
id < letters[1:6]
Hits(from, to, 7, 15, id)
Hits(from, to, 7, 15, id, sort.by.query=TRUE)
## 
## selectHits()
## 
x < c("a", "b", "a", "c", "d")
table < c("a", "e", "d", "a", "a", "d")
hits < findMatches(x, table) # sorts the hits by query
hits
selectHits(hits, select="all") # noop
selectHits(hits, select="first")
selectHits(hits, select="last")
selectHits(hits, select="arbitrary")
selectHits(hits, select="count")
## 
## remapHits()
## 
Lnodes.remapping < factor(c(a="A", b="B", c="C", d="D")[x],
levels=LETTERS[1:4])
remapHits(hits, Lnodes.remapping=Lnodes.remapping)
## See ?`Hitsexamples` in the IRanges package for more examples of basic
## manipulation of Hits objects.
## 
## SelfHits objects
## 
hits2 < SelfHits(c(2, 3, 3, 3, 3, 3, 4, 4, 4), c(4, 3, 2:4, 2, 2:3, 2), 4)
## Hits 2 and 4 are self hits (from 3rd node to itself):
which(isSelfHit(hits2))
## Hits 4, 6, 7, 8, and 9, are redundant hits:
which(isRedundantHit(hits2))
hits3 < findMatches(x)
hits3[!isSelfHit(hits3)]
hits3[!(isSelfHit(hits3)  isRedundantHit(hits3))]
