Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error in testthat due to NA handling in test-17-bedgraph.r when exporting meth.diff as log-transformed value #331

Open
2 tasks
alexg9010 opened this issue Nov 12, 2024 · 0 comments · May be fixed by #332
Open
2 tasks

Comments

@alexg9010
Copy link
Collaborator

alexg9010 commented Nov 12, 2024

The recent Bioconductor check on nebbiolo1 for the methylKit package version 1.33.0 encountered an error in testthat.R.
An error occurred in the test suite tests/testthat.R, specifically in test-17-bedgraph.r:19:1. The error was caused by a scan() function call in R, where it expected a numeric (real) value but encountered 'NA'.

Reason

This error occurs when we want to export the meth.diffvalue as log transformed value. This will lead to NA output, which causes rtracklayer to complain upon import. similiar to perc.meththe meth.diff value should not be allowed to be transformed.

Summary of Error:

In test-17-bedgraph.r:

══ Failed tests ════════════════════════════════════════════════════════════════
── Error ('test-17-bedgraph.r:19:1'): (code run outside of test_that()) ──────
Error in scan(file = file, what = what, sep = sep, quote = quote, dec = dec, nmax = nrows, skip = 0, na.strings = na.strings, quiet = TRUE, fill = fill, strip.white = strip.white, blank.lines.skip = blank.lines.skip, multi.line = FALSE, comment.char = comment.char, allowEscapes = allowEscapes, flush = flush, encoding = encoding, skipNul = skipNul): scan() expected 'a real', got 'NA'

Details:

  • Line 19 causes failure:

    # getting a bedgraph file from a methylDiff object containing differential
    # methylation percentages
    outFile <- tempfile(pattern = "mdiff.",tmpdir = outDir,fileext = ".bed")
    bedgraph(methylDiff.obj, file.name=outFile, col.name="meth.diff",
    unmeth=FALSE,log.transform=FALSE,negative=FALSE,add.on="")
    tt <- rtracklayer::import.bedGraph(outFile)
    outFile2 <- tempfile(pattern = "mdiff.",tmpdir = outDir,fileext = ".bed")
    suppressWarnings(bedgraph(methylDiff.obj,col.name = "meth.diff",
    log.transform = TRUE,negative = TRUE,file.name = outFile2))
    tt2 <- rtracklayer::import.bedGraph(outFile2)

  • Error Message:

Error in scan(file = file, ...): scan() expected 'a real', got 'NA'

  • Environment: Linux (Ubuntu 24.04.1 LTS), R Under development (unstable), gcc 13.2.0.

Suggested Fixes

  • Disallow transformation of meth.diff values
  • update tests

Testthat Log

Expand

methylKit.Rcheck/tests/testthat.Rout.fail


R Under development (unstable) (2024-10-21 r87258) -- "Unsuffered Consequences"
Copyright (C) 2024 The R Foundation for Statistical Computing
Platform: x86_64-pc-linux-gnu

R is free software and comes with ABSOLUTELY NO WARRANTY.
You are welcome to redistribute it under certain conditions.
Type 'license()' or 'licence()' for distribution details.

R is a collaborative project with many contributors.
Type 'contributors()' for more information and
'citation()' on how to cite R or R packages in publications.

Type 'demo()' for some demos, 'help()' for on-line help, or
'help.start()' for an HTML browser interface to help.
Type 'q()' to quit R.

> library(testthat)
> library(methylKit)
Loading required package: GenomicRanges
Loading required package: stats4
Loading required package: BiocGenerics
Loading required package: generics

Attaching package: 'generics'

The following objects are masked from 'package:base':

    as.difftime, as.factor, as.ordered, intersect, is.element, setdiff,
    setequal, union


Attaching package: 'BiocGenerics'

The following objects are masked from 'package:generics':

    intersect, setdiff, setequal, union

The following objects are masked from 'package:stats':

    IQR, mad, sd, var, xtabs

The following objects are masked from 'package:base':

    Filter, Find, Map, Position, Reduce, anyDuplicated, aperm, append,
    as.data.frame, basename, cbind, colnames, dirname, do.call,
    duplicated, eval, evalq, get, grep, grepl, intersect, is.unsorted,
    lapply, mapply, match, mget, order, paste, pmax, pmax.int, pmin,
    pmin.int, rank, rbind, rownames, sapply, saveRDS, setdiff,
    setequal, table, tapply, union, unique, unsplit, which.max,
    which.min

