Skip to content

Commit

Permalink
Remove deprecated workflow publish [DSL2]
Browse files Browse the repository at this point in the history
  • Loading branch information
pditommaso committed Apr 12, 2020
1 parent 6b655b1 commit 1bd7b4a
Show file tree
Hide file tree
Showing 5 changed files with 4 additions and 95 deletions.
Expand Up @@ -108,10 +108,10 @@ class NextflowDSLImpl implements ASTTransformation {
static class DslCodeVisitor extends ClassCodeVisitorSupport {

@Deprecated final static String WORKFLOW_GET = 'get'
@Deprecated final static String WORKFLOW_PUBLISH = 'publish'
final static String WORKFLOW_TAKE = 'take'
final static String WORKFLOW_EMIT = 'emit'
final static String WORKFLOW_MAIN = 'main'
@Deprecated final static String WORKFLOW_PUBLISH = 'publish'

final static Random RND = new Random()

Expand Down Expand Up @@ -415,10 +415,6 @@ class NextflowDSLImpl implements ASTTransformation {
return createAssignX(stat, body, type, uniqueNames)
}

if( type == WORKFLOW_PUBLISH ) {
return createAssignX(stat, body, type, uniqueNames)
}

syntaxError(stat, "Workflow malformed parameter definition")
return stat
}
Expand Down Expand Up @@ -509,9 +505,7 @@ class NextflowDSLImpl implements ASTTransformation {
syntaxError(stm, "Workflow 'get' is not supported anymore use 'take' instead")

case WORKFLOW_PUBLISH:
if( !anonymous ) {
syntaxError(stm, "Publish declaration is only allowed in main workflow definition")
}
syntaxError(stm, "Workflow 'publish' is not supported anymore use process 'publishDir' instead")

case WORKFLOW_TAKE:
case WORKFLOW_EMIT:
Expand Down
Expand Up @@ -23,8 +23,6 @@ import groovyx.gpars.dataflow.DataflowWriteChannel
import nextflow.exception.MissingValueException
import nextflow.exception.ScriptRuntimeException
import nextflow.extension.CH
import nextflow.extension.PublishOp

/**
* Models a script workflow component
*
Expand All @@ -42,8 +40,6 @@ class WorkflowDef extends BindableDef implements ChainableDef, ExecutionContext

private List<String> declaredOutputs

private Map<String,Map> declaredPublish

private Set<String> variableNames

private BaseScript owner
Expand All @@ -67,7 +63,6 @@ class WorkflowDef extends BindableDef implements ChainableDef, ExecutionContext
// now it can access the parameters
this.declaredInputs = new ArrayList<>(resolver.getTakes().keySet())
this.declaredOutputs = new ArrayList<>(resolver.getEmits().keySet())
this.declaredPublish = new LinkedHashMap<>(resolver.getPublish())
this.variableNames = getVarNames0()
}

Expand Down Expand Up @@ -164,29 +159,7 @@ class WorkflowDef extends BindableDef implements ChainableDef, ExecutionContext
}
return new ChannelOut(channels)
}

protected publishOutputs(Map<String,Map> publishDefs) {
for( Map.Entry<String,Map> pub : publishDefs.entrySet() ) {
final name = pub.key
final opts = pub.value
if( !binding.hasVariable(name) )
throw new MissingValueException("Missing workflow publish parameter: $name")
final obj = binding.getVariable(name)

if( CH.isChannel(obj) ) {
new PublishOp(CH.getReadChannel(obj), opts).apply()
}

else if( obj instanceof ChannelOut ) {
for( DataflowWriteChannel ch : ((ChannelOut)obj) ) {
new PublishOp(CH.getReadChannel(ch), opts).apply()
}
}

else throw new IllegalArgumentException("Illegal workflow publish parameter: $name value: $obj")
}
}



Object run(Object[] args) {
binding = new WorkflowBinding(owner)
Expand All @@ -208,7 +181,6 @@ class WorkflowDef extends BindableDef implements ChainableDef, ExecutionContext
closure.call()
// collect the workflow outputs
output = collectOutputs(declaredOutputs)
publishOutputs(declaredPublish)
return output
}

Expand All @@ -223,12 +195,10 @@ class WorkflowParamsResolver implements GroovyInterceptable {

static final private String TAKE_PREFIX = '_take_'
static final private String EMIT_PREFIX = '_emit_'
@Deprecated static final private String PUBLISH_PREFIX = '_publish_'


Map<String,Object> takes = new LinkedHashMap<>(10)
Map<String,Object> emits = new LinkedHashMap<>(10)
Map<String,Map> publish = new LinkedHashMap<>(10)

@Override
def invokeMethod(String name, Object args) {
Expand All @@ -238,14 +208,8 @@ class WorkflowParamsResolver implements GroovyInterceptable {
else if( name.startsWith(EMIT_PREFIX) )
emits.put(name.substring(EMIT_PREFIX.size()), args)

else if( name.startsWith(PUBLISH_PREFIX)) {
log.warn1 "Workflow `publish` is deprecated -- Use process directive `publishDir` instead"
publish.put(name.substring(PUBLISH_PREFIX.size()), argToPublishOpts(args))
}

else
throw new MissingMethodException(name, WorkflowDef, args)

}

private Map argsToMap(Object args) {
Expand Down
Expand Up @@ -183,12 +183,8 @@ class WorkflowDefTest extends Dsl2Spec {

when:
def script = (TestScript)new GroovyShell(new ScriptBinding(), config).parse(SCRIPT).run()
def meta = ScriptMeta.get(script)
then:
meta.definitions.size() == 1
meta.getWorkflow(null) .declaredInputs == []
meta.getWorkflow(null) .declaredVariables == ['baz.out', 'x', '$out0']
meta.getWorkflow(null) .getDeclaredPublish() == [foo: [:], bar: [to:'some/path'], '$out0': [to:'other/path']]
thrown(MultipleCompilationErrorsException)
}

def 'should not allow publish is sub-workflow' () {
Expand Down
15 changes: 0 additions & 15 deletions tests/checks/workflow-publish-dsl2.nf/.checks

This file was deleted.

30 changes: 0 additions & 30 deletions tests/workflow-publish-dsl2.nf

This file was deleted.

1 comment on commit 1bd7b4a

@DaGaMs
Copy link
Contributor

@DaGaMs DaGaMs commented on 1bd7b4a Apr 25, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the recommended alternative to workfow publish then? I actually really like it, because it allows me to have the an explicit statement in the main workflow of where things should go. Otherwise it's hidden in the nextflow.config file. It also makes it hard to output the result of multiple sub-workflows to different directories. For example, I perform variant calling with 3 different programs in 3 sub-workflows. The last process in each case is "annotateVcf". However, I want to ouput the resulting vcf file to 3 different directories, depending on sub-workflow. Previously, I was able to do:

[...]
subWorkFlowA {
    take: input
    main:
        step1A(input) | step2 | step3
    emit:
        step3.out
}
subWorkFlowB {
    take: input
    main:
        step1B(input) | step2 | step3
    emit:
        step3.out
}
workflow {
main:
    subWorkflowA(inputBam)
    subWorkflowB(inputBam)
    subWorkflowC(inputBam)
publish:
    subWorkflowA.out to: "A"
    subWorkflowB.out to: "B"
    subWorkflowC.out to: "C"
}

Without publish in the main workflow, this gets very hairy. I actually think a dedicated publish operator would be the best solution (see #1540)

Please sign in to comment.