Package 'tidyCoverage'

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-11-19 04:30:21 UTC
Source: https://github.com/bioc/tidyCoverage

Help Index


aggregate

Description

Bin coverage contained in a CoverageExperiment into an AggregatedCoverage object.

Usage

## S4 method for signature 'CoverageExperiment'
aggregate(x, bin = 1, ...)

Arguments

x

a CoverageExperiment object

bin

an integer to bin each assay by. The width of the AggregatedCoverage object should be a multiple of bin.

...

ignored

Value

an AggregatedCoverage object

Examples

data(ce)
aggregate(ce, bin = 10)

as_tibble

Description

Coerce an CoverageExperiment or AggregatedCoverage object into a tibble

Usage

## S3 method for class 'AggregatedCoverage'
as_tibble(x, ...)

Arguments

x

an CoverageExperiment object

...

ignored

Value

tibble

Examples

data(ac)
as_tibble(ac)

CoverageExperiment

Description

#' @description

Usage

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())

Arguments

tracks

A genomic track imported as a RleList or a named list of genomic tracks.

features

A set of features imported as GRanges or a named GRangesList.

...

Passed to the relevant method

x

a CoverageExperiment object

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.

Details

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.

Value

A CoverageExperiment object

Examples

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)

Example CoverageExperiment and AggregatedCoverage objects

Description

Two 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).

Usage

data(ce)

data(ac)

Format

CoverageExperiment object containing 1 features set and 2 tracks.

AggregatedCoverage object containing 1 features set and 2 tracks.

Details

Data was generated in yeast (S288c) and aligned to reference R64-1-1.


Expand a CoverageExperiment object

Description

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.

Usage

## S3 method for class 'CoverageExperiment'
expand(data, ..., .name_repair = NULL)

Arguments

data

a CoverageExperiment object

..., .name_repair

ignored

Value

a tibble object

Examples

data(ce)
ce

expand(ce)

Plotting functions

Description

#' @description

Usage

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"))

Arguments

mapping

Aesthetics for geom_*. By default, no color/fill aesthetic is specified, but they can be assigned to a variable with mapping = aes(...). Note that x and y are automatically filled.

data

Data frame passed to geom_*. Typically a CoverageExperiment object (expanded to a tibble) or a AggregatedCoverage object.

..., na.rm, show.legend, inherit.aes

Argument passed to ggplot internal functions

unit

Rounding of x axis (any of c('b', 'kb', 'Mb')).

ci

Should the confidence interval be plotted by geom_aggrcoverage()? (default: TRUE)

grid

Should the plot grid by displayed? (default: FALSE).

type

Choose between "line" and "area" style for geom_coverage().

Details

Plotting functions for tidyCoverage objects

Value

A ggplot object'

Examples

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

Description

show method for CoverageExperiment and AggregatedCoverage objects

Usage

## 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, ...)

Arguments

object

a CoverageExperiment or AggregatedCoverage object

x

Object to format or print.

...

Passed on to tbl_format_setup().

n

Number of rows to show. If NULL, the default, will print all rows if less than the print_max option. Otherwise, will print as many rows as specified by the print_min option.

setup

a setup object returned from pillar::tbl_format_setup().

Value

⁠Prints a message to the console describing the contents of the ⁠CoverageExperimentorAggregatedCoverage' objects.

Examples

data(ce)
print(ce)
data(ac)
print(ac)