Loading required package: S4Vectors

Attaching package: 'S4Vectors'

The following object is masked from 'package:utils':

    findMatches

The following objects are masked from 'package:base':

    I, expand.grid, unname

Loading required package: IRanges
Loading required package: GenomeInfoDb
> 
> 
> 
> test_check("methylKit")
Using internal DSS code... 
Using internal DSS code... 
[ FAIL 1 | WARN 0 | SKIP 0 | PASS 224 ]

══ Failed tests ════════════════════════════════════════════════════════════════
── Error ('test-17-bedgraph.r:19:1'): (code run outside of `test_that()`) ──────
Error in `scan(file = file, what = what, sep = sep, quote = quote, dec = dec, 
    nmax = nrows, skip = 0, na.strings = na.strings, quiet = TRUE, 
    fill = fill, strip.white = strip.white, blank.lines.skip = blank.lines.skip, 
    multi.line = FALSE, comment.char = comment.char, allowEscapes = allowEscapes, 
    flush = flush, encoding = encoding, skipNul = skipNul)`: scan() expected 'a real', got 'NA'
Backtrace:
     ▆
  1. ├─rtracklayer::import.bedGraph(outFile2) at test-17-bedgraph.r:19:1
  2. └─rtracklayer::import.bedGraph(outFile2)
  3.   ├─BiocIO::import(con, "bedGraph", ...)
  4.   └─BiocIO::import(con, "bedGraph", ...)
  5.     ├─BiocIO::import(FileForFormat(con, format), ...)
  6.     └─rtracklayer::import(FileForFormat(con, format), ...)
  7.       └─rtracklayer (local) .local(con, format, text, ...)
  8.         ├─rtracklayer::import.ucsc(...)
  9.         └─rtracklayer::import.ucsc(...)
 10.           └─rtracklayer (local) .local(con, ...)
 11.             ├─rtracklayer::import.ucsc(...)
 12.             └─rtracklayer::import.ucsc(...)
 13.               ├─BiocIO::import(con, "ucsc", ...)
 14.               └─BiocIO::import(con, "ucsc", ...)
 15.                 ├─BiocIO::import(FileForFormat(con, format), ...)
 16.                 └─rtracklayer::import(FileForFormat(con, format), ...)
 17.                   └─rtracklayer (local) .local(con, format, text, ...)
 18.                     ├─BiocGenerics::lapply(seq_along(trackLines), makeTrackSet)
 19.                     └─base::lapply(seq_along(trackLines), makeTrackSet)
 20.                       └─rtracklayer (local) FUN(X[[i]], ...)
 21.                         ├─BiocIO::import(...)
 22.                         └─BiocIO::import(...)
 23.                           ├─BiocIO::import(FileForFormat(con, format), ...)
 24.                           └─rtracklayer::import(FileForFormat(con, format), ...)
 25.                             └─rtracklayer (local) .local(con, format, text, ...)
 26.                               ├─S4Vectors::DataFrame(...)
 27.                               └─utils::read.table(...)
 28.                                 └─base::scan(...)

[ FAIL 1 | WARN 0 | SKIP 0 | PASS 224 ]
Error: Test failures
Execution halted

alexg9010 added a commit that referenced this issue Nov 12, 2024
Fixes #331

Fix the error in `tests/testthat/test-17-bedgraph.r` due to NA handling in `meth.diff` export as log-transformed value.

* **R/bedgraph.R**
  - Disallow transformation of `meth.diff` values in `bedgraph` function for `methylDiff` objects.
  - Add a check to ensure `log.transform` is `FALSE` when `col.name` is `meth.diff`.

* **tests/testthat/test-17-bedgraph.r**
  - Update tests to ensure `log.transform` is not allowed for `meth.diff` values.
  - Add a test to check for error when `log.transform` is `TRUE` for `meth.diff`.
  - Add tests for `methylDiffDB` objects to ensure `log.transform` is not allowed for `meth.diff` values.

* **R/methylDBFunctions.R**
  - Add a check to ensure `log.transform` is `FALSE` when `col.name` is `meth.diff`.
  - Disallow transformation of `meth.diff` values in `bedgraph` function for `methylDiffDB` objects.

---

For more details, open the [Copilot Workspace session](https://copilot-workspace.githubnext.com/al2na/methylKit/issues/331?shareId=XXXX-XXXX-XXXX-XXXX).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant