-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit 6063d36
Showing
29 changed files
with
3,574 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
^LICENSE\.md$ | ||
^README\.Rmd$ | ||
^\.github$ | ||
^_pkgdown\.yml$ | ||
^docs$ | ||
^pkgdown$ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
*.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
The Bioconductor community values | ||
|
||
* an open approach to science that promotes the sharing of ideas, code, and expertise | ||
* collaboration | ||
* diversity and inclusivity | ||
* a kind and welcoming environment | ||
* community contributions | ||
|
||
In line with these values, Bioconductor is dedicated to providing a welcoming, supportive, collegial, experience free of harassment, intimidation, and bullying regardless of: | ||
|
||
* identity: gender, gender identity and expression, sexual orientation, disability, physical appearance, ethnicity, body size, race, age, religion, etc. | ||
* intellectual position: approaches to data analysis, software preferences, coding style, scientific perspective, etc. | ||
* stage of career | ||
|
||
In order to uphold these values, members of the Bioconductor community are required to follow the Code of Conduct.The latest version of Bioconductor project Code of Conduct is available at http://bioconductor.org/about/code-of-conduct/. Please read the Code of Conduct before contributing to this project. | ||
|
||
Thank you! |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
name: rworkflows | ||
'on': | ||
push: | ||
branches: | ||
- master | ||
- main | ||
- devel | ||
- RELEASE_** | ||
pull_request: | ||
branches: | ||
- master | ||
- main | ||
- devel | ||
- RELEASE_** | ||
jobs: | ||
rworkflows: | ||
permissions: write-all | ||
runs-on: ${{ matrix.config.os }} | ||
name: ${{ matrix.config.os }} (${{ matrix.config.r }}) | ||
container: ${{ matrix.config.cont }} | ||
strategy: | ||
fail-fast: ${{ false }} | ||
matrix: | ||
config: | ||
- os: ubuntu-latest | ||
bioc: devel | ||
r: auto | ||
cont: ghcr.io/bioconductor/bioconductor_docker:devel | ||
rspm: ~ | ||
- os: macOS-latest | ||
bioc: release | ||
r: auto | ||
cont: ~ | ||
rspm: ~ | ||
- os: windows-latest | ||
bioc: release | ||
r: auto | ||
cont: ~ | ||
rspm: ~ | ||
steps: | ||
- uses: neurogenomics/rworkflows@master | ||
with: | ||
run_bioccheck: ${{ false }} | ||
run_rcmdcheck: ${{ true }} | ||
as_cran: ${{ true }} | ||
run_vignettes: ${{ true }} | ||
has_testthat: ${{ true }} | ||
run_covr: ${{ true }} | ||
run_pkgdown: ${{ true }} | ||
has_runit: ${{ false }} | ||
has_latex: ${{ false }} | ||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} | ||
run_docker: ${{ false }} | ||
DOCKER_TOKEN: ${{ secrets.DOCKER_TOKEN }} | ||
runner_os: ${{ runner.os }} | ||
cache_version: cache-v1 | ||
docker_registry: ghcr.io |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
inst/doc | ||
docs |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
Package: AggregatedCoverage | ||
Title: Coverage metrics over aligned genomic features of interest | ||
Version: 0.99.0 | ||
Date: 2023-11-09 | ||
Authors@R: | ||
person("First", "Last", , "[email protected]", role = c("aut", "cre"), | ||
comment = c(ORCID = "YOUR-ORCID-ID")) | ||
Description: What the package does (one paragraph). | ||
License: MIT + file LICENSE | ||
URL: | ||
BugReports: https://support.bioconductor.org/tag/AggregatedCoverage | ||
biocViews: Software | ||
Encoding: UTF-8 | ||
Roxygen: list(markdown = TRUE) | ||
RoxygenNote: 7.2.3 | ||
Imports: | ||
SummarizedExperiment, | ||
dplyr, | ||
GenomicRanges, | ||
GenomeInfoDb, | ||
methods, | ||
BiocParallel | ||
Suggests: | ||
plyranges, | ||
rtracklayer, | ||
ggplot2, | ||
TxDb.Hsapiens.UCSC.hg19.knownGene, | ||
GenomicFeatures, | ||
BiocStyle, | ||
knitr, | ||
rmarkdown, | ||
sessioninfo, | ||
testthat (>= 3.0.0) | ||
Config/testthat/edition: 3 | ||
VignetteBuilder: knitr |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
YEAR: 2023 | ||
COPYRIGHT HOLDER: AggregatedCoverage authors |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# MIT License | ||
|
||
Copyright (c) 2023 AggregatedCoverage authors | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
# Generated by roxygen2: do not edit by hand | ||
|
||
S3method(as_tibble,AggregatedCoverage) | ||
export(AggregatedCoverage) | ||
import(GenomeInfoDb) | ||
import(GenomicRanges) | ||
import(SummarizedExperiment) | ||
import(methods) | ||
importFrom(BiocParallel,bplapply) | ||
importFrom(BiocParallel,bpparam) | ||
importFrom(SummarizedExperiment,SummarizedExperiment) | ||
importFrom(SummarizedExperiment,assay) | ||
importFrom(SummarizedExperiment,assays) | ||
importFrom(SummarizedExperiment,colData) | ||
importFrom(SummarizedExperiment,rowData) | ||
importFrom(SummarizedExperiment,rowRanges) | ||
importFrom(dplyr,as_tibble) | ||
importFrom(dplyr,bind_cols) | ||
importFrom(dplyr,bind_rows) | ||
importFrom(dplyr,filter) | ||
importFrom(dplyr,mutate) | ||
importFrom(dplyr,relocate) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,107 @@ | ||
#' AggregatedCoverage | ||
#' | ||
#' This function initiates a `AggregatedCoverage` object. | ||
#' | ||
#' @param tracks Named list of genomic tracks (RleList) | ||
#' @param features Named GRangesList | ||
#' @param width Width at which each feature will be rescaled | ||
#' @param BPPARAM Passed to BiocParallel | ||
#' @return A `AggregatedCoverage` object | ||
#' | ||
#' @import GenomicRanges | ||
#' @import GenomeInfoDb | ||
#' @import SummarizedExperiment | ||
#' @importFrom dplyr filter | ||
#' @importFrom dplyr bind_rows | ||
#' @importFrom dplyr bind_cols | ||
#' @importFrom dplyr mutate | ||
#' @importFrom dplyr relocate | ||
#' @import methods | ||
#' @importFrom SummarizedExperiment SummarizedExperiment | ||
#' @importFrom SummarizedExperiment colData | ||
#' @importFrom SummarizedExperiment rowData | ||
#' @importFrom SummarizedExperiment rowRanges | ||
#' @importFrom SummarizedExperiment assay | ||
#' @importFrom SummarizedExperiment assays | ||
#' @importFrom BiocParallel bpparam | ||
#' @importFrom BiocParallel bplapply | ||
#' @export | ||
#' | ||
#' @examples | ||
#' library(plyranges) | ||
#' library(rtracklayer) | ||
#' scc1_peaks <- system.file("extdata", "Scc1-peaks.narrowPeak", package = "AggregatedCoverage") |> | ||
#' import() | ||
#' conv_loci <- system.file("extdata", "conv_transcription_loci.bed", package = "AggregatedCoverage") |> | ||
#' import() | ||
#' features <- GRangesList(Scc1 = scc1_peaks, Conv_transcription = conv_loci) | ||
#' tracks <- list( | ||
#' Scc1 = system.file("extdata", "Scc1-vs-input.bw", package = "AggregatedCoverage") |> import(as = 'Rle'), | ||
#' RNA_fwd = system.file("extdata", "SRR2045244.fwd.CPM.bw", package = "AggregatedCoverage") |> import(as = 'Rle'), | ||
#' RNA_rev = system.file("extdata", "SRR2045244.rev.CPM.bw", package = "AggregatedCoverage") |> import(as = 'Rle') | ||
#' ) | ||
#' AC <- AggregatedCoverage(tracks, features, 3000) | ||
#' AC | ||
|
||
AggregatedCoverage <- function(tracks, features, width, BPPARAM = BiocParallel::bpparam()) { | ||
|
||
## Check that input lists are named | ||
stopifnot(length(unique(names(tracks))) == length(tracks)) | ||
stopifnot(length(unique(names(features))) == length(features)) | ||
|
||
## Extend and filter features | ||
tracks <- .set_seqinfo(tracks) | ||
si <- seqinfo(tracks[[1]])[[1]] | ||
features <- lapply(features, .resize_granges, width = width, seqinfo = si) | ||
|
||
## Prepare cData and rData | ||
cData <- data.frame( | ||
track = names(tracks) | ||
) | ||
rData <- GRangesList(features) | ||
mcols(rData) <- data.frame( | ||
features = names(features) | ||
) | ||
|
||
## Aggregate scores | ||
dfs <- BiocParallel::bplapply(names(tracks), function(t) { | ||
lapply(names(features), function(f) { | ||
df <- .compute_cov(tracks[[t]], features[[f]]) | ||
df$track <- t | ||
df$features <- f | ||
return(df) | ||
}) |> dplyr::bind_rows() | ||
}, BPPARAM = BPPARAM) |> dplyr::bind_rows() | ||
|
||
## Fill out different assay matrices | ||
m0 <- matrix( | ||
list(), | ||
nrow = length(features), ncol = length(tracks) | ||
) | ||
colnames(m0) <- names(tracks) | ||
rownames(m0) <- names(features) | ||
assays <- c("mean", "median", "min", "max", "sd", "se", "ci_low", "ci_high") | ||
l_assays <- vector("list", length = length(assays)) | ||
names(l_assays) <- assays | ||
for (assay in assays) { | ||
m <- m0 | ||
for (t in names(tracks)) { | ||
df <- dplyr::filter(dfs, track == t) | ||
for (f in names(features)) { | ||
m[f, t][[1]] <- dplyr::filter(df, features == f)[[assay]] | ||
} | ||
} | ||
l_assays[[assay]] <- m | ||
} | ||
|
||
AC <- methods::new( | ||
"AggregatedCoverage", | ||
SummarizedExperiment::SummarizedExperiment( | ||
rowRanges = rData, | ||
colData = cData, | ||
assays = l_assays | ||
) | ||
) | ||
|
||
return(AC) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
methods::setClass( | ||
"AggregatedCoverage", | ||
contains = c("RangedSummarizedExperiment") | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#' @importFrom dplyr as_tibble | ||
#' @export | ||
|
||
as_tibble.AggregatedCoverage <- function(x, ...) { | ||
tracks <- colData(x)$track | ||
features <- rowData(x)$features | ||
assays <- names(assays(x)) | ||
w <- width(rowRanges(x)[[1]])[[1]] | ||
lapply(tracks, function(t) { | ||
lapply(features, function(f) { | ||
lapply(assays(x), `[[`, f, t) |> | ||
stats::setNames(assays) |> | ||
dplyr::bind_cols() |> | ||
dplyr::mutate( | ||
coord = seq(-w/2, w/2-1, 1), | ||
track = t, features = f | ||
) |> | ||
dplyr::relocate(coord) |> | ||
dplyr::relocate(features) |> | ||
dplyr::relocate(track) | ||
}) |> dplyr::bind_rows() | ||
}) |> dplyr::bind_rows() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
.set_seqinfo <- function(tracks) { | ||
n <- names(tracks) | ||
sls <- lapply(tracks, lengths) | ||
has_seqlengths <- any(!is.na(lapply(sls, sum))) | ||
if (!has_seqlengths) { | ||
sis <- lapply(tracks, function(rle) { | ||
Seqinfo( | ||
names(lengths(rle)), | ||
lengths(rle) | ||
) | ||
}) |> unique() | ||
if (length(unique(sis)) > 1) | ||
stop("More than 1 seqinfo inferred from the tracks.") | ||
si <- sis[[1]] | ||
} | ||
else { | ||
sl <- sls[[which(!is.na(lapply(sls, sum)))[[1]]]] | ||
si <- list(Seqinfo( | ||
names(sl), | ||
sl | ||
)) | ||
} | ||
tracks <- lapply(tracks, function(rle) { | ||
GenomeInfoDb::seqinfo(rle) <- si | ||
return(rle) | ||
}) | ||
names(tracks) <- n | ||
return(tracks) | ||
} | ||
|
||
.resize_granges <- function(gr, width, seqinfo) { | ||
GenomeInfoDb::seqlevels(gr, pruning.mode = "coarse") <- GenomeInfoDb::seqlevels(seqinfo) | ||
GenomeInfoDb::seqinfo(gr) <- seqinfo | ||
gr <- suppressWarnings(resize(gr, fix = 'center', width = width)) | ||
w <- width | ||
gr <- trim(gr) | ||
gr <- gr[width(gr) == w] | ||
} | ||
|
||
.compute_cov <- function(rle, gr) { | ||
scores <- NumericList(rle[gr]) |> as.matrix() | ||
mean <- colMeans(scores, na.rm = TRUE) | ||
median <- apply(scores, 2, median, na.rm = TRUE) | ||
min <- apply(scores, 2, min, na.rm = TRUE) | ||
max <- apply(scores, 2, max, na.rm = TRUE) | ||
sd <- apply(scores, 2, sd, na.rm = TRUE) | ||
se <- sd/sqrt(nrow(scores)) | ||
ci_low <- mean - qt(1 - (0.05 / 2), nrow(scores) - 1) * se | ||
ci_high <- mean + qt(1 - (0.05 / 2), nrow(scores) - 1) * se | ||
data.frame( | ||
coord = seq(-ncol(scores)/2, ncol(scores)/2-1, 1), | ||
mean = mean, median = median, min = min, max = max, | ||
sd = sd, se = se, ci_low = ci_low, ci_high = ci_high | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# AggregatedCoverage | ||
|
||
<!-- badges: start --> | ||
<!-- badges: end --> | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
url: ~ | ||
template: | ||
bootstrap: 5 | ||
|
Oops, something went wrong.