title: snakemake derive multiple variables from input file names
body: <p>I have a problem with deriving variables from input file names - especially if you want to split based on a delimiter. I have tried different approaches (which I can't get to work) and the only one that works so far, fails in the end, because its looking for all possible variations of variables (and hence input files that don't exist).</p>
  <p>My problem - the input files are named in the following pattern:
  <code>18AR1376_S57_R2_001.fastq.gz</code></p>
  <p>My initial definition of variables at the beginning:<br />
  <code>SAMPLES, = glob_wildcards(&quot;../run_links/{sample}_R1_001.fastq.gz&quot;)</code></p>
  <p>but that ends up with my files all being named <code>18AR1376_S57</code> subsequently and I'd like to remove _S57 (which refers to the sample sheet id).</p>
  <p>An approach that I have found while searching and which works is this:<br />
  <code>SAMPLES,SHEETID, = glob_wildcards(&quot;../run_links/{sample}_{SHEETID}_R1.001.fastq.gz&quot;}</code><br />
  but it looks for all possible combinations of sample and sheetid, and hence looks for input files that don't exist.</p>
  <p>I then tried a more basic python approach:</p>
  <pre><code>SAMPLES, = glob_wildcards(&quot;../run_links/{sample}_R1_001.fastq.gz&quot;)
  ID,=expand([{sample}.split(&quot;_&quot;)[0]], sample=SAMPLES)``
  </code></pre>
  <p>but that doesn't work at all</p>
  <p>and then I tried keeping my original wildcard glob
  <code>SAMPLES, = glob_wildcards(&quot;../run_links/{sample}_R1_001.fastq.gz&quot;)</code>
  but define new outputfile names (based on instructions I found in another forum) - but that gives me a syntax error that I can't figure out.</p>
  <pre><code>rule trim:
      input:
          R1 = &quot;../run_links/{sample}_R1_001.fastq.gz&quot;, 
          R2 = &quot;../run_links/{sample}_R2_001.fastq.gz&quot;
      params:
          prefix=lambda wildcards, output: 
      output:
          R1_Pair = [&quot;./output/trimmed/{}_R1_trim_PE.fastq&quot;.format({sample}.split(&quot;_&quot;)[0])],  #or the below version
          R1_Sing = [&quot;./output/trimmed/{}_R1_trim_SE.fastq&quot;.format(a) for a in {sample}.split(&quot;_&quot;)],
          R2_Pair = [&quot;./output/trimmed/{}_R2_trim_PE.fastq&quot;.format(a) for a in {sample}.split(&quot;_&quot;)],
          R2_Sing = [&quot;./output/trimmed/{}_R2_trim_SE.fastq&quot;.format(a) for a in {sample}.split(&quot;_&quot;)]
      resources:
          cpus=8
      log:
          &quot;../logs/trim_{sample}.log&quot;
      conda:
          &quot;envs/trim.yaml&quot;
      shell:
          &quot;&quot;&quot;
          trimmomatic PE -trimlog {log} -threads {resources.cpus} {input.R1} {input.R2} {output.R1_Pair} {output.R1_Sing} {output.R2_Pair} {output.R2_Sing} HEADCROP:10 ILLUMINACLIP:scripts/Truseq-Adapter.fa:2:30:10 LEADING:20 TRAILING:20 SLIDINGWINDOW:4:20 MINLEN:50
          &quot;&quot;&quot;
  </code></pre>
  <p>So, two options,</p>
  <ol>
  <li>beginning of workflow: split the sample into sample and sample sheet id</li>
  <li>define new output names and use split on delimiter <code>_</code> of {sample}</li>
  </ol>
  <p>Does anybody have tips on how to approach this?
  Thanks</p>
  <p>Thanks!</p>