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

View channel only when parameter is set #5831

Open
gh-byounggreenwald opened this issue Feb 28, 2025 · 5 comments
Open

View channel only when parameter is set #5831

gh-byounggreenwald opened this issue Feb 28, 2025 · 5 comments

Comments

@gh-byounggreenwald
Copy link

Hi!

I am trying to do a view throughout my pipeline if I pass params.test_run as true. I like the behavior of view over dump, so prefer to do that if possible.

with just view, and some process in my workflow, the following works

process | view

this does not

process | { params.test_run ? view : map{ x -> x } }

it gives the error
Missing process or function or([Script_5fd23086685935fc$_runScript_closure7$_closure36$_closure54@137a4b54])

Lastly I would like to set this to a variable to use it in my workflow, something like

view_if_test = { params.test_run ? view : map{ x -> x } }

workflow {
process | view_if_test 
}

is this possible?

Thanks!

@bentsherman
Copy link
Member

This should work:

process | (params.test_run ? view : map{ x -> x })

But what about view do you like over dump?

@mahesh-panchal
Copy link
Contributor

You could also do it in the view operator itself.

workflow {
    Channel.of(1..3)
    | view { x -> params.debug ? x : '' }
}

@gh-byounggreenwald
Copy link
Author

Thanks both :)

The structure of view is what i am used to looking at to track how the channel are behaving; its probably more I should just learn to examine the dump output.

I do have issues if I do dump without a tag -- from docs it seemed like this should be supported, but maybe not?

@gh-byounggreenwald
Copy link
Author

is there a way to save this to a custom operator? should this work?

view_if_test = (params.test_run ? view : map{ x -> x })

workflow {

process | view_if_test

}

@mahesh-panchal
Copy link
Contributor

You can define a function

def debug_view (ch) {
    ch | (params.test ? view : map { x -> x } )
}

workflow {
    debug_view(Channel.of(1..3))
}

Also I think it's best to use .dump with a tag. When you use --dump-channels you can leave off the arg for all channels, or you can give it a string which can also be a pattern to print one more channels.

workflow {
    Channel.of(1..3).dump(tag:'ch_numbers', pretty: true)
    Channel.of('A'..'C').dump(tag:'ch_letters')
}
nextflow run main -dump-channels
nextflow run main -dump-channels 'ch_*'
nextflow run main -dump-channels 'ch_letters'

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

No branches or pull requests

3 participants