Skip to content

Commit fa97230

Browse files
authored
Fix bug with workflow output index file (#6328)
Signed-off-by: Ben Sherman <[email protected]>
1 parent 4fd97b9 commit fa97230

File tree

6 files changed

+60
-19
lines changed

6 files changed

+60
-19
lines changed

docs/workflow.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -588,7 +588,7 @@ workflow {
588588
ch_samples = channel.of(
589589
[id: 1, name: 'sample 1', fastq_1: '1a.fastq', fastq_2: '1b.fastq'],
590590
[id: 2, name: 'sample 2', fastq_1: '2a.fastq', fastq_2: '2b.fastq'],
591-
[id: 3, name: 'sample 3', fastq_1: '3a.fastq', fastq_2: '3b.fastq']
591+
[id: 3, name: 'sample 3', fastq_1: '3a.fastq', fastq_2: null]
592592
)
593593
594594
publish:
@@ -610,7 +610,7 @@ The above example will write the following CSV file to `results/samples.csv`:
610610
```
611611
"1","sample 1","results/fastq/1a.fastq","results/fastq/1b.fastq"
612612
"2","sample 2","results/fastq/2a.fastq","results/fastq/2b.fastq"
613-
"3","sample 3","results/fastq/3a.fastq","results/fastq/3b.fastq"
613+
"3","sample 3","results/fastq/3a.fastq",""
614614
```
615615

616616
You can customize the index file with additional directives, for example:
@@ -629,7 +629,7 @@ This example will produce the following index file:
629629
"id"|"name"|"fastq_1"|"fastq_2"
630630
"1"|"sample 1"|"results/fastq/1a.fastq"|"results/fastq/1b.fastq"
631631
"2"|"sample 2"|"results/fastq/2a.fastq"|"results/fastq/2b.fastq"
632-
"3"|"sample 3"|"results/fastq/3a.fastq"|"results/fastq/3b.fastq"
632+
"3"|"sample 3"|"results/fastq/3a.fastq"|""
633633
```
634634

635635
:::{note}

modules/nextflow/src/main/groovy/nextflow/extension/PublishOp.groovy

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -276,17 +276,15 @@ class PublishOp {
276276
}
277277

278278
if( value instanceof Map ) {
279-
return value
280-
.findAll { k, v -> v != null }
281-
.collectEntries { k, v ->
282-
if( v instanceof Path )
283-
return Map.entry(k, normalizePath(v, targetResolver))
284-
if( v instanceof Collection<Path> )
285-
return Map.entry(k, normalizePaths(v, targetResolver))
286-
if( v instanceof Map )
287-
return Map.entry(k, normalizePaths(v, targetResolver))
288-
return Map.entry(k, v)
289-
}
279+
return value.collectEntries { k, v ->
280+
if( v instanceof Path )
281+
return Map.entry(k, normalizePath(v, targetResolver))
282+
if( v instanceof Collection<Path> )
283+
return Map.entry(k, normalizePaths(v, targetResolver))
284+
if( v instanceof Map )
285+
return Map.entry(k, normalizePaths(v, targetResolver))
286+
return [k, v]
287+
}
290288
}
291289

292290
throw new IllegalArgumentException("Index file record must be a list, map, or file: ${value} [${value.class.simpleName}]")

modules/nextflow/src/main/groovy/nextflow/script/OutputDsl.groovy

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,10 @@ class OutputDsl {
190190
setOption('header', value)
191191
}
192192

193+
void header(String... value) {
194+
setOption('header', value as List)
195+
}
196+
193197
void path(String value) {
194198
setOption('path', value)
195199
}

modules/nextflow/src/main/groovy/nextflow/util/CsvWriter.groovy

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,9 @@ class CsvWriter {
4646
else if( header instanceof List ) {
4747
columns = header
4848
}
49+
else {
50+
columns = null
51+
}
4952

5053
path.delete()
5154

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package nextflow.util
2+
3+
import spock.lang.Specification
4+
import test.TestHelper
5+
/**
6+
*
7+
* @author Ben Sherman <[email protected]>
8+
*/
9+
class CsvWriterTest extends Specification {
10+
11+
def 'should write csv file'() {
12+
given:
13+
def file = TestHelper.createInMemTempFile()
14+
and:
15+
def records = [
16+
[id: 1, fastq_1: '1_1.fastq', fastq_2: '1_2.fastq'],
17+
[id: 2, fastq_1: '2_1.fastq', fastq_2: '2_2.fastq'],
18+
[id: 3, fastq_1: '3_1.fastq', fastq_2: null],
19+
]
20+
21+
when:
22+
new CsvWriter([:]).apply(records, file)
23+
then:
24+
file.text == '''\
25+
"1","1_1.fastq","1_2.fastq"
26+
"2","2_1.fastq","2_2.fastq"
27+
"3","3_1.fastq",""
28+
'''.stripIndent()
29+
30+
when:
31+
new CsvWriter([header: true]).apply(records, file)
32+
then:
33+
file.text == '''\
34+
"id","fastq_1","fastq_2"
35+
"1","1_1.fastq","1_2.fastq"
36+
"2","2_1.fastq","2_2.fastq"
37+
"3","3_1.fastq",""
38+
'''.stripIndent()
39+
}
40+
41+
}

modules/nf-lang/src/main/java/nextflow/script/dsl/OutputDsl.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -105,11 +105,6 @@ interface IndexDsl extends DslScope {
105105
/* List<String> | Boolean */
106106
void header(Object value);
107107

108-
@Description("""
109-
Closure which defines how to transform each published value into a CSV record. The closure should return a list or map. By default, no transformation is applied.
110-
""")
111-
void mapper(Closure value);
112-
113108
@Description("""
114109
The name of the index file relative to the target path (required).
115110
""")

0 commit comments

Comments
 (0)