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

Ability to use 'name' attribute with path() output #4943

Open
stevekm opened this issue Apr 23, 2024 · 2 comments
Open

Ability to use 'name' attribute with path() output #4943

stevekm opened this issue Apr 23, 2024 · 2 comments

Comments

@stevekm
Copy link
Contributor

stevekm commented Apr 23, 2024

It would be nice if we could change the file output name in the output directive, the same way you can do with input, like this;

process FOO {
    tag "${id}"
    publishDir "${params.outdir}", mode: "copy"

    input:
    val(id)

    output:
    // THIS WORKS; path(".command.sh"), topic: commands
    // THIS does not work;
    tuple val(id), val(task.process), path(".command.sh", name: "${id}.${task.process}.txt"), topic: commands

    script:
    """
    """
}

Currently it seems you would have to do something like this;

publishDir "${params.outdir}", mode: "copy", overwrite: true, saveAs: { filename ->
            if (filename == ".command.sh"){
                return "${id}.${task.process}.command.txt"
            }
        return filename
    }

though that still does not actually propagate down through the output channel, so your downstream processes will be forced to do the renaming, or you would have to rename in a separate closure

(example method of renaming in a downstream method)

channel.topic("commands").collectFile(storeDir:"${params.collectDir}") { id, proc, cmdtxt ->
        return [ "${id}.${proc}.command.txt".replace(":", "_"), cmdtxt.text ]
    }

would be easier if it could be just embedded in the output directive

@bentsherman
Copy link
Member

You could accomplish this in the script:

script:
"""
cp .command.sh ${id}.${task.process}.txt
"""

You shouldn't rename helper files because it can break the Nextflow runtime. Copying them is fine, but still a bit sketchy since these files are internal, they aren't like a public user-facing API

@stevekm
Copy link
Contributor Author

stevekm commented Apr 23, 2024

my goal is to avoid doing it in the script section

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