title: Nextflow - How to avoid random sample IDs for input files in two or more channels with "Join" or similar operator?
body: <p>I have implemented some NGS data analysis workflows with Nextflow. I used &quot;Paired End&quot; channels (fromFilePairs method) for some of my workflow processes. I ran into a problem I wasn't expecting after multiple workflow executions : <strong>my samples ID would sometimes be mixed, resulting in inaccurate outputs for the processes where it happened</strong>. I think this is related to the <strong>Non-deterministic input channels issue</strong> (<a href="https://www.nextflow.io/blog/2019/troubleshooting-nextflow-resume.html" rel="nofollow noreferrer">https://www.nextflow.io/blog/2019/troubleshooting-nextflow-resume.html</a>).</p>
  <p>Let's suppose I apply my worklow on these paired-end files : sample1_R{1,2}.fastq, sample2_R{1,2}.fastq</p>
  <pre><code>process Step1 {
      input:
          tuple pair_ID, file(A) from channelA
          tuple pair_ID, file(B) from channelB
          tuple pair_ID, file(C) from channelC
  ...
  }
  </code></pre>
  <p>For this kind of process with more than one &quot;tuple pair_ID&quot; as input, the data pair_ID (= my samples names) can be mixed up and my process would end up using randomly <em>input files A and B</em> of the <strong>sample1</strong>, and the <em>input file C</em> of the <strong>sample2</strong> instead of <em>all files (A,B,C)</em> of the <strong>same pair_ID</strong> (key = only sample1 or only sample2).
  I had this randomly mixed input filenames issue (which impacted the outputs) after several workflow executions, after using -resume when an error occurred but also after full successful workflow runs.</p>
  <p>In order to have the same key (pair_ID) between the input files emitted by each of the 3 channels, I used the <code>join</code> operator:</p>
  <pre><code>Process Step1 {
      input:
          tuple pair_ID, file(A), file(B), file(C) from channelA.join(channelB).join(channelC)
  ...
  }
  </code></pre>
  <p>This operator seems to make everything work as expected, I don't see any mix in my sample IDs and in my final outputs. In the doc (<a href="https://www.nextflow.io/docs/latest/operator.html?highlight=join#join" rel="nofollow noreferrer">https://www.nextflow.io/docs/latest/operator.html?highlight=join#join</a>), <code>join</code> seems to be suited for a 2 channels use only, so I am unsure if I am using it right for 3 channels.</p>
  <p><strong>Is my method using <code>join</code> legit ?</strong> Or does it still have some flaws ?
  <strong>Is there a better way to correct my issue ?</strong>
  If I am unsure that this method is correct to avoid any mix in my samples ID, I might change to another workflow management system such as Snakemake but I would really like to solve this issue and to continue using Nextflow.</p>
  <p>Thank you in advance, don't hesitate if something isn't clear !</p>