3

我正在使用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:“目标规则可能不包含通配符。请指定具体文件或不带通配符的规则。”

问题是什么?

4

1 回答 1

6

为了使用动态功能,您需要有另一个以动态文件为输入的规则。像这样:

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}”。

于 2017-06-30T09:50:56.947 回答