~ubuntu-branches/ubuntu/wily/r-bioc-genomicranges/wily-proposed

« back to all changes in this revision

Viewing changes to man/nearest-methods.Rd

  • Committer: Package Import Robot
  • Author(s): Andreas Tille
  • Date: 2013-10-18 10:40:04 UTC
  • Revision ID: package-import@ubuntu.com-20131018104004-ktm4ub0pcoybnir6
Tags: upstream-1.12.4
ImportĀ upstreamĀ versionĀ 1.12.4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
\name{nearest-methods}
 
2
 
 
3
\alias{nearest-methods}
 
4
 
 
5
\alias{precede,GenomicRanges,GenomicRanges-method}
 
6
\alias{precede,GenomicRanges,missing-method}
 
7
\alias{follow,GenomicRanges,GenomicRanges-method}
 
8
\alias{follow,GenomicRanges,missing-method}
 
9
\alias{nearest,GenomicRanges,GenomicRanges-method}
 
10
\alias{nearest,GenomicRanges,missing-method}
 
11
\alias{distance,GenomicRanges,GenomicRanges-method}
 
12
\alias{distanceToNearest,GenomicRanges,GenomicRanges-method}
 
13
\alias{distanceToNearest,GenomicRanges,missing-method}
 
14
 
 
15
\title{Finding the nearest genomic range neighbor}
 
16
 
 
17
\description{
 
18
  The \code{nearest}, \code{precede}, \code{follow}, \code{distance}
 
19
  and \code{distanceToNearest} methods for \code{\linkS4class{GenomicRanges}}
 
20
  objects and subclasses.
 
21
}
 
22
 
 
23
\usage{
 
24
\S4method{precede}{GenomicRanges,GenomicRanges}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...)
 
25
\S4method{precede}{GenomicRanges,missing}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...)
 
26
 
 
27
\S4method{follow}{GenomicRanges,GenomicRanges}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...)
 
28
\S4method{follow}{GenomicRanges,missing}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...)
 
29
 
 
30
\S4method{nearest}{GenomicRanges,GenomicRanges}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...)
 
31
\S4method{nearest}{GenomicRanges,missing}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...)
 
32
 
 
33
\S4method{distanceToNearest}{GenomicRanges,GenomicRanges}(x, subject, ignore.strand=FALSE, ...)
 
34
\S4method{distanceToNearest}{GenomicRanges,missing}(x, subject, ignore.strand=FALSE, ...)
 
35
 
 
36
\S4method{distance}{GenomicRanges,GenomicRanges}(x, y, ignore.strand=FALSE, ...)
 
37
}
 
38
 
 
39
\arguments{
 
40
  \item{x}{The query \link{GenomicRanges} instance.
 
41
  }
 
42
  \item{subject}{The subject \link{GenomicRanges} instance
 
43
    within which the nearest neighbors are found. Can be missing,
 
44
    in which case \code{x} is also the subject. 
 
45
  }
 
46
  \item{y}{For the \code{distance} method, a \code{GRanges} instance.
 
47
    Cannot be missing. If \code{x} and \code{y} are not the same
 
48
    length, the shortest will be recycled to match the length of the 
 
49
    longest.
 
50
  }
 
51
  \item{select}{Logic for handling ties. By default, all methods
 
52
    select a single interval (arbitrary for \code{nearest},
 
53
    the first by order in \code{subject} for \code{precede}, and the
 
54
    last for \code{follow}). 
 
55
 
 
56
    When \code{select="all"} a \link[IRanges]{Hits} object is returned with 
 
57
    all matches for \code{x}. If \code{x} does not have a match in 
 
58
    \code{subject} the \code{x} is not included in the \code{Hits} object. 
 
59
  }
 
60
  \item{ignore.strand}{
 
61
    A \code{logical} indicating if the strand of the input ranges
 
62
    should be ignored. When \code{TRUE}, strand is set to \code{'+'}.
 
63
  }
 
64
  \item{...}{Additional arguments for methods.}
 
65
}
 
