diff --git a/conf/modules.config b/conf/modules.config index 37798f8d..60e0629d 100644 --- a/conf/modules.config +++ b/conf/modules.config @@ -399,6 +399,14 @@ process { ] } + withName: MAKE_REPORT_BUNDLE { + publishDir = [ + path: { "${params.outdir}/report" }, + mode: params.publish_dir_mode, + pattern: '*.zip' + ] + } + withName: CUSTOM_MATRIXFILTER { publishDir = [ enabled: false diff --git a/modules.json b/modules.json index dcf9482f..0340f17b 100644 --- a/modules.json +++ b/modules.json @@ -67,7 +67,7 @@ }, "rmarkdownnotebook": { "branch": "master", - "git_sha": "603ecbd9f45300c9788f197d2a15a005685b4220", + "git_sha": "4e640839b1076da7c2a2a4a8f160815e00eedfba", "installed_by": ["modules"] }, "shinyngs/app": { @@ -94,6 +94,11 @@ "branch": "master", "git_sha": "d0b4fc03af52a1cc8c6fb4493b921b57352b1dd8", "installed_by": ["modules"] + }, + "zip": { + "branch": "master", + "git_sha": "363ab4f7ed481242f5b1d73f81ffe76cea33fdaf", + "installed_by": ["modules"] } } }, diff --git a/modules/nf-core/rmarkdownnotebook/main.nf b/modules/nf-core/rmarkdownnotebook/main.nf index 45ed550b..3eda8ee9 100644 --- a/modules/nf-core/rmarkdownnotebook/main.nf +++ b/modules/nf-core/rmarkdownnotebook/main.nf @@ -18,10 +18,11 @@ process RMARKDOWNNOTEBOOK { path input_files output: - tuple val(meta), path("*.html") , emit: report - tuple val(meta), path ("artifacts/*") , emit: artifacts, optional: true - tuple val(meta), path ("session_info.log"), emit: session_info - path "versions.yml" , emit: versions + tuple val(meta), path("*.html") , emit: report + tuple val(meta), path("*.parameterised.Rmd") , emit: parameterised_notebook, optional: true + tuple val(meta), path ("artifacts/*") , emit: artifacts, optional: true + tuple val(meta), path ("session_info.log") , emit: session_info + path "versions.yml" , emit: versions when: task.ext.when == null || task.ext.when @@ -53,10 +54,53 @@ process RMARKDOWNNOTEBOOK { params_cmd = dump_params_yml(nb_params) render_cmd = """\ params = yaml::read_yaml('.params.yml') - rmarkdown::render('${prefix}.Rmd', params=params, envir=new.env()) + + # Instead of rendering with params, produce a version of the R + # markdown with param definitions set, so the notebook itself can + # be reused + rmd_content <- readLines('${prefix}.Rmd') + + # Extract YAML content between the first two '---' + start_idx <- which(rmd_content == "---")[1] + end_idx <- which(rmd_content == "---")[2] + rmd_yaml_content <- paste(rmd_content[(start_idx+1):(end_idx-1)], collapse = "\\n") + rmd_params <- yaml::yaml.load(rmd_yaml_content) + + # Override the params + rmd_params[['params']] <- modifyList(rmd_params[['params']], params) + + # Recursive function to add 'value' to list elements, except for top-level + add_value_recursively <- function(lst, is_top_level = FALSE) { + if (!is.list(lst)) { + return(lst) + } + + lst <- lapply(lst, add_value_recursively) + if (!is_top_level) { + lst <- list(value = lst) + } + return(lst) + } + + # Reformat nested lists under 'params' to have a 'value' key recursively + rmd_params[['params']] <- add_value_recursively(rmd_params[['params']], is_top_level = TRUE) + + # Convert back to YAML string + updated_yaml_content <- as.character(yaml::as.yaml(rmd_params)) + + # Remove the old YAML content + rmd_content <- rmd_content[-((start_idx+1):(end_idx-1))] + + # Insert the updated YAML content at the right position + rmd_content <- append(rmd_content, values = unlist(strsplit(updated_yaml_content, split = "\\n")), after = start_idx) + + writeLines(rmd_content, '${prefix}.parameterised.Rmd') + + # Render based on the updated file + rmarkdown::render('${prefix}.parameterised.Rmd', output_file='${prefix}.html', envir = new.env()) """ } else { - render_cmd = "rmarkdown::render('${prefix}.Rmd')" + render_cmd = "rmarkdown::render('${prefix}.Rmd', output_file='${prefix}.html')" } """ diff --git a/tower.yml b/tower.yml index 098d132c..98dd2a5f 100644 --- a/tower.yml +++ b/tower.yml @@ -1,6 +1,8 @@ reports: "**/report/*.html": display: "Final differential abundance report" + "**/report/*.zip": + display: "Report bundle (markdown + input files)" pipeline_info/**: display: "Pipeline run info" "**/plots/exploratory/**/html/*.html": diff --git a/workflows/differentialabundance.nf b/workflows/differentialabundance.nf index 5f2ed24a..72bccf88 100644 --- a/workflows/differentialabundance.nf +++ b/workflows/differentialabundance.nf @@ -127,6 +127,7 @@ include { AFFY_JUSTRMA as AFFY_JUSTRMA_RAW } from '../modules/n include { AFFY_JUSTRMA as AFFY_JUSTRMA_NORM } from '../modules/nf-core/affy/justrma/main' include { PROTEUS_READPROTEINGROUPS as PROTEUS } from '../modules/nf-core/proteus/readproteingroups/main' include { GEOQUERY_GETGEO } from '../modules/nf-core/geoquery/getgeo/main' +include { ZIP as MAKE_REPORT_BUNDLE } from '../modules/nf-core/zip/main' /* ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ @@ -584,6 +585,15 @@ workflow DIFFERENTIALABUNDANCE { ch_report_input_files ) + // Make a report bundle comprising the markdown document and all necessary + // input files + + MAKE_REPORT_BUNDLE( + RMARKDOWNNOTEBOOK.out.parameterised_notebook + .combine(ch_report_input_files) + .map{[it[0], it[1..-1]]} + ) + } /*