| Title: | Extract and aggregate genomic coverage over features of interest |
|---|---|
| Description: | `tidyCoverage` framework enables tidy manipulation of collections of genomic tracks and features using `tidySummarizedExperiment` methods. It facilitates the extraction, aggregation and visualization of genomic coverage over individual or thousands of genomic loci, relying on `CoverageExperiment` and `AggregatedCoverage` classes. This accelerates the integration of genomic track data in genomic analysis workflows. |
| Authors: | Jacques Serizay [aut, cre] |
| Maintainer: | Jacques Serizay <[email protected]> |
| License: | MIT + file LICENSE |
| Version: | 1.9.0 |
| Built: | 2026-05-15 10:11:22 UTC |
| Source: | https://github.com/bioc/tidyCoverage |
Bin coverage contained in a CoverageExperiment into an
AggregatedCoverage object.
## S4 method for signature 'CoverageExperiment' aggregate(x, bin = 1, ...)## S4 method for signature 'CoverageExperiment' aggregate(x, bin = 1, ...)
x |
a |
bin |
an integer to bin each assay by. The |
... |
ignored |
an AggregatedCoverage object
data(ce) aggregate(ce, bin = 10)data(ce) aggregate(ce, bin = 10)
Coerce an CoverageExperiment or AggregatedCoverage object into a tibble
## S3 method for class 'AggregatedCoverage' as_tibble(x, ...)## S3 method for class 'AggregatedCoverage' as_tibble(x, ...)
x |
A data frame, list, matrix, or other object that could reasonably be coerced to a tibble. |
... |
Unused, for extensibility. |
tibble
The default behavior is to silently remove row names.
New code should explicitly convert row names to a new column using the
rownames argument.
For existing code that relies on the retention of row names, call
pkgconfig::set_config("tibble::rownames" = NA) in your script or in your
package's .onLoad() function.
Using as_tibble() for vectors is superseded as of version 3.0.0,
prefer the more expressive as_tibble_row() and
as_tibble_col() variants for new code.
tibble() constructs a tibble from individual columns. enframe()
converts a named vector to a tibble with a column of names and column of
values. Name repair is implemented using vctrs::vec_as_names().
data(ac) as_tibble(ac)data(ac) as_tibble(ac)
CoverageExperiment objects store coverages for individual
tracks over different sets of features. The coverage
assay contains a separate matrix for each combination of
track x features. CoverageExperiment objects are instantiated
using the CoverageExperiment() function, and can be
coarsened using the coarsen() function.
CoverageExperiment(tracks, features, ...) coarsen(x, window, ...) ## S4 method for signature 'BigWigFileList,GRangesList' CoverageExperiment( tracks, features, width = NULL, center = FALSE, scale = FALSE, ignore.strand = TRUE, window = 1, BPPARAM = BiocParallel::bpparam() ) ## S4 method for signature 'BigWigFileList,GRanges' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'BigWigFileList,list' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'BigWigFile,GRangesList' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'BigWigFile,GRanges' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'BigWigFile,list' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'list,GRangesList' CoverageExperiment( tracks, features, width = NULL, center = FALSE, scale = FALSE, ignore.strand = TRUE, window = 1, BPPARAM = BiocParallel::bpparam() ) ## S4 method for signature 'list,GRanges' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'list,list' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'RleList,GRangesList' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'RleList,GRanges' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'RleList,list' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'CoverageExperiment' coarsen(x, window = 1, BPPARAM = BiocParallel::bpparam())CoverageExperiment(tracks, features, ...) coarsen(x, window, ...) ## S4 method for signature 'BigWigFileList,GRangesList' CoverageExperiment( tracks, features, width = NULL, center = FALSE, scale = FALSE, ignore.strand = TRUE, window = 1, BPPARAM = BiocParallel::bpparam() ) ## S4 method for signature 'BigWigFileList,GRanges' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'BigWigFileList,list' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'BigWigFile,GRangesList' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'BigWigFile,GRanges' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'BigWigFile,list' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'list,GRangesList' CoverageExperiment( tracks, features, width = NULL, center = FALSE, scale = FALSE, ignore.strand = TRUE, window = 1, BPPARAM = BiocParallel::bpparam() ) ## S4 method for signature 'list,GRanges' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'list,list' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'RleList,GRangesList' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'RleList,GRanges' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'RleList,list' CoverageExperiment(tracks, features, ...) ## S4 method for signature 'CoverageExperiment' coarsen(x, window = 1, BPPARAM = BiocParallel::bpparam())
tracks |
A genomic track imported as a |
features |
A set of features imported as |
... |
Passed to the relevant method |
x |
a |
window |
an integer to coarsen coverage by. |
width |
Width to resize each set of genomic features |
scale, center
|
Logical, whether to scale and/or center tracks prior to summarization |
ignore.strand |
Logical, whether to not take the features strand information |
BPPARAM |
Passed to BiocParallel. |
A CoverageExperiment object
library(rtracklayer) library(purrr) library(plyranges) TSSs_bed <- system.file("extdata", "TSSs.bed", package = "tidyCoverage") features <- import(TSSs_bed) |> filter(strand == '+') ############################################################################# ## 1. Creating a `CoverageExperiment` object from a single BigWigFile ############################################################################# RNA_fwd <- system.file("extdata", "RNA.fwd.bw", package = "tidyCoverage") tracks <- BigWigFile(RNA_fwd) CoverageExperiment(tracks, features, width = 5000) ############################################################################# ## 2. Creating a `CoverageExperiment` object from a BigWigFileList ############################################################################# RNA_rev <- system.file("extdata", "RNA.rev.bw", package = "tidyCoverage") tracks <- BigWigFileList(list(RNA_fwd = RNA_fwd, RNA_rev = RNA_rev)) CoverageExperiment(tracks, features, width = 5000) ############################################################################# ## 3. Creating a `CoverageExperiment` object from imported bigwig files ############################################################################# tracks <- list( RNA_fwd = system.file("extdata", "RNA.fwd.bw", package = "tidyCoverage"), RNA_rev = system.file("extdata", "RNA.rev.bw", package = "tidyCoverage") ) |> map(import, as = 'Rle') CoverageExperiment(tracks, features, width = 5000) ############################################################################# ## 4. Correct for strandness when recovering coverage ############################################################################# TSSs_bed <- system.file("extdata", "TSSs.bed", package = "tidyCoverage") features <- list( TSS_fwd = import(TSSs_bed) |> filter(strand == '+'), TSS_rev = import(TSSs_bed) |> filter(strand == '-') ) tracks <- list( RNA_fwd = system.file("extdata", "RNA.fwd.bw", package = "tidyCoverage"), RNA_rev = system.file("extdata", "RNA.rev.bw", package = "tidyCoverage") ) |> map(import, as = 'Rle') CoverageExperiment(tracks, features, width = 5000, ignore.strand = FALSE) ############################################################################# ## Aggregating a `CoverageExperiment` object ############################################################################# data(ce) coarsen(ce, window = 10)library(rtracklayer) library(purrr) library(plyranges) TSSs_bed <- system.file("extdata", "TSSs.bed", package = "tidyCoverage") features <- import(TSSs_bed) |> filter(strand == '+') ############################################################################# ## 1. Creating a `CoverageExperiment` object from a single BigWigFile ############################################################################# RNA_fwd <- system.file("extdata", "RNA.fwd.bw", package = "tidyCoverage") tracks <- BigWigFile(RNA_fwd) CoverageExperiment(tracks, features, width = 5000) ############################################################################# ## 2. Creating a `CoverageExperiment` object from a BigWigFileList ############################################################################# RNA_rev <- system.file("extdata", "RNA.rev.bw", package = "tidyCoverage") tracks <- BigWigFileList(list(RNA_fwd = RNA_fwd, RNA_rev = RNA_rev)) CoverageExperiment(tracks, features, width = 5000) ############################################################################# ## 3. Creating a `CoverageExperiment` object from imported bigwig files ############################################################################# tracks <- list( RNA_fwd = system.file("extdata", "RNA.fwd.bw", package = "tidyCoverage"), RNA_rev = system.file("extdata", "RNA.rev.bw", package = "tidyCoverage") ) |> map(import, as = 'Rle') CoverageExperiment(tracks, features, width = 5000) ############################################################################# ## 4. Correct for strandness when recovering coverage ############################################################################# TSSs_bed <- system.file("extdata", "TSSs.bed", package = "tidyCoverage") features <- list( TSS_fwd = import(TSSs_bed) |> filter(strand == '+'), TSS_rev = import(TSSs_bed) |> filter(strand == '-') ) tracks <- list( RNA_fwd = system.file("extdata", "RNA.fwd.bw", package = "tidyCoverage"), RNA_rev = system.file("extdata", "RNA.rev.bw", package = "tidyCoverage") ) |> map(import, as = 'Rle') CoverageExperiment(tracks, features, width = 5000, ignore.strand = FALSE) ############################################################################# ## Aggregating a `CoverageExperiment` object ############################################################################# data(ce) coarsen(ce, window = 10)
CoverageExperiment and AggregatedCoverage objectsTwo example objects are provided in the tidyCoverage package:
ce: a CoverageExperiment dataset containing stranded RNA-seq coverage
(forward and reverse) over Scc1 peaks (± 1kb).
ac: an AggregatedCoverage object obtained with aggregate(ce).
data(ce) data(ac)data(ce) data(ac)
CoverageExperiment object containing 1 features set and 2 tracks.
AggregatedCoverage object containing 1 features set and 2 tracks.
Data was generated in yeast (S288c) and aligned to reference R64-1-1.
A CoverageExperiment object can be coerced into a tibble using the
tidySummarizedExperiment package, but this will not turn
each coverage matrix into a "long" format. The expand function
provided here allows one to coerce a CoverageExperiment
object into a long data frame, and adds the ranges
and seqnames to the resulting tibble.
## S3 method for class 'CoverageExperiment' expand(data, ..., .name_repair = NULL)## S3 method for class 'CoverageExperiment' expand(data, ..., .name_repair = NULL)
data |
A data frame. |
... |
<
When used with factors, When used with continuous variables, you may need to fill in values
that do not appear in the data: to do so use expressions like
|
.name_repair |
One of |
a tibble object
With grouped data frames created by dplyr::group_by(), expand() operates
within each group. Because of this, you cannot expand on a grouping column.
complete() to expand list objects. expand_grid()
to input vectors rather than a data frame.
data(ce) ce expand(ce)data(ce) ce expand(ce)
Plotting functions for tidyCoverage objects. Two geoms are provided:
geom_coverage(): for plotting coverages over individual loci.
geom_aggrcoverage(): for plotting aggregated coverages with confidence intervals.
See the Details section for more information on the aesthetics used by each geom.
geom_aggrcoverage( mapping = NULL, data = NULL, ..., unit = c("kb", "Mb", "b"), ci = TRUE, grid = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_coverage( mapping = NULL, data = NULL, ..., type = c("area", "line"), unit = c("kb", "Mb", "b"), grid = FALSE, alpha = 0.6, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, raster = TRUE ) scale_y_coverage() scale_x_genome(unit = c("kb", "Mb", "b"))geom_aggrcoverage( mapping = NULL, data = NULL, ..., unit = c("kb", "Mb", "b"), ci = TRUE, grid = FALSE, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) geom_coverage( mapping = NULL, data = NULL, ..., type = c("area", "line"), unit = c("kb", "Mb", "b"), grid = FALSE, alpha = 0.6, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE, raster = TRUE ) scale_y_coverage() scale_x_genome(unit = c("kb", "Mb", "b"))
mapping |
Set of aesthetic mappings created by aes().
By default, no color/fill aesthetic
is specified, but they can be assigned to a variable with |
data |
Data frame passed to geom_*. Typically a |
..., na.rm, show.legend, inherit.aes
|
Argument passed to |
unit |
Rounding of x axis (any of c('b', 'kb', 'Mb')). |
ci |
Should the confidence interval be plotted by |
grid |
Should the plot grid by displayed? (default: FALSE). |
type |
Choose between "line" and "area" style for |
alpha |
Transparency level for |
raster |
Should the plot be rasterized for faster rendering? (default: TRUE) |
These geoms are drawn using geom_line/ribbon/area() so they support the same
aesthetics: colour, linetype and linewidth. Both geoms also support
the unit argument to control the x axis units (b, kb, Mb).
In addition, they each support additional arguments:
geom_coverage uses a type argument to switch between line plot and area plots;
geom_aggrcoverage uses a ci argument to toggle the confidence interval display.
A ggplot object
library(rtracklayer) library(plyranges) library(ggplot2) library(purrr) TSSs_bed <- system.file("extdata", "TSSs.bed", package = "tidyCoverage") features <- list( TSS_fwd = import(TSSs_bed) |> filter(strand == '+'), TSS_rev = import(TSSs_bed) |> filter(strand == '-'), conv_sites = import(system.file("extdata", "conv_transcription_loci.bed", package = "tidyCoverage")) ) tracks <- list( RNA_fwd = system.file("extdata", "RNA.fwd.bw", package = "tidyCoverage"), RNA_rev = system.file("extdata", "RNA.rev.bw", package = "tidyCoverage"), Scc1 = system.file("extdata", "Scc1.bw", package = "tidyCoverage") ) |> map(import, as = 'Rle') ce <- CoverageExperiment(tracks, features, width = 5000, center = TRUE, scale = TRUE) ac <- aggregate(ce) ############################################################################# ## 1. Plotting aggregated coverage ############################################################################# ac |> as_tibble() |> ggplot() + geom_aggrcoverage(aes(col = track)) + facet_grid(track ~ features) + geom_vline(xintercept = 0, color = 'black', linetype = 'dashed', linewidth = 0.5) ############################################################################# ## 2. Plotting track coverages over individual loci ############################################################################# ce2 <- CoverageExperiment( tracks, GRangesList(list(locus1 = "II:400001-455000", locus2 = "IV:720001-775000")), window = 50 ) expand(ce2) |> mutate(coverage = ifelse(track != 'Scc1', scales::oob_squish(coverage, c(0, 50)), coverage)) |> ggplot() + geom_coverage(aes(fill = track)) + facet_grid(track~features, scales = 'free')library(rtracklayer) library(plyranges) library(ggplot2) library(purrr) TSSs_bed <- system.file("extdata", "TSSs.bed", package = "tidyCoverage") features <- list( TSS_fwd = import(TSSs_bed) |> filter(strand == '+'), TSS_rev = import(TSSs_bed) |> filter(strand == '-'), conv_sites = import(system.file("extdata", "conv_transcription_loci.bed", package = "tidyCoverage")) ) tracks <- list( RNA_fwd = system.file("extdata", "RNA.fwd.bw", package = "tidyCoverage"), RNA_rev = system.file("extdata", "RNA.rev.bw", package = "tidyCoverage"), Scc1 = system.file("extdata", "Scc1.bw", package = "tidyCoverage") ) |> map(import, as = 'Rle') ce <- CoverageExperiment(tracks, features, width = 5000, center = TRUE, scale = TRUE) ac <- aggregate(ce) ############################################################################# ## 1. Plotting aggregated coverage ############################################################################# ac |> as_tibble() |> ggplot() + geom_aggrcoverage(aes(col = track)) + facet_grid(track ~ features) + geom_vline(xintercept = 0, color = 'black', linetype = 'dashed', linewidth = 0.5) ############################################################################# ## 2. Plotting track coverages over individual loci ############################################################################# ce2 <- CoverageExperiment( tracks, GRangesList(list(locus1 = "II:400001-455000", locus2 = "IV:720001-775000")), window = 50 ) expand(ce2) |> mutate(coverage = ifelse(track != 'Scc1', scales::oob_squish(coverage, c(0, 50)), coverage)) |> ggplot() + geom_coverage(aes(fill = track)) + facet_grid(track~features, scales = 'free')
CoverageExperiment and AggregatedCoverage objectsshow method for CoverageExperiment and AggregatedCoverage objects
object |
a |
setup |
a setup object returned from |
Prints a message to the console describing the contents of the CoverageExperimentorAggregatedCoverage' objects.
data(ce) print(ce) data(ac) print(ac)data(ce) print(ce) data(ac) print(ac)