66
 
 
67
\details{
 
68
  \itemize{
 
69
    \item{nearest: }{
 
70
      Performs conventional nearest neighbor finding.
 
71
      Returns an integer vector containing the index of the nearest neighbor 
 
72
      range in \code{subject} for each range in \code{x}. If there is no 
 
73
      nearest neighbor \code{NA} is returned. For details of the algorithm
 
74
      see the man page in IRanges, ?\code{nearest}. 
 
75
    }
 
76
    \item{precede: }{
 
77
      For each range in \code{x}, \code{precede} returns
 
78
      the index of the range in \code{subject} that is directly 
 
79
      preceded by the range in \code{x}. Overlapping ranges are excluded.
 
80
      \code{NA} is returned when there are no qualifying ranges in
 
81
      \code{subject}.
 
82
    }
 
83
    \item{follow: }{
 
84
      The opposite of \code{precede}, \code{follow} returns
 
85
      the index of the range in \code{subject} that is directly followed by the
 
86
      range in \code{x}. Overlapping ranges are excluded. \code{NA} is returned 
 
87
      when there are no qualifying ranges in \code{subject}.
 
88
    }
 
89
    \item{Orientation and Strand: }{
 
90
      The relevant orientation for \code{precede} and \code{follow} 
 
91
      is 5' to 3', consistent with the direction of translation. 
 
92
      Because positional numbering along a chromosome is from left to 
 
93
      right and transcription takes place from 5' to 3', \code{precede} and 
 
94
      \code{follow} can appear to have `opposite' behavior on the \code{+}
 
95
      and \code{-} strand. Using positions 5 and 6 as an example, 5 precedes 
 
96
      6 on the \code{+} strand but follows 6 on the \code{-} strand.
 
97
 
 
98
      A range with strand \code{*} can be compared to ranges on either the
 
99
      \code{+} or \code{-} strand. Below we outline the priority when ranges 
 
100
      on multiple strands are compared. When \code{ignore.strand=TRUE} all 
 
101
      ranges are treated as if on the \code{+} strand. 
 
102
      \itemize{
 
103
        \item{}{x on + strand can match to ranges on both + and 
 
104
          * strands. In the case of a tie the first range by order 
 
105
          is chosen.
 
106
        } 
 
107
        \item{}{x on - strand can match to ranges on both - and 
 
108
          * strands. In the case of a tie the first range by order 
 
109
          is chosen.
 
110
        } 
 
111
        \item{}{x on * strand can match to ranges on any of +, 
 
112
          - or * strands. In the case of a tie the first range by
 
113
          order is chosen.
 
114
        }
 
115
      }
 
116
    }
 
117
    \item{distanceToNearest: }{Returns the distance for each range in \code{x}
 
118
      to its nearest neighbor in the \code{subject}. 
 
119
    }
 
120
    \item{distance: }{
 
121
      Returns the distance for each range in \code{x} to the range in \code{y}.
 
122
      The behavior of \code{distance} has changed in Bioconductor 2.12.
 
123
      See the man page \code{?distance} in IRanges for details.  
 
124
    }
 
125
  }
 
126
}
 
127
 
 
128
\value{
 
129
  For \code{nearest}, \code{precede} and \code{follow}, an integer
 
130
  vector of indices in \code{subject}, or a \code{\linkS4class{Hits}} if 
 
131
  \code{select="all"}.
 
132
 
 
133
  For \code{distanceToNearest}, a \code{Hits} object with a column for
 
134
  the \code{query} index (queryHits), \code{subject} index (subjectHits)
 
135
  and the \code{distance} between the pair.
 
136
 
 
137
  For \code{distance}, an integer vector of distances between the ranges
 
138
  in \code{x} and \code{y}.
 
139
}
 
140
 
 
141
\author{P. Aboyoun and V. Obenchain <vobencha@fhcrc.org>}
 
142
 
 
143
\seealso{
 
144
  \itemize{
 
145
    \item The \link{GenomicRanges} and \link{GRanges} classes.
 
146
    \item The \link[IRanges]{Ranges} and \link[IRanges]{Hits} classes in the
 
147
          IRanges package.
 
148
    \item The \link[IRanges]{nearest-methods} man page in the IRanges package.
 
149
    \item \link[GenomicRanges]{findOverlaps-methods} for finding just the
 
150
          overlapping ranges.
 
151
  }
 
152
}
 
153
 
 
154
\examples{
 
155
  ## -----------------------------------------------------------
 
156
  ## precede() and follow()
 
157
  ## -----------------------------------------------------------
 
158
  query <- GRanges("A", IRanges(c(5, 20), width=1), strand="+")
 
159
  subject <- GRanges("A", IRanges(rep(c(10, 15), 2), width=1),
 
160
                          strand=c("+", "+", "-", "-"))
 
161
  precede(query, subject)
 
162
  follow(query, subject)
 
163
 
 
164
  strand(query) <- "-"
 
165
  precede(query, subject)
 
166
  follow(query, subject)
 
167
 
 
168
  ## ties choose first in order
 
169
  query <- GRanges("A", IRanges(10, width=1), c("+", "-", "*"))
 
170
  subject <- GRanges("A", IRanges(c(5, 5, 5, 15, 15, 15), width=1),
 
171
                          rep(c("+", "-", "*"), 2))
 
172
  precede(query, subject)
 
173
  precede(query, rev(subject))
 
174
 
 
175
  ## ignore.strand=TRUE treats all ranges as '+'
 
176
  precede(query[1], subject[4:6], select="all", ignore.strand=FALSE)
 
177
  precede(query[1], subject[4:6], select="all", ignore.strand=TRUE)
 
178
 
 
179
 
 
180
  ## -----------------------------------------------------------
 
181
  ## nearest()
 
182
  ## -----------------------------------------------------------
 
183
  ## When multiple ranges overlap an "arbitrary" range is chosen
 
184
  query <- GRanges("A", IRanges(5, 15))
 
185
  subject <- GRanges("A", IRanges(c(1, 15), c(5, 19)))
 
186
  nearest(query, subject)
 
187
 
 
188
  ## select="all" returns all hits
 
189
  nearest(query, subject, select="all")
 
190
 
 
191
  ## Ranges in 'x' will self-select when 'subject' is present
 
192
  query <- GRanges("A", IRanges(c(1, 10), width=5))
 
193
  nearest(query, query)
 
194
 
 
195
  ## Ranges in 'x' will not self-select when 'subject' is missing
 
196
  nearest(query)
 
197
 
 
198
  ## -----------------------------------------------------------
 
199
  ## distance(), distanceToNearest()
 
200
  ## -----------------------------------------------------------
 
201
  ## Adjacent, overlap, separated by 1
 
202
  query <- GRanges("A", IRanges(c(1, 2, 10), c(5, 8, 11)))
 
203
  subject <- GRanges("A", IRanges(c(6, 5, 13), c(10, 10, 15)))
 
204
  distance(query, subject)
 
205
 
 
206
  ## recycling
 
207
  distance(query[1], subject)
 
208
 
 
209
  ## zero-width ranges
 
210
  zw <- GRanges("A", IRanges(4,3))
 
211
  stopifnot(distance(zw, GRanges("A", IRanges(3,4))) == 0L)
 
212
  sapply(-3:3, function(i) 
 
213
      distance(shift(zw, i), GRanges("A", IRanges(4,3))))
 
214
 
 
215
  query <- GRanges(c("A", "B"), IRanges(c(1, 5), width=1))
 
216
  distanceToNearest(query, subject)
 
217
}
 
218
 
 
219
\keyword{utilities}