title: combine to outputs of diffrent rules in Snakemake
body: <p>I would like to use snakemake to first merge some files and than later process other files based on that merge. (Less abstract: I want to combine control IGG bam files of two different sets and than use those to perform peakcalling on other files.</p>
  <p>In a minimal example, the folder structure would look like this.</p>
  <pre><code>├── data
  │   ├── toBeMerged
  │   │   ├── singleA
  │   │   ├── singleB
  │   │   ├── singleC
  │   │   └── singleD
  │   └── toBeProcessed
  │       ├── NotProcess1
  │       ├── NotProcess2
  │       ├── NotProcess3
  │       ├── NotProcess4
  │       └── NotProcess5
  ├── merge.cfg
  ├── output
  │   ├── mergeAB_merge
  │   ├── mergeCD_merge
  │   ├── NotProcess1_processed
  │   ├── NotProcess2_processed
  │   ├── NotProcess3_processed
  │   ├── NotProcess4_processed
  │   └── NotProcess5_processed
  ├── process.cfg
  └── Snakefile
  </code></pre>
  <p>Which files are combined and which are processed are defined in two config files.
  merge.cfg</p>
  <pre><code>singlePath  controlName
  data/toBeMerged/singleA output/controlAB
  data/toBeMerged/singleB output/controlAB
  data/toBeMerged/singleC output/controlCD
  data/toBeMerged/singleD output/controlCD
  </code></pre>
  <p>and process.cfg</p>
  <pre><code>controlName inName
  output/controlAB    data/toBeProcessed/NotProcess1
  output/controlAB    data/toBeProcessed/NotProcess2
  output/controlCD    data/toBeProcessed/NotProcess3
  output/controlCD    data/toBeProcessed/NotProcess4
  output/controlAB    data/toBeProcessed/NotProcess5
  </code></pre>
  <p>I am currently stuck with a snakefile like this, which itself does not work and gives me the error that both rules are ambiguous. And even if I would get it to work, I suspect, that this not the &quot;correct&quot; way, since the  process rule, should have {mergeName} as input to build its dag. But this does not work, since then I would need two wildcarts in one rule.</p>
  <pre><code>import pandas as pd
  cfgMerge = pd.read_table(&quot;merge.cfg&quot;).set_index(&quot;controlName&quot;, drop=False)
  cfgProc= pd.read_table(&quot;process.cfg&quot;).set_index(&quot;inName&quot;, drop=False)
  
  
  rule all:
      input:
          expand('{mergeName}', mergeName= cfgMerge.controlName),
          expand('{rawName}_processed', rawName= cfgProc.inName)
  
  rule merge:
      input:
          lambda wc: cfgMerge[cfgMerge.controlName == wc.mergeName].singlePath
      output:
          &quot;{mergeName}&quot;
      shell:
          &quot;cat {input} &gt; {output}&quot;
  
  rule process:
      input:
          inMerge=lambda wc: cfgProc[cfgProc.inName == wc.rawName].controlName.iloc[0],
          Name=lambda wc: cfgProc[cfgProc.inName == wc.rawName].inName.iloc[0]
      output:
          '{rawName}_processed'
      shell:
      &quot;cat {input.inMerge} {input.Name} &gt; {output}&quot;
  </code></pre>
  <p>I guess the key problem is how to use the output of a rule as the input for another one, when it does not depend on the same wildcard, or includes other another wildcard.</p>