Learn R Programming

InteractionSet (version 1.0.4)

Interaction subsetting: Interaction subsetting and combining

Description

Methods to subset or combine InteractionSet or GInteractions objects.

Usage

"["(x, i, j, ..., drop=TRUE) "["(x, i, j) <- value
"rbind"(..., deparse.level=1) "c"(x, ..., recursive=FALSE)
"split"(x, f, drop=FALSE)
## Each of the above methods has an identical equivalent for ## InteractionSet objects (not shown for brevity).
"subset"(x, i, j) "cbind"(..., deparse.level=1)

Arguments

x
A GInteractions or InteractionSet object.
i, j
A vector of logical or integer subscripts. For InteractionSet objects, these indicate the rows and columns to be subsetted for i and j, respectively. Rows correspond to pairwise interactions while columns correspond to samples. For GInteractions objects, i indicates the genomic interactions to be retained. j is ignored as there is no concept of samples in this class.
value
A GInteractions or InteractionSet object with length or number of rows equal to length of i (or that of x, if i is not specified). For InteractionSet objects, the number of columns must be equal to the length of j (or number of columns in x, if j is not specified).
...
For rbind and c, ... contains GInteractions or InteractionSet objects to be combined row-wise, depending on the method. All objects must be of the same class. For c, any objects are additional to that already specified in x. For cbind, ... contains InteractionSet objects to be combined column-wise. For all other methods, this argument is ignored.
f
A vector-like object of length equal to length(x) (for GInteractions objects) or nrow(x) (for InteractionSet objects), indicating how entries/rows of x are to be split into separate objects. This is usually a factor.
drop
A logical scalar, indicating if levels of f that do not occur should be dropped in split,InteractionSet-method. This is ignored by the other methods.
deparse.level
An integer scalar; see ?base::cbind for a description of this argument.
recursive
An integer scalar, ignored.

Value

A subsetted or combined object of the same class as x.

Details for GInteractions

Subsetting operations will return a GInteractions object containing the specified interactions. Values of the anchor1 and anchor2 slots will be appropriately subsetted in the returned object, along with any metadata in mcols. However, note that the value of regions will not be modified by subsetting. rbind and c are synonyms and will concatenate GInteractions objects. These methods will check whether the regions slot of all supplied objects are the same, in which case the regions and anchor indices are used directly. Otherwise, a new GRanges is constructed containing the (sorted) union of all regions across the input objects. Anchor indices in each object are refactored appropriately to refer to the relevant entries in this new object. Note that the column names in mcols must be identical across all supplied objects in rbind and c. The column names of mcols for the regions slot must also be identical across objects. If GInteractions objects of different strictness (i.e., StrictGInteractions and ReverseGInteractions) are concatenated, the returned object will be of the same class as the first supplied object. split produces a list of GInteractions objects, where each entry of the list corresponds to a level of f. Each GInteractions object contains all rows associated with the corresponding level of f. For short index vectors, subsetting a GInteractions object prior to calling anchors may be much faster than the reverse procedure. This is because the anchors getter will construct a GRanges(List) containing the genomic loci for all pairwise interactions. Subsetting beforehand ensures that only loci for the desired interactions are included. This avoids constructing the entire object just to subset it later.

Details for InteractionSet

Subsetting behaves in much the same way as that for the SummarizedExperiment class. Interactions are treated as rows and will be subsetted as such. All subsetting operations will return an InteractionSet with the specified interactions (rows) or samples (columns). Again, note that the value of regions will not be modified by subsetting. cbind will combine objects with the same interactions but different samples. Errors will occur if the interactions are not identical between objects (i.e., must have same values in the interactions slots). Additional restrictions apply on the column and assay names - see cbind,SummarizedExperiment-method for details. rbind and c will combine objects with the same samples but different interactions. In this case, the interactions need not be identical, and will be combined using the methods described above for GInteractions objects. Again, additional restrictions apply - see rbind,SummarizedExperiment-method for details. split produces a list of InteractionSet objects, where each entry of the list corresponds to a level of f. Each InteractionSet object contains all rows associated with the corresponding level of f.

See Also

InteractionSet-class

Examples

Run this code
example(GInteractions, echo=FALSE)

# Subsetting:    
gi[1,]
gi[1:2,]
gi[3]
gi[3:4]

temp.gi <- gi
temp.gi[3:4] <- gi[1:2]

# Combining:
rbind(gi, gi)
c(gi, gi)

new.gi <- gi
regions(new.gi) <- resize(regions(new.gi), width=20, fix="start")
rbind(gi, new.gi)

# Splitting:
f <- sample(4, length(gi), replace=TRUE)
out <- split(gi, f)
out[[1]]

#################
# Same can be done for an InteractionSet object:

example(InteractionSet, echo=FALSE)

# Subsetting:    
iset[1,]
iset[1:2,]
iset[,1]
iset[,1:2]
iset[3,3]
iset[3:4,3:4]

# Combining:
cbind(iset, iset)
rbind(iset, iset)
c(iset, iset)

new.iset <- iset
regions(new.iset) <- resize(regions(new.iset), width=20, fix="start")
rbind(iset, new.iset)

# Splitting:
out <- split(iset, f)
out[[1]]

Run the code above in your browser using DataLab