Skip to content

Commit

Permalink
multiqc: parse plots and write only when rds
Browse files Browse the repository at this point in the history
  • Loading branch information
pdiakumis committed Nov 30, 2023
1 parent b875fac commit fdc404b
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 6 deletions.
19 changes: 16 additions & 3 deletions R/multiqc.R
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
#' x <- "/path/to/multiqc_data.json"
#' mqc <- MultiqcFile$new(x)
#' mqc_parsed <- mqc$read() # or read(mqc)
#' mqc$write(mqc_parsed, out_dir = tempdir(), prefix = "sample705", out_format = "both")
#' mqc$write(mqc_parsed, out_dir = tempdir(), prefix = "sample705", out_format = "tsv")
#' mqc_plots_parsed <- mqc$read(plot = TRUE, plot_names = "everything")
#' mqc$write(mqc_plots_parsed, out_dir = tempdir(), prefix = "sample705", out_format = "rds")
#' }
#' @export
MultiqcFile <- R6::R6Class(
Expand All @@ -19,11 +21,19 @@ MultiqcFile <- R6::R6Class(
#' @description
#' Reads the `multiqc_data.json` file output from MultiQC.
#'
#' @param plot Return tibble with data for plots (def: FALSE).
#' @param plot_names Names of plots to parse. Use "everything" if you wantz all
#' the plotz.
#' @return A tidy tibble.
#' - label:
read = function() {
read = function(plot = FALSE, plot_names = NULL) {
x <- self$path
multiqc_tidy_json(x)
res <- multiqc_tidy_json(x)
if (plot) {
p <- multiqc_parse_plots(x, plot_names = plot_names)
res <- list(metrics = res, plots = p)
}
return(res)
},

#' @description
Expand All @@ -40,6 +50,9 @@ MultiqcFile <- R6::R6Class(
prefix <- file.path(out_dir, prefix)
}
# prefix2 <- glue("{prefix}multiqc")
# only write plots if output format is rds, else need to destructure the whole thing...
has_plots_and_not_rds <- !inherits(d, "data.frame") && out_format != "rds"
assertthat::assert_that(!has_plots_and_not_rds)
write_dracarys(obj = d, prefix = prefix, out_format = out_format, drid = drid)
}
)
Expand Down
16 changes: 14 additions & 2 deletions man/MultiqcFile.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-roxytest-testexamples-multiqc.R
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

# File R/multiqc.R: @testexamples

test_that("Function multiqc_date_fmt() @ L284", {
test_that("Function multiqc_date_fmt() @ L297", {

cdate <- "2023-04-07, 09:09 UTC"
(res1 <- multiqc_date_fmt(cdate))
Expand Down

0 comments on commit fdc404b

Please sign in to comment.