Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Snakemake: 'Missing input files' due to wrong wildcard expansion

Tags:

snakemake

I am new to Snakemake and I want to write a very simple Snakefile with a rule that processes each input file separately to an output file, but somehow my wildcards aren't interpreted correctly.

I have set up a minimal, reproducible example environment in Ubuntu 18.04 with the input files "test/test1.txt", "test/test2.txt", and a Snakefile. (snakemake version 5.5.4)

Snakefile:

ins = glob_wildcards("test/{f}.txt")

rule all:
  input: expand("out/{f}.txt", f=ins)

rule test:
  input: "test/{f}.txt"
  output: "out/{f}.txt"
  shell: "touch {output}"

This Snakefile throws the following error while building the DAG of jobs:

Missing input files for rule test:
test/['test1', 'test2'].txt

Any ideas how to fix this error?

like image 993
Bluescreen Avatar asked Jul 30 '19 13:07

Bluescreen


People also ask

How do I use wildcards in snakemake?

The wildcards object can be accessed in the same way as input and output, which is described above. For example, if another rule in the workflow requires the file 101/file.A.txt, Snakemake recognizes that this rule is able to produce it by setting dataset=101 and group=A .

Can I use snakemake to create an input file?

In particular, input files should not be combined with very general rules that can be applied to create almost any file: Snakemake will try to apply the rule, and will report the exceptions of your input function as errors. For a practical example, see the Snakemake Tutorial ( Step 3: Input functions ).

Why can’t I manually import workflows into snakemake?

Sometimes, it is necessary to access further source files that are in a directory relative to the current Snakefile. Since workflows can be imported from remote locations (e.g. when using modules ), it is important to not do this manually, so that Snakemake has the chance to cache these files locally before they are accessed.

How do I Touch an empty file in snakemake?

This can be achieved by “touching” empty files that denote that a certain task was completed. Snakemake supports this via the touch flag: rule all: input: "mytask.done" rule mytask: output: touch("mytask.done") shell: "mycommand ..."


1 Answers

I think you need to use ins.f or something similar:

expand("out/{f}.txt", f= ins.f)

The reason is explained in the FAQ

[glob_wildcards returns] a named tuple that contains a list of values for each wildcard.

like image 164
dariober Avatar answered Oct 10 '22 01:10

dariober