diff --git a/R/findOverlaps-GIntervalTree-methods.R b/R/findOverlaps-GIntervalTree-methods.R index e09f7a4..eb79b60 100644 --- a/R/findOverlaps-GIntervalTree-methods.R +++ b/R/findOverlaps-GIntervalTree-methods.R @@ -85,3 +85,7 @@ setMethod("findOverlaps", c("GenomicRanges", "GIntervalTree"), Hits(q_hits, s_hits, q_len, s_len) }) +setMethod("countOverlaps", c("GenomicRanges", "GIntervalTree"), + countOverlaps.definition +) + diff --git a/R/nearest-methods.R b/R/nearest-methods.R index 23c4ec8..baf0deb 100644 --- a/R/nearest-methods.R +++ b/R/nearest-methods.R @@ -46,7 +46,8 @@ queryLength=as.integer(max(c(0, queryHits))), subjectLength=as.integer(max(c(0, subjectHits)))) { - Hits(queryHits, subjectHits, queryLength, subjectLength) + o <- S4Vectors:::orderIntegerPairs(queryHits, subjectHits) + Hits(queryHits[o], subjectHits[o], queryLength, subjectLength) } .findPrecedeFollow_pmin <- diff --git a/man/GIntervalTree-class.Rd b/man/GIntervalTree-class.Rd index 0ea293c..9594cd8 100644 --- a/man/GIntervalTree-class.Rd +++ b/man/GIntervalTree-class.Rd @@ -35,7 +35,7 @@ \title{GIntervalTree objects} \description{ - The GRanges class is a container for the genomic locations and + The GIntervalTree class is a container for the genomic locations and their associated annotations. } diff --git a/man/GRanges-class.Rd b/man/GRanges-class.Rd index f240e74..8a51484 100644 --- a/man/GRanges-class.Rd +++ b/man/GRanges-class.Rd @@ -58,7 +58,6 @@ \alias{[,List,GenomicRanges-method} \alias{[,list,GenomicRanges-method} \alias{c,GenomicRanges-method} -\alias{tile,GenomicRanges-method} \alias{window,GenomicRanges-method} % $ and $<- methods: @@ -331,15 +330,6 @@ elements are removed from the returned object if \code{drop} is \code{TRUE}. } - \item{}{ - \code{tile(x, n, width)}: Splits \code{x} into a - \code{GRangesList}, each element of which corresponds to a tile, - or partition, of \code{x}. Specify the tile geometry with either - \code{n} or \code{width} (not both). Passing \code{n} creates - \code{n} tiles of approximately equal width, truncated by sequence - end, while passing \code{width} tiles the region with ranges of - the given width, again truncated by sequence end. - } } } diff --git a/man/findOverlaps-methods.Rd b/man/findOverlaps-methods.Rd index 8ce0923..3d7c9b6 100644 --- a/man/findOverlaps-methods.Rd +++ b/man/findOverlaps-methods.Rd @@ -20,6 +20,7 @@ \alias{countOverlaps,GenomicRanges,Vector-method} \alias{countOverlaps,Vector,GenomicRanges-method} \alias{countOverlaps,GenomicRanges,GenomicRanges-method} +\alias{countOverlaps,GenomicRanges,GIntervalTree-method} \alias{countOverlaps,GRangesList,Vector-method} \alias{countOverlaps,Vector,GRangesList-method} \alias{countOverlaps,GRangesList,GRangesList-method} @@ -72,25 +73,29 @@ \usage{ \S4method{findOverlaps}{GenomicRanges,GenomicRanges}(query, subject, - maxgap = 0L, minoverlap = 1L, - type = c("any", "start", "end", "within", "equal"), - select = c("all", "first", "last", "arbitrary"), - ignore.strand = FALSE) + maxgap=0L, minoverlap=1L, + type=c("any", "start", "end", "within", "equal"), + select=c("all", "first", "last", "arbitrary"), + algorithm=c("nclist", "intervaltree"), + ignore.strand=FALSE) \S4method{countOverlaps}{GenomicRanges,GenomicRanges}(query, subject, - maxgap = 0L, minoverlap = 1L, - type = c("any", "start", "end", "within", "equal"), - ignore.strand = FALSE) + maxgap=0L, minoverlap=1L, + type=c("any", "start", "end", "within", "equal"), + algorithm=c("nclist", "intervaltree"), + ignore.strand=FALSE) \S4method{overlapsAny}{GenomicRanges,GenomicRanges}(query, subject, - maxgap = 0L, minoverlap = 1L, - type = c("any", "start", "end", "within", "equal"), - ignore.strand = FALSE) + maxgap=0L, minoverlap=1L, + type=c("any", "start", "end", "within", "equal"), + algorithm=c("nclist", "intervaltree"), + ignore.strand=FALSE) \S4method{subsetByOverlaps}{GenomicRanges,GenomicRanges}(query, subject, - maxgap = 0L, minoverlap = 1L, - type = c("any", "start", "end", "within", "equal"), - ignore.strand = FALSE) + maxgap=0L, minoverlap=1L, + type=c("any", "start", "end", "within", "equal"), + algorithm=c("nclist", "intervaltree"), + ignore.strand=FALSE) } \arguments{ @@ -141,7 +146,7 @@ \value{ For \code{findOverlaps} either a \link[S4Vectors]{Hits} object when - \code{select = "all"} or an integer vector otherwise. + \code{select="all"} or an integer vector otherwise. For \code{countOverlaps} an integer vector containing the tabulated query overlap hits. @@ -174,31 +179,25 @@ \examples{ ## GRanges object: -gr <- - GRanges(seqnames = - Rle(c("chr1", "chr2", "chr1", "chr3"), c(1, 3, 2, 4)), - ranges = - IRanges(1:10, width = 10:1, names = head(letters,10)), - strand = - Rle(strand(c("-", "+", "*", "+", "-")), - c(1, 2, 2, 3, 2)), - score = 1:10, - GC = seq(1, 0, length=10)) +gr <- GRanges( + seqnames=Rle(c("chr1", "chr2", "chr1", "chr3"), c(1, 3, 2, 4)), + ranges=IRanges(1:10, width=10:1, names=head(letters,10)), + strand=Rle(strand(c("-", "+", "*", "+", "-")), c(1, 2, 2, 3, 2)), + score=1:10, + GC=seq(1, 0, length=10) + ) gr ## GRangesList object: -gr1 <- - GRanges(seqnames = "chr2", ranges = IRanges(4:3, 6), - strand = "+", score = 5:4, GC = 0.45) -gr2 <- - GRanges(seqnames = c("chr1", "chr1"), - ranges = IRanges(c(7,13), width = 3), - strand = c("+", "-"), score = 3:4, GC = c(0.3, 0.5)) -gr3 <- - GRanges(seqnames = c("chr1", "chr2"), - ranges = IRanges(c(1, 4), c(3, 9)), - strand = c("-", "-"), score = c(6L, 2L), GC = c(0.4, 0.1)) -grl <- GRangesList("gr1" = gr1, "gr2" = gr2, "gr3" = gr3) +gr1 <- GRanges(seqnames="chr2", ranges=IRanges(4:3, 6), + strand="+", score=5:4, GC=0.45) +gr2 <- GRanges(seqnames=c("chr1", "chr1"), + ranges=IRanges(c(7,13), width=3), + strand=c("+", "-"), score=3:4, GC=c(0.3, 0.5)) +gr3 <- GRanges(seqnames=c("chr1", "chr2"), + ranges=IRanges(c(1, 4), c(3, 9)), + strand=c("-", "-"), score=c(6L, 2L), GC=c(0.4, 0.1)) +grl <- GRangesList("gr1"=gr1, "gr2"=gr2, "gr3"=gr3) ## Overlapping two GRanges objects: table(!is.na(findOverlaps(gr, gr1, select="arbitrary"))) @@ -206,17 +205,17 @@ countOverlaps(gr, gr1) findOverlaps(gr, gr1) subsetByOverlaps(gr, gr1) -countOverlaps(gr, gr1, type = "start") -findOverlaps(gr, gr1, type = "start") -subsetByOverlaps(gr, gr1, type = "start") +countOverlaps(gr, gr1, type="start") +findOverlaps(gr, gr1, type="start") +subsetByOverlaps(gr, gr1, type="start") -findOverlaps(gr, gr1, select = "first") -findOverlaps(gr, gr1, select = "last") +findOverlaps(gr, gr1, select="first") +findOverlaps(gr, gr1, select="last") findOverlaps(gr1, gr) -findOverlaps(gr1, gr, type = "start") -findOverlaps(gr1, gr, type = "within") -findOverlaps(gr1, gr, type = "equal") +findOverlaps(gr1, gr, type="start") +findOverlaps(gr1, gr, type="within") +findOverlaps(gr1, gr, type="equal") ## using a GIntervalTree gtree <- GIntervalTree(gr1) @@ -230,20 +229,20 @@ table(!is.na(findOverlaps(grl, gr, select="first"))) countOverlaps(grl, gr) findOverlaps(grl, gr) subsetByOverlaps(grl, gr) -countOverlaps(grl, gr, type = "start") -findOverlaps(grl, gr, type = "start") -subsetByOverlaps(grl, gr, type = "start") -findOverlaps(grl, gr, select = "first") +countOverlaps(grl, gr, type="start") +findOverlaps(grl, gr, type="start") +subsetByOverlaps(grl, gr, type="start") +findOverlaps(grl, gr, select="first") ## using a GIntervalTree table(!is.na(findOverlaps(grl, gtree, select="first"))) countOverlaps(grl, gtree) findOverlaps(grl, gtree) subsetByOverlaps(grl, gtree) -countOverlaps(grl, gtree, type = "start") -findOverlaps(grl, gtree, type = "start") -subsetByOverlaps(grl, gtree, type = "start") -findOverlaps(grl, gtree, select = "first") +countOverlaps(grl, gtree, type="start") +findOverlaps(grl, gtree, type="start") +subsetByOverlaps(grl, gtree, type="start") +findOverlaps(grl, gtree, select="first") ## Overlapping two GRangesList objects: countOverlaps(grl, rev(grl)) diff --git a/man/nearest-methods.Rd b/man/nearest-methods.Rd index f94e8d7..f3564b9 100644 --- a/man/nearest-methods.Rd +++ b/man/nearest-methods.Rd @@ -21,14 +21,14 @@ } \usage{ -\S4method{precede}{GenomicRanges,GenomicRanges}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...) -\S4method{precede}{GenomicRanges,missing}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...) +\S4method{precede}{GenomicRanges,GenomicRanges}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE) +\S4method{precede}{GenomicRanges,missing}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE) -\S4method{follow}{GenomicRanges,GenomicRanges}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...) -\S4method{follow}{GenomicRanges,missing}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...) +\S4method{follow}{GenomicRanges,GenomicRanges}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE) +\S4method{follow}{GenomicRanges,missing}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE) -\S4method{nearest}{GenomicRanges,GenomicRanges}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...) -\S4method{nearest}{GenomicRanges,missing}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE, ...) +\S4method{nearest}{GenomicRanges,GenomicRanges}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE) +\S4method{nearest}{GenomicRanges,missing}(x, subject, select=c("arbitrary", "all"), ignore.strand=FALSE) \S4method{distanceToNearest}{GenomicRanges,GenomicRanges}(x, subject, ignore.strand=FALSE, ...) \S4method{distanceToNearest}{GenomicRanges,missing}(x, subject, ignore.strand=FALSE, ...) diff --git a/man/tile-methods.Rd b/man/tile-methods.Rd index 1c24515..d83ce14 100644 --- a/man/tile-methods.Rd +++ b/man/tile-methods.Rd @@ -7,7 +7,7 @@ \description{ \code{\link[IRanges]{tile}} method for - \link{GenomicRanges}. Partitions the each range into a set of + \link{GenomicRanges}. Partitions each range into a set of tiles. Tiles are defined in terms of their number or width. } @@ -31,6 +31,15 @@ } } +\details{ + Splits \code{x} into a \code{GRangesList}, each element of which corresponds + to a tile, or partition, of \code{x}. Specify the tile geometry with either + \code{n} or \code{width} (not both). Passing \code{n} creates \code{n} tiles + of approximately equal width, truncated by sequence end, while passing + \code{width} tiles the region with ranges of the given width, again truncated + by sequence end. +} + \value{ A \code{GRangesList} object, each element of which corresponds to a tile. }