user8707594
user8707594

Reputation:

'Wildcards' object has no attribute 'output'

I get an error for a rather simple rule. I have to write a task file for another program, expecting a tsv file. I read a certain number of parameters from my config file and write them to a file with a shell command.

Code:

rule create_tasks:
    output:
        temp("tasks_{sample}.tsv")
    params:
        ID="{sample}",
        file=lambda wc: samples["path"][wc.sample] ,
        bigwig=lambda wc: samples["bigwig"][wc.sample] ,
        ambig=lambda wc: samples["ambig"][wc.sample] 
    shell:
        
        'echo -e "{params.ID}\t{params.file}" > {output}' 

When I execute the workflow, I get the following error:

Building DAG of jobs...
Using shell: /usr/bin/bash
Provided cluster nodes: 1
Job counts:
        count   jobs
        1       create_tasks
        1

[Mon Oct 12 14:48:15 2020]
rule create_tasks:
    output: tasks_sampleA.tsv
    jobid: 0
    wildcards: sample=sampleA

echo -e "sampleA    /Path/To/sampleA.bed               " > tasks_sampleA.tsv
WorkflowError in line 23 of /path/to/workflow.snakefile:
'Wildcards' object has no attribute 'output'
  File "/path/to/miniconda/envs/snakemake_submit/lib/python3.8/site-packages/snakemake/executors/__init__.py", line 111, in run_jobs
  File "/path/to/miniconda/envs/snakemake_submit/lib/python3.8/site-packages/snakemake/executors/__init__.py", line 1233, in run 

I should mention, that two of the variables are empty and that I expect the tabs/whitespaces in the echo command.

Does anybody have an explanation, why snakemake is trying to find output in the wildcards? I am expecially confused, because it is printing the correct command.

Upvotes: 2

Views: 745

Answers (1)

James Hawley
James Hawley

Reputation: 153

I've run into this same problem. The issue is probably in how you invoked Snakemake from the command line. For example, this was my Snakefile rule:

rule sort:
    input:
        "{file}.bam",
    output:
        "{file}.sorted.bam",
        "{file}.sorted.bai",
    shell:
        "sambamba sort {input}"

I don't even have params or wildcards explicitly anywhere in there. But when I run it on my Slurm HPC I get the same error:

snakemake -j 10 -c "sbatch {cluster.params}" -u cluster.yaml

The Wildcards (note the capital "W") and params objects weren't from the rule. They came from the cluster execution of the rule, and the error was thrown when trying to parse the cluster.yaml file.

There was no cluster parameter specification in my cluster.yaml file for the sort rule, so the error was thrown. I fixed this by adding

sort:
    params: "..."

to my cluster.yaml file. In your case, add cluster submission options under a create_tasks: ... list. You can also add a __default__: ... list as the default submission parameters for any job, by default, unless it matches another rule.

Upvotes: 2

Related Questions