forked from jimhester/GenomicRanges
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGenomicRangesList-class.R
45 lines (36 loc) · 1.42 KB
/
GenomicRangesList-class.R
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
36
37
38
39
40
41
42
43
44
45
### =========================================================================
### GenomicRangesList objects
### -------------------------------------------------------------------------
###
### A List of GenomicRanges objects. Subclasses not necessarily have the same
### "compound" semantics as GRangesList.
###
setClass("GenomicRangesList",
prototype = prototype(elementType = "GenomicRanges"),
contains = "List")
setClass("SimpleGenomicRangesList",
contains = c("GenomicRangesList", "SimpleList"))
### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Constructor.
###
GenomicRangesList <- function(...) {
args <- list(...)
if (length(args) == 1 && is.list(args[[1]]))
args <- args[[1]]
S4Vectors:::new_SimpleList_from_list("SimpleGenomicRangesList", args)
}
### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Coercion.
###
setAs("RangedDataList", "GenomicRangesList",
function(from) GenomicRangesList(lapply(from, as, "GRanges")))
setAs("GenomicRangesList", "RangedDataList",
function(from) RangedDataList(lapply(from, as, "RangedData")))
### - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
### Utilities.
###
setMethod("stack", "GenomicRangesList", function(x, indName = "sample") {
x_flat <- unlist(x, use.names = FALSE)
mcols(x_flat) <- cbind(IRanges:::.stack.ind(x, indName), mcols(x_flat))
x_flat
})