Skip to content

Commit

Permalink
fix: add an expand method from tidyr generic rather than S4Vectors
Browse files Browse the repository at this point in the history
  • Loading branch information
js2264 committed Dec 12, 2023
1 parent a4322ad commit 56e13df
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
18 changes: 9 additions & 9 deletions R/expand.R
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
#' @aliases expand,CoverageExperiment-method
#' @rdname expand
#'
#' @param x a `CoverageExperiment` object
#' @param data a `CoverageExperiment` object
#' @param ...,.name_repair ignored
#' @return a `tibble` object
#'
Expand All @@ -24,18 +24,18 @@
#'
#' expand(ce)

expand.CoverageExperiment <- function(x, ..., .name_repair = NULL) {
tracks <- colData(x)$track
features <- rowData(x)$features
w <- width(rowRanges(x)[[1]])[[1]]
bin <- w / ncol(assay(x, "coverage")[1, 1][[1]])
expand.CoverageExperiment <- function(data, ..., .name_repair = NULL) {
tracks <- colData(data)$track
features <- rowData(data)$features
w <- width(rowRanges(data)[[1]])[[1]]
bin <- w / ncol(assay(data, "coverage")[1, 1][[1]])
df <- lapply(features, function(f) {
rr <- rowRanges(x)[[f]]
rr <- rowRanges(data)[[f]]
rrdf <- as.data.frame(rr)
coord <- lapply(seq_len(nrow(rrdf)), function(K) seq(rrdf[K, 'start'], rrdf[K, 'end'], by = bin)) |> unlist()
coord.scaled <- lapply(seq_len(nrow(rrdf)), function(K) seq(-w/2, w/2-1, by = bin)) |> unlist()
lapply(tracks, function(t) {
m <- assay(x, "coverage")[f, t][[1]] |>
m <- assay(data, "coverage")[f, t][[1]] |>
as.data.frame() |>
dplyr::mutate(
track = t, features = f,
Expand All @@ -55,7 +55,7 @@ expand.CoverageExperiment <- function(x, ..., .name_repair = NULL) {
}) |> dplyr::bind_rows()
}) |>
dplyr::bind_rows() |>
dplyr::left_join(colData(x) |> as.data.frame(), by = 'track') |>
dplyr::left_join(colData(data) |> as.data.frame(), by = 'track') |>
dplyr::group_by(track, features, ranges)
return(df)
}
4 changes: 2 additions & 2 deletions man/expand.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion tests/testthat/test-compute-filter-import-plot.R
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ test_that("expand method works", {
CE <- CoverageExperiment(
tracks, features, width = 100, scale = TRUE, center = TRUE
)
expect_true(all(dim(expand(CE)) == c(402600, 7)))
expect_true(all(dim(expand(CE)) == c(402600, 8)))
expect_true(all(colnames(expand(CE)) == c("track", "features", "chr", "ranges", "strand", "coord", "coverage", "coord.scaled")))
})

Expand Down

0 comments on commit 56e13df

Please sign in to comment.