snakemake 参数探索:如何将选项传递给 shell 指令中的命令?

snakemake parameter exploration: how to pass options to a command in shell directive?

我正在使用 Paramspace 实用程序执行参数探索,如 here 所述。我已经读取了 pandas 数据帧中的参数,接下来我希望将这些参数作为 shell 命令的选项值传递,但不知道如何传递。

在下面的最小示例中,我希望传递参数 s(在数据帧 df 中读取)作为 shell 指令中 head 命令的选项 -n 的值。

from snakemake.utils import Paramspace
import pandas as pd

df = pd.DataFrame(
    {'s' : [1, 2, 3]},
    index = [1, 2, 3]
    )

paramspace_empty = Paramspace(df)

rule all:
    input:
        expand("results/{params}.tsv", params=paramspace_empty.instance_patterns)

rule simulate_empty:
    output:
        f"results/{paramspace_empty.wildcard_pattern}.tsv"
    params:
        simulation=paramspace_empty.instance
    shell: """
        head input.txt > {output}    
    """

我尝试了以下和类似的变体,但没有任何效果。

shell: """
    head -n {params.simulation['s']} input.txt > {output}
"""

以上示例是从测试参数空间实用程序的 Snakefile here 中提取(并稍作修改)的。

我似乎遗漏了一些基本的或微不足道的东西。提前感谢您的帮助。

大功告成,不需要引用字典键。这是一个稍微修改过的工作版本:

import pandas as pd
from snakemake.utils import Paramspace

df = pd.DataFrame({"s": [1, 2, 3]}, index=[1, 2, 3])

paramspace_empty = Paramspace(df, filename_params="*")


rule all:
    input:
        expand("{params}.tsv", params=paramspace_empty.instance_patterns),


rule simulate_empty:
    output:
        f"{paramspace_empty.wildcard_pattern}.tsv",
    params:
        simulation=paramspace_empty.instance,
    shell:
        """
        seq 10 | head -n {params.simulation[s]} > {output}
        """