| GRangesList-class {GenomicRanges} | R Documentation |
GRangesList objects
Description
The GRangesList class is a container for storing a collection of GRanges objects. It is a subclass of GenomicRangesList. It exists in 2 flavors: SimpleGRangesList and CompressedGRangesList. Each flavor uses a particular internal representation. The CompressedGRangesList flavor is the default. It is particularly efficient for storing a large number of list elements and operating on them.
Constructors
GRangesList(..., compress=TRUE):-
Creates a GRangesList object using the GRanges objects supplied in
..., either consecutively or in a list. By default a CompressedGRangesList instance is returned, that is, a GRangesList object of the CompressedGRangesList flavor. Usecompress=FALSEto get a SimpleGRangesList instance instead. makeGRangesListFromFeatureFragments(seqnames=Rle(factor()), fragmentStarts=list(), fragmentEnds=list(), fragmentWidths=list(), strand=character(0), sep=","):-
Constructs a GRangesList object from a list of fragmented features. See the Examples section below.
Accessors
In the code snippets below, x is a GRangesList object.
length(x):-
Get the number of list elements.
names(x),names(x) <- value:-
Get or set the names on
x. seqnames(x),seqnames(x) <- value:-
Get or set the sequence names in the form of an RleList.
valuecan be an RleList or CharacterList object. ranges(x, use.mcols=FALSE),ranges(x) <- value:-
Get or set the ranges in the form of a CompressedIRangesList.
valuecan be an IntegerRangesList object. start(x),start(x) <- value:-
Get or set
start(ranges(x)). end(x),end(x) <- value:-
Get or set
end(ranges(x)). width(x),width(x) <- value:-
Get or set
width(ranges(x)). strand(x),strand(x) <- value:-
Get or set the strand in the form of an RleList object.
valuecan be an RleList, CharacterList or single character.valueas a single character converts all ranges inxto the samevalue; for selective strand conversion (i.e., mixed+and-) use RleList or CharacterList. mcols(x, use.names=FALSE),mcols(x) <- value:-
Get or set the metadata columns.
valuecan beNULL, or a data.frame-like object (i.e. DataFrame or data.frame) holding element-wise metadata. elementNROWS(x):-
Get a vector of the
lengthof each of the list element. isEmpty(x):-
Returns a logical indicating either if the GRangesList has no elements or if all its elements are empty.
seqinfo(x),seqinfo(x) <- value:-
Get or set the information about the underlying sequences.
valuemust be a Seqinfo object. seqlevels(x),seqlevels(x, pruning.mode=c("error", "coarse", "fine", "tidy")) <- value:-
Get or set the sequence levels.
seqlevels(x)is equivalent toseqlevels(seqinfo(x))or tolevels(seqnames(x)), those 2 expressions being guaranteed to return identical character vectors on a GRangesList object.valuemust be a character vector with no NAs. See?seqlevelsfor more information. seqlengths(x),seqlengths(x) <- value:-
Get or set the sequence lengths.
seqlengths(x)is equivalent toseqlengths(seqinfo(x)).valuecan be a named non-negative integer or numeric vector eventually with NAs. isCircular(x),isCircular(x) <- value:-
Get or set the circularity flags.
isCircular(x)is equivalent toisCircular(seqinfo(x)).valuemust be a named logical vector eventually with NAs. genome(x),genome(x) <- value:-
Get or set the genome identifier or assembly name for each sequence.
genome(x)is equivalent togenome(seqinfo(x)).valuemust be a named character vector eventually with NAs. seqlevelsStyle(x),seqlevelsStyle(x) <- value:-
Get or set the seqname style for
x. See the seqlevelsStyle generic getter and setter in the GenomeInfoDb package for more information. score(x), score(x) <- value:-
Get or set the
scoremetadata column.
Coercion
In the code snippets below, x is a GRangesList object.
as.data.frame(x, row.names=NULL, optional=FALSE, ..., value.name="value", use.outer.mcols=FALSE, group_name.as.factor=FALSE):-
Coerces
xto adata.frame. See as.data.frame on theListman page for details (?List). as.list(x, use.names = TRUE):-
Creates a list containing the elements of
x. as(x, "IRangesList"):-
Turns
xinto an IRangesList object.
When x is a list of GRanges, it can be coerced to a
GRangesList.
as(x, "GRangesList"):-
Turns
xinto aGRangesList.
Subsetting
In the following code snippets, x is a GRangesList object.
x[i, j],x[i, j] <- value:-
Get or set elements
iwith optional metadata columnsmcols(x)[,j], whereican be missing; an NA-free logical, numeric, or character vector; a logical-Rle object, or an AtomicList object. x[[i]],x[[i]] <- value:-
Get or set element
i, whereiis a numeric or character vector of length 1. x$name,x$name <- value:-
Get or set element
name, wherenameis a name or character vector of length 1. head(x, n = 6L):-
If
nis non-negative, returns the first n elements of the GRangesList object. Ifnis negative, returns all but the lastabs(n)elements of the GRangesList object. rep(x, times, length.out, each):-
Repeats the values in
xthrough one of the following conventions:timesVector giving the number of times to repeat each element if of length
length(x), or to repeat the whole vector if of length 1.length.outNon-negative integer. The desired length of the output vector.
eachNon-negative integer. Each element of
xis repeatedeachtimes.
subset(x, subset):-
Returns a new object of the same class as
xmade of the subset using logical vectorsubset, where missing values are taken asFALSE. tail(x, n = 6L):-
If
nis non-negative, returns the last n list elements of the GRangesList object. Ifnis negative, returns all but the firstabs(n)list elements of the GRangesList object.
Combining
In the code snippets below, x is a GRangesList object.
c(x, ...):-
Combines
xand the GRangesList objects in...together. Any object in...must belong to the same class asx, or to one of its subclasses, or must beNULL. The result is an object of the same class asx. append(x, values, after = length(x)):-
Inserts the
valuesintoxat the position given byafter, wherexandvaluesare of the same class. unlist(x, recursive = TRUE, use.names = TRUE):-
Concatenates the elements of
xinto a single GRanges object.
Looping
In the code snippets below, x is a GRangesList object.
endoapply(X, FUN, ...):-
Similar to
lapply, but performs an endomorphism, i.e. returns an object ofclass(X). lapply(X, FUN, ...):-
Like the standard
lapplyfunction defined in the base package, thelapplymethod for GRangesList objects returns a list of the same length asX, with each element being the result of applyingFUNto the corresponding element ofX. Map(f, ...):-
Applies a function to the corresponding elements of given GRangesList objects.
mapply(FUN, ..., MoreArgs=NULL, SIMPLIFY=TRUE, USE.NAMES=TRUE):-
Like the standard
mapplyfunction defined in the base package, themapplymethod for GRangesList objects is a multivariate version ofsapply. mendoapply(FUN, ..., MoreArgs = NULL):-
Similar to
mapply, but performs an endomorphism across multiple objects, i.e. returns an object ofclass(list(...)[[1]]). Reduce(f, x, init, right = FALSE, accumulate = FALSE):-
Uses a binary function to successively combine the elements of
xand a possibly given initial value.f-
A binary argument function.
init-
An R object of the same kind as the elements of
x. right-
A logical indicating whether to proceed from left to right (default) or from right to left.
nomatch-
The value to be returned in the case when "no match" (no element satisfying the predicate) is found.
sapply(X, FUN, ..., simplify=TRUE, USE.NAMES=TRUE):-
Like the standard
sapplyfunction defined in the base package, thesapplymethod for GRangesList objects is a user-friendly version oflapplyby default returning a vector or matrix if appropriate.
Author(s)
P. Aboyoun & H. Pagès
See Also
-
GRanges objects.
-
seqinfoin the GenomeInfoDb package. -
IntegerRangesList objects in the IRanges package.
-
RleList objects in the IRanges package.
-
DataFrameList objects in the IRanges package.
-
intra-range-methods, inter-range-methods, coverage-methods, setops-methods, and findOverlaps-methods.
-
GenomicRangesList objects.
Examples
## Construction with GRangesList():
gr1 <- GRanges("chr2", IRanges(3, 6),
strand="+", score=5L, GC=0.45)
gr2 <- GRanges(c("chr1", "chr1"), IRanges(c(7,13), width=3),
strand=c("+", "-"), score=3:4, GC=c(0.3, 0.5))
gr3 <- GRanges(c("chr1", "chr2"), IRanges(c(1, 4), c(3, 9)),
strand=c("-", "-"), score=c(6L, 2L), GC=c(0.4, 0.1))
grl <- GRangesList(gr1=gr1, gr2=gr2, gr3=gr3)
grl
## Summarizing elements:
elementNROWS(grl)
table(seqnames(grl))
## Extracting subsets:
grl[seqnames(grl) == "chr1", ]
grl[seqnames(grl) == "chr1" & strand(grl) == "+", ]
## Renaming the underlying sequences:
seqlevels(grl)
seqlevels(grl) <- sub("chr", "Chrom", seqlevels(grl))
grl
## Coerce to IRangesList (seqnames and strand information is lost):
as(grl, "IRangesList")
## isDisjoint():
isDisjoint(grl)
## disjoin():
disjoin(grl) # metadata columns and order NOT preserved
## Construction with makeGRangesListFromFeatureFragments():
filepath <- system.file("extdata", "feature_frags.txt",
package="GenomicRanges")
featfrags <- read.table(filepath, header=TRUE, stringsAsFactors=FALSE)
grl2 <- with(featfrags,
makeGRangesListFromFeatureFragments(seqnames=targetName,
fragmentStarts=targetStart,
fragmentWidths=blockSizes,
strand=strand))
names(grl2) <- featfrags$RefSeqID
grl2