findOverlaps-methods {GenomicAlignments} | R Documentation

## Finding overlapping genomic alignments

### Description

Finds range overlaps between a GAlignments, GAlignmentPairs, or GAlignmentsList object, and another range-based object.

NOTE: The `findOverlaps` generic function and methods for IntegerRanges and IntegerRangesList objects are defined and documented in the IRanges package. The methods for GRanges and GRangesList objects are defined and documented in the GenomicRanges package.

GAlignments, GAlignmentPairs, and GAlignmentsList objects also support `countOverlaps`, `overlapsAny`, and `subsetByOverlaps` thanks to the default methods defined in the IRanges package and to the `findOverlaps` method defined in this package and documented below.

### Usage

    ## S4 method for signature 'GAlignments,GAlignments'
    findOverlaps(query, subject,
        maxgap=-1L, minoverlap=0L,
        type=c("any", "start", "end", "within"),
        select=c("all", "first", "last", "arbitrary"),
        ignore.strand=FALSE)

### Arguments

`query, subject` | A GAlignments, GAlignmentPairs, or GAlignmentsList object for either `query` or `subject`. A vector-like object containing ranges for the other one.
`maxgap, minoverlap, type, select` | See `?findOverlaps` in the IRanges package for a description of these arguments.
`ignore.strand` | When set to `TRUE`, the strand information is ignored in the overlap calculations.

### Details

When the query or the subject (or both) is a GAlignments object, it is first turned into a GRangesList object (with `as( , "GRangesList")`) and then the rules described previously apply. GAlignmentsList objects are coerced to GAlignments then to a GRangesList. Feature indices are mapped back to the original GAlignmentsList list elements.

When the query is a GAlignmentPairs object, it is first turned into a GRangesList object (with `as( , "GRangesList")`) and then the rules described previously apply.

### Value

A Hits object when `select="all"` or an integer vector otherwise.

### See Also

- `findOverlaps`.

- Hits-class.

- GRanges-class.

- GRangesList-class.

- GAlignments-class.

- GAlignmentPairs-class.

- GAlignmentsList-class.

### Examples

    ex1_file <- system.file("extdata", "ex1.bam", package="Rsamtools")
    galn <- readGAlignments(ex1_file)

    subject <- granges(galn)[1]

    ## Note the absence of query no. 9 (i.e. 'galn[9]') in this result:
    as.matrix(findOverlaps(galn, subject))

    ## This is because, by default, findOverlaps()/countOverlaps() are
    ## strand specific:
    galn[8:10]
    countOverlaps(galn[8:10], subject)
    countOverlaps(galn[8:10], subject, ignore.strand=TRUE)

    ## Count alignments in 'galn' that DO overlap with 'subject' vs those
    ## that do NOT:
    table(overlapsAny(galn, subject))
    ## Extract those that DO:
    subsetByOverlaps(galn, subject)

    ## GAlignmentsList
    galist <- GAlignmentsList(galn[8:10], galn[3000:3002])
    gr <- GRanges(c("seq1", "seq1", "seq2"),
                  IRanges(c(15, 18, 1233), width=1),
                  strand=c("-", "+", "+"))

    countOverlaps(galist, gr)
    countOverlaps(galist, gr, ignore.strand=TRUE)
    findOverlaps(galist, gr)
    findOverlaps(galist, gr, ignore.strand=TRUE)

[Package GenomicAlignments version 1.22.1 Index]