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

Commit a9f31b5

Browse files
authored
Merge pull request #118 from nvnieuwk/feat/format-filepathpattern
format file-path-pattern
2 parents 4884fae + 83a6b5c commit a9f31b5

File tree

6 files changed

+58
-6
lines changed

6 files changed

+58
-6
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,10 @@
1111
- 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/))
1212
- 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))
1313

14+
## New features
15+
16+
- 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))
17+
1418
# Version 1.0.0 - Tonkotsu
1519

1620
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.

docs/nextflow_schema/nextflow_schema_specification.md

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -342,13 +342,16 @@ Example usage is as follows:
342342
The available `format` types are below:
343343

344344
`file-path`
345-
: States if the provided value is a file. Does not check its existence, but it does check that the path is not a directory.
345+
: States that the provided value is a file. Does not check its existence, but it does check that the path is not a directory.
346346

347347
`directory-path`
348-
: 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.
348+
: 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.
349349

350350
`path`
351-
: States if the provided value is a path (file or directory). Does not check its existence.
351+
: States that the provided value is a path (file or directory). Does not check its existence.
352+
353+
`file-path-pattern`
354+
: 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.
352355

353356
### `exists`
354357

docs/nextflow_schema/sample_sheet_schema_specification.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,8 @@ Please refer to the [Nextflow schema specification](../nextflow_schema/nextflow_
7878
Be sure to set `"type": "string"` and `"format": "file-path"` for these properties,
7979
so that nf-validation correctly returns this sample sheet field as a `Nextflow.file` object.
8080

81+
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.
82+
8183
## Sample sheet keys
8284

8385
Below are the properties that are specific to sample sheet schema.
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
package nextflow.validation
2+
3+
import java.nio.file.Path
4+
import groovy.util.logging.Slf4j
5+
6+
import org.everit.json.schema.FormatValidator
7+
import nextflow.Nextflow
8+
9+
@Slf4j
10+
public class FilePathPatternValidator implements FormatValidator {
11+
12+
@Override
13+
public Optional<String> validate(final String subject) {
14+
if (subject.startsWith('s3://')) {
15+
log.debug("S3 paths are not supported by 'FilePathPatternValidator': '${subject}'")
16+
return Optional.empty()
17+
}
18+
ArrayList files = Nextflow.file(subject) as ArrayList
19+
ArrayList errors = []
20+
21+
if(files.size() == 0) {
22+
return Optional.of("No files were found using the globbing pattern '${subject}'" as String)
23+
}
24+
for( file : files ) {
25+
if (file.isDirectory()) {
26+
errors.add("'${file.toString()}' is not a file, but a directory" as String)
27+
}
28+
}
29+
if(errors.size > 0) {
30+
return Optional.of(errors.join('\n'))
31+
}
32+
return Optional.empty()
33+
}
34+
}

plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -258,10 +258,17 @@ class SamplesheetConverter {
258258

259259
// Check and convert to the desired format
260260
def String format = field['value']['format']
261-
if(format && format.contains("path")) {
262-
def Path inputFile = Nextflow.file(input) as Path
263-
return inputFile
261+
if(format) {
262+
if(format == "file-path-pattern") {
263+
def ArrayList inputFiles = Nextflow.file(input) as ArrayList
264+
return inputFiles
265+
}
266+
if(format.contains("path")) {
267+
def Path inputFile = Nextflow.file(input) as Path
268+
return inputFile
269+
}
264270
}
271+
265272

266273
// Return the plain string value
267274
return result

plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ class SchemaValidator extends PluginExtensionPoint {
351351
.addFormatValidator("file-path", new FilePathValidator())
352352
.addFormatValidator("directory-path", new DirectoryPathValidator())
353353
.addFormatValidator("path", new PathValidator())
354+
.addFormatValidator("file-path-pattern", new FilePathPatternValidator())
354355
.build()
355356
final schema = schemaLoader.load().build()
356357

@@ -526,6 +527,7 @@ class SchemaValidator extends PluginExtensionPoint {
526527
.addFormatValidator("file-path", new FilePathValidator())
527528
.addFormatValidator("directory-path", new DirectoryPathValidator())
528529
.addFormatValidator("path", new PathValidator())
530+
.addFormatValidator("file-path-pattern", new FilePathPatternValidator())
529531
.build()
530532
final schema = schemaLoader.load().build()
531533

0 commit comments

Comments
 (0)