From 0bbbd9a8ab713c3d027b61de76a5b6af6935c0cc Mon Sep 17 00:00:00 2001 From: Arthur Gymer <24782660+awgymer@users.noreply.github.com> Date: Mon, 23 Oct 2023 23:25:07 +0100 Subject: [PATCH 1/4] feat: add json to all schema options --- examples/fromSamplesheetBasic/pipeline/nextflow_schema.json | 2 +- examples/fromSamplesheetMeta/pipeline/nextflow_schema.json | 2 +- examples/fromSamplesheetOrder/pipeline/nextflow_schema.json | 2 +- examples/paramsHelp/pipeline/nextflow_schema.json | 2 +- examples/paramsSummaryLog/pipeline/nextflow_schema.json | 2 +- examples/paramsSummaryMap/pipeline/nextflow_schema.json | 2 +- examples/validateParameters/log.txt | 2 +- examples/validateParameters/pipeline/nextflow_schema.json | 2 +- .../pipeline/nextflow_schema.json | 2 +- .../pipeline/nextflow_schema.json | 2 +- .../src/main/nextflow/validation/SamplesheetConverter.groovy | 2 +- plugins/nf-validation/src/testResources/nextflow_schema.json | 2 +- 12 files changed, 12 insertions(+), 12 deletions(-) diff --git a/examples/fromSamplesheetBasic/pipeline/nextflow_schema.json b/examples/fromSamplesheetBasic/pipeline/nextflow_schema.json index 6d31af41..3efe8c4a 100644 --- a/examples/fromSamplesheetBasic/pipeline/nextflow_schema.json +++ b/examples/fromSamplesheetBasic/pipeline/nextflow_schema.json @@ -17,7 +17,7 @@ "format": "file-path", "mimetype": "text/csv", "schema": "assets/schema_input.json", - "pattern": "^\\S+\\.(csv|tsv|yaml)$", + "pattern": "^\\S+\\.(csv|tsv|yaml|json)$", "description": "Path to comma-separated file containing information about the samples in the experiment.", "help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).", "fa_icon": "fas fa-file-csv" diff --git a/examples/fromSamplesheetMeta/pipeline/nextflow_schema.json b/examples/fromSamplesheetMeta/pipeline/nextflow_schema.json index 6d31af41..3efe8c4a 100644 --- a/examples/fromSamplesheetMeta/pipeline/nextflow_schema.json +++ b/examples/fromSamplesheetMeta/pipeline/nextflow_schema.json @@ -17,7 +17,7 @@ "format": "file-path", "mimetype": "text/csv", "schema": "assets/schema_input.json", - "pattern": "^\\S+\\.(csv|tsv|yaml)$", + "pattern": "^\\S+\\.(csv|tsv|yaml|json)$", "description": "Path to comma-separated file containing information about the samples in the experiment.", "help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).", "fa_icon": "fas fa-file-csv" diff --git a/examples/fromSamplesheetOrder/pipeline/nextflow_schema.json b/examples/fromSamplesheetOrder/pipeline/nextflow_schema.json index 6d31af41..3efe8c4a 100644 --- a/examples/fromSamplesheetOrder/pipeline/nextflow_schema.json +++ b/examples/fromSamplesheetOrder/pipeline/nextflow_schema.json @@ -17,7 +17,7 @@ "format": "file-path", "mimetype": "text/csv", "schema": "assets/schema_input.json", - "pattern": "^\\S+\\.(csv|tsv|yaml)$", + "pattern": "^\\S+\\.(csv|tsv|yaml|json)$", "description": "Path to comma-separated file containing information about the samples in the experiment.", "help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).", "fa_icon": "fas fa-file-csv" diff --git a/examples/paramsHelp/pipeline/nextflow_schema.json b/examples/paramsHelp/pipeline/nextflow_schema.json index 6d31af41..3efe8c4a 100644 --- a/examples/paramsHelp/pipeline/nextflow_schema.json +++ b/examples/paramsHelp/pipeline/nextflow_schema.json @@ -17,7 +17,7 @@ "format": "file-path", "mimetype": "text/csv", "schema": "assets/schema_input.json", - "pattern": "^\\S+\\.(csv|tsv|yaml)$", + "pattern": "^\\S+\\.(csv|tsv|yaml|json)$", "description": "Path to comma-separated file containing information about the samples in the experiment.", "help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).", "fa_icon": "fas fa-file-csv" diff --git a/examples/paramsSummaryLog/pipeline/nextflow_schema.json b/examples/paramsSummaryLog/pipeline/nextflow_schema.json index 6d31af41..3efe8c4a 100644 --- a/examples/paramsSummaryLog/pipeline/nextflow_schema.json +++ b/examples/paramsSummaryLog/pipeline/nextflow_schema.json @@ -17,7 +17,7 @@ "format": "file-path", "mimetype": "text/csv", "schema": "assets/schema_input.json", - "pattern": "^\\S+\\.(csv|tsv|yaml)$", + "pattern": "^\\S+\\.(csv|tsv|yaml|json)$", "description": "Path to comma-separated file containing information about the samples in the experiment.", "help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).", "fa_icon": "fas fa-file-csv" diff --git a/examples/paramsSummaryMap/pipeline/nextflow_schema.json b/examples/paramsSummaryMap/pipeline/nextflow_schema.json index 6d31af41..3efe8c4a 100644 --- a/examples/paramsSummaryMap/pipeline/nextflow_schema.json +++ b/examples/paramsSummaryMap/pipeline/nextflow_schema.json @@ -17,7 +17,7 @@ "format": "file-path", "mimetype": "text/csv", "schema": "assets/schema_input.json", - "pattern": "^\\S+\\.(csv|tsv|yaml)$", + "pattern": "^\\S+\\.(csv|tsv|yaml|json)$", "description": "Path to comma-separated file containing information about the samples in the experiment.", "help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).", "fa_icon": "fas fa-file-csv" diff --git a/examples/validateParameters/log.txt b/examples/validateParameters/log.txt index 1721c298..a294ef41 100644 --- a/examples/validateParameters/log.txt +++ b/examples/validateParameters/log.txt @@ -6,5 +6,5 @@ ERROR ~ ERROR: Validation of pipeline parameters failed! -- Check '.nextflow.log' file for details The following invalid input values have been detected: -* --input: string [samplesheet.txt] does not match pattern ^\S+\.(csv|tsv|yaml)$ (samplesheet.txt) +* --input: string [samplesheet.txt] does not match pattern ^\S+\.(csv|tsv|yaml|json)$ (samplesheet.txt) * --input: the file 'samplesheet.txt' does not exist (samplesheet.txt) diff --git a/examples/validateParameters/pipeline/nextflow_schema.json b/examples/validateParameters/pipeline/nextflow_schema.json index 6d31af41..3efe8c4a 100644 --- a/examples/validateParameters/pipeline/nextflow_schema.json +++ b/examples/validateParameters/pipeline/nextflow_schema.json @@ -17,7 +17,7 @@ "format": "file-path", "mimetype": "text/csv", "schema": "assets/schema_input.json", - "pattern": "^\\S+\\.(csv|tsv|yaml)$", + "pattern": "^\\S+\\.(csv|tsv|yaml|json)$", "description": "Path to comma-separated file containing information about the samples in the experiment.", "help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).", "fa_icon": "fas fa-file-csv" diff --git a/examples/validationFailUnrecognisedParams/pipeline/nextflow_schema.json b/examples/validationFailUnrecognisedParams/pipeline/nextflow_schema.json index 6d31af41..3efe8c4a 100644 --- a/examples/validationFailUnrecognisedParams/pipeline/nextflow_schema.json +++ b/examples/validationFailUnrecognisedParams/pipeline/nextflow_schema.json @@ -17,7 +17,7 @@ "format": "file-path", "mimetype": "text/csv", "schema": "assets/schema_input.json", - "pattern": "^\\S+\\.(csv|tsv|yaml)$", + "pattern": "^\\S+\\.(csv|tsv|yaml|json)$", "description": "Path to comma-separated file containing information about the samples in the experiment.", "help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).", "fa_icon": "fas fa-file-csv" diff --git a/examples/validationWarnUnrecognisedParams/pipeline/nextflow_schema.json b/examples/validationWarnUnrecognisedParams/pipeline/nextflow_schema.json index 6d31af41..3efe8c4a 100644 --- a/examples/validationWarnUnrecognisedParams/pipeline/nextflow_schema.json +++ b/examples/validationWarnUnrecognisedParams/pipeline/nextflow_schema.json @@ -17,7 +17,7 @@ "format": "file-path", "mimetype": "text/csv", "schema": "assets/schema_input.json", - "pattern": "^\\S+\\.(csv|tsv|yaml)$", + "pattern": "^\\S+\\.(csv|tsv|yaml|json)$", "description": "Path to comma-separated file containing information about the samples in the experiment.", "help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).", "fa_icon": "fas fa-file-csv" diff --git a/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy b/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy index 8ea96873..bd5b1648 100644 --- a/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy +++ b/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy @@ -215,7 +215,7 @@ class SamplesheetConverter { Path samplesheetFile ) { def String extension = samplesheetFile.getExtension() - if (extension in ["csv", "tsv", "yml", "yaml"]) { + if (extension in ["csv", "tsv", "yml", "yaml", "json"]) { return extension == "yml" ? "yaml" : extension } diff --git a/plugins/nf-validation/src/testResources/nextflow_schema.json b/plugins/nf-validation/src/testResources/nextflow_schema.json index 5f8b637a..5c8a10d1 100644 --- a/plugins/nf-validation/src/testResources/nextflow_schema.json +++ b/plugins/nf-validation/src/testResources/nextflow_schema.json @@ -16,7 +16,7 @@ "type": "string", "format": "file-path", "mimetype": "text/csv", - "pattern": "^\\S+\\.(csv|tsv|yaml)$", + "pattern": "^\\S+\\.(csv|tsv|yaml|json)$", "description": "Path to comma-separated file containing information about the samples in the experiment.", "help_text": "You will need to create a design file with information about the samples in your experiment before running the pipeline. Use this parameter to specify its location. It has to be a comma-separated file with 3 columns, and a header row. See [usage docs](https://nf-co.re/testpipeline/usage#samplesheet-input).", "fa_icon": "fas fa-file-csv" From 6b5c6b47216cb78e53befe956b7aadc42fb75552 Mon Sep 17 00:00:00 2001 From: Arthur Gymer <24782660+awgymer@users.noreply.github.com> Date: Mon, 23 Oct 2023 23:26:05 +0100 Subject: [PATCH 2/4] feat: add code to parse JSON to objects. (v similar to yaml code) --- .../validation/SamplesheetConverter.groovy | 8 ++++++++ .../nextflow/validation/SchemaValidator.groovy | 16 ++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy b/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy index bd5b1648..6fb6a300 100644 --- a/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy +++ b/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy @@ -78,6 +78,14 @@ class SamplesheetConverter { return ["empty": it] as Map } } + else if(fileType == "json"){ + samplesheetList = new JsonSlurper().parseText(samplesheetFile.text).collect { + if(containsHeader) { + return it as Map + } + return ["empty": it] as Map + } + } else { Path fileSamplesheet = Nextflow.file(samplesheetFile) as Path samplesheetList = fileSamplesheet.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter, quote:'"') diff --git a/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy b/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy index 4c0b053e..1a22c6df 100644 --- a/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy +++ b/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy @@ -199,6 +199,14 @@ class SchemaValidator extends PluginExtensionPoint { return ["empty": it] as Map } } + else if(fileType == "json"){ + fileContent = new JsonSlurper().parseText(samplesheetFile.text).collect { + if(containsHeader) { + return it as Map + } + return ["empty": it] as Map + } + } else { fileContent = samplesheetFile.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter) } @@ -437,6 +445,14 @@ class SchemaValidator extends PluginExtensionPoint { return ["empty": it] as Map } } + else if(fileType == "json"){ + fileContent = new JsonSlurper().parseText(file_path.text).collect { + if(containsHeader) { + return it as Map + } + return ["empty": it] as Map + } + } else { fileContent = file_path.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter) } From 70e13d8922a902103f6bb5793b25ee35e842e990 Mon Sep 17 00:00:00 2001 From: Arthur Gymer <24782660+awgymer@users.noreply.github.com> Date: Mon, 23 Oct 2023 23:29:11 +0100 Subject: [PATCH 3/4] feat: Add tests for JSON to match existing tests for YAML/CSV/TSV. Add tests for failure for TSV/CSV/JSON to match YAML one. --- .../PluginExtensionMethodsTest.groovy | 118 +++++++++++++++++- .../SamplesheetConverterTest.groovy | 53 ++++++++ 2 files changed, 167 insertions(+), 4 deletions(-) diff --git a/plugins/nf-validation/src/test/nextflow/validation/PluginExtensionMethodsTest.groovy b/plugins/nf-validation/src/test/nextflow/validation/PluginExtensionMethodsTest.groovy index 247629db..b9677dce 100644 --- a/plugins/nf-validation/src/test/nextflow/validation/PluginExtensionMethodsTest.groovy +++ b/plugins/nf-validation/src/test/nextflow/validation/PluginExtensionMethodsTest.groovy @@ -125,7 +125,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{ schema_dest.delete() } - def 'should validate a schema csv' () { + def 'should validate a schema - CSV' () { given: def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString() def SCRIPT_TEXT = """ @@ -148,7 +148,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{ !stdout } - def 'should validate a schema tsv' () { + def 'should validate a schema - TSV' () { given: def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString() def SCRIPT_TEXT = """ @@ -171,7 +171,7 @@ class PluginExtensionMethodsTest extends Dsl2Spec{ !stdout } - def 'should validate a schema yaml' () { + def 'should validate a schema - YAML' () { given: def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString() def SCRIPT_TEXT = """ @@ -194,7 +194,88 @@ class PluginExtensionMethodsTest extends Dsl2Spec{ !stdout } - def 'should validate a schema yaml with failures' () { + def 'should validate a schema - JSON' () { + given: + def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString() + def SCRIPT_TEXT = """ + params.input = 'src/testResources/correct.json' + params.outdir = 'src/testResources/testDir' + include { validateParameters } from 'plugin/nf-validation' + + validateParameters(parameters_schema: '$schema') + """ + + when: + dsl_eval(SCRIPT_TEXT) + def stdout = capture + .toString() + .readLines() + .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } + + then: + noExceptionThrown() + !stdout + } + + def 'should validate a schema with failures - CSV' () { + given: + def schema = Path.of('src/testResources/nextflow_schema_with_samplesheet.json').toAbsolutePath().toString() + def SCRIPT_TEXT = """ + params.input = 'src/testResources/wrong.csv' + params.outdir = 'src/testResources/testDir' + include { validateParameters } from 'plugin/nf-validation' + + validateParameters(parameters_schema: '$schema') + """ + + when: + dsl_eval(SCRIPT_TEXT) + def stdout = capture + .toString() + .readLines() + .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } + + then: + def error = thrown(SchemaValidationException) + def errorMessages = error.message.readLines() + errorMessages[0] == "\033[0;31mThe following errors have been detected:" + errorMessages[2] == "* -- Entry 1: Missing required value: sample" + errorMessages[3] == "* -- Entry 1 - strandedness: Strandedness must be provided and be one of 'forward', 'reverse' or 'unstranded' (weird)" + errorMessages[4] == "* -- Entry 1 - fastq_2: FastQ file for reads 2 cannot contain spaces and must have extension '.fq.gz' or '.fastq.gz' (test1_fastq2.fasta)" + errorMessages[5] == "* -- Entry 2 - sample: Sample name must be provided and cannot contain spaces (test 2)" + !stdout + } + + def 'should validate a schema with failures - TSV' () { + given: + def schema = Path.of('src/testResources/nextflow_schema_with_samplesheet.json').toAbsolutePath().toString() + def SCRIPT_TEXT = """ + params.input = 'src/testResources/wrong.tsv' + params.outdir = 'src/testResources/testDir' + include { validateParameters } from 'plugin/nf-validation' + + validateParameters(parameters_schema: '$schema') + """ + + when: + dsl_eval(SCRIPT_TEXT) + def stdout = capture + .toString() + .readLines() + .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } + + then: + def error = thrown(SchemaValidationException) + def errorMessages = error.message.readLines() + errorMessages[0] == "\033[0;31mThe following errors have been detected:" + errorMessages[2] == "* -- Entry 1: Missing required value: sample" + errorMessages[3] == "* -- Entry 1 - strandedness: Strandedness must be provided and be one of 'forward', 'reverse' or 'unstranded' (weird)" + errorMessages[4] == "* -- Entry 1 - fastq_2: FastQ file for reads 2 cannot contain spaces and must have extension '.fq.gz' or '.fastq.gz' (test1_fastq2.fasta)" + errorMessages[5] == "* -- Entry 2 - sample: Sample name must be provided and cannot contain spaces (test 2)" + !stdout + } + + def 'should validate a schema with failures - YAML' () { given: def schema = Path.of('src/testResources/nextflow_schema_with_samplesheet.json').toAbsolutePath().toString() def SCRIPT_TEXT = """ @@ -223,6 +304,35 @@ class PluginExtensionMethodsTest extends Dsl2Spec{ !stdout } + def 'should validate a schema with failures - JSON' () { + given: + def schema = Path.of('src/testResources/nextflow_schema_with_samplesheet.json').toAbsolutePath().toString() + def SCRIPT_TEXT = """ + params.input = 'src/testResources/wrong.json' + params.outdir = 'src/testResources/testDir' + include { validateParameters } from 'plugin/nf-validation' + + validateParameters(parameters_schema: '$schema') + """ + + when: + dsl_eval(SCRIPT_TEXT) + def stdout = capture + .toString() + .readLines() + .findResults {it.contains('WARN nextflow.validation.SchemaValidator') || it.startsWith('* --') ? it : null } + + then: + def error = thrown(SchemaValidationException) + def errorMessages = error.message.readLines() + errorMessages[0] == "\033[0;31mThe following errors have been detected:" + errorMessages[2] == "* -- Entry 1: Missing required value: sample" + errorMessages[3] == "* -- Entry 1 - strandedness: Strandedness must be provided and be one of 'forward', 'reverse' or 'unstranded' (weird)" + errorMessages[4] == "* -- Entry 1 - fastq_2: FastQ file for reads 2 cannot contain spaces and must have extension '.fq.gz' or '.fastq.gz' (test1_fastq2.fasta)" + errorMessages[5] == "* -- Entry 2 - sample: Sample name must be provided and cannot contain spaces (test 2)" + !stdout + } + def 'should find unexpected params' () { given: def schema = Path.of('src/testResources/nextflow_schema.json').toAbsolutePath().toString() diff --git a/plugins/nf-validation/src/test/nextflow/validation/SamplesheetConverterTest.groovy b/plugins/nf-validation/src/test/nextflow/validation/SamplesheetConverterTest.groovy index 4c64043a..4fa571ca 100644 --- a/plugins/nf-validation/src/test/nextflow/validation/SamplesheetConverterTest.groovy +++ b/plugins/nf-validation/src/test/nextflow/validation/SamplesheetConverterTest.groovy @@ -137,6 +137,33 @@ class SamplesheetConverterTest extends Dsl2Spec{ stdout.contains("[[string1:extraField, string2:extraField, integer1:10, integer2:10, boolean1:true, boolean2:true], string1, 25, false, ${this.getRootString()}/src/testResources/test.txt, ${this.getRootString()}/src/testResources/testDir, ${this.getRootString()}/src/testResources/testDir, unique3, 1, itDoesExist]" as String) } + def 'should work fine - JSON' () { + given: + def SCRIPT_TEXT = ''' + include { fromSamplesheet } from 'plugin/nf-validation' + + params.input = 'src/testResources/correct.json' + + workflow { + Channel.fromSamplesheet("input", parameters_schema:"src/testResources/nextflow_schema_with_samplesheet_converter.json").view() + } + ''' + + when: + dsl_eval(SCRIPT_TEXT) + def stdout = capture + .toString() + .readLines() + .findResults {it.startsWith('[[') ? it : null } + + then: + noExceptionThrown() + stdout.contains("[[string1:fullField, string2:fullField, integer1:10, integer2:10, boolean1:true, boolean2:true], string1, 25.12, false, ${this.getRootString()}/src/testResources/test.txt, ${this.getRootString()}/src/testResources/testDir, ${this.getRootString()}/src/testResources/test.txt, unique1, 1, itDoesExist]" as String) + stdout.contains("[[string1:value, string2:value, integer1:0, integer2:0, boolean1:true, boolean2:true], string1, 25.08, false, [], [], [], [], [], itDoesExist]") + stdout.contains("[[string1:dependentRequired, string2:dependentRequired, integer1:10, integer2:10, boolean1:true, boolean2:true], string1, 25, false, [], [], [], unique2, 1, itDoesExist]") + stdout.contains("[[string1:extraField, string2:extraField, integer1:10, integer2:10, boolean1:true, boolean2:true], string1, 25, false, ${this.getRootString()}/src/testResources/test.txt, ${this.getRootString()}/src/testResources/testDir, ${this.getRootString()}/src/testResources/testDir, unique3, 1, itDoesExist]" as String) + } + def 'no header - CSV' () { given: def SCRIPT_TEXT = ''' @@ -187,6 +214,32 @@ class SamplesheetConverterTest extends Dsl2Spec{ stdout.contains("[test_2]") } + def 'no header - JSON' () { + given: + def SCRIPT_TEXT = ''' + include { fromSamplesheet } from 'plugin/nf-validation' + + params.input = 'src/testResources/no_header.json' + + workflow { + Channel.fromSamplesheet("input", parameters_schema:"src/testResources/nextflow_schema_with_samplesheet_no_header.json").view() + } + ''' + + when: + dsl_eval(SCRIPT_TEXT) + def stdout = capture + .toString() + .readLines() + .findResults {it.startsWith('[') ? it : null } + + then: + noExceptionThrown() + stdout.contains("[test_1]") + stdout.contains("[test_2]") + } + + def 'extra field' () { given: def SCRIPT_TEXT = ''' From 724900515b3ceb58cb20e439727be61c8c89f7bb Mon Sep 17 00:00:00 2001 From: Arthur Gymer <24782660+awgymer@users.noreply.github.com> Date: Mon, 23 Oct 2023 23:31:49 +0100 Subject: [PATCH 4/4] feat: add new test data --- .../src/testResources/correct.json | 45 +++++++++++++++++++ .../src/testResources/no_header.json | 4 ++ .../nf-validation/src/testResources/wrong.csv | 3 ++ .../src/testResources/wrong.json | 12 +++++ .../nf-validation/src/testResources/wrong.tsv | 3 ++ 5 files changed, 67 insertions(+) create mode 100644 plugins/nf-validation/src/testResources/correct.json create mode 100644 plugins/nf-validation/src/testResources/no_header.json create mode 100644 plugins/nf-validation/src/testResources/wrong.csv create mode 100644 plugins/nf-validation/src/testResources/wrong.json create mode 100644 plugins/nf-validation/src/testResources/wrong.tsv diff --git a/plugins/nf-validation/src/testResources/correct.json b/plugins/nf-validation/src/testResources/correct.json new file mode 100644 index 00000000..8ff5eb9d --- /dev/null +++ b/plugins/nf-validation/src/testResources/correct.json @@ -0,0 +1,45 @@ +[ + { + "field_1": "fullField", + "field_2": 10, + "field_3": true, + "field_4": "string1", + "field_5": 25.12, + "field_6": false, + "field_7": "src/testResources/test.txt", + "field_8": "src/testResources/testDir", + "field_9": "src/testResources/test.txt", + "field_10": "unique1", + "field_11": 1 + }, + { + "field_4": "string1", + "field_5": 25.08, + "field_6": false + }, + { + "field_1": "dependentRequired", + "field_2": 10, + "field_3": true, + "field_4": "string1", + "field_5": 25, + "field_6": false, + "field_7": null, + "field_8": null, + "field_10": "unique2", + "field_11": 1 + }, + { + "field_1": "extraField", + "field_2": 10, + "field_3": true, + "field_4": "string1", + "field_5": 25, + "field_6": false, + "field_7": "src/testResources/test.txt", + "field_8": "src/testResources/testDir", + "field_9": "src/testResources/testDir", + "field_10": "unique3", + "field_11": 1 + } + ] \ No newline at end of file diff --git a/plugins/nf-validation/src/testResources/no_header.json b/plugins/nf-validation/src/testResources/no_header.json new file mode 100644 index 00000000..9ba45bcc --- /dev/null +++ b/plugins/nf-validation/src/testResources/no_header.json @@ -0,0 +1,4 @@ +[ + "test_1", + "test_2" +] \ No newline at end of file diff --git a/plugins/nf-validation/src/testResources/wrong.csv b/plugins/nf-validation/src/testResources/wrong.csv new file mode 100644 index 00000000..e06a5ce7 --- /dev/null +++ b/plugins/nf-validation/src/testResources/wrong.csv @@ -0,0 +1,3 @@ +sample,fastq_1,fastq_2,strandedness +,test1_fastq1.fastq.gz,test1_fastq2.fasta,weird +test 2,test2_fastq1.fastq.gz,,forward \ No newline at end of file diff --git a/plugins/nf-validation/src/testResources/wrong.json b/plugins/nf-validation/src/testResources/wrong.json new file mode 100644 index 00000000..d1346b6e --- /dev/null +++ b/plugins/nf-validation/src/testResources/wrong.json @@ -0,0 +1,12 @@ +[ + { + "fastq_1": "test1_fastq1.fastq.gz", + "fastq_2": "test1_fastq2.fasta", + "strandedness": "weird" + }, + { + "sample": "test 2", + "fastq_1": "test2_fastq1.fastq.gz", + "strandedness": "forward" + } + ] \ No newline at end of file diff --git a/plugins/nf-validation/src/testResources/wrong.tsv b/plugins/nf-validation/src/testResources/wrong.tsv new file mode 100644 index 00000000..9ac1a596 --- /dev/null +++ b/plugins/nf-validation/src/testResources/wrong.tsv @@ -0,0 +1,3 @@ +sample fastq_1 fastq_2 strandedness + test1_fastq1.fastq.gz test1_fastq2.fasta weird +test 2 test2_fastq1.fastq.gz forward \ No newline at end of file