Use the name of a (named) workflow from inside it?

Hi there!

I call the same named workflow twice, so it is imported with aliases. When this subworkflow prints or `view` something, I would like to know from which “aliased workflow” the message came from.

Here is a dummy example:

// main.nf

include { sub as subA;
          sub as subB } from './subworkflows.nf'

subA()

subB()
// subworkflows.nf

workflow sub {
    main:

    some_processes
    | view { "In workflow ${thisworkflow.aliasName}: $it" } // imaginary syntax
}

Wanted output:

In workflow subA: xyz
In workflow subB: xyz

This would be useful for logging purposes, but maybe there’s a better way to solve this problem.

One other possibility would be to provide params specifically to each workflow alias, but I don’t think that’s possible?

Thanks in advance!

I don’t think it is possible to reflect on the workflow name like that. I would say the best practice is to use workflow inputs to facilitate this, even if it’s a bit more verbose:

workflow sub {
  take:
  extra_name

  main:
  // ...
    .view { "In workflow ${extra_name} ..." }

  // ...
}
workflow {
  subA('A', ...)
  subB('B', ...)
}

Ah, I didn’t think that having a workflow input that is not a Channel was possible!

That solves it, thank you!

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.