为什么我不能在snakemake规则中使用变量名进行拆分呢



见下文,我不明白为什么我的参数par1和par2是相同的,尽管有.split((函数。

请参阅这个可运行的自包含示例。

你的遗嘱需要做";触摸id1-one.input id2-two.input;在工作目录中。

files=["id1-one", "id2-two"]
rule all:
input:
expand("{sample}.output",sample=files)

rule myrule:
params:
par1 = "{sample}",
par2 = "{sample}".split("-")
input:
i = "{sample}.input"
output:
o = "{sample}.output"
shell:
"./myprog -i ${input.i} -o {output.o} par1: {params.par1} par2: {params.par2}"

运行输出为:

$ snakemake -s small3.smk --cores 10 -n -p
Building DAG of jobs...
Job stats:
job       count    min threads    max threads
------  -------  -------------  -------------
all           1              1              1
myrule        2              1              1
total         3              1              1

[Sat Dec 11 18:59:02 2021]
rule myrule:
input: id2-two.input
output: id2-two.output
jobid: 2
wildcards: sample=id2-two
resources: tmpdir=/var/folders/jb/b9y_67gx3v727w68k7mgrpdm0000gn/T
./myprog -i $id2-two.input -o id2-two.output par1: id2-two par2: id2-two
[Sat Dec 11 18:59:02 2021]
rule myrule:
input: id1-one.input
output: id1-one.output
jobid: 1
wildcards: sample=id1-one
resources: tmpdir=/var/folders/jb/b9y_67gx3v727w68k7mgrpdm0000gn/T
./myprog -i $id1-one.input -o id1-one.output par1: id1-one par2: id1-one
[Sat Dec 11 18:59:02 2021]
localrule all:
input: id1-one.output, id2-two.output
jobid: 0
resources: tmpdir=/var/folders/jb/b9y_67gx3v727w68k7mgrpdm0000gn/T
Job stats:
job       count    min threads    max threads
------  -------  -------------  -------------
all           1              1              1
myrule        2              1              1
total         3              1              1
This was a dry-run (flag -n). The order of jobs does not reflect the order of execution.

您应该在params中使用一个输入函数来获得您想要的:

rule myrule:
params:
params3 = lambda wildcards: wildcards.sample.split("-")
...
shell:
"par1: {params.par1} par2: {params.par2} par3: {params.par3} par3[0]: {params.par3[0]}"

扩展到,对于id1-one:

par1: id1-one par2: id1-one par3: id1 one par3[0]: id1

最新更新