nextflow icon indicating copy to clipboard operation
nextflow copied to clipboard

Operator ifEmpty results in a error when applied to a dataflow variable

Open msmootsgi opened this issue 9 years ago • 11 comments

We've seen the following exception in two different pipelines beginning with version 0.24.0 that were previously working in version 0.23.4. We haven't had any luck tracking down the cause.

Mar-22 16:08:51.557 [Actor Thread 16] ERROR n.extension.DataflowExtensions - @unknown
java.lang.IllegalStateException: A DataflowVariable can only be assigned once. Only re-assignments to an equal value are allowed.
    at groovyx.gpars.dataflow.expression.DataflowExpression.bind(DataflowExpression.java:368)
    at sun.reflect.GeneratedMethodAccessor15.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1218)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1027)
    at groovy.runtime.metaclass.NextflowDelegatingMetaClass.invokeMethod(NextflowDelegatingMetaClass.java:79)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:113)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at nextflow.extension.DataflowExtensions$_ifEmpty_closure51.doCall(DataflowExtensions.groovy:1771)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1027)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:42)
    at org.codehaus.groovy.runtime.callsite.CallSiteArray.defaultCall(CallSiteArray.java:48)
    at org.codehaus.groovy.runtime.callsite.PogoMetaClassSite.call(PogoMetaClassSite.java:57)
    at org.codehaus.groovy.runtime.callsite.AbstractCallSite.call(AbstractCallSite.java:125)
    at nextflow.extension.DataflowExtensions$2.afterStop(DataflowExtensions.groovy:265)
    at groovyx.gpars.dataflow.operator.DataflowProcessor.fireAfterStop(DataflowProcessor.java:324)
    at groovyx.gpars.dataflow.operator.DataflowProcessorActor.afterStop(DataflowProcessorActor.java:59)
    at sun.reflect.GeneratedMethodAccessor32.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1218)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1027)
    at org.codehaus.groovy.runtime.InvokerHelper.invokePojoMethod(InvokerHelper.java:913)
    at org.codehaus.groovy.runtime.InvokerHelper.invokeMethod(InvokerHelper.java:904)
    at groovyx.gpars.actor.Actor.callDynamic(Actor.java:369)
    at groovyx.gpars.actor.Actor.handleTermination(Actor.java:320)
    at groovyx.gpars.actor.AbstractLoopingActor.terminate(AbstractLoopingActor.java:204)
    at groovyx.gpars.dataflow.operator.DataflowProcessor.terminate(DataflowProcessor.java:147)
    at groovyx.gpars.dataflow.operator.DataflowProcessor$terminate$2.call(Unknown Source)
    at nextflow.extension.DataflowExtensions$_subscribeImpl_closure3.doCall(DataflowExtensions.groovy:298)
    at sun.reflect.GeneratedMethodAccessor72.invoke(Unknown Source)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:498)
    at org.codehaus.groovy.reflection.CachedMethod.invoke(CachedMethod.java:93)
    at groovy.lang.MetaMethod.doMethodInvoke(MetaMethod.java:325)
    at org.codehaus.groovy.runtime.metaclass.ClosureMetaClass.invokeMethod(ClosureMetaClass.java:294)
    at groovy.lang.MetaClassImpl.invokeMethod(MetaClassImpl.java:1027)
    at groovy.lang.Closure.call(Closure.java:414)
    at groovyx.gpars.dataflow.operator.DataflowOperatorActor.startTask(DataflowOperatorActor.java:120)
    at groovyx.gpars.dataflow.operator.DataflowOperatorActor.onMessage(DataflowOperatorActor.java:108)
    at groovyx.gpars.actor.impl.SDAClosure$1.call(SDAClosure.java:43)
    at groovyx.gpars.actor.AbstractLoopingActor.runEnhancedWithoutRepliesOnMessages(AbstractLoopingActor.java:293)
    at groovyx.gpars.actor.AbstractLoopingActor.access$400(AbstractLoopingActor.java:30)
    at groovyx.gpars.actor.AbstractLoopingActor$1.handleMessage(AbstractLoopingActor.java:93)
    at groovyx.gpars.util.AsyncMessagingCore.run(AsyncMessagingCore.java:132)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)

msmootsgi avatar Mar 22 '17 20:03 msmootsgi

It should be an binding (ie. <<) of a value to a singleton channel, in a ifEmpty operator:

nextflow.extension.DataflowExtensions$_ifEmpty_closure51.doCall(DataflowExtensions.groovy:1771)

This must be related to #301. What is a happening is that processes that can only be execute once create single channel (aka dataflow variable). This is equivalent to a channel created with a Channel.value() method. These channels can be assigned only once.

How are using that channel in the ifEmpty operator?

pditommaso avatar Mar 22 '17 20:03 pditommaso

Here's one example of a way that we use ifEmpty

if(params.active) {

    Channel.fromPath( params.folder + "/" + params.prefix + "*.ht2" )
        .ifEmpty{ error "Missing index" }
        .toSortedList()
        .set{ index_ch }

} else {

    Channel
        .empty()
        .set{ index_ch }

}

This is how we've been handling conditional input without mucking up the processes with when statements.

msmootsgi avatar Mar 22 '17 20:03 msmootsgi

I don't this is the problem. This snippet is running fine. Don't you have something like this:

ifEmpty { foo << value }

or

ifEmpty { foo.bind(value) }

where foo is a channel created by a process.

pditommaso avatar Mar 22 '17 20:03 pditommaso

Just grepping for ifEmpty in the two pipelines I see:

.ifEmpty{ error "Missing HISAT2 index" }
.ifEmpty { error "Cannot find any reads matching: ${params.reads.path}" }
file(ht2_ss) from ss_for_ht2.ifEmpty("none").first()
.merge( primary_annotation2.ifEmpty{"NULL"} ) {a, b -> [a, b]}

So just two cases - on where we call error and one where we provide a default value.

msmootsgi avatar Mar 22 '17 20:03 msmootsgi

I think the problem is this

file(ht2_ss) from ss_for_ht2.ifEmpty("none").first()

pditommaso avatar Mar 22 '17 20:03 pditommaso

Can you explain what the problem is? That code looks a lot like what I see here: https://www.nextflow.io/docs/latest/operator.html#ifempty.

msmootsgi avatar Mar 22 '17 21:03 msmootsgi

The problem is that, as a consequence of #301, that channel can be bound only to a value. That in your case it's none but then this line will produce that error.

This is a bug. I will release a patch in a couple of days.

pditommaso avatar Mar 22 '17 21:03 pditommaso

Got it, thanks. We'll be exporting NXF_VER=0.23.4in the meantime!

msmootsgi avatar Mar 22 '17 21:03 msmootsgi

I've just uploaded 0.24.1-SNAPSHOT that should solve the problem.

pditommaso avatar Mar 22 '17 21:03 pditommaso

Yes, we can confirm that 0.24.1-SNAPSHOT fixes the problem. Thanks for the incredible turnaround!

msmootsgi avatar Mar 22 '17 22:03 msmootsgi

✌️

pditommaso avatar Mar 22 '17 22:03 pditommaso