我有一个nextflow脚本,它从文本文件中创建一个变量,并且我需要将该变量的值传递给命令行顺序(这是一个bioconda包)。这两个进程发生在“脚本”部分中。我尝试使用'$‘符号调用变量,没有任何结果,我想是因为在nextflow脚本的脚本部分使用该符号是为了调用输入部分中定义的变量。
为了让自己更清楚,下面是我试图实现的一个代码示例:
params.gz_file = '/path/to/file.gz'
params.fa_file = '/path/to/file.fa'
params.output_dir = '/path/to/outdir'
input_file = file(params.gz_file)
fasta_file = file(params.fa_file)
process foo {
//publishDir "${params.output_dir}", mode: 'copy',
input:
path file from input_file
path fasta from fasta_file
output:
file ("*.html")
script:
"""
echo 123 > number.txt
parameter=`cat number.txt`
create_report $file $fasta --flanking $parameter
"""
}
通过doig,我收到的错误是:
Error executing process > 'foo'
Caused by:
Unknown variable 'parameter' -- Make sure it is not misspelt and defined somewhere in the script before using it
有没有任何方法可以调用脚本中的变量parameter
,而不需要Nextflow将其解释为输入文件?提前感谢!
发布于 2021-03-11 03:17:17
脚本块的文档在这里很有用:
由于Nextflow对字符串中的变量替换使用相同的Bash语法,因此您需要根据是否要在Nextflow上下文中(或在Bash环境执行中)中计算变量来仔细地管理它们。
一种解决方案是使用反斜杠(\
)字符作为前缀来转义shell (Bash)变量,如下面的示例所示:
process foo {
script:
"""
echo 123 > number.txt
parameter="\$(cat number.txt)"
echo "\${parameter}"
"""
}
另一种解决方案是使用壳块,其中美元($
)变量由shell (Bash解释器)管理,感叹号(!
)变量由Nextflow处理。例如:
process bar {
echo true
input:
val greeting from 'Hello', 'Hola', 'Bonjour'
shell:
'''
echo 123 > number.txt
parameter="$(cat number.txt)"
echo "!{greeting} parameter ${parameter}"
'''
}
发布于 2021-03-10 21:47:57
在顶部的'params‘部分中声明“参数”。
params.parameter="1234"
(..)
script:
"""
(...)
create_report $file $fasta --flanking ${params.parameter}
(...)
"""
(...)
并使用“-参数87678”调用"nextflow run“。
https://stackoverflow.com/questions/66568781
复制相似问题