Search code examples
bashsnakemake

Cannot execute bash script in Snakemake


This is my first question on Snakemake as the existing resources and forums helped me immensely to solve most of my problems.

The problem I currently had is that I cannot make the bash script execute in Snakemake, though I was able to execute the same bash script just fine on the command line

Here is how I run the bash script on the command line successfully

bash scripts/genome_coverage.sh -m results/mapped_reads -o final_out.txt

But when I run it in Snakemake, I get the error.

Here is the rule in the Snakefile that corresponds to the executing bash script

rule genome_coverage:
    input:
        "results/mapped_reads"
    output:
        "genome_coverage.txt"
    script:
        "scripts/genome_coverage.sh -m {input} -o {output}"

And this is the error I am getting. I don't know what I am doing wrong here

Error in rule genome_coverage:
    jobid: 16
    output: genome_coverage.txt
RuleException:
NameError in line 153 of /Illumina-mRNA/Snakefile:
The name 'input' is unknown in this context. Please make sure that you defined that variable. Also note that braces not used for variable access have to be escaped by repeating them, i.e. {{print $1}}

Solution

  • You need to replace script with shell:

    rule genome_coverage:
        input:
            "results/mapped_reads"
        output:
            "genome_coverage.txt"
        shell:
            "scripts/genome_coverage.sh -m {input} -o {output}"