snakemake 中的动态输出

Dynamic output in snakemake

我正在使用 snakemake 开发管道。我正在尝试为目录中的每个文件创建指向新目标的符号链接。我提前不知道会有多少文件,所以我尝试使用动态输出。

rule source:
    output: dynamic('{n}.txt')
    run:
        source_dir = config["windows"]
        source = os.listdir(source_dir)
        for w in source:
            shell("ln -s %s/%s source/%s" % (source_dir, w, w))

这是我得到的错误:

WorkflowError: "Target rules may not contain wildcards. Please specify concrete files or a rule without wildcards."

问题是什么?

为了使用动态功能,你需要有另一个规则,其中动态文件是输入。像这样:

rule target:
  input: dynamic('{n}.txt')
  
rule source:
  output: dynamic('{n}.txt')
  run:
    source_dir = config["windows"]
    source = os.listdir(source_dir)
    for w in source:
      shell("ln -s %s/%s source/%s" % (source_dir, w, w))

这样,Snakemake 就会知道通配符需要什么属性。

提示:当你使用通配符时,你总是需要定义它。在此示例中,在目标规则的输入中调用 dynamic 将定义通配符“{n}”。