我正在尝试将Snakemake与奇点结合使用,并且我注意到,使用奇点时,简单的awk
命令不再起作用。最后一行中的$1
被bash代替,而不是awk
用作第一字段。
这是一个最小的工作示例( Snakefile ):
singularity: "docker://debian:stretch"
rule all:
input: "test.txt"
rule test:
output:
"test.txt"
shell:
"cat /etc/passwd | awk -F':' '{{print $1}}' > {output}"
当我运行snakemake
时没有出现奇异之处时,输出test.txt
看起来像预期的那样(仅包含用户名)。当我运行snakemake --use-singularity
时,文件包含整行,例如root:x:0:0:root:/root:/bin/bash
。
这是Snakemake的日志:
$ snakemake --use-singularity --printshellcmd
Building DAG of jobs...
Using shell: /usr/bin/bash
Provided cores: 1
Rules claiming more threads will be scaled down.
Job counts:
count jobs
1 all
1 test
2
rule test:
output: test.txt
jobid: 1
cat /etc/passwd | awk -F':' '{print $1}' > test.txt
Activating singularity image /scratch/test/.snakemake/singularity/fa9c8c7220ff16e314142a5d78ad6cff.simg
Finished job 1.
1 of 2 steps (50%) done
localrule all:
input: test.txt
jobid: 0
Finished job 0.
2 of 2 steps (100%) done
答案 0 :(得分:2)
我遇到了类似的问题,经过大量的反复试验终于解决了它。当前(2018年11月,对于Snakemake 5.3),此文件尚未记录,因此我认为最好将其放在此处以供将来参考以帮助他人...
以上所有示例在bash -c上均错误地使用了双引号,而Snakemake并非如此。取而代之的是,Snakemake使用bash -c ' modified_command '
来调用奇点,因此使用单引号。
首先,这改变了命令中特殊字符的处理方式。其次,到目前为止,Snakemake会将实际命令中的所有单引号替换为转义版本\'。但是,仅当与奇点一起使用时才适用。
因此,如果您的命令包含单引号,则使用--use-singularity提交时或在正常模式下运行时,事情都会中断。我知道在这两种情况下都有效的唯一可行解决方案如下:
shell: """awk "{{OFS="\\t"}};{{print \$2}}" {input}"""
因此,以下规则适用:
我希望这会有所帮助,一旦实现更新,我将更新此帖子。
答案 1 :(得分:0)
我尝试了您的示例,它在最新的Snakemake版本5.1.4中运行良好。更新到最新版本后,您确定这仍然是您的问题吗?
答案 2 :(得分:0)
与$
一起运行时,{@ {1}}必须转义。
bash -c
将您的snakemake代码更改为:
$ bash -c "cat temp.tab | awk '{if (\$1==1) print;}' " | head -2
1 26554252 26554595 1 1
1 156246251 156246680 2 2
$ bash -c "cat temp.tab | awk '{if ($1==1) print;}' " | head -2
awk: cmd. line:1: {if (==1) print;}
awk: cmd. line:1: ^ syntax error