Skip to content
This repository has been archived by the owner on Aug 20, 2024. It is now read-only.

Commit

Permalink
Merge pull request #118 from nvnieuwk/feat/format-filepathpattern
Browse files Browse the repository at this point in the history
format file-path-pattern
  • Loading branch information
nvnieuwk authored Oct 18, 2023
2 parents 4884fae + 83a6b5c commit a9f31b5
Show file tree
Hide file tree
Showing 6 changed files with 58 additions and 6 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
9 changes: 6 additions & 3 deletions docs/nextflow_schema/nextflow_schema_specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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`

Expand Down
2 changes: 2 additions & 0 deletions docs/nextflow_schema/sample_sheet_schema_specification.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> 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()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()

Expand Down

0 comments on commit a9f31b5

Please sign in to comment.