ContactMatrix accessors {InteractionSet} | R Documentation

## ContactMatrix accessors

### Description

Methods to get and set fields in an ContactMatrix object.

### Usage

    ## S4 method for signature 'ContactMatrix'
    anchors(x, type="both", id=FALSE)
    ## S4 method for signature 'ContactMatrix'
    anchorIds(x, type="both")
    ## S4 replacement method for signature 'ContactMatrix'
    anchorIds(x, type="both") <- value

    ## S4 method for signature 'ContactMatrix'
    regions(x)
    ## S4 replacement method for signature 'ContactMatrix'
    regions(x) <- value
    ## S4 replacement method for signature 'ContactMatrix'
    replaceRegions(x) <- value
    ## S4 replacement method for signature 'ContactMatrix'
    appendRegions(x) <- value
    ## S4 method for signature 'ContactMatrix'
    reduceRegions(x)

    ## S4 method for signature 'ContactMatrix'
    show(x)
    ## S4 method for signature 'ContactMatrix'
    as.matrix(x)
    ## S4 replacement method for signature 'ContactMatrix'
    as.matrix(x) <- value
    ## S4 method for signature 'ContactMatrix'
    t(x)

    ## S4 method for signature 'ContactMatrix'
    dim(x)
    ## S4 method for signature 'ContactMatrix'
    dimnames(x)
    ## S4 replacement method for signature 'ContactMatrix'
    dimnames(x) <- value
    ## S4 method for signature 'ContactMatrix'
    length(x)

### Arguments

`x` | A ContactMatrix object.
`type` | a string specifying which anchors are to be extracted or replaced.
`id` | a scalar logical indicating whether indices or GRanges should be returned.
`value` | For `anchorIds<-`, a list of two integer vectors when `type="both"`. The first and second vectors must have length equal to the number of rows and columns of `x`, respectively. For `type="row"` or `"column"`, only one vector needs to be supplied corresponding to either the rows or columns. For `regions<-`, a GRanges object of length equal to that of `regions(x)`. For `newRegions<-`, a GRanges object that is a superset of all entries in `regions(x)` involved in interactions. For `appendRegions<-`, a GRanges of any length containing additional regions. For `as.matrix<-`, a matrix-like object of the same dimensions as that in the `matrix` slot. For `dimnames<-`, a list of two character vectors corresponding to the row and column names, respectively. These can also be passed separately via `rownames<-` and `colnames<-`.

### Details

The return value of `anchors` varies depending on `type` and `id`:

- If `id=FALSE`, a GRanges object is returned containing the regions specified by the `anchor1` or `anchor2` slots in `x`, for `type=="row"` or `"column"`, respectively.

- If `id=FALSE` and `type="both"`, a list is returned with two entries `row` and `column`, containing regions specified by `anchor1` and `anchor2` respectively.

- If `id=TRUE`, the integer vectors in the `anchor1` or `anchor2` slots of `x` are returned directly, depending on `type`. A list of length two is returned for `type="both"`, containing both of these vectors.

Note that `anchorIds` is equivalent to calling `anchors` with `id=TRUE`.

Replacement in `anchorIds<-` can only be performed using anchor indices. If `type="both"`, a list of two integer vectors is required in `value`, specifying the indices of the row- and column-wise interacting regions in `x`. If `type="row"` or `"column"`, an integer vector is required to replace the existing row- or column-wise indices in the `anchor1` or `anchor2` slot, respectively.

For `regions`, a GRanges is returned equal to the `regions` slot in `x`. For `regions<-`, the GRanges in `value` is used to replace the `regions` slot. Resorting of the replacement GRanges is performed automatically, along with re-indexing of the anchors. In addition, the input GRanges must be of the same length as the existing object in the `regions` slot. The `newRegions` replacement method can take variable length GRanges, but requires that the replacement contain (at least) all ranges contained in `anchors(x)`. The `appendRegions` replacement method appends extra intervals to the existing `regions` slot of `x`. The `reduceRegions` method removes unused entries in the `regions` slot, to save memory – see `reduceRegions,GInteractions-method` for more details.

The `show` method will print out various details of the object, such as the dimensions of the `matrix` slot and the length of the `regions` slot. The `as.matrix` method will return the value of the `matrix` slot, containing a matrix-like object of interaction data. Replacement with a matrix-like object of the same dimensions can be performed using the `as.matrix<-` function. The `t` method will transpose the matrix, i.e., switch the rows and columns (and switch the vectors in the `anchor1` and `anchor2` slots).

The `dim` method will return a vector of length 2, containing the dimensions of the `matrix` slot. The `dimnames` method will return a list of length 2, containing the row and column names of `matrix` (these can be modified with the `dimnames<-` method). The `length` method will return an integer scalar corresponding to the total number of entries in the `matrix` slot.

As the ContactMatrix class inherits from the `Annotated` class, additional metadata can be stored in the `metadata` slot. This can be accessed or modified with `metadata,Annotated-method`.

### Value

For the getters, values in various slots of `x` are returned, while for the setters, the slots of `x` are modified accordingly – see Details.

### Author(s)

Aaron Lun

### See Also

`ContactMatrix-class`

### Examples

    example(ContactMatrix, echo=FALSE) # Generate a nice object.
    show(x)

    # Various matrix methods:
    as.matrix(x)
    t(x)

    nrow(x)
    ncol(x)
    length(x)

    # Accessing anchor ranges or indices:
    anchors(x)
    anchors(x, type="row")
    anchors(x, id=TRUE)

    anchors(x, id=TRUE, type="row")
    anchors(x, id=TRUE, type="column")

    # Modifying anchor indices:
    nregs <- length(regions(x))
    anchorIds(x) <- list(sample(nregs, nrow(x), replace=TRUE),
                       sample(nregs, ncol(x), replace=TRUE))
    anchors(x, id=TRUE, type="row")
    anchors(x, id=TRUE, type="column")

    # Accessing or modifying regions:
    regions(x)
    regions(x)$score <- runif(length(regions(x)))

    new.ranges <- c(regions(x), resize(regions(x), fix="center", width=50))
    try(regions(x) <- new.ranges) # Fails
    replaceRegions(x) <- new.ranges # Succeeds

    length(regions(x))
    appendRegions(x) <- GRanges("chrA", IRanges(5:10+1000, 1100+5:10), score=runif(6))
    length(regions(x))

    reduceRegions(x)

    # Setting metadata
    metadata(x)$name <- "I am a contact matrix"
    metadata(x)

[Package InteractionSet version 1.18.1 Index]