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.3.0 |
Built: | 2024-12-19 04:26:47 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 |
an |
... |
ignored |
tibble
data(ac) as_tibble(ac)
data(ac) as_tibble(ac)
#' @description
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. |
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.
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 |
... , .name_repair
|
ignored |
a tibble
object
data(ce) ce expand(ce)
data(ce) ce expand(ce)
#' @description
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, na.rm = FALSE, show.legend = NA, inherit.aes = 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, na.rm = FALSE, show.legend = NA, inherit.aes = TRUE ) scale_y_coverage() scale_x_genome(unit = c("kb", "Mb", "b"))
mapping |
Aesthetics for geom_*. 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 |
Plotting functions for tidyCoverage objects
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')
show method for CoverageExperiment
and AggregatedCoverage
objects
## S4 method for signature 'CoverageExperiment' show(object) ## S4 method for signature 'AggregatedCoverage' show(object) ## S3 method for class 'CoverageExperiment' print(x, ..., n = NULL) ## S3 method for class 'AggregatedCoverage' print(x, ..., n = NULL) ## S3 method for class 'tidyCoverageExperiment' tbl_format_header(x, setup, ...) ## S3 method for class 'tidyAggregatedCoverage' tbl_format_header(x, setup, ...)
## S4 method for signature 'CoverageExperiment' show(object) ## S4 method for signature 'AggregatedCoverage' show(object) ## S3 method for class 'CoverageExperiment' print(x, ..., n = NULL) ## S3 method for class 'AggregatedCoverage' print(x, ..., n = NULL) ## S3 method for class 'tidyCoverageExperiment' tbl_format_header(x, setup, ...) ## S3 method for class 'tidyAggregatedCoverage' tbl_format_header(x, setup, ...)
object |
a |
x |
Object to format or print. |
... |
Passed on to |
n |
Number of rows to show. If |
setup |
a setup object returned from |
Prints a message to the console describing the contents of the
CoverageExperimentor
AggregatedCoverage' objects.
data(ce) print(ce) data(ac) print(ac)
data(ce) print(ce) data(ac) print(ac)