|
| 1 | +# tidyCoverage |
| 2 | + |
| 3 | +## Load libraries and example datasets |
| 4 | + |
| 5 | +```r |
| 6 | +library(tidyCoverage) |
| 7 | +library(tidySummarizedExperiment) |
| 8 | +library(rtracklayer) |
| 9 | +library(plyranges) |
| 10 | +library(purrr) |
| 11 | +library(ggplot2) |
| 12 | + |
| 13 | +# ~~~~~~~~~~~~~~~ Import genomic features into a named list ~~~~~~~~~~~~~~~ # |
| 14 | +features <- list( |
| 15 | + TSSs = system.file("extdata", "TSSs.bed", package = "tidyCoverage"), |
| 16 | + conv_sites = system.file("extdata", "conv_transcription_loci.bed", package = "tidyCoverage") |
| 17 | +) |> map(~ import(.x)) |
| 18 | + |
| 19 | +# ~~~~~~~~~~~~ Import coverage tracks into a `BigWigFileList` ~~~~~~~~~~~~~ # |
| 20 | +tracks <- list( |
| 21 | + Scc1 = system.file("extdata", "Scc1.bw", package = "tidyCoverage"), |
| 22 | + RNA_fwd = system.file("extdata", "RNA.fwd.bw", package = "tidyCoverage"), |
| 23 | + RNA_rev = system.file("extdata", "RNA.rev.bw", package = "tidyCoverage"), |
| 24 | + PolII = system.file("extdata", "PolII.bw", package = "tidyCoverage"), |
| 25 | + MNase = system.file("extdata", "MNase.bw", package = "tidyCoverage") |
| 26 | +) |> BigWigFileList() |
| 27 | +``` |
| 28 | + |
| 29 | +## Plot tracks coverage aggregated over genomic features |
| 30 | + |
| 31 | +```r |
| 32 | +CoverageExperiment(tracks, features, width = 3000, ignore.strand = FALSE) |> |
| 33 | + filter(track %in% c('MNase', 'PolII')) |> |
| 34 | + filter(features == 'TSSs') |> |
| 35 | + aggregate() |> |
| 36 | + ggplot(aes(x = coord, y = mean)) + |
| 37 | + geom_ribbon(aes(ymin = ci_low, ymax = ci_high, fill = track), alpha = 0.2) + |
| 38 | + geom_line(aes(col = track)) + |
| 39 | + facet_grid(track ~ ., scales = "free") + |
| 40 | + labs(x = 'Distance from TSS', y = 'Signal coverage') + |
| 41 | + theme_bw() + |
| 42 | + theme(legend.position = 'top') |
| 43 | +``` |
| 44 | + |
| 45 | + |
| 46 | + |
| 47 | +## Plot coverage over a single locus |
| 48 | + |
| 49 | +```r |
| 50 | +CoverageExperiment(tracks, GRanges("II:450001-455000"), width = 5000) |> |
| 51 | + expand() |> |
| 52 | + ggplot(aes(x = coord, y = coverage)) + |
| 53 | + geom_col(aes(fill = track, col = track)) + |
| 54 | + facet_grid(track~., scales = 'free') + |
| 55 | + scale_x_continuous(expand = c(0, 0)) + |
| 56 | + theme_bw() + |
| 57 | + theme(legend.position = "none", aspect.ratio = 0.1) |
| 58 | +``` |
| 59 | + |
| 60 | + |
0 commit comments