Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ifEmpty operator doesn't return expected value (value channel) #4953

Open
onuryukselen opened this issue Apr 26, 2024 · 5 comments
Open

ifEmpty operator doesn't return expected value (value channel) #4953

onuryukselen opened this issue Apr 26, 2024 · 5 comments

Comments

@onuryukselen
Copy link

onuryukselen commented Apr 26, 2024

Expected behavior and actual behavior

I anticipate receiving the file() block when the channel is empty. However, it looks like it returns queue channel and it gets consumed after one job submission. Are there any other way to check whether the channel is empty?

Steps to reproduce the problem

Here is the example code to reproduce the problem:

ch = channel.from( 1, 3, 5, 7 )
ch_empty_file = file("$baseDir/NO_FILE")
secondChannel = channel.empty()
testChn= secondChannel.ifEmpty(ch_empty_file)

process test {

input:
   val(a)
   file(b)

   script:
   """
   """
}

process test2 {

input:
  val(a)
  file(b)

  script:
  """
  """
}

workflow {
test (ch,ch_empty_file)
test2(ch,testChn)
}

Program output

N E X T F L O W ~ version 23.10.1
Launching /opt/run1372/test.nf [exotic_swartz] DSL2 - revision: 663225ff37
[1b/66845b] Submitted process > test (1)
[8c/7fb0e1] Submitted process > test (2)
[41/eda731] Submitted process > test2 (1)
[f5/470f5e] Submitted process > test (3)
[ac/f0ad1a] Submitted process > test (4)

It executes test2 only once. I was expecting 4 test2 jobs similar to test process.

Environment

  • Nextflow version: [23.10.1]
  • Java version: [openjdk 18.0.2-ea 2022-07-19]
  • Operating system: [Linux]
  • Bash version: (5.1.16)
@onuryukselen onuryukselen changed the title ifEmpty operator doesn't return expected value ifEmpty operator doesn't return expected value (value channel) Apr 29, 2024
@onuryukselen
Copy link
Author

Hello, have you been able to replicate the issue? Do you think my expectation about the ifEmpty operator is correct?

@bentsherman
Copy link
Member

It turns out the docs are incorrect. They say that ifEmpty returns a value channel but actually it always returns a queue channel. I will review the operator return types more carefully and update the docs

@onuryukselen
Copy link
Author

I see. Could you please suggest another way to check whether the channel is empty or not? I want to return Value Channel if channel is empty.

@bentsherman
Copy link
Member

bentsherman commented May 6, 2024

I recommend that you explicitly combine the process inputs instead of relying on the implicit value channel behavior:

process test2 {
  input:
  tuple val(a), file(b)

  script:
  """
  """
}

workflow {
  test (ch,ch_empty_file)
  test2( ch.combine(testChn) )
}

@onuryukselen
Copy link
Author

onuryukselen commented May 6, 2024

My goal is creating optional input for a process, so "combine" operator might not work for some cases. For example if secondChannel is empty, I want to use file("$baseDir/NO_FILE") so that process will work even secondChannel is empty.

Similar to https://nextflow-io.github.io/patterns/optional-input/ but I need to check channel. So is there any way to write condition like this:

testChn= secondChannel.ifEmpty("empty")
if (testChn.value == "empty"){
  testChn = file("$baseDir/NO_FILE")
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants