Description Usage Arguments Value Inflating to a ContactMatrix Deflating from a ContactMatrix Interpreting zeroes in a sparse matrix Author(s) See Also Examples
Inflate a GInteractions or InteractionSet into a ContactMatrix, or deflate a ContactMatrix to an InteractionSet.
1 2 3 4 5 6 7 8 | ## S4 method for signature 'GInteractions'
inflate(x, rows, columns, fill=TRUE, swap=TRUE, sparse=FALSE, ...)
## S4 method for signature 'InteractionSet'
inflate(x, rows, columns, assay=1L, sample=1L, fill, swap=TRUE, sparse=FALSE, ...)
## S4 method for signature 'ContactMatrix'
deflate(x, collapse=TRUE, extract, use.zero, use.na, ...)
|
x |
A GInteractions or InteractionSet object for |
rows, columns |
An integer, logical or character vector, a GRanges object or |
assay |
A numeric scalar indicating the assay of the InteractionSet object, from which values are extracted to fill the ContactMatrix. |
sample |
A numeric scalar indicating the sample (i.e., column) of the assay to extract values to fill the ContactMatrix. |
fill |
A vector (usually logical or numeric) of length equal to |
swap |
A logical scalar indicating whether filling should also be performed after swapping anchor indices. |
sparse |
A logical scalar indicating whether the inflated matrix should use a sparseMatrix representation. |
collapse |
A logical scalar indicating whether duplicated interactions should be removed from |
extract |
A logical vector or matrix indicating which entries of |
use.zero, use.na |
A logical scalar indicating whether to convert zero or |
... |
For For |
For inflate
, a ContactMatrix is returned.
For deflate
, an InteractionSet object is returned.
The inflate
method will return a ContactMatrix where the rows and columns correspond to specified regions of interest in rows
and columns
.
Regions can be specified by supplying an object of various types:
If it is an integer vector, it is assumed to refer to intervals in the regions
slot of the input object x
.
Values of the vector need not be sorted or unique, but must lie within [1, regions(x)]
.
If it is a logical vector, it will subset to retain intervals in regions(x)
that are TRUE
.
If it is a character vector, it is assumed to contain the names of the reference sequences of interest (i.e., chromosome names).
If it is a GRanges object, overlapsAny
will be called to identify the overlapping intervals of regions(x)
.
If it is NULL
, all regions in regions(x)
will be used to construct that dimension of the ContactMatrix.
For the GInteractions method, values in the matrix are filled based on user-supplied values in fill
.
Each element of fill
corresponds to an interaction in x
and is used to set the matrix entry at the matching row/column.
Some entries of the matrix will correspond to pairwise interactions that are not present in x
- these are filled with NA
values.
By default, filling is repeated after swapping the anchor indices.
This means that the value of the matrix at (1, 2) will be the same as that at (2, 1), i.e., the matrix is symmetric around the diagonal of the interaction space.
However, if swap=FALSE
, filling is performed so that the first and second anchor indices correspond strictly to rows and columns, respectively.
This may be preferable if the order of the anchors contains some relevant information.
In all cases, if duplicated interactions are present in x
(and redundant permutations, when swap=TRUE
), one will be arbitrarily chosen to fill the matrix.
For the InteractionSet inflate
method, entries in the matrix are filled in based on the values in the first sample of the first assay when fill
is missing.
For more complex x
, values from different assays and samples can be extracted using the assay
and sample
arguments.
Note that if fill
is specified, it will override any extraction of values from the assays.
If sparse=TRUE
, inflate
will return a ContactMatrix containing a sparseMatrix in the matrix
slot.
Here, entries without a corresponding interaction in x
are set to zero, not NA
.
See below for some considerations when interpreting zeroes and NA
s in contact matrices.
The default fill=TRUE
has the effect of producing a logical sparse matrix in the output ContactMatrix, indicating which pairs of regions were present in x
.
The deflate
method will return an InteractionSet where each relevant entry in the ContactMatrix is converted into a pairwise interaction.
Relevant entries are defined as those that are non-zero, if use.zero
is FALSE
; and non-NA
, if use.na
is FALSE
.
If x
contains a sparseMatrix representation, the former is set to FALSE
while the latter is set to TRUE
, if either are not specified.
For all other matrices, use.zero=TRUE
and use.na=FALSE
by default.
If extract
is specified, this overrides all values of use.zero
and use.na
.
A typical application would be to deflate
a number of ContactMatrix objects with the same extract
matrix.
This ensures that the resulting InteractionSet objects can be easily combined with cbind
, as the interactions are guaranteed to be the same.
Otherwise, different interactions may be extracted depending on the presence of zero or NA
values.
The values of all matrix entries are stored as a one-sample assay, with each value corresponding to its pairwise interaction after conversion.
Duplicate interactions are removed by default, along with redundant permutations of the anchor indices.
These can be included in the returned object by setting collapse=FALSE
.
This setting will also store the pairs as a GInteractions object, rather than using the default StrictGInteractions object where duplicates are not stored.
Additional arguments can be used to specify the colData
and metadata
, which are stored in the ContactMatrix itself.
Storing data as a sparseMatrix may be helpful as it is more memory-efficient for sparse areas of the interaction space.
However, users should keep in mind that the zero values in the sparseMatrix may not represent zeroes in fill
.
The majority of these values are likely to be zero just because there was no corresponding interaction in x
to set it to a non-zero value.
Whether or not this is a problem depends on the application.
For example, if fill
represents count data and only interactions with non-zero counts are stored in x
, then setting all other entries to zero is sensible.
However, in other cases, it is not appropriate to fill entries corresponding to missing interactions with zero.
If fill
represents, e.g., log-fold changes, then setting missing entries to a value of zero will be misleading.
One could simply ignore zeroes altogether, though this will also discard entries that are genuinely zero.
These problems are largely avoided with the default dense matrices, where missing entries are simply set to NA
.
Aaron Lun
InteractionSet-class
,
GInteractions-class
,
ContactMatrix-class
,
sparseMatrix-class
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 | example(InteractionSet, echo=FALSE)
inflate(iset, 1:10, 1:10)
inflate(iset, 1:10, 1:10, sparse=TRUE)
inflate(iset, 1:10, 1:5+10)
inflate(iset, "chrA", 1:5+10)
inflate(iset, "chrA", "chrB")
inflate(iset, "chrA", GRanges("chrB", IRanges(1, 10)))
y <- inflate(iset, 1:10, 1:10)
iset2 <- deflate(y)
iset2
assay(iset2)
y <- inflate(iset, 1:10, 1:10, swap=FALSE)
iset2 <- deflate(y)
iset2
assay(iset2)
# Testing with different fillings:
y <- inflate(iset, 1:10, 1:10, sample=2)
iset2 <- deflate(y)
assay(iset2)
y <- inflate(iset, 1:10, 1:10, fill=rowSums(assay(iset)))
iset2 <- deflate(y)
assay(iset2)
y2 <- inflate(interactions(iset), 1:10, 1:10, rowSums(assay(iset)))
identical(y, y2) # should be TRUE
# Effect of 'collapse'
y <- inflate(iset, c(8, 1:10), 1:10)
deflate(y)
deflate(y, collapse=FALSE)
|
Add the following code to your website.
For more information on customizing the embed code, read Embedding Snippets.