我使用NextFlow和DSL2语法。我想将最后的结果路径定义为命令行参数。然而,据我所知,NextFlow进程不识别directive作用域中的input变量(参见下面的最小示例)。
终极问题:我如何将“基本目录”传递给一个进程,然后该进程可以附加到该路径(例如,publishDir("${results_dir}/MY_PROC_RESULTS/", mode = "copy"))?如果这不是最好的方法,也可以接受其他建议。
真的很感谢你的帮助!
下面是一个很小的例子:
MY_WORKFLOW.nf
/*
* Make this pipeline a nextflow 2 implementation
*/
nextflow.enable.dsl=2
include {SUB_WORKFLOW_WF} from './SUB_WORKFLOW_WF_PROCS.nf'
/*
* Define the directory to publish final results in.
*/
params.results_dir = "${projectDir}/results"
results_dir = params.results_dir
workflow{
SUB_WORKFLOW_WF(results_dir)
}SUB_WORKFLOW_WF_PROCS.nf
workflow SUB_WORKFLOW_WF {
take:
results_dir
main:
println results_dir // This works
MY_PROC(results_dir)
}
process MY_PROC {
/*
* Workflow fails with ERROR 1 if the following line is included. Fails
* with ERROR 2 if the following line is excluded.
*/
println $results_dir
publishDir("${results_dir}/MY_PROC_RESULTS/", mode = "copy")
input:
path(results_dir)
script:
"""
echo "Hello"
"""
}结果
错误1
No such variable: $results_dir
-- Check script './SUB_WORKFLOW_WF_PROCS.nf' at line: 11 or see '.nextflow.log' file for more details误差2
Error executing process > 'SUB_WORKFLOW_WF:MY_PROC'
Caused by:
Not a valid PublishDir entry [org.codehaus.groovy.runtime.GStringImpl] null/MY_PROC_RESULTS发布于 2022-01-13 00:11:56
您将得到第一个错误,因为全局范围中没有“$results_dir”变量。第二个错误有点神秘,但实际上只是语法错误。“mode”声明只需要一个冒号,就像Groovy一样,可以将键和值分开:
publishDir("${results_dir}/MY_PROC_RESULTS/", mode: "copy")因此,与其传递变量,不如先在脚本的开头定义管道参数,然后再进行“包含”声明。然后,将从包含上下文继承这些param。例如:
MY_WORKFLOW.nf
nextflow.enable.dsl=2
params.publish_dir = './results'
include { SUB_WORKFLOW_WF } from './SUB_WORKFLOW_WF_PROCS.nf'
workflow{
SUB_WORKFLOW_WF()
}SUB_WORKFLOW_WF_PROCS.nf
workflow SUB_WORKFLOW_WF {
MY_PROC()
}
process MY_PROC {
publishDir(
path: "${params.publish_dir}/MY_PROC_RESULTS",
mode: 'copy',
)
output:
path "proc_results.txt"
"""
touch "proc_results.txt"
"""
}结果:
$ nextflow run ./MY_WORKFLOW.nf
N E X T F L O W ~ version 21.04.3
Launching `./MY_WORKFLOW.nf` [shrivelled_montalcini] - revision: d31b4930b9
executor > local (1)
[2b/08e223] process > SUB_WORKFLOW_WF:MY_PROC [100%] 1 of 1 ✔$ find ./results/MY_PROC_RESULTS/proc_results.txt
./results/MY_PROC_RESULTS/proc_results.txthttps://stackoverflow.com/questions/70689180
复制相似问题