Multiple publishDir for one process in nextflow config

Hi!

I want two flags which each should trigger the publication of files with different endings:

process {
	withLabel: "fastqc" {
		if (params.fastqcrawout != false){
				publishDir = [
				path: { "${params.out}/fastqcraw" },
				mode: "copy",
				pattern: "*fastqc.zip"

			]
		}
		if (params.fastqcout != false){
			publishDir = [
				path: { "${params.out}/fastqc" },
				mode: "copy",
				pattern: "*.html"
			]
		}
	}
}

The issue is now obviously that if I use both flags, the second publishDir overwrites the first one. Is there any possibility solve this issue in the config file, like appending to the first one or something?

Thanks in advance!

I’d recommend looking at the way the nf-core flagship pipelines deal with this issue (example here)

The nf-core community uses a saveAs that returns nil if the parameter isn’t set, the file will not be published. A slightly cleaner alternative (imho) is to use the “enabled” argument to publishDir:

process {
  withLabel: "fastqc" {
    publishDir = [
      [
        path: { "${params.out}/fastqcraw" },
        mode: 'copy',
        pattern: "*fastqc.zip",
        enabled: params.fastqcrawout
      ],
      [
        path: { "${params.out}/fastqc" },
        mode: 'copy',
        pattern: "*.html",
        enabled: params.fastqcout
      ]
    ]
  }
}
1 Like