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

Commit 26f5631

Browse files
authored
Merge pull request #134 from nvnieuwk/add-quotes-for-csv
Add support for double quotes in samplesheets
2 parents bc51bc5 + 5dc7b13 commit 26f5631

File tree

6 files changed

+43
-5
lines changed

6 files changed

+43
-5
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# nextflow-io/nf-validation: Changelog
22

3+
# Version 1.1.3 - Asahikawa
4+
5+
## Improvements
6+
7+
- Added support for double quotes (`"`) in CSV and TSV samplesheets ([#134](https://github.com/nextflow-io/nf-validation/pull/134))
8+
39
# Version 1.1.2 - Wakayama
410

511
## Bug fixes

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ class SamplesheetConverter {
8080
}
8181
else {
8282
Path fileSamplesheet = Nextflow.file(samplesheetFile) as Path
83-
samplesheetList = fileSamplesheet.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter, quote:'"')
83+
samplesheetList = fileSamplesheet.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter, quote:'\"')
8484
}
8585

8686
// Field checks + returning the channels

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,7 +200,7 @@ class SchemaValidator extends PluginExtensionPoint {
200200
}
201201
}
202202
else {
203-
fileContent = samplesheetFile.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter)
203+
fileContent = samplesheetFile.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter, quote:'\"')
204204
}
205205
def List<Map<String,String>> fileContentCasted = castToType(fileContent, types)
206206
if (validateFile(false, samplesheetFile.toString(), fileContentCasted, schemaFile.toString(), baseDir, s3PathCheck)) {
@@ -438,7 +438,7 @@ class SchemaValidator extends PluginExtensionPoint {
438438
}
439439
}
440440
else {
441-
fileContent = file_path.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter)
441+
fileContent = file_path.splitCsv(header:containsHeader ?: ["empty"], strip:true, sep:delimiter, quote:'\"')
442442
}
443443
def List<Map<String,String>> fileContentCasted = castToType(fileContent, types)
444444
if (validateFile(useMonochromeLogs, key, fileContentCasted, schema_name, baseDir, s3PathCheck)) {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
Manifest-Version: 1.0
22
Plugin-Id: nf-validation
3-
Plugin-Version: 1.1.2
3+
Plugin-Version: 1.1.3
44
Plugin-Class: nextflow.validation.ValidationPlugin
55
Plugin-Provider: nextflow
66
Plugin-Requires: >=22.10.0

plugins/nf-validation/src/test/nextflow/validation/SamplesheetConverterTest.groovy

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,34 @@ class SamplesheetConverterTest extends Dsl2Spec{
8383
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)
8484
}
8585

86-
def 'should work fine - TSV' () {
86+
def 'should work fine - quoted CSV' () {
87+
given:
88+
def SCRIPT_TEXT = '''
89+
include { fromSamplesheet } from 'plugin/nf-validation'
90+
91+
params.input = 'src/testResources/correct_quoted.csv'
92+
93+
workflow {
94+
Channel.fromSamplesheet("input", parameters_schema:"src/testResources/nextflow_schema_with_samplesheet_converter.json").view().first().map {println(it[0].getClass())}
95+
}
96+
'''
97+
98+
when:
99+
dsl_eval(SCRIPT_TEXT)
100+
def stdout = capture
101+
.toString()
102+
.readLines()
103+
.findResults {it.startsWith('[[') ? it : null }
104+
105+
then:
106+
noExceptionThrown()
107+
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)
108+
stdout.contains("[[string1:value, string2:value, integer1:0, integer2:0, boolean1:true, boolean2:true], string1, 25.08, false, [], [], [], [], [], itDoesExist]")
109+
stdout.contains("[[string1:dependentRequired, string2:dependentRequired, integer1:10, integer2:10, boolean1:true, boolean2:true], string1, 25, false, [], [], [], unique2, 1, itDoesExist]")
110+
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)
111+
}
112+
113+
def 'should work fine - TSV' () {
87114
given:
88115
def SCRIPT_TEXT = '''
89116
include { fromSamplesheet } from 'plugin/nf-validation'
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
field_1,field_2,field_3,field_4,field_5,field_6,field_7,field_8,field_9,field_10,field_11
2+
"fullField",10,"true","string1",25.12,false,"src/testResources/test.txt",src/testResources/testDir,src/testResources/test.txt,unique1,1
3+
,,,string1,"25.08",false,"",,,,,
4+
"dependentRequired",10,true,string1,25,"false",,,,"unique2",1
5+
"extraField",10,true,string1,25,false,src/testResources/test.txt,"src/testResources/testDir",src/testResources/testDir,unique3,1

0 commit comments

Comments
 (0)