ContactMatrix overlaps {InteractionSet} | R Documentation

## Find overlaps between GRanges and a ContactMatrix

### Description

Find overlaps between a set of linear intervals in a GRanges object, and the set of regions representing the rows or columns of a ContactMatrix.

### Usage

    ## S4 method for signature 'ContactMatrix,GRanges'
    overlapsAny(query, subject, maxgap=0L, minoverlap=1L,
        type=c("any", "start", "end", "within", "equal"),
        ignore.strand=TRUE)

    ## S4 method for signature 'ContactMatrix,GRangesList'
    overlapsAny(query, subject, maxgap=0L, minoverlap=1L,
        type=c("any", "start", "end", "within", "equal"),
        ignore.strand=TRUE, use.region="both")

    # The same call is used for the methods taking GRangesList, GInteractions and
    # InteractionSet objects as 'subject'. For brevity, these will not be listed.

### Arguments

`query` | A ContactMatrix object.
`subject` | A GRanges, GRangesList, GInteractions or InteractionSet object.
`maxgap, minoverlap, type` | See `?findOverlaps` in the GenomicRanges package.
`ignore.strand` | See `?findOverlaps` in the GenomicRanges package.
`use.region` | A string specifying how the interacting regions are to be matched to row/column regions.

### Details

When `subject` is a GRanges, overlaps are identified between the row regions of `query` and the regions in `subject`. This is repeated for the column regions of `query`. A list of two logical vectors is returned, specifying the rows and columns in `query` that are overlapped by any region in `subject`. These vectors can be directly used to subset `query`. Alternatively, they can be used in `outer` to generate a logical matrix for masking – see Examples.

For all other classes of `subject`, two-dimensional overlaps are identified. A logical matrix is returned indicating which entries in the ContactMatrix have overlaps with the specified interactions. For any given entry, an overlap is only considered if the regions for the corresponding row and column both overlap anchor regions in the `subject`. See `?"findOverlaps,GInteractions,GInteractions-method"` for more details.

If `use.region="both"`, overlaps between any row/column region and the first/second interacting region of `subject` are considered. If `use.region="same"`, only overlaps between row regions and the first interacting regions, or between column regions and the second interacting regions are considered. If `use.region="reverse"`, only overlaps between row regions and the second interacting regions, or between row regions and the first interacting regions are considered.

### Value

For `overlapsAny,ContactMatrix,GRanges-method`, a named list of two logical vectors is returned specifying the rows of columns of `query` overlapped by `subject`.

For the other `overlapsAny` methods, a logical matrix is returned indicating which entries in `query` are overlapped by `subject`.

### Author(s)

Aaron Lun

### See Also

`ContactMatrix-class`, `findOverlaps`

### Examples

    example(ContactMatrix, echo=FALSE)

    of.interest <- resize(sample(regions(x), 2), width=1, fix="center")
    olap <- overlapsAny(x, of.interest)
    olap
    x[olap$row,]
    x[,olap$column]
    x[olap$row,olap$column]

    keep <- outer(olap$row, olap$column, "|") # OR mask
    temp <- as.matrix(x)
    temp[!keep] <- NA

    keep <- outer(olap$row, olap$column, "&") # AND mask
    temp <- as.matrix(x)
    temp[!keep] <- NA

    # Two dimensional overlaps.
    pairing <- GRangesList(first=regions(x), second=regions(x))
    olap <- overlapsAny(x, pairing)
    olap
    olap <- overlapsAny(sort(x), pairing) # A bit prettier
    olap

[Package InteractionSet version 1.15.3 Index]