Learn R Programming

bumphunter (version 1.12.0)

annotateNearest: Annotate the results of nearest

Description

Annotate the results of nearest with more information about the type of match.

Usage

annotateNearest(x, subject, annotate = TRUE, ...)

Arguments

x
The query. An IRanges or GenomicRanges object, or a data.frame with columns for start, end, and, optionally, chr or seqnames.
subject
The subject. An IRanges or GenomicRanges object, or a data.frame with columns for start, end, and, optionally, chr or seqnames.
annotate
Whether to annotate the result.
...
Arguments passed along to nearest.

Value

A data frame with columns c("distance", "subjectHits", "type", "amountOverlap", "insideDistamce", "size1", "size2") unless annotate is FALSE, in which case only the first two columns are returned as an integer matrix.
dist
Signed distance to the nearest target. Queries downstream from (i.e. past) their nearest target are given a negative distance.
subjectHits
The index of the nearest target.
type
one of c("inside", "cover", "disjoint", "overlap").
amountOverlap
The width of the overlap region, if any.
insideDistance
When a query is contained in its nearest target, the signed minimum of the two distances target-start-to-query-start and query-end-to-target-end. The former is taken positive, and the latter, which wins in ties, negative. dist will be 0 in this case.
size1
equals width(x).
size2
equals width(subject).

Details

This function runs nearest and then annotates the nearest hit. Note that the nearest subject range to a given query may not be unique and we arbitrarily chose one as done by default by nearest.

See Also

nearest, matchGenes

Examples

Run this code
query <- GRanges(seqnames = 'chr1', IRanges(c(1, 4, 9), c(5, 7, 10)))
subject <- GRanges('chr1', IRanges(c(2, 2, 10), c(2, 3, 12)))
nearest(query, subject)
distanceToNearest(query, subject)

## showing 'cover' and 'disjoint', and 'amountOverlap'
annotateNearest(query, subject)

## showing 'inside' and 'insideDist', and 'amountOverlap'
annotateNearest(subject, query)
annotateNearest(GRanges('chr1', IRanges(3,3)), GRanges('chr1', IRanges(2,5)))
annotateNearest(GRanges('chr1', IRanges(3,4)), GRanges('chr1', IRanges(2,5)))
annotateNearest(GRanges('chr1', IRanges(4,4)), GRanges('chr1', IRanges(2,5)))

Run the code above in your browser using DataLab