Skip to content

Commit 3fa5131

Browse files
committed
fix non-local samplesheets
1 parent 34e8fea commit 3fa5131

File tree

4 files changed

+47
-9
lines changed

4 files changed

+47
-9
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-schema: Changelog
22

3+
# Version 2.5.1
4+
5+
## Bug fixes
6+
7+
1. Fixed a bug where non-local samplesheets couldn't be validated and converted.
8+
39
# Version 2.5.0
410

511
## New features

build.gradle

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,10 @@ nextflowPlugin {
3131
indexUrl = 'https://github.com/nextflow-io/plugins/blob/main/plugins.json'
3232
}
3333
}
34+
35+
test {
36+
jvmArgs += [
37+
'--add-opens', 'java.base/sun.net.www.protocol.ftp=ALL-UNNAMED'
38+
]
39+
}
3440
}

src/main/groovy/nextflow/validation/utils/Files.groovy

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ public class Files {
111111
//
112112
private static Path sanitize(Path file) {
113113
// Check if sanitization is needed
114-
def BufferedReader reader = new BufferedReader(new FileReader(file.toFile()))
114+
def reader = file.newReader()
115115
def String firstLine = reader.readLine()
116116
reader.close()
117117
if (!firstLine.endsWith(",") && !firstLine.endsWith("\t")) {
@@ -123,18 +123,15 @@ public class Files {
123123

124124
def Scanner scanner = new Scanner(file.toFile())
125125
def PrintWriter writer = new PrintWriter(tempFile)
126-
def Boolean headerSanitized = false
127-
while (scanner.hasNextLine()) {
128-
def String line = scanner.nextLine()
126+
file.withReader {
127+
def String line
129128
// Remove trailing commas or tabs from the line
130-
if (!headerSanitized) {
131-
line = line.replaceAll("[,\\t]*\$", "")
132-
headerSanitized = true
129+
while( line = it.readLine() ) {
130+
def String sanitized_line = line.replaceAll("[,\\t]*\$", "")
131+
writer.println(sanitized_line)
133132
}
134-
writer.println(line)
135133
}
136134
writer.close()
137-
scanner.close()
138135
return tempFile.toPath()
139136
}
140137

src/test/groovy/nextflow/validation/SamplesheetConverterTest.groovy

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,5 +722,34 @@ class SamplesheetConverterTest extends Dsl2Spec{
722722
stdout.contains("[[nullValue:null], 25, defaultString, true, test]")
723723
stdout.contains("[[nullValue:null], 0, defaultString, true, null]")
724724
}
725+
726+
def 'should work fine - CSV from URL' () {
727+
given:
728+
def SCRIPT_TEXT = '''
729+
include { samplesheetToList } from 'plugin/nf-schema'
730+
731+
params.input = "https://github.com/nextflow-io/nf-schema/raw/refs/heads/master/src/testResources/correct.csv"
732+
params.schema = "src/testResources/schema_input.json"
733+
734+
workflow {
735+
Channel.fromList(samplesheetToList(params.input, params.schema))
736+
.view()
737+
}
738+
'''
739+
740+
when:
741+
dsl_eval(SCRIPT_TEXT)
742+
def stdout = capture
743+
.toString()
744+
.readLines()
745+
.findResults {it.startsWith('[[') ? it : null }
746+
747+
then:
748+
noExceptionThrown()
749+
stdout.contains("[[string1:fullField, string2:fullField, integer1:10, integer2:10, boolean1:true, boolean2:true], string1, 25.12, false, ${getRootString()}/src/testResources/test.txt, ${getRootString()}/src/testResources/testDir, ${getRootString()}/src/testResources/test.txt, unique1, 1, itDoesExist]" as String)
750+
stdout.contains("[[string1:value, string2:value, integer1:0, integer2:0, boolean1:true, boolean2:true], string1, 25.08, false, [], [], [], [], [], itDoesExist]")
751+
stdout.contains("[[string1:dependentRequired, string2:dependentRequired, integer1:10, integer2:10, boolean1:true, boolean2:true], string1, 25, false, [], [], [], unique2, 1, itDoesExist]")
752+
stdout.contains("[[string1:extraField, string2:extraField, integer1:10, integer2:10, boolean1:true, boolean2:true], string1, 25, false, ${getRootString()}/src/testResources/test.txt, ${getRootString()}/src/testResources/testDir, ${getRootString()}/src/testResources/testDir, unique3, 1, itDoesExist]" as String)
753+
}
725754

726755
}

0 commit comments

Comments
 (0)