我正在尝试找出如何检查 channel 是否为空。
例如,我有两个进程。仅当设置了参数/标志的组合时,第一个进程才会运行,如果是这样,还检查来自另一个进程的输入文件(通过 channel 输入)是否不为空,然后为第二个进程创建一个新的输入文件(以最终替换默认的)。作为一个简化的示例:
.....
.....
// create the channel here to force nextflow to wait for the first process
_chNewInputForProcessTwo = Channel.create()
process processOne {
when:
params.conditionOne && parameters.conditionTwo
input:
file inputFile from _channelUpstreamProcess
output:
file("my.output.file") into _chNewInputForProcessTwo
script:
"""
# check if we need to produce new input for second process (i.e., input file not empty)
if [ -s ${inputFIle} ]
then
<super_command_to_generate_new_fancy_input_for_second_process> > "my.output.file"
else
echo "No need to create new input"
fi
"""
}
// and here I would like to check if new input was generated or leave the "default" one
_chInputProcessTwo = Channel.from(_chNewInputForProcessTwo).ifEmpty(Channel.value(params.defaultInputProcessTwo))
process secondProcess {
input:
file inputFile from _chInputProcessTwo
......
......
etc.
当我尝试使用这种方法运行时,它会失败,因为 channel _chNewInputForProcessTwo
包含 DataflowQueue(queue=[])
,因此实际上并不为空。
我尝试了一些查看文档以及 google groups 和 gitter 上的线程的方法。试图将其设置为空,但随后它提示我试图使用该 channel 两次。放置 create().close()
等
有没有一种干净/合理的方法来做到这一点?我可以使用值 channel 来完成此操作,并让第一个进程在 stdout
上输出一些字符串,以供第二个进程拾取和检查,但这对我来说似乎很脏。
如有任何建议/反馈,我们将不胜感激。预先感谢您!
马吕斯
最佳答案
最好避免尝试检查 channel 是否为空。如果您的 channel 可能为空,并且您需要在 channel 中使用默认值,则可以使用 ifEmpty运营商提供一份。请注意,单个值隐式为 value channel 。我认为您需要的是:
myDefaultInputFile = file(params.defaultInputProcessTwo)
chInputProcessTwo = chNewInputForProcessTwo.ifEmpty(myDefaultInputFile)
此外,通常不需要调用 Channel.create()
。
关于channel - 检查nextflow channel 是否为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/64042860/