text: user3839: How could I filter outputs of a process in the input of the next process? Filtering works fine in channel, but if I try to filter outputs I got compilation error. I tried as follows:
  Channel
  .fromFilePairs("${params.dir}*.{bed,bim,fam}",size:3)
  .set {data}
      process step1a {
      input:
      tuple val(sample_name), path(bfiles) from data
      output:
      tuple val("${prefix}"), path("${prefix}.{bed,bim,fam}") into (step1a_out,step1a_bim)
      script:
      """
      plink --bfile "${sample_name}" --chr 1-22 --out "${prefix}.step1b" --make-bed
      """
      }
      process step1b {
      input:
      tuple val(bim), path(bims) from step1a_bim.filter{bim, files -> name =~/*bim/}
      tuple val(sample_name), path(bfiles) from step1a_out
      output:
      path("${prefix}.step1b.snplist.txt")
      tuple val("${sample_name}"), path("${sample_name}.step1c.{bed,bim,fam}") into step1b_results
      script:
      """
      awk '{ if ((\\\$5=="T" && \\\$6=="A")||(\\\$5=="A" && \\\$6=="T")||(\\\$5=="C" && \\\$6=="G")||(\\\$5=="G" && \\\$6=="C")) print \\\$2, "ambig" ; else print \\\$2 ;}' "${prefix}.step1b.bim" | grep ambig > "${prefix}.step1b.snplist.txt"
      plink --bfile "${prefix}.step1b" --exclude "${prefix}.step1b.snplist.txt" --make-bed --out "${prefix}.step1c"
  """
  
  It gives me
  Compilation error
  -cause: Unexpected input: '{'
  process step1b {
  
  Step1a gives me chr1.step1b.bed|bim|fam, chr2.step1b.bed|bim|fam.......chr22.step1b.bed|bim|fam (22 plink files)
  I need to access prefix of those outputs to run plink and other tools to generate chr1.step1c.bed|bim|fam ...chr22.step1c.bed|bim|fam (another 22 plink files). run awk to generate chr1.step1b.snplist.txt .... chr22.step1b.snplist.txt (22 txt files).
  Any help to filter the inputs so that I could use only *bim files from step1a_bim? Also how to select prefix of files in the input of processes that are from step1a_out to run plink? Does it make sense now?
  Best Reagrds
  Zillur
  
  user3818: Instead of outputting all files and filtering for only bim, output only bims:
  output:
  tuple val("${prefix}"), path("${prefix}.{bed,bim,fam}") into (step1a_out,step1a_bim)
  
  Do
  output:
  tuple val("${prefix}"), path("${prefix}.{bed,bim,fam}") into step1a_out
  tuple val("${prefix}"), path("${prefix}.bim") into step1a_bim
  
  So you can skip your complicated filter:
  process step1b {
      input:
      tuple val(bim), path(bimfile) from step1a_bim
      output:
      path("${prefix}.step1b.snplist.txt")
  tuple val("${sample_name}"), path("${sample_name}.step1c.{bed,bim,fam}") into 
  step1b_results
      script:
      """
      awk '{ if ((\\\\\$5=="T" && \\\\\$6=="A")||(\\\\\$5=="A" && \\\\\$6=="T")||(\\\\\$5=="C" && \\\\\$6=="G")||(\\\\\$5=="G" && \\\\\$6=="C")) print \\\\\$2, "ambig" ; else print \\\\\$2 ;}' "$bimfile" | grep ambig > "${prefix}.step1b.snplist.txt"
      plink --bfile "${prefix}.step1b" --exclude "${prefix}.step1b.snplist.txt" --make-bed --out "${prefix}.step1c"
  
  """
  
  ```
  
  
original_text: 3839: <p>How could I filter outputs of a process in the input of the next process? Filtering works fine in channel, but if I try to filter outputs I got compilation error. I tried as follows:</p>
  <pre><code>Channel
  .fromFilePairs(&quot;<span class="math-container">${params.dir}*.{bed,bim,fam}",size:3)
  .set {data}
      process step1a {
      input:
      tuple val(sample_name), path(bfiles) from data
      output:
      tuple val("${prefix}"), path("${prefix}.{bed,bim,fam}") into (step1a_out,step1a_bim)
      script:
      """
      plink --bfile "${sample_name}" --chr 1-22 --out "${prefix}.step1b" --make-bed
      """
      }
      process step1b {
      input:
      tuple val(bim), path(bims) from step1a_bim.filter{bim, files -&gt; name =~/*bim/}
      tuple val(sample_name), path(bfiles) from step1a_out
      output:
      path("${prefix}.step1b.snplist.txt")
      tuple val("${sample_name}"), path("${sample_name}.step1c.{bed,bim,fam}") into step1b_results
      script:
      """
      awk '{ if ((\\\$5=="T" &amp;&amp; \\\$6=="A")||(\\\$5=="A" &amp;&amp; \\\$6=="T")||(\\\$5=="C" &amp;&amp; \\\$6=="G")||(\\\$5=="G" &amp;&amp; \\\$6=="C")) print \\\$2, "ambig" ; else print \\\$2 ;}' "${prefix}.step1b.bim" | grep ambig &gt; "${prefix}.step1b.snplist.txt"
      plink --bfile "${prefix}.step1b" --exclude "${prefix}.step1b.snplist.txt" --make-bed --out "$</span>{prefix}.step1c&quot;
  &quot;&quot;&quot;
  </code></pre>
  <p>It gives me</p>
  <pre><code>Compilation error
  -cause: Unexpected input: '{'
  process step1b {
  </code></pre>
  <p>Step1a gives me chr1.step1b.bed|bim|fam, chr2.step1b.bed|bim|fam.......chr22.step1b.bed|bim|fam (22 plink files)
  I need to access prefix of those outputs to run plink and other tools to generate chr1.step1c.bed|bim|fam ...chr22.step1c.bed|bim|fam (another 22 plink files). run awk to generate chr1.step1b.snplist.txt .... chr22.step1b.snplist.txt (22 txt files).
  Any help to filter the inputs so that I could use only *bim files from step1a_bim? Also how to select prefix of files in the input of processes that are from step1a_out to run plink? Does it make sense now?</p>
  <p>Best Reagrds
  Zillur</p>
   3818: <p>Instead of outputting all files and filtering for only bim, output only bims:</p>
  <pre><code>output:
  tuple val(&quot;${prefix}&quot;), path(&quot;${prefix}.{bed,bim,fam}&quot;) into (step1a_out,step1a_bim)
  </code></pre>
  <p>Do</p>
  <pre><code>output:
  tuple val(&quot;${prefix}&quot;), path(&quot;${prefix}.{bed,bim,fam}&quot;) into step1a_out
  tuple val(&quot;${prefix}&quot;), path(&quot;${prefix}.bim&quot;) into step1a_bim
  </code></pre>
  <p>So you can skip your complicated filter:</p>
  <pre><code>process step1b {
      input:
      tuple val(bim), path(bimfile) from step1a_bim
      output:
      path(&quot;<span class="math-container">${prefix}.step1b.snplist.txt")
  tuple val("$</span>{sample_name}&quot;), path(&quot;<span class="math-container">${sample_name}.step1c.{bed,bim,fam}") into 
  step1b_results
      script:
      """
      awk '{ if ((\\\\\$5=="T" &amp;&amp; \\\\\$6=="A")||(\\\\\$5=="A" &amp;&amp; \\\\\$6=="T")||(\\\\\$5=="C" &amp;&amp; \\\\\$6=="G")||(\\\\\$5=="G" &amp;&amp; \\\\\$6=="C")) print \\\\\$2, "ambig" ; else print \\\\\$2 ;}' "$</span>bimfile&quot; | grep ambig &gt; &quot;<span class="math-container">${prefix}.step1b.snplist.txt"
      plink --bfile "$</span>{prefix}.step1b&quot; --exclude &quot;<span class="math-container">${prefix}.step1b.snplist.txt" --make-bed --out "$</span>{prefix}.step1c&quot;
  
  &quot;&quot;&quot;
  
  <span class="math-container">```</span>
  </code></pre>
  