Skip to content

Commit

Permalink
Also allow PDF output; add PDF tests
Browse files Browse the repository at this point in the history
  • Loading branch information
fasterius committed Feb 7, 2024
1 parent b44dea9 commit 839cae0
Show file tree
Hide file tree
Showing 5 changed files with 160 additions and 36 deletions.
15 changes: 12 additions & 3 deletions modules/nf-core/quartonotebook/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,8 @@ process QUARTONOTEBOOK {
path input_files

output:
tuple val(meta), path("*.html") , emit: html
tuple val(meta), path("*.html") , emit: html, optional: true
tuple val(meta), path("*.pdf") , emit: pdf, optional: true
tuple val(meta), path("artifacts/*"), emit: artifacts, optional: true
tuple val(meta), path("params.yml") , emit: params_yaml, optional: true
path "versions.yml" , emit: versions
Expand All @@ -39,6 +40,10 @@ process QUARTONOTEBOOK {
def implicit_params = (task.ext.implicit_params == null) ? true : task.ext.implicit_params
def meta_params = (task.ext.meta_params == null) ? true : task.ext.meta_params

// Get notebook base name and file extension for building final output name
def nb_name = notebook.getBaseName()
def nb_extension = notebook.getExtension()

// Dump parameters to yaml file.
// Using a YAML file over using the CLI params because
// - No issue with escaping
Expand Down Expand Up @@ -77,8 +82,12 @@ process QUARTONOTEBOOK {
quarto render \\
${notebook} \\
${render_args} \\
${args} \\
--output ${prefix}.html
${args}
# Change report name to use the prefix and the rendered filetype extension
REPORT=\$(find . -name "${nb_name}.*" -not -name "*.${nb_extension}")
EXTENSION="\${REPORT/.\\/${nb_name}./}"
mv "\$REPORT" "${prefix}.\$EXTENSION"
cat <<-END_VERSIONS > versions.yml
"${task.process}":
Expand Down
4 changes: 4 additions & 0 deletions modules/nf-core/quartonotebook/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,10 @@ output:
type: file
description: The HTML report generated by Quarto.
pattern: "*.html"
- pdf:
type: file
description: The PDF report generated by Quarto.
pattern: "*.pdf"
- artifacts:
type: file
description: Artifacts generated by during report execution.
Expand Down
55 changes: 54 additions & 1 deletion modules/nf-core/quartonotebook/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ nextflow_process {
[ id:'test' ], // meta map
file(params.test_data['generic']['notebooks']['quarto_python'], checkIfExists: true) // Notebook
]
input[1] = [] // Parameters
input[1] = [:] // Parameters
input[2] = [] // Input files
"""
}
Expand Down Expand Up @@ -166,6 +166,59 @@ nextflow_process {

}

test("test notebook - pdf - [qmd:r]") {

config "./pdf.config"

when {
process {
"""
input[0] = [
[ id:'test' ], // meta map
file(params.test_data['generic']['notebooks']['quarto_r'], checkIfExists: true) // Notebook
]
input[1] = [:] // parameters
input[2] = [] // input files
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out.versions).match() },
{ assert path(process.out.pdf[0][1]).exists() }
)
}

}

test("test notebook - pdf [qmd:python]") {

config "./pdf.config"

when {
process {
"""
input[0] = [
[ id:'test' ], // meta map
file(params.test_data['generic']['notebooks']['quarto_python'], checkIfExists: true) // Notebook
]
input[1] = [:] // Parameters
input[2] = [] // Input files
"""
}
}

then {
assertAll(
{ assert process.success },
{ assert snapshot(process.out.versions).match() },
{ assert path(process.out.pdf[0][1]).exists() }
)
}

}
test("test notebook - stub - [qmd:r]") {

config "./no-parametrization.config"
Expand Down
Loading

0 comments on commit 839cae0

Please sign in to comment.