Skip to content

Commit 75e4714

Browse files
bentshermanjorgee
andauthored
Fix issue with optional workflow output (#6519)
Signed-off-by: Ben Sherman <bentshermann@gmail.com> Co-authored-by: Jorge Ejarque <jorgee@users.noreply.github.com>
1 parent ce680c5 commit 75e4714

File tree

4 files changed

+42
-23
lines changed

4 files changed

+42
-23
lines changed

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ import org.yaml.snakeyaml.Yaml
3333
class DumpHelper {
3434

3535
static def deepConvertToString(value, nullValue = '') {
36-
if( value instanceof List )
36+
if( value instanceof Collection )
3737
value.collect { it -> deepConvertToString(it) }
3838

3939
else if( value instanceof Map )
@@ -53,7 +53,7 @@ class DumpHelper {
5353
}
5454

5555
static String prettyPrint(value) {
56-
if( value instanceof List || value instanceof Map || value instanceof Path )
56+
if( value instanceof Collection || value instanceof Map || value instanceof Path )
5757
return prettyPrintJson(value)
5858
else
5959
return InvokerHelper.inspect(value)

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ class PublishOp {
141141
// the resulting mapping to create a saveAs closure
142142
final mapping = dsl.build()
143143
if( mapping instanceof Map<String,String> )
144-
return { filename -> outputDir.resolve(mapping[filename]) }
144+
return { filename -> filename in mapping ? outputDir.resolve(mapping[filename]) : null }
145145

146146
// if the resolved publish path is a string, resolve it
147147
// against the base output directory
@@ -172,6 +172,8 @@ class PublishOp {
172172
}
173173

174174
private void publish0(Path source, String target) {
175+
if( source == null || target == null )
176+
return
175177
log.trace "Publishing ${source} to ${target}"
176178
if( mapping == null )
177179
mapping = [:]
@@ -278,11 +280,11 @@ class PublishOp {
278280
if( value instanceof Map ) {
279281
return value.collectEntries { k, v ->
280282
if( v instanceof Path )
281-
return Map.entry(k, normalizePath(v, targetResolver))
283+
return [k, normalizePath(v, targetResolver)]
282284
if( v instanceof Collection<Path> )
283-
return Map.entry(k, normalizePaths(v, targetResolver))
285+
return [k, normalizePaths(v, targetResolver)]
284286
if( v instanceof Map )
285-
return Map.entry(k, normalizePaths(v, targetResolver))
287+
return [k, normalizePaths(v, targetResolver)]
286288
return [k, v]
287289
}
288290
}
@@ -307,8 +309,11 @@ class PublishOp {
307309
// if the target resolver is a closure, use it to transform
308310
// the source filename to the target path
309311
if( targetResolver instanceof Closure<Path> ) {
312+
// note: the closure can return null to e.g. not
313+
// publish specific files
310314
final relPath = sourceDir.relativize(path).toString()
311-
return (targetResolver.call(relPath) as Path).normalize()
315+
final resolvedPath = targetResolver.call(relPath) as Path
316+
return resolvedPath?.normalize()
312317
}
313318

314319
// if the target resolver is a directory, resolve the source

tests/checks/output-dsl.nf/.checks

Lines changed: 26 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
1-
#
2-
# run normal mode
3-
#
4-
echo First run
1+
2+
echo "Initial run"
53
$NXF_RUN --save_bam_bai | tee stdout
64

75
[[ $(grep INFO .nextflow.log | grep -c 'Submitted process > fastqc') == 3 ]] || false
@@ -26,10 +24,7 @@ $NXF_RUN --save_bam_bai | tee stdout
2624
[[ -f results/summary_data/fastqc.txt ]] || false
2725

2826

29-
#
30-
# one more time to make sure 'overwrite' is fine
31-
#
32-
echo Second run
27+
echo "Run again with overwrite enabled"
3328
$NXF_RUN --save_bam_bai | tee stdout
3429

3530
[[ $(grep INFO .nextflow.log | grep -c 'Submitted process > fastqc') == 3 ]] || false
@@ -54,10 +49,29 @@ $NXF_RUN --save_bam_bai | tee stdout
5449
[[ -f results/summary_data/fastqc.txt ]] || false
5550

5651

57-
#
58-
# clean & run resume mode
59-
#
60-
echo Third run
52+
echo "Run with some outputs disabled"
53+
rm -rf results
54+
55+
$NXF_RUN -resume | tee stdout
56+
57+
[[ $(grep INFO .nextflow.log | grep -c 'Cached process > fastqc') == 3 ]] || false
58+
[[ $(grep INFO .nextflow.log | grep -c 'Cached process > align') == 3 ]] || false
59+
[[ $(grep INFO .nextflow.log | grep -c 'Cached process > quant') == 3 ]] || false
60+
61+
[[ -f results/log/alpha.fastqc.log ]] || false
62+
[[ -f results/log/beta.fastqc.log ]] || false
63+
[[ -f results/log/delta.fastqc.log ]] || false
64+
[[ ! -e results/align ]] || false
65+
[[ -L results/quant/alpha ]] || false
66+
[[ -L results/quant/beta ]] || false
67+
[[ -L results/quant/delta ]] || false
68+
[[ -f results/samples.csv ]] || false
69+
[[ -f results/summary_report.html ]] || false
70+
[[ -f results/summary_data/data.json ]] || false
71+
[[ -f results/summary_data/fastqc.txt ]] || false
72+
73+
74+
echo "Resumed run"
6175
rm -rf results
6276

6377
$NXF_RUN --save_bam_bai -resume | tee stdout

tests/output-dsl.nf

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -93,8 +93,8 @@ workflow {
9393
[
9494
id: id,
9595
fastqc: fastqc,
96-
bam: params.save_bam_bai ? bam : null,
97-
bai: params.save_bam_bai ? bai : null,
96+
bam: bam,
97+
bai: bai,
9898
quant: quant
9999
]
100100
}
@@ -114,8 +114,8 @@ output {
114114
samples {
115115
path { sample ->
116116
sample.fastqc >> 'log/'
117-
sample.bam >> 'align/'
118-
sample.bai >> 'align/'
117+
sample.bam >> (params.save_bam_bai ? 'align/' : null)
118+
sample.bai >> (params.save_bam_bai ? 'align/' : null)
119119
sample.quant >> "quant/${sample.id}"
120120
}
121121
index {

0 commit comments

Comments
 (0)