1
process A {
...
output:
path("*linkedfrag"), emit: lf
path("*hapblock"), emit: hb

publishDir ???
...
}

Is there a way to publish lf to ${params.outdir}/lf/ and hb to ${params.outdir}/hb/ ? I dont want to emit lf as "lf/*linkedfrag" etc

Cai Bian
  • 141
  • 1
  • 6

1 Answers1

1

One way would be to actually specify more than one publishDir directive. This approach provides increased flexibility by giving you the option to specify a different set of rules for each directive. To publish your output files to different target directories, you could just use the pattern parameter to select the files to publish from the overall set of output files:

process A {

    publishDir "${params.outdir}/lf", pattern: "*linkedfrag"
    publishDir "${params.outdir}/hb", pattern: "*hapblock"

    ...
}

Another way would be to use the saveAs parameter to set the required path. This example uses a ternary operator, but you could also use an if/else-if/else block1:

process A {

    publishDir (
        path: params.outdir,
        saveAs: { fn ->
            fn.endsWith('linkedfrag') ? "lf/${fn}" :
            fn.endsWith('hapblock') ? "hb/${fn}" :
            fn
        }
    )

    ...
}
Steve
  • 51,466
  • 13
  • 89
  • 103
  • Thanks a lot. what if I want to save the output to both lf and hb subdirectories? – Cai Bian May 01 '23 at 08:00
  • 1
    @CaiBian I think the only way would be to use multiple `publishDir` directives, like in the first example. Just remove the `pattern` parameter to publish all of the (declared) files to these sub-directories. – Steve May 02 '23 at 02:25