Last data update: 2014.03.03

R: Finding the nearest range neighbor in...
nearest-methodsR Documentation

Finding the nearest range neighbor in RangedSummarizedExperiment objects

Description

This man page documents the nearest methods and family (i.e. precede, follow, distance, and distanceToNearest methods) for RangedSummarizedExperiment objects.

Usage

## S4 method for signature 'RangedSummarizedExperiment,ANY'
precede(x, subject, select=c("arbitrary", "all"),
        ignore.strand=FALSE)
## S4 method for signature 'ANY,RangedSummarizedExperiment'
precede(x, subject, select=c("arbitrary", "all"),
        ignore.strand=FALSE)

## S4 method for signature 'RangedSummarizedExperiment,ANY'
follow(x, subject, select=c("arbitrary", "all"),
        ignore.strand=FALSE)
## S4 method for signature 'ANY,RangedSummarizedExperiment'
follow(x, subject, select=c("arbitrary", "all"),
        ignore.strand=FALSE)

## S4 method for signature 'RangedSummarizedExperiment,ANY'
nearest(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE)
## S4 method for signature 'ANY,RangedSummarizedExperiment'
nearest(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE)

## S4 method for signature 'RangedSummarizedExperiment,ANY'
distance(x, y, ignore.strand=FALSE, ...)
## S4 method for signature 'ANY,RangedSummarizedExperiment'
distance(x, y, ignore.strand=FALSE, ...)

## S4 method for signature 'RangedSummarizedExperiment,ANY'
distanceToNearest(x, subject, ignore.strand=FALSE, ...)
## S4 method for signature 'ANY,RangedSummarizedExperiment'
distanceToNearest(x, subject, ignore.strand=FALSE, ...)

Arguments

x, subject

One of these two arguments must be a RangedSummarizedExperiment object.

select, ignore.strand

See ?nearest in the GenomicRanges package.

y

For the distance methods, one of x or y must be a RangedSummarizedExperiment object.

...

Additional arguments for methods.

Details

These methods operate on the rowRanges component of the RangedSummarizedExperiment object, which can be a GenomicRanges or GRangesList object.

More precisely, if any of the above functions is passed a RangedSummarizedExperiment object thru the x, subject, and/or y argument, then it behaves as if rowRanges(x), rowRanges(subject), and/or rowRanges(y) had been passed instead.

See ?nearest in the GenomicRanges package for the details of how nearest and family operate on GenomicRanges and GRangesList objects.

Value

See ?nearest in the GenomicRanges package.

See Also

  • RangedSummarizedExperiment objects.

  • The nearest man page in the GenomicRanges package where the nearest family of methods for GenomicRanges and GRangesList objects is documented.

Examples

nrows <- 20; ncols <- 6
counts <- matrix(runif(nrows * ncols, 1, 1e4), nrows)
rowRanges <- GRanges(rep(c("chr1", "chr2"), c(5, 15)),
                     IRanges(sample(1000L, 20), width=100),
                     strand=Rle(c("+", "-"), c(12, 8)))
colData <- DataFrame(Treatment=rep(c("ChIP", "Input"), 3),
                     row.names=LETTERS[1:6])
rse0 <- SummarizedExperiment(assays=SimpleList(counts=counts),
                             rowRanges=rowRanges, colData=colData)
rse1 <- shift(rse0, 100)

res <- nearest(rse0, rse1)
res
stopifnot(identical(res, nearest(rowRanges(rse0), rowRanges(rse1))))
stopifnot(identical(res, nearest(rse0, rowRanges(rse1))))
stopifnot(identical(res, nearest(rowRanges(rse0), rse1)))

res <- nearest(rse0)  # missing subject
res
stopifnot(identical(res, nearest(rowRanges(rse0))))

hits <- nearest(rse0, rse1, select="all")
hits
stopifnot(identical(
  hits,
  nearest(rowRanges(rse0), rowRanges(rse1), select="all")
))
stopifnot(identical(
  hits,
  nearest(rse0, rowRanges(rse1), select="all")
))
stopifnot(identical(
  hits,
  nearest(rowRanges(rse0), rse1, select="all")
))

Results


R version 3.3.1 (2016-06-21) -- "Bug in Your Hair"
Copyright (C) 2016 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu (64-bit)

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(SummarizedExperiment)
Loading required package: GenomicRanges
Loading required package: BiocGenerics
Loading required package: parallel

Attaching package: 'BiocGenerics'

The following objects are masked from 'package:parallel':

    clusterApply, clusterApplyLB, clusterCall, clusterEvalQ,
    clusterExport, clusterMap, parApply, parCapply, parLapply,
    parLapplyLB, parRapply, parSapply, parSapplyLB

