title: lambda function in snakemake output
body: <p>I currently have a snakemake workflow that requires the use of lambda wildcards, set up as follows:</p>
  
  <p>Snakefile:</p>
  
  <pre><code>configfile: "config.yaml"
  workdir: config["work"]
  
  rule all:
      input:
          expand("logs/bwa/{ref}.log", ref=config["refs"])
  
  rule bwa_index:
      input:
          lambda wildcards: 'data/'+config["refs"][wildcards.ref]+".fna.gz"
      output:
          "logs/bwa/{ref}.log"
      log:
          "logs/bwa/{ref}.log"
      shell:
          "bwa index {input} 2&amp;&gt;1 {log}"
  </code></pre>
  
  <p>Config file:</p>
  
  <pre><code>work: /datasets/work/AF_CROWN_RUST_WORK/2020-02-28_GWAS
  
  refs:
      12NC29: GCA_002873275.1_ASM287327v1_genomic
      12SD80: GCA_002873125.1_ASM287312v1_genomic
  </code></pre>
  
  <p>This works, but I've had to use a hack to get the output of <code>bwa_index</code> to play with the input of <code>all</code>. My hack is to generate a log file as part of <code>bwa_index</code>, set the log to the output of <code>bwa_index</code>, and then set the input of <code>all</code> to these log files. As I said, it works, but I don't like it.
  The problem is that the true outputs of <code>bwa_index</code> are of the format, for example, <code>GCA_002873275.1_ASM287327v1_genomic.fna.sa</code>. So, to specify these output files, I would need to use a lambda function for the output, something like:</p>
  
  <pre><code>rule bwa_index:
      input:
          lambda wildcards: 'data/'+config["refs"][wildcards.ref]+".fna.gz"
      output:
          lambda wildcards: 'data/'+config["refs"][wildcards.ref]+".fna.sa"
      log:
          "logs/bwa/{ref}.log"
      shell:
          "bwa index {input} 2&amp;&gt;1 {log}"
  </code></pre>
  
  <p>and then use a lambda function with expand for the input of <code>rule all</code>. However, snakemake will not accept functions as output, so I'm at a complete loss how to do this (other than my hack). Does anyone have suggestions of a sensible solution? TIA!</p>