From 5dc7b13b4cec918b840350019d504e1e21ac7e90 Mon Sep 17 00:00:00 2001 From: Nicolas Vannieuwkerke Date: Tue, 21 Nov 2023 11:12:22 +0100 Subject: [PATCH] Add support for double quotes in samplesheets --- CHANGELOG.md | 6 ++++ .../validation/SamplesheetConverter.groovy | 2 +- .../validation/SchemaValidator.groovy | 4 +-- .../src/resources/META-INF/MANIFEST.MF | 2 +- .../SamplesheetConverterTest.groovy | 29 ++++++++++++++++++- .../src/testResources/correct_quoted.csv | 5 ++++ 6 files changed, 43 insertions(+), 5 deletions(-) create mode 100644 plugins/nf-validation/src/testResources/correct_quoted.csv diff --git a/CHANGELOG.md b/CHANGELOG.md index 2adeb2fe..8f425546 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # nextflow-io/nf-validation: Changelog +# Version 1.1.3 - Asahikawa + +## Improvements + +- Added support for double quotes (`"`) in CSV and TSV samplesheets ([#134](https://github.com/nextflow-io/nf-validation/pull/134)) + # Version 1.1.2 - Wakayama ## Bug fixes diff --git a/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy b/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy index 8ea96873..a9fea0f4 100644 --- a/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy +++ b/plugins/nf-validation/src/main/nextflow/validation/SamplesheetConverter.groovy @@ -80,7 +80,7 @@ class SamplesheetConverter { } else { Path fileSamplesheet = Nextflow.file(samplesheetFile) as Path - samplesheetList = fileSamplesheet.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter, quote:'"') + samplesheetList = fileSamplesheet.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter, quote:'\"') } // Field checks + returning the channels diff --git a/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy b/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy index 4c0b053e..9d701125 100644 --- a/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy +++ b/plugins/nf-validation/src/main/nextflow/validation/SchemaValidator.groovy @@ -200,7 +200,7 @@ class SchemaValidator extends PluginExtensionPoint { } } else { - fileContent = samplesheetFile.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter) + fileContent = samplesheetFile.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter, quote:'\"') } def List> fileContentCasted = castToType(fileContent, types) if (validateFile(false, samplesheetFile.toString(), fileContentCasted, schemaFile.toString(), baseDir, s3PathCheck)) { @@ -438,7 +438,7 @@ class SchemaValidator extends PluginExtensionPoint { } } else { - fileContent = file_path.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter) + fileContent = file_path.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter, quote:'\"') } def List> fileContentCasted = castToType(fileContent, types) if (validateFile(useMonochromeLogs, key, fileContentCasted, schema_name, baseDir, s3PathCheck)) { diff --git a/plugins/nf-validation/src/resources/META-INF/MANIFEST.MF b/plugins/nf-validation/src/resources/META-INF/MANIFEST.MF index b7cbc4f7..16d6abc2 100644 --- a/plugins/nf-validation/src/resources/META-INF/MANIFEST.MF +++ b/plugins/nf-validation/src/resources/META-INF/MANIFEST.MF @@ -1,6 +1,6 @@ Manifest-Version: 1.0 Plugin-Id: nf-validation -Plugin-Version: 1.1.2 +Plugin-Version: 1.1.3 Plugin-Class: nextflow.validation.ValidationPlugin Plugin-Provider: nextflow Plugin-Requires: >=22.10.0 diff --git a/plugins/nf-validation/src/test/nextflow/validation/SamplesheetConverterTest.groovy b/plugins/nf-validation/src/test/nextflow/validation/SamplesheetConverterTest.groovy index 4c64043a..fea9e780 100644 --- a/plugins/nf-validation/src/test/nextflow/validation/SamplesheetConverterTest.groovy +++ b/plugins/nf-validation/src/test/nextflow/validation/SamplesheetConverterTest.groovy @@ -83,7 +83,34 @@ 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 - TSV' () { + def 'should work fine - quoted CSV' () { + given: + def SCRIPT_TEXT = ''' + include { fromSamplesheet } from 'plugin/nf-validation' + + params.input = 'src/testResources/correct_quoted.csv' + + workflow { + Channel.fromSamplesheet("input", parameters_schema:"src/testResources/nextflow_schema_with_samplesheet_converter.json").view().first().map {println(it[0].getClass())} + } + ''' + + 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 'should work fine - TSV' () { given: def SCRIPT_TEXT = ''' include { fromSamplesheet } from 'plugin/nf-validation' diff --git a/plugins/nf-validation/src/testResources/correct_quoted.csv b/plugins/nf-validation/src/testResources/correct_quoted.csv new file mode 100644 index 00000000..02ce600e --- /dev/null +++ b/plugins/nf-validation/src/testResources/correct_quoted.csv @@ -0,0 +1,5 @@ +field_1,field_2,field_3,field_4,field_5,field_6,field_7,field_8,field_9,field_10,field_11 +"fullField",10,"true","string1",25.12,false,"src/testResources/test.txt",src/testResources/testDir,src/testResources/test.txt,unique1,1 +,,,string1,"25.08",false,"",,,,, +"dependentRequired",10,true,string1,25,"false",,,,"unique2",1 +"extraField",10,true,string1,25,false,src/testResources/test.txt,"src/testResources/testDir",src/testResources/testDir,unique3,1 \ No newline at end of file