The following objects are masked from 'package:stats':

    IQR, mad, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, append,
    as.data.frame, cbind, colnames, do.call, duplicated, eval, evalq,
    get, grep, grepl, intersect, is.unsorted, lapply, lengths, mapply,
    match, mget, order, paste, pmax, pmax.int, pmin, pmin.int, rank,
    rbind, rownames, sapply, setdiff, sort, table, tapply, union,
    unique, unsplit

Loading required package: S4Vectors
Loading required package: stats4

Attaching package: 'S4Vectors'

The following objects are masked from 'package:base':

    colMeans, colSums, expand.grid, rowMeans, rowSums

Loading required package: IRanges
Loading required package: GenomeInfoDb
Loading required package: Biobase
Welcome to Bioconductor

    Vignettes contain introductory material; view with
    'browseVignettes()'. To cite Bioconductor, see
    'citation("Biobase")', and for packages 'citation("pkgname")'.

> png(filename="/home/ddbj/snapshot/RGM3/R_BC/result/SummarizedExperiment/nearest-methods.Rd_%03d_medium.png", width=480, height=480)
> ### Name: nearest-methods
> ### Title: Finding the nearest range neighbor in RangedSummarizedExperiment
> ###   objects
> ### Aliases: nearest-methods precede
> ###   precede,RangedSummarizedExperiment,ANY-method
> ###   precede,ANY,RangedSummarizedExperiment-method
> ###   precede,RangedSummarizedExperiment,RangedSummarizedExperiment-method
> ###   follow follow,RangedSummarizedExperiment,ANY-method
> ###   follow,ANY,RangedSummarizedExperiment-method
> ###   follow,RangedSummarizedExperiment,RangedSummarizedExperiment-method
> ###   nearest nearest,RangedSummarizedExperiment,ANY-method
> ###   nearest,ANY,RangedSummarizedExperiment-method
> ###   nearest,RangedSummarizedExperiment,RangedSummarizedExperiment-method
> ###   distance distance,RangedSummarizedExperiment,ANY-method
> ###   distance,ANY,RangedSummarizedExperiment-method
> ###   distance,RangedSummarizedExperiment,RangedSummarizedExperiment-method
> ###   distanceToNearest
> ###   distanceToNearest,RangedSummarizedExperiment,ANY-method
> ###   distanceToNearest,ANY,RangedSummarizedExperiment-method
> ###   distanceToNearest,RangedSummarizedExperiment,RangedSummarizedExperiment-method
> ### Keywords: methods utilities
> 
> ### ** Examples
> 
> nrows <- 20; ncols <- 6
> counts <- matrix(runif(nrows * ncols, 1, 1e4), nrows)
> rowRanges <- GRanges(rep(c("chr1", "chr2"), c(5, 15)),
+                      IRanges(sample(1000L, 20), width=100),
+                      strand=Rle(c("+", "-"), c(12, 8)))
> colData <- DataFrame(Treatment=rep(c("ChIP", "Input"), 3),
+                      row.names=LETTERS[1:6])
> rse0 <- SummarizedExperiment(assays=SimpleList(counts=counts),
+                              rowRanges=rowRanges, colData=colData)
> rse1 <- shift(rse0, 100)
> 
> res <- nearest(rse0, rse1)
> res
 [1]  1  2  2  4  5  6 12 12  6  6 11 12 17 14 15 14 14 17 13 17
> stopifnot(identical(res, nearest(rowRanges(rse0), rowRanges(rse1))))
> stopifnot(identical(res, nearest(rse0, rowRanges(rse1))))
> stopifnot(identical(res, nearest(rowRanges(rse0), rse1)))
> 
> res <- nearest(rse0)  # missing subject
> res
 [1]  4  3  2  5  4  9 12 12  6  9  8  8 20 16 19 14 13 20 20 19
> stopifnot(identical(res, nearest(rowRanges(rse0))))
> 
> hits <- nearest(rse0, rse1, select="all")
> hits
Hits object with 28 hits and 0 metadata columns:
       queryHits subjectHits
       <integer>   <integer>
   [1]         1           1
   [2]         2           2
   [3]         3           2
   [4]         4           4
   [5]         5           5
   ...       ...         ...
  [24]        19          18
  [25]        19          20
  [26]        20          13
  [27]        20          17
  [28]        20          18
  -------
  queryLength: 20 / subjectLength: 20
> stopifnot(identical(
+   hits,
+   nearest(rowRanges(rse0), rowRanges(rse1), select="all")
+ ))
> stopifnot(identical(
+   hits,
+   nearest(rse0, rowRanges(rse1), select="all")
+ ))
> stopifnot(identical(
+   hits,
+   nearest(rowRanges(rse0), rse1, select="all")
+ ))
> 
> 
> 
> 
> 
> dev.off()
null device 
          1 
>