Skip to content

Commit

Permalink
Tested devel after bugfix
Browse files Browse the repository at this point in the history
  • Loading branch information
smped committed May 18, 2024
1 parent d8dd019 commit ab84ee0
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
Package: extraChIPs
Version: 1.8.1
Version: 1.9.2
Title: Additional functions for working with ChIP-Seq data
Authors@R: person("Stevie", "Pederson",
email = "[email protected]",
Expand Down
5 changes: 3 additions & 2 deletions R/addDiffStatus.R
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,11 @@ setMethod(
stopifnot(is.numeric(x[[sig_col]]))
sig <- x[[sig_col]] < alpha
status <- case_when(
!sig ~ other[[1]],
is.na(sig) | is.na(fc) ~ missing[[1]],
!sig ~ other[[1]],
fc > abs(cutoff) ~ up[[1]],
fc < -abs(cutoff) ~ down[[1]]
fc < -abs(cutoff) ~ down[[1]],
TRUE ~ other[[1]]
)
## Do we need to add an explicit NA value here?
lv <- unique(c(other, down, up, missing))
Expand Down
8 changes: 6 additions & 2 deletions R/colToRanges.R
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,8 @@
#' @param seqinfo A seqinfo object to be applied to the new GRanges object.
#' Ignored if the column is already a GRanges object
#' @param ... Used to pass arguments to lower-level functions
#' @param keep_metadata logical(1) If the original object is a GRanges object,
#' retain all metadata from the original ranges in the replaced ranges
#'
#' @importFrom methods as
#' @import GenomicRanges
Expand Down Expand Up @@ -57,9 +59,11 @@ setMethod(
#' @export
setMethod(
"colToRanges", signature = signature(x = "GRanges"),
function(x, var, ...) {
function(x, var, ..., keep_metadata = TRUE) {
df <- mcols(x)
colToRanges(df, var, ...)
gr <- colToRanges(df, var, ...)
if (keep_metadata) metadata(gr) <- metadata(x)
gr
}
)
#' @import GenomicRanges
Expand Down
5 changes: 4 additions & 1 deletion man/colToRanges-methods.Rd

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

5 changes: 4 additions & 1 deletion tests/testthat/test_colToRanges.R
Original file line number Diff line number Diff line change
@@ -1,17 +1,20 @@
sq <- Seqinfo("chr1", 100, FALSE, "test")
x <- GRanges(c("chr1:1-10", "chr1:6-15", "chr1:51-60"), seqinfo = sq)
df <- data.frame(logFC = rnorm(3), logCPM = rnorm(3,8), p = 10^-rexp(3))
gr <-mergeByCol(x, df, col = "logCPM", pval = "p")
gr <- mergeByCol(x, df, col = "logCPM", pval = "p")
metadata(gr) <- list(check = TRUE)

test_that("Coercion is correct where it should be", {
new_gr <- colToRanges(gr, "keyval_range")
expect_s4_class(new_gr, "GRanges")
expect_true(metadata(new_gr)$check)
expect_equal(
colnames(mcols(new_gr)),
c("n_windows", "n_up", "n_down", "logCPM", "logFC", "p", "p_fdr")
)
expect_equal(length(new_gr), 2)
df$gr <- as.character(x)
## Now try using a df
new_gr <- colToRanges(df, "gr", seqinfo = sq)
expect_s4_class(new_gr, "GRanges")
expect_equal(seqinfo(new_gr), sq)
Expand Down

0 comments on commit ab84ee0

Please sign in to comment.