ate50eggs
ate50eggs

Reputation: 454

Dynamic output in snakemake

I'm using snakemake to develop a pipeline. I'm trying to create symbolic links for every file in a directory to a new target. I don't know ahead of time how many files there will be, so I'm trying to use dynamic output.

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))

This is the error I get:

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

What is the issue?

Upvotes: 3

Views: 4238

Answers (1)

Pereira Hugo
Pereira Hugo

Reputation: 337

In order to use the dynamic function, you need to have another rule in which the dynamic files are the input. Like this:

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))

This way, Snakemake will know what it needs to attribute for the wildcard.

Hint: when you use a wildcard, you always have to define it. In this example, calling dynamic in the input of the target rule will define the wildcard '{n}'.

Upvotes: 6

Related Questions