nf-core_modules/modules/jupyternotebook/parametrize.nf
Gregor Sturm 2ad98162f3
Notebook modules (#617)
* Draft rmarkdown module

* stub jupyter notebook module

* Create yaml file with params

* Update meta.yml for rmarkdown module

* Add comment on YAML

* Update notebooks module, clean up parametrize.nf

* Two separate channels for parameters and input files

* Fix Rmd render script

* Add tests for rmarkdown

* Fix tests for rmarkdown module

* Update checksums

* Fix tests for jupyter

* Test without Grab()

* Update software versions

* update rmarkdown dependencies

* Draft for multiple versions

* Fix indent of script

* Fix indent in rmarkdown script

* Emit version.syml

* Update modules/rmarkdown/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/rmarkdown/meta.yml

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/rmarkdown/meta.yml

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Rename rmarkdown to rmarkdownnotebook

* Add rmarkdown mulled biocontainer

* Write sessionInfo to separate log file

* Update rmarkdownnotebook

* Sessioninfo does not have a stable md5sum

* Update jupyternotebook

* Update meta

* Add jupyternotebook biocontainers

* Handle Groovy Gstrings in parameterize

* Update to versions.yml

* Update functions.nf

* Fix versions yaml

* Fix EC lint

* Update modules/rmarkdownnotebook/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Update modules/jupyternotebook/main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>

* Use official test data

* Harshilify

* Make parameters channel clearer

* Apply suggestions from code review

Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>

* Apply suggestions from code review

* Update main.nf

Co-authored-by: James A. Fellows Yates <jfy133@gmail.com>
Co-authored-by: Harshil Patel <drpatelh@users.noreply.github.com>
2021-10-24 20:51:56 +02:00

44 lines
1.4 KiB
Text

import org.yaml.snakeyaml.Yaml
import org.yaml.snakeyaml.representer.Representer
import org.yaml.snakeyaml.DumperOptions
/**
* Multiline code blocks need to have the same indentation level
* as the `script:` section. This function re-indents code to the specified level.
*/
def indent_code_block(code, n_spaces) {
def indent_str = " ".multiply(n_spaces)
return code.stripIndent().split("\n").join("\n" + indent_str)
}
/**
* Create a config YAML file from a groovy map
*
* @params task The process' `task` variable
* @returns a line to be inserted in the bash script.
*/
def dump_params_yml(params) {
DumperOptions options = new DumperOptions();
options.setDefaultFlowStyle(DumperOptions.FlowStyle.BLOCK);
// Properly handle Groovy GStrings
// see https://stackoverflow.com/a/35108062/2340703
def representer = new Representer() {{
this.multiRepresenters.put(GString, this.representers.get(String))
}}
def yaml = new Yaml(representer, options)
def yaml_str = yaml.dump(params)
// Writing the .params.yml file directly as follows does not work.
// It only works in 'exec:', but not if there is a `script:` section:
// task.workDir.resolve('.params.yml').text = yaml_str
// Therefore, we inject it into the bash script:
return """\
cat <<"END_PARAMS_SECTION" > ./.params.yml
${indent_code_block(yaml_str, 8)}
END_PARAMS_SECTION
"""
}