From e870db17c58a1da605099c70365fc3e0a64b0dce Mon Sep 17 00:00:00 2001 From: Ben Sherman Date: Fri, 24 Feb 2023 01:37:07 -0600 Subject: [PATCH 1/2] Add support for default values for process inputs Signed-off-by: Ben Sherman --- docs/process.rst | 43 +++++++++++++++++++ .../groovy/nextflow/script/ProcessDef.groovy | 14 +++++- .../nextflow/script/params/BaseInParam.groovy | 14 ++++++ tests/process-input-default-value.nf | 23 ++++++++++ 4 files changed, 92 insertions(+), 2 deletions(-) create mode 100644 tests/process-input-default-value.nf diff --git a/docs/process.rst b/docs/process.rst index 18262e6f11..0d92466ea1 100644 --- a/docs/process.rst +++ b/docs/process.rst @@ -895,6 +895,49 @@ It outputs:: See also: :ref:`channel-types`. +Inputs with default values +-------------------------- + +.. note:: + This feature requires Nextflow version 23.03.0-edge or later. + +Process inputs can be defined with a default value, so that they don't have to be +specified when calling the process. Default values can be useful for process inputs +that aren't always used. For example:: + + process foo { + input: + val metadata + path ('star/*'), defaultValue: [] + path ('hisat2/*'), defaultValue: [] + path ('salmon/*'), defaultValue: [] + output: + stdout + script: + """ + echo 'metadata: ${metadata}' + [[ -d star ]] && ls star || echo 'skipping star directory' + [[ -d hisat2 ]] && ls hisat2 || echo 'skipping hisat2 directory' + [[ -d salmon ]] && ls salmon || echo 'skipping salmon directory' + """ + } + + workflow { + metadata = Channel.of('foo') + foo(metadata) | view + } + +There are a few important caveats to keep in mind when using default values:: + +* Inputs with a default value must be declared after inputs without a default value. + +* If you provide a value for an input, then you must also provide values for all inputs + that precede it, even if those inputs have default values. In the example above, if you + wanted to provide a value for the ``salmon`` input, you would have to provide values for + the ``star`` and ``hisat2`` inputs as well, regardless of whether you use the default + values for those inputs. + + Outputs ======= diff --git a/modules/nextflow/src/main/groovy/nextflow/script/ProcessDef.groovy b/modules/nextflow/src/main/groovy/nextflow/script/ProcessDef.groovy index 6774db05e2..51b57a78e1 100644 --- a/modules/nextflow/src/main/groovy/nextflow/script/ProcessDef.groovy +++ b/modules/nextflow/src/main/groovy/nextflow/script/ProcessDef.groovy @@ -170,17 +170,27 @@ class ProcessDef extends BindableDef implements IterableDef, ChainableDef { // get params final params = ChannelOut.spread(args) + // sanity check - if( params.size() != declaredInputs.size() ) + if( params.size() > declaredInputs.size() ) throw new ScriptRuntimeException(missMatchErrMessage(processName, declaredInputs.size(), params.size())) // set input channels for( int i=0; i Date: Wed, 24 May 2023 17:53:40 +0200 Subject: [PATCH 2/2] Add support for AWS SSE env variables Signed-off-by: Paolo Di Tommaso --- .../nextflow/cloud/aws/config/AwsS3Config.groovy | 4 ++-- .../cloud/aws/config/AwsS3ConfigTest.groovy | 14 ++++++++++++++ 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/plugins/nf-amazon/src/main/nextflow/cloud/aws/config/AwsS3Config.groovy b/plugins/nf-amazon/src/main/nextflow/cloud/aws/config/AwsS3Config.groovy index e479925314..5ff28aac75 100644 --- a/plugins/nf-amazon/src/main/nextflow/cloud/aws/config/AwsS3Config.groovy +++ b/plugins/nf-amazon/src/main/nextflow/cloud/aws/config/AwsS3Config.groovy @@ -50,8 +50,8 @@ class AwsS3Config { this.debug = opts.debug as Boolean this.endpoint = opts.endpoint ?: SysEnv.get('AWS_S3_ENDPOINT') this.storageClass = parseStorageClass((opts.storageClass ?: opts.uploadStorageClass) as String) // 'uploadStorageClass' is kept for legacy purposes - this.storageEncryption = parseStorageEncryption(opts.storageEncryption as String) - this.storageKmsKeyId = opts.storageKmsKeyId + this.storageEncryption = parseStorageEncryption(opts.storageEncryption as String) ?: SysEnv.get('NXF_AWS_SSE_MODE') + this.storageKmsKeyId = opts.storageKmsKeyId ?: SysEnv.get('NXF_AWS_SSE_KMS_KEY_ID') this.pathStyleAccess = opts.s3PathStyleAccess as Boolean this.s3Acl = parseS3Acl(opts.s3Acl as String) } diff --git a/plugins/nf-amazon/src/test/nextflow/cloud/aws/config/AwsS3ConfigTest.groovy b/plugins/nf-amazon/src/test/nextflow/cloud/aws/config/AwsS3ConfigTest.groovy index 116a64456b..0f5cd1f643 100644 --- a/plugins/nf-amazon/src/test/nextflow/cloud/aws/config/AwsS3ConfigTest.groovy +++ b/plugins/nf-amazon/src/test/nextflow/cloud/aws/config/AwsS3ConfigTest.groovy @@ -121,4 +121,18 @@ class AwsS3ConfigTest extends Specification { SysEnv.pop() } + + def 'should set storage encryption via env variable' () { + given: + SysEnv.push([NXF_AWS_SSE_MODE: 'aws:kms', NXF_AWS_SSE_KMS_KEY_ID: 'xyz1']) + + when: + def client = new AwsS3Config([:]) + then: + client.storageKmsKeyId == 'xyz1' + client.storageEncryption == 'aws:kms' + + cleanup: + SysEnv.pop() + } }