madreblu
madreblu

Reputation: 383

Iterate over 2 parameters in a Snakemake rule

I have 2 parameters for which I am trying to iterate over in a Snakemake. This is normally feasible using expand however, I want to use a parameter from the expand into the command line:

STEPSMSA=["0","10","20","30","40"]
LENGTHS=["30","35","40","45","50"]

rule sim:                                                                                                                                                                                               
input: expand("simulations/gen_{step}.fa",step=STEPSMSA)                                                                                                                                                
output: expand("simulations/gen_{step}_n1000000_l{len}.fa",step=STEPSMSA,len=LENGTHS)                                                                                                                   
shell: expand("simulate  -n 10000000 -l {len} {input} |gzip > {output}",len=LENGTHS)                                                                           

Note that "simulate" is an internal UNIX program that is accessible. What I would like is to run:

simulate  -n 10000000 -l 30 simulations/gen_0.fa |gzip > simulations/gen_0_n1000000_l30.fa
simulate  -n 10000000 -l 35 simulations/gen_0.fa |gzip > simulations/gen_0_n1000000_l35.fa
simulate  -n 10000000 -l 40 simulations/gen_0.fa |gzip > simulations/gen_0_n1000000_l40.fa
...
simulate  -n 10000000 -l 50 simulations/gen_40.fa |gzip > simulations/gen_40_n1000000_l50.fa

Is there any way to specify this using Snakemake?

Upvotes: 0

Views: 274

Answers (1)

dariober
dariober

Reputation: 9062

So you want simulations/gen_{step}_n1000000_l{len}.fa for all combinations of step and len, right? If so, you could do:

STEPSMSA=["0","10","20","30","40"]
LENGTHS=["30","35","40","45","50"]

rule all:
    input:
        expand("simulations/gen_{step}_n1000000_l{len}.fa", step=STEPSMSA, len=LENGTHS)

rule sim:                                                                                                                                                                                               
    input: 
        "simulations/gen_{step}.fa"                                                                                                                                             
    output: 
        "simulations/gen_{step}_n1000000_l{len}.fa"
    shell: 
        "simulate  -n 10000000 -l {wildcards.len} {input} | gzip > {output}"

Upvotes: 1

Related Questions