Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 15 additions & 27 deletions modules/nf-core/jupyternotebook/main.nf
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ process JUPYTERNOTEBOOK {
tuple val(meta), path(notebook)
val parameters
path input_files
val kernel_

output:
tuple val(meta), path("*.html") , emit: report
Expand All @@ -25,38 +26,25 @@ process JUPYTERNOTEBOOK {

script:
def prefix = task.ext.prefix ?: "${meta.id}"
def parametrize = (task.ext.parametrize == null) ? true : task.ext.parametrize
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
def kernel = task.ext.kernel ?: '-'
def kernel = kernel_ ?: '-'
// Implicit parameters can be overwritten by supplying a value with parameters
notebook_parameters = [
meta: meta,
cpus: task.cpus,
] + (parameters ?: [:])

// Dump parameters to yaml file.
// Using a yaml file over using the CLI params because
// * no issue with escaping
// * allows to pass nested maps instead of just single values
def params_cmd = ""
def render_cmd = ""
def meta_string = meta.collect { key, value -> "${key}: ${value}" }.join('\n')
def params_string = parameters.collect { key, value -> "${key}: ${value}" }.join('\n')
if (parametrize) {
if (implicit_params) {
params_cmd += 'echo cpus: ' + task.cpus + ' >> ./.params.yml \n'
params_cmd += 'echo "artifact_dir: artifacts" >> ./.params.yml \n'
params_cmd += 'echo "input_dir: ./" >> ./.params.yml \n'
}
if (meta_params) {
params_cmd += 'echo "' + meta_string + '" >> ./.params.yml \n'
}
params_cmd += 'echo "' + params_string + '" >> ./.params.yml'
render_cmd = "papermill -f .params.yml"
} else {
render_cmd = "papermill"
}
def yamlBuilder = new groovy.yaml.YamlBuilder()
yamlBuilder.call(notebook_parameters)
def yaml_content = yamlBuilder.toString().tokenize('\n').join("\n ")
"""
set -o pipefail

# write .params.yml file if required
$params_cmd
# Dump parameters to yaml file
cat <<- END_YAML_PARAMS > params.yml
${yaml_content}
END_YAML_PARAMS

# Create output directory
mkdir artifacts
Expand All @@ -72,7 +60,7 @@ process JUPYTERNOTEBOOK {

# Convert notebook to ipynb using jupytext, execute using papermill, convert using nbconvert
jupytext --to notebook --output - --set-kernel ${kernel} ${notebook} > ${notebook}.ipynb
${render_cmd} ${notebook}.ipynb ${notebook}.executed.ipynb
papermill -f params.yml ${notebook}.ipynb ${notebook}.executed.ipynb
jupyter nbconvert --stdin --to html --output ${prefix}.html < ${notebook}.executed.ipynb

cat <<-END_VERSIONS > versions.yml
Expand Down
18 changes: 12 additions & 6 deletions modules/nf-core/jupyternotebook/meta.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,21 +15,24 @@ tools:
homepage: https://github.com/mwouts/jupytext/
documentation: https://jupyter.org/documentation
tool_dev_url: https://github.com/mwouts/jupytext/
license: ["MIT"]
license:
- "MIT"
identifier: ""
- papermill:
description: Parameterize, execute, and analyze notebooks
homepage: https://github.com/nteract/papermill
documentation: http://papermill.readthedocs.io/en/latest/
tool_dev_url: https://github.com/nteract/papermill
license: ["BSD 3-clause"]
license:
- "BSD 3-clause"
identifier: ""
- nbconvert:
description: Parameterize, execute, and analyze notebooks
homepage: https://nbconvert.readthedocs.io/en/latest/
documentation: https://nbconvert.readthedocs.io/en/latest/
tool_dev_url: https://github.com/jupyter/nbconvert
license: ["BSD 3-clause"]
license:
- "BSD 3-clause"
identifier: ""
input:
- - meta:
Expand All @@ -42,8 +45,8 @@ input:
description: Jupyter notebook or jupytext representation thereof
pattern: "*.{ipynb,py,md,Rmd,myst}"
ontologies:
- edam: http://edamontology.org/format_3996 # Python script
- edam: http://edamontology.org/format_4000 # R markdown
- edam: http://edamontology.org/format_3996
- edam: http://edamontology.org/format_4000
- parameters:
type: map
description: |
Expand All @@ -54,6 +57,9 @@ input:
description: One or multiple files serving as input data for the notebook.
pattern: "*"
ontologies: []
- kernel_:
type: string
description: Name of the kernel to use.
output:
report:
- - meta:
Expand Down Expand Up @@ -82,7 +88,7 @@ output:
description: File containing software versions
pattern: "versions.yml"
ontologies:
- edam: http://edamontology.org/format_3750 # YAML
- edam: http://edamontology.org/format_3750
authors:
- "@grst"
maintainers:
Expand Down
16 changes: 4 additions & 12 deletions modules/nf-core/jupyternotebook/tests/main.nf.test
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,13 @@ nextflow_process {
test("generic - md") {

when {
params {
module_args = ['parametrize':false]
}
process {
"""
input[0] = [[id:'test_jupyter'],
file(params.modules_testdata_base_path + 'generic/notebooks/jupyter/ipython_notebook.md', checkIfExists:true)]
input[1] = [:]
input[2] = []
input[3] = ''
"""
}
}
Expand All @@ -39,15 +37,13 @@ nextflow_process {
test("generic - md - parametrize") {

when {
params {
module_args = ['parametrize':true]
}
process {
"""
input[0] = [[id:'test_jupyter'],
file(params.modules_testdata_base_path + 'generic/notebooks/jupyter/ipython_notebook.md', checkIfExists:true)]
input[1] = [input_filename:"hello.txt", n_iter:12]
input[2] = file(params.modules_testdata_base_path + 'generic/txt/hello.txt', checkIfExists:true)
input[3] = ''
"""
}
}
Expand All @@ -68,15 +64,13 @@ nextflow_process {


when {
params {
module_args = ['parametrize':true]
}
process {
"""
input[0] = [[id:'test_jupyter'],
file(params.modules_testdata_base_path + 'generic/notebooks/jupyter/ipython_notebook.ipynb', checkIfExists:true)]
input[1] = [input_filename:"hello.txt", n_iter:12]
input[2] = file(params.modules_testdata_base_path + 'generic/txt/hello.txt', checkIfExists:true)
input[3] = ''
"""
}
}
Expand All @@ -98,15 +92,13 @@ nextflow_process {
options "-stub"

when {
params {
module_args = ['parametrize':false]
}
process {
"""
input[0] = [[id:'test_jupyter'],
file(params.modules_testdata_base_path + 'generic/notebooks/jupyter/ipython_notebook.md', checkIfExists:true)]
input[1] = [:]
input[2] = []
input[3] = ''
"""
}
}
Expand Down
32 changes: 16 additions & 16 deletions modules/nf-core/jupyternotebook/tests/main.nf.test.snap
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,19 @@
"id": "test_jupyter"
},
[
"artifact.txt:md5,8ddd8be4b179a529afa5f2ffae4b9858"

]
]
],
[
"versions.yml:md5,d117eb87cb1392fe15e7b46ba822825a"
"versions.yml:md5,fc2a7a3269fbae7ce3d9c8a17b91de01"
]
],
"timestamp": "2026-03-13T20:41:47.791483035",
"meta": {
"nf-test": "0.9.2",
"nextflow": "24.10.6"
},
"timestamp": "2025-05-30T11:35:17.89341504"
"nf-test": "0.9.4",
"nextflow": "25.10.4"
}
},
"generic - md - stub": {
"content": [
Expand Down Expand Up @@ -70,11 +70,11 @@
]
}
],
"timestamp": "2025-05-29T14:34:50.943899122",
"meta": {
"nf-test": "0.9.2",
"nextflow": "25.04.2"
},
"timestamp": "2025-05-29T14:34:50.943899122"
}
},
"generic - md - parametrize": {
"content": [
Expand All @@ -86,19 +86,19 @@
"id": "test_jupyter"
},
[
"artifact.txt:md5,8ddd8be4b179a529afa5f2ffae4b9858"

]
]
],
[
"versions.yml:md5,d117eb87cb1392fe15e7b46ba822825a"
"versions.yml:md5,fc2a7a3269fbae7ce3d9c8a17b91de01"
]
],
"timestamp": "2026-03-13T20:41:31.036482511",
"meta": {
"nf-test": "0.9.2",
"nextflow": "24.10.6"
},
"timestamp": "2025-05-30T11:34:58.272377123"
"nf-test": "0.9.4",
"nextflow": "25.10.4"
}
},
"generic - md": {
"content": [
Expand All @@ -108,10 +108,10 @@
"versions.yml:md5,fc2a7a3269fbae7ce3d9c8a17b91de01"
]
],
"timestamp": "2025-05-30T11:28:28.193453013",
"meta": {
"nf-test": "0.9.2",
"nextflow": "24.10.6"
},
"timestamp": "2025-05-30T11:28:28.193453013"
}
}
}
5 changes: 0 additions & 5 deletions modules/nf-core/jupyternotebook/tests/nextflow.config
Original file line number Diff line number Diff line change
@@ -1,5 +0,0 @@
process {
withName: "JUPYTERNOTEBOOK" {
ext = params.module_args
}
}
Loading