【问题标题】:params passed to input paths' wildcard传递给输入路径\'通配符的参数
【发布时间】:2022-10-15 13:19:50
【问题描述】:

我正在 Snakemake 7.2.1 中开发管道。 我有一个保存在config.yaml 中的参数列表,我想将它们传递给脚本。同一个配置文件还包含一个我需要用来运行规则的列表。 config.yaml 的示例:

entry0:
  - 1
  - 2
  - 3
entry1:
  - 1
  - 2
  - 3
entry2:
  - 1
  - 2
  - 3

做到了这一点:

configfile: "config.yaml"
output_folder="/output/path"
variable = config.get("entry0")

rule all:
  input:
    expand(f"{output_folder}/newfile_{{variable}}_{{p1}}_{{p2}}.txt",
           variable = variable, p1 = config.get("entry1"), p2 = config.get("entry2"))

rule run_with_parameters:
  input:
    f"{output_folder}/file_{{variable}}.txt"
  output:
    f"{output_folder}/newfile_{{variable}}.{{params.param1}}_{{params.param2}}.txt"
  params:
    param1 = config.get("entry1"),
    param2 = config.get("entry2")
  shell:
    "awk -v p1={params.param1} -v p2={params.param1} {input} > {output}"

但这不起作用,因为参数也在输入中传递给variable

MissingInputException in line XX of Snakefile:
Missing input files for rule snp_stats_sibs_all_snps:
    output: /output/path/newfile_1_1_1.txt
    wildcards: variable=1.1_1
    affected files:
        /output/path/file_1.1_1.txt

我还尝试了Paramspace,结果相似(input: 中的所有内容也都得到了扩展)。

我希望 params 仅在我调用它们的输出中被解析,因为 3 个输入文件是相同的。

我怎样才能做到这一点?

【问题讨论】:

    标签: parameters snakemake


    【解决方案1】:

    Snakemake 会自动从文件名中推导出通配符。例如,您的规则都请求文件/output/path/newfile_1_2_3.txt

    如果您有一条规则 abc 可以将文件名与通配符匹配,例如

    rule abc
      output:
        "output/path/newfile_{v1}_{v2}_{v3}.txt"
    

    ,则该规则将用于生成请求的文件。

    在您的示例中,这意味着您不需要在规则run_with_parameters 中从配置文件中查找参数,因为您可以从文件名中推断出参数。

    如果我正确理解您的问题,那么您的示例将如下所示:

    configfile: "config.yaml"
    output_folder="/output/path"
    
    rule all:
      input:
        expand(f"{output_folder}/newfile_{{variable}}_{{p1}}_{{p2}}.txt",
               variable = config["entry0"], p1 = config["entry1"], p2 = config["entry2"])
    
    rule run_with_parameters:
      input:
        f"{output_folder}/file_{{v1}}.txt"
      output:
        f"{output_folder}/newfile_{{v1}}_{{p1}}_{{p2}}.txt"
      shell:
        "awk -v p1={p1} -v p2={p2} {input} > {output}"
    

    我还用config[] 替换了config.get(),但两者都可以。

    【讨论】:

    • 但是,如何将参数传递给规则?
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2022-11-20
    • 1970-01-01
    • 2023-04-09
    • 2011-10-12
    • 2021-12-02
    • 2018-12-26
    • 1970-01-01
    相关资源
    最近更新 更多