Hervé Pagès, Martin Morgan
February 4, 2015
See slides.
GRanges
GRangesList
GRangesList inherits from CompressedList
library(GenomicRanges)
showClass("GRangesList")
## Class "GRangesList" [package "GenomicRanges"]
## 
## Slots:
##                                                             
## Name:         unlistData   elementMetadata      partitioning
## Class:           GRanges         DataFrame PartitioningByEnd
##                                           
## Name:        elementType          metadata
## Class:         character              list
## 
## Extends: 
## Class "CompressedList", directly
## Class "GenomicRangesList", directly
## Class "GenomicRangesORGRangesList", directly
## Class "List", by class "CompressedList", distance 2
## Class "Vector", by class "CompressedList", distance 3
## Class "Annotated", by class "CompressedList", distance 4
Consequences: unlist() and relist() are very cheap.
The unlist() / relist() pattern can be used in many situations 
where looping over the GRangesList would be inefficient.
Example:
library(TxDb.Dmelanogaster.UCSC.dm3.ensGene)
## Loading required package: GenomicFeatures
## Loading required package: AnnotationDbi
## Loading required package: Biobase
## Welcome to Bioconductor
## 
##     Vignettes contain introductory material; view with
##     'browseVignettes()'. To cite Bioconductor, see
##     'citation("Biobase")', and for packages 'citation("pkgname")'.
## 
## 
## Attaching package: 'AnnotationDbi'
## 
## The following object is masked from 'package:GenomeInfoDb':
## 
##     species
txdb <- TxDb.Dmelanogaster.UCSC.dm3.ensGene
tx_by_gn <- transcriptsBy(txdb, by="gene")
unlisted <- unlist(tx_by_gn)
TSS <- ifelse(strand(unlisted) == "+", start(unlisted), end(unlisted))
TSS <- GRanges(seqnames(unlisted), IRanges(TSS, width=1), strand(unlisted))
TSS_by_gn <- relist(TSS, tx_by_gn)
mcols(TSS) <- mcols(unlisted)
TSS_by_gn <- relist(TSS, tx_by_gn) 
See HOWTOs vignette in the GenomicRanges package