Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

snakemake threads wildcards not found

I have a snakemake rule like:

rule get_coverage:
    input: 
        cram=lambda wildcards: expand(config['input']['cram'][wildcards.reference_genome], #access_id = access_id[wildcards.sample_name], 
                                        sample_name='{sample_name}'), 
        bai=lambda wildcards: expand(config['input']['cram'][wildcards.reference_genome] + '.crai', #access_id = access_id[wildcards.sample_name], 
                                        sample_name='{sample_name}'),
        ref=lambda wildcards: config['reference_genome'][wildcards.reference_genome],
        chrom_size=lambda wildcards: config['chrom_size'][wildcards.reference_genome]
    output: 
        coverage=directory(config['output']['median_coverage'])
    conda: 
        src + '/env/acc_mask.yml'
    threads: 19
    script: 
        """
        mosdepth \
            -n \
            -t {threads} \
            --use-median \
            -f {input.ref} \
            -b {input.chrom_size} \
            {output.median_coverage} \
            {input.cram}
        """

I got a error:

RuleException:
NameError in line xxx of xxx.smk:
The name 'threads' 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 ...

In my impression, threads, as a wildcards, can be replaced in the shell. Is there anything wrong with my script?

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You are correct that {threads} can be used in a shell directive. It cannot be used in a script directive however. Your rule contains the latter, so fixing that should make it work:

rule get_coverage:
    input: 
        cram=lambda wildcards: expand(config['input']['cram'][wildcards.reference_genome], #access_id = access_id[wildcards.sample_name], 
                                        sample_name='{sample_name}'), 
        bai=lambda wildcards: expand(config['input']['cram'][wildcards.reference_genome] + '.crai', #access_id = access_id[wildcards.sample_name], 
                                        sample_name='{sample_name}'),
        ref=lambda wildcards: config['reference_genome'][wildcards.reference_genome],
        chrom_size=lambda wildcards: config['chrom_size'][wildcards.reference_genome]
    output: 
        coverage=directory(config['output']['median_coverage'])
    conda: 
        src + '/env/acc_mask.yml'
    threads: 19
    shell: 
        """
        mosdepth \
            -n \
            -t {threads} \
            --use-median \
            -f {input.ref} \
            -b {input.chrom_size} \
            {output.median_coverage} \
            {input.cram}
        """
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading