diff --git a/CHANGELOG.md b/CHANGELOG.md index 5e2b7b6..1fca546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -11,6 +11,10 @@ - Floats and doubles should now be created when using the `number` type in the schema ([#113](https://github.com/nextflow-io/nf-validation/pull/113/)) - When `0` is used as a default value in the schema, a `0` will now be used as the value in the `.fromSamplesheet()` channel instead of `null` ([#114](https://github.com/nextflow-io/nf-validation/pull/114)) +## New features + +- Added `file-path-pattern` format to check every file fetched using a glob pattern. Using a glob is now also possible in the samplesheet and will create a list of all files found using that glob pattern. ([#118](https://github.com/nextflow-io/nf-validation/pull/118)) + # Version 1.0.0 - Tonkotsu The nf-validation plugin is now in production use across many pipelines and has (we hope) now reached a point of relative stability. The bump to major version v1.0.0 signifies that it is suitable for use in production pipelines. diff --git a/docs/nextflow_schema/nextflow_schema_specification.md b/docs/nextflow_schema/nextflow_schema_specification.md index 3077ef0..586dd11 100644 --- a/docs/nextflow_schema/nextflow_schema_specification.md +++ b/docs/nextflow_schema/nextflow_schema_specification.md @@ -342,13 +342,16 @@ Example usage is as follows: The available `format` types are below: `file-path` -: States if the provided value is a file. Does not check its existence, but it does check that the path is not a directory. +: States that the provided value is a file. Does not check its existence, but it does check that the path is not a directory. `directory-path` -: States if the provided value is a directory. Does not check its existence, but if it exists, it does check that the path is not a file. +: States that the provided value is a directory. Does not check its existence, but if it exists, it does check that the path is not a file. `path` -: States if the provided value is a path (file or directory). Does not check its existence. +: States that the provided value is a path (file or directory). Does not check its existence. + +`file-path-pattern` +: States that the provided value is a globbing pattern that will be used to fetch files. Checks that the pattern is valid and that at least one file is found. ### `exists` diff --git a/docs/nextflow_schema/sample_sheet_schema_specification.md b/docs/nextflow_schema/sample_sheet_schema_specification.md index e349707..86a44e5 100644 --- a/docs/nextflow_schema/sample_sheet_schema_specification.md +++ b/docs/nextflow_schema/sample_sheet_schema_specification.md @@ -78,6 +78,8 @@ Please refer to the [Nextflow schema specification](../nextflow_schema/nextflow_ Be sure to set `"type": "string"` and `"format": "file-path"` for these properties, so that nf-validation correctly returns this sample sheet field as a `Nextflow.file` object. +When using the `file-path-pattern` format for a globbing pattern, a list will be created with all files found by the globbing pattern. See [here](../nextflow_schema/nextflow_schema_specification.md#file-path-pattern) for more information. + ## Sample sheet keys Below are the properties that are specific to sample sheet schema. diff --git a/plugins/nf-validation/src/main/nextflow/validation/FormatValidators/FilePathPatternValidator.groovy b/plugins/nf-validation/src/main/nextflow/validation/FormatValidators/FilePathPatternValidator.groovy new file mode 100644 index 0000000..fff8b36 --- /dev/null +++ b/plugins/nf-validation/src/main/nextflow/validation/FormatValidators/FilePathPatternValidator.groovy @@ -0,0 +1,34 @@ +package nextflow.validation + +import java.nio.file.Path +import groovy.util.logging.Slf4j + +import org.everit.json.schema.FormatValidator +import nextflow.Nextflow + +@Slf4j +public class FilePathPatternValidator implements FormatValidator { + + @Override + public Optional validate(final String subject) { + if (subject.startsWith('s3://')) { + log.debug("S3 paths are not supported by 'FilePathPatternValidator': '${subject}'") + return Optional.empty() + } + ArrayList files = Nextflow.file(subject) as ArrayList + ArrayList errors = [] + + if(files.size() == 0) { + return Optional.of("No files were found using the globbing pattern '${subject}'" as String) + } + for( file : files ) { + if (file.isDirectory()) { + errors.add("'${file.toString()}' is not a file, but a directory" as String) + } + } + if(errors.size > 0) { + return Optional.of(errors.join('\n')) + } + return Optional.empty() + } +} \ No newline at end of file diff --git a/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy b/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy index 009eb93..8ea9687 100644 --- a/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy +++ b/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy @@ -258,10 +258,17 @@ class SamplesheetConverter { // Check and convert to the desired format def String format = field['value']['format'] - if(format && format.contains("path")) { - def Path inputFile = Nextflow.file(input) as Path - return inputFile + if(format) { + if(format == "file-path-pattern") { + def ArrayList inputFiles = Nextflow.file(input) as ArrayList + return inputFiles + } + if(format.contains("path")) { + def Path inputFile = Nextflow.file(input) as Path + return inputFile + } } + // Return the plain string value return result diff --git a/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy b/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy index 0e124a2..861393e 100644 --- a/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy +++ b/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy @@ -351,6 +351,7 @@ class SchemaValidator extends PluginExtensionPoint { .addFormatValidator("file-path", new FilePathValidator()) .addFormatValidator("directory-path", new DirectoryPathValidator()) .addFormatValidator("path", new PathValidator()) + .addFormatValidator("file-path-pattern", new FilePathPatternValidator()) .build() final schema = schemaLoader.load().build() @@ -526,6 +527,7 @@ class SchemaValidator extends PluginExtensionPoint { .addFormatValidator("file-path", new FilePathValidator()) .addFormatValidator("directory-path", new DirectoryPathValidator()) .addFormatValidator("path", new PathValidator()) + .addFormatValidator("file-path-pattern", new FilePathPatternValidator()) .build() final schema = schemaLoader.load().build()