From 0b6c04d2bdc5b606c24414294e3149bd766092df Mon Sep 17 00:00:00 2001 From: Christopher Hakkaart Date: Mon, 11 Nov 2024 15:09:13 +0100 Subject: [PATCH 1/3] Add section and example for lib Signed-off-by: Christopher Hakkaart --- docs/cli.md | 10 ++++++++++ docs/sharing.md | 8 +++++++- 2 files changed, 17 insertions(+), 1 deletion(-) diff --git a/docs/cli.md b/docs/cli.md index 016c4f2075..85c72718ed 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -62,6 +62,16 @@ The `-bg` option is used to invoke the nextflow execution in the background and $ nextflow -bg run nextflow-io/hello ``` +### Custom `lib` directory + +Set a custom library extension path: + +```console +$ nextflow -lib /custom/library COMMAND [arg...] +``` + +The `-lib` option is used to add a directory to the classpath. All Groovy classes defined in this directory instead of the default `lib/` directory in the Nextflow project root will be available inside the Nextflow workflow. + ### Soft configuration override Add the specified file to configuration set. diff --git a/docs/sharing.md b/docs/sharing.md index 61a840e9f8..c0e0246f12 100644 --- a/docs/sharing.md +++ b/docs/sharing.md @@ -117,7 +117,13 @@ For example, shebang definitions `#!/usr/bin/python` and `#!/usr/local/bin/pytho #### The `lib` directory -Any Groovy scripts or JAR files in the `lib` directory will be automatically loaded and made available to your pipeline scripts. The `lib` directory is a useful way to provide utility code or external libraries without cluttering the pipeline scripts. +The `lib` directory is a useful way to add utility code or external libraries without cluttering the pipeline scripts. Any Groovy scripts or JAR files in the `lib` directory in the project directory root will be available inside the Nextflow workflow automatically. + +The library extension path can be customized using the `-lib` option in your run command: + +```bash +nextflow run -lib /path/to/custom/lib/directory +``` ### Data From e228578a068bd4d5dd0a762fd1a6fd604125186b Mon Sep 17 00:00:00 2001 From: Christopher Hakkaart Date: Tue, 12 Nov 2024 09:31:52 +0100 Subject: [PATCH 2/3] Remove reference to -lib Signed-off-by: Christopher Hakkaart --- docs/cli.md | 10 ---------- docs/sharing.md | 6 ------ 2 files changed, 16 deletions(-) diff --git a/docs/cli.md b/docs/cli.md index 85c72718ed..016c4f2075 100644 --- a/docs/cli.md +++ b/docs/cli.md @@ -62,16 +62,6 @@ The `-bg` option is used to invoke the nextflow execution in the background and $ nextflow -bg run nextflow-io/hello ``` -### Custom `lib` directory - -Set a custom library extension path: - -```console -$ nextflow -lib /custom/library COMMAND [arg...] -``` - -The `-lib` option is used to add a directory to the classpath. All Groovy classes defined in this directory instead of the default `lib/` directory in the Nextflow project root will be available inside the Nextflow workflow. - ### Soft configuration override Add the specified file to configuration set. diff --git a/docs/sharing.md b/docs/sharing.md index c0e0246f12..8acdad6e31 100644 --- a/docs/sharing.md +++ b/docs/sharing.md @@ -119,12 +119,6 @@ For example, shebang definitions `#!/usr/bin/python` and `#!/usr/local/bin/pytho The `lib` directory is a useful way to add utility code or external libraries without cluttering the pipeline scripts. Any Groovy scripts or JAR files in the `lib` directory in the project directory root will be available inside the Nextflow workflow automatically. -The library extension path can be customized using the `-lib` option in your run command: - -```bash -nextflow run -lib /path/to/custom/lib/directory -``` - ### Data In general, input data should be provided by external sources using parameters which can be controlled by the user. This way, a pipeline can be easily reused to process different datasets which are appropriate for the pipeline. From fe65e0ad513207bb70c0af651a4c47564bcd8907 Mon Sep 17 00:00:00 2001 From: Christopher Hakkaart Date: Tue, 12 Nov 2024 11:30:41 +0100 Subject: [PATCH 3/3] Add example Signed-off-by: Christopher Hakkaart --- docs/sharing.md | 53 ++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 52 insertions(+), 1 deletion(-) diff --git a/docs/sharing.md b/docs/sharing.md index 8acdad6e31..50afb391a8 100644 --- a/docs/sharing.md +++ b/docs/sharing.md @@ -117,7 +117,58 @@ For example, shebang definitions `#!/usr/bin/python` and `#!/usr/local/bin/pytho #### The `lib` directory -The `lib` directory is a useful way to add utility code or external libraries without cluttering the pipeline scripts. Any Groovy scripts or JAR files in the `lib` directory in the project directory root will be available inside the Nextflow workflow automatically. +The `lib` directory can be used to add utility code or external libraries without cluttering the pipeline scripts. The `lib` directory in the Nextflow project root is added to the classpath by default. Classes or packages defined in the `lib` directory will be available in the execution context. Scripts or functions defined outside of classes will not be available in the execution context. + +For example, `lib/DNASequence.groovy` defines the `DNASequence` class: + +```groovy +// lib/DNASequence.groovy +class DNASequence { + String sequence + + // Constructor + DNASequence(String sequence) { + this.sequence = sequence.toUpperCase() // Ensure sequence is in uppercase for consistency + } + + // Method to calculate melting temperature using the Wallace rule + double getMeltingTemperature() { + int gCount = sequence.count('G') + int cCount = sequence.count('C') + int aCount = sequence.count('A') + int tCount = sequence.count('T') + + // Wallace rule calculation + double tm = 4 * (gCount + cCount) + 2 * (aCount + tCount) + return tm + } + + String toString() { + return "DNA[$sequence]" + } +} +``` + +The `DNASequence` class is available in the execution context: + +```nextflow +// main.nf +workflow { + Channel.of('ACGTTGCAATGCCGTA', 'GCGTACGGTACGTTAC') + .map { seq -> new DNASequence(seq) } + .view { dna -> + def meltTemp = dna.getMeltingTemperature() + "Found sequence '$dna' with melting temperaure ${meltTemp}°C" + } +} +``` + +It returns: + +``` +Found sequence 'DNA[ACGTTGCAATGCCGTA]' with melting temperaure 48.0°C +Found sequence 'DNA[GCGTACGGTACGTTAC]' with melting temperaure 50.0°C +``` ### Data