GRangesFactor objects
GRangesFactor(x, levels, index=NULL, ...) # constructor function
x, levels |
Like with the When When |
index |
|
... |
Optional metadata columns. |
A GRangesFactor object.
GRangesFactor objects support the accessors documented in the man page for Factor objects.
In addition, the following getters are supported for convenience:
seqnames()
, start()
, end()
, width()
,
strand()
, seqinfo()
, granges()
, and ranges()
.
When called on GRangesFactor object x
, they all behave as if they
were called on unfactor(x)
.
See ?unfactor
for more information.
GRangesFactor objects support the coercions documented in the man page for Factor objects.
In addition, coercion back and forth between GRanges and
GRangesFactor is supported via as(x, "GRanges")
and
as(x, "GRangesFactor")
.
A GRangesFactor object can be subsetted with [
, like a
Factor object.
2 or more GRangesFactor objects can be concatenated with c()
.
The result of this concatenation is another GRangesFactor object.
See Concatenation section in ?Factor
.
See Comparing & Ordering section in ?Factor
.
Hervé Pagès
GRanges objects.
Factor objects in the S4Vectors package for the parent class of GRangesFactor.
anyDuplicated
in the BiocGenerics
package.
showClass("GRangesFactor") # GRangesFactor extends Factor ## --------------------------------------------------------------------- ## CONSTRUCTOR & ACCESSORS ## --------------------------------------------------------------------- set.seed(123) ir0 <- IRanges(sample(5, 8, replace=TRUE), width=10, names=letters[1:8]) gr0 <- GRanges("chrA", ir0, ID=paste0("ID", 1:8)) ## Use explicit levels: gr1 <- GRanges("chrA", IRanges(1:6, width=10)) grf1 <- GRangesFactor(gr0, levels=gr1) grf1 length(grf1) names(grf1) levels(grf1) # gr1 nlevels(grf1) as.integer(grf1) # encoding ## If we don't specify the levels, they'll be set to unique(gr0): grf2 <- GRangesFactor(gr0) grf2 length(grf2) names(grf2) levels(grf2) # unique(gr0) nlevels(grf2) as.integer(grf2) ## --------------------------------------------------------------------- ## DECODING ## --------------------------------------------------------------------- unfactor(grf1) stopifnot(identical(gr0, unfactor(grf1))) stopifnot(identical(gr0, unfactor(grf2))) unfactor(grf1, use.names=FALSE) unfactor(grf1, ignore.mcols=TRUE) ## --------------------------------------------------------------------- ## COERCION ## --------------------------------------------------------------------- grf2b <- as(gr0, "GRangesFactor") # same as GRangesFactor(gr0) stopifnot(identical(grf2, grf2b)) as.factor(grf2) as.factor(grf1) as.character(grf1) # same as unfactor(as.factor(grf1)), # and also same as as.character(unfactor(grf1)) ## --------------------------------------------------------------------- ## CONCATENATION ## --------------------------------------------------------------------- gr3 <- GRanges("chrA", IRanges(c(5, 2, 8:6), width=10)) grf3 <- GRangesFactor(levels=gr3, index=2:4) grf13 <- c(grf1, grf3) grf13 levels(grf13) stopifnot(identical(c(unfactor(grf1), unfactor(grf3)), unfactor(grf13))) ## --------------------------------------------------------------------- ## COMPARING & ORDERING ## --------------------------------------------------------------------- grf1 == grf2 # same as unfactor(grf1) == unfactor(grf2) order(grf1) # same as order(unfactor(grf1)) order(grf2) # same as order(unfactor(grf2)) ## The levels of the GRangesFactor influence the order of the table: table(grf1) table(grf2)
Please choose more modern alternatives, such as Google Chrome or Mozilla Firefox.