nextflow中如何获取当前临时工作目录的路径

How to get the path of the current temporary working directory in nextflow

我正在尝试在进程临时目录中创建一个文件,nextflow 使用 nextflow 的本机脚本语言 (Groovy) 检查输出。

这是一个最小的例子:

#!/usr/bin/env nextflow
nextflow.enable.dsl = 2

process test {
    echo true
    output:
        file('createMe')
    exec:
    path = 'createMe'
    println path
    output = file(path)
    output.append('exemplary file content')
}

workflow {
    test()
}

当使用 python 作为脚本语言时,只需在当前目录中创建文件即可,但此处失败并显示以下消息:

Error executing process > 'test'

Caused by:
  Missing output file(s) `createMe` expected by process `test`

Source block:
  path = 'createMe'
  println path
  output = file(path)
  output.append('exemplary file content')

Work dir:
  /home/some_user/some_path/work/89/915376cbedb92fac3e0a9b18536809

Tip: view the complete command output by changing to the process work dir and entering the command `cat .command.out`

我也尝试将路径设置为 workDir + '/createMe',但实际工作目录似乎是该路径的子目录。

几天前确实存在一个关于此确切行为的问题 (#2628)。解决方法是使用task.workDir指定任务工作目录:

This is caused by the fact the relative path is always resolved by the Jvm against the main current launching directory.

Therefore the task work directory should be taken using the attribute task.workDir e.g.

task.workDir.resolve('test.txt').text = "hello $world"

https://github.com/nextflow-io/nextflow/issues/2628#issuecomment-1034189393