From 79b54d4cbd7e7042f63527940881ef51f07194ce Mon Sep 17 00:00:00 2001 From: Chase Mateusiak Date: Sun, 18 May 2025 20:25:25 -0500 Subject: [PATCH 1/2] Update optional-input.nf update to current idiom --- optional-input.nf | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/optional-input.nf b/optional-input.nf index 60ddca0..4e80a9d 100644 --- a/optional-input.nf +++ b/optional-input.nf @@ -27,7 +27,8 @@ */ params.inputs = "$projectDir/data/prots/*{1,2,3}.fa" -params.filter = "$projectDir/assets/NO_FILE" +// pass a empty array. this evaluates to false +params.filter = [] process foo { debug true @@ -36,7 +37,7 @@ process foo { path opt script: - def filter = opt.name != 'NO_FILE' ? "--filter $opt" : '' + def filter = opt ? "--filter ${opt}" : "" """ echo your_command --input $seq $filter """ From 878fdea1e5e0c4e0cf45c0506469f51075e9b443 Mon Sep 17 00:00:00 2001 From: Chase Mateusiak Date: Sun, 18 May 2025 20:30:21 -0500 Subject: [PATCH 2/2] Update optional-input.md updating the docs markdown, also --- docs/optional-input.md | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/docs/optional-input.md b/docs/optional-input.md index 8d0c56d..157b982 100644 --- a/docs/optional-input.md +++ b/docs/optional-input.md @@ -4,27 +4,23 @@ One or more processes have an optional input file. ## Solution -Use a special file name to mark the absence of the file parameter. - -Create an empty file in `assets`: -``` -touch assets/NO_FILE -``` +Pass an empty array to the optional input. The empty array will be evaluated to `false`. ## Code ```groovy params.inputs = "$projectDir/data/prots/*{1,2,3}.fa" -params.filter = "$projectDir/assets/NO_FILE" +// pass a empty array. this evaluates to false +params.filter = [] process foo { - debug true + debug true input: path seq path opt script: - def filter = opt.name != 'NO_FILE' ? "--filter $opt" : '' + def filter = opt ? "--filter ${opt}" : "" """ echo your_command --input $seq $filter """ @@ -32,7 +28,7 @@ process foo { workflow { prots_ch = Channel.fromPath(params.inputs, checkIfExists:true) - opt_file = file(params.filter, checkIfExists:true) + opt_file = file(params.filter) foo(prots_ch, opt_file) }