0
votes

I have a problem with indexing my snakemake wildcards in a function. For some reason the order of how the the variables are stored in the "Wildcards" list varies. I use the function to generate the paths for the input files for one of my rules, and as the position of the correct values changes, the rule only succeeds once every couple queries. How can I control or fix the position of wildcard in the "Wildcards" list? I added the relevant content of my Snakefile.

Thank you, zuup

#!/usr/bin/env python3
import glob
import re

R_BIN = "Rscript"

pop = "lineA lineB".split()
group = "test control".split()
chrom = "X Y".split()

def getInput(Wildcards):
    pop = str(Wildcards[0])
    group = str(Wildcards[1])
    chrom = str(Wildcards[2])
    path = "Resources/bed/" + pop + "_" + group + r"_rep[1-5]/" + pop + "_" + group + r"_rep[1-5]_chr" + chrom + ".bed"
    return(glob.glob(path))

rule BED2BS:
    input:
        getInput
    output:
        wd + "Resources/bs/{pop}_{group}/{group}_chr{chrom}.RDS"
    shell:
        R_BIN + " Scripts/Script1.R {input} {output}"
1
Please give a minimal reproducible example. I really don't know what you are talking about. - John Coleman
I'm very sorry. I'm talking about problems with the workflow manager Snakemake and just realised that I really did not make that clear (except in the tags). I added this information and extended the code. - Zuup
You still haven't explained where this "Wildcards" list comes from, what it is, and what you expect it to be. All anyone can glean from your question is that there is some sort of a mismatch between what the list actually contains and what you expect it to contain. Just guessing -- you made it from a dictionary which you converted into a list and are being thrown by the fact that dictionaries don't have a well-defined order, so that the order you get when you convert the values or the keys into a list is essentially random. - John Coleman
The wildcards object is generated by Snakemake. The whole question is perfectly understandable for people familiar with Snakemake. Please note that the Snakemake language is a domain specific syntax extension of Python. Apart from that, your guess goes in the right direction. Internally, the wildcards object is derived from a dictionary. - Johannes Köster

1 Answers

6
votes

The wildcard order from the is not preserved by Snakemake (note that different output and input files can use the same wildcards in different orders. Hence there is no canonical order that could be derived from the occurrence of the wildcards in the file pattern). However, you can address the wildcard values by name, e.g.,:

wildcards.group

Please consider to go through the Snakemake tutorial.