bash流程替换中的GNU并行参数占位符 [英] GNU Parallel argument placeholder in bash process substitution
问题描述
我有以下GNU并行命令.
I have the following GNU parallel command.
parallel --gnu --jobs 4 \
normalize-by-median.py \
-k 20 -C 20 --paired -N 4 -x 6e9 \
--out pdom-{}-diginorm.fq \
pdom-{}.fq.gz \
::: 200bp 500bp 1kb 3kb 8kb
我想在写入磁盘之前压缩输出.通常,我只是将其通过管道发送到 gzip -c
,但是不幸的是,这个特定的Python脚本没有选择将输出发送到stdout.然后,我认为我可以改用流程替代.我尝试了以下方法.
I would like to compress the output before writing to disk. Normally I would just pipe this to gzip -c
, but unfortunately this particular Python script does not have the option to send output to stdout. I then thought I could use process substitution instead. I tried the following.
parallel --gnu --jobs 4 \
normalize-by-median.py \
-k 20 -C 20 --paired -N 4 -x 6e9 \
--out >(gzip -c - > pdom-{}-diginorm.fq.gz) \
pdom-{}.fq.gz \
::: 200bp 500bp 1kb 3kb 8kb
但是,在后一个示例中,花括号由子进程按字面意义进行解释,而不是作为GNU并行参数的占位符.有什么办法可以使它正常工作吗?
However, the curly braces in this latter example get interpreted literally by the subprocess, rather than as a placeholder for the GNU parallel arguments. Is there any way I can get this to work?
推荐答案
您的问题是>()在GNU Parallel甚至启动之前就已经被解释了.因此,您需要引用它才能将其提供给GNU Parallel:
Your problem is that >() is interpreted before GNU Parallel even starts. So you need to quote that to give it to GNU Parallel:
parallel --gnu --jobs 4 \
normalize-by-median.py \
-k 20 -C 20 --paired -N 4 -x 6e9 \
--out '>(gzip -c - > pdom-{}-diginorm.fq.gz)' \
pdom-{}.fq.gz \
::: 200bp 500bp 1kb 3kb 8kb
对于版本> 20140822,您可以执行以下操作:
With version >20140822 you can do this:
parallel --plus --gnu --jobs 4 \
normalize-by-median.py \
-k 20 -C 20 --paired -N 4 -x 6e9 \
--out '>(gzip > {..}-diginorm.fq.gz)' \
{} \
::: pdom-*
这篇关于bash流程替换中的GNU并行参数占位符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!