<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>

CC BY-SA 4.0
2021-03-23T17:44:34.307Z
Thanks `@Pallie` . I tried your method. In that case, I got `Process 'step1b' input file name collision -- There are multiple input files for each of the following file names: chr5.step1b.bim`. Any suggestion?
zillur rahman
CC BY-SA 4.0
2021-03-23T18:20:09.533Z
The `step1a_bim` is a subset of `step1a_out` which produce bed|bim|fam files.
zillur rahman
CC BY-SA 4.0
2021-03-23T19:01:12.277Z
I could divide process `step1b` into two processes and could use `step1a_out`. But how could I use only *.bim files as input? Because `step1a_out` produce all *.bim, *.bed and *.fam files. For one process I need all three (bed|bim|fam) and for another I need only bim files. I am not sure how to subset the elements of a channel.
zillur rahman
CC BY-SA 4.0
2021-03-23T14:03:12.650Z
2021-03-23T14:03:12.650Z
Pallie
<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>

CC BY-SA 4.0
2021-03-23T12:04:28.430Z
In case of a compilation error it is more useful if you post your actual code, properly formatted, and your error message.
Pallie
CC BY-SA 4.0
2021-03-23T13:07:37.793Z
@Pallie, I edited my question above. Does it clarify my issues on outputs and inputs?
zillur rahman
<plink><nextflow>
nextflow: Filter outputs of a process
# nextflow: Filter outputs of a process

(Asked by: username_0 on 2021-03-22)

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

**Tags:** plink, nextflow
> **Comments:**
> **username_1**: In case of a compilation error it is more useful if you post your actual code, properly formatted, and your error message.  
> **username_0**: @Pallie, I edited my question above. Does it clarify my issues on outputs and inputs?  

---

## 1 answers

### Answer by username_1 on 2021-03-23. Score: 1

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"

"""

```

> **Comments:**
> **username_0**: Thanks `@Pallie` . I tried your method. In that case, I got `Process 'step1b' input file name collision -- There are multiple input files for each of the following file names: chr5.step1b.bim`. Any suggestion?  
> **username_0**: The `step1a_bim` is a subset of `step1a_out` which produce bed|bim|fam files.  
> **username_0**: I could divide process `step1b` into two processes and could use `step1a_out`. But how could I use only *.bim files as input? Because `step1a_out` produce all *.bim, *.bed and *.fam files. For one process I need all three (bed|bim|fam) and for another I need only bim files. I am not sure how to subset the elements of a channel.  

---

