<p>If, in your input definition, you specify a string to represent your filename and provide <a href="https://www.nextflow.io/docs/latest/process.html#multiple-input-files" rel="nofollow noreferrer">multiple file inputs</a> as a collection, a numerical suffix is appended to each filename:</p>
<blockquote>
<p>When a target file name is defined in the input parameter and a
collection of files is received by the process, the file name will be
appended by a numerical suffix representing its ordinal position in
the list.</p>
</blockquote>
<p>When you use the <a href="https://www.nextflow.io/docs/latest/operator.html#flatten" rel="nofollow noreferrer">flatten</a> operator, the collection is flattened such that each entry becomes a separate entry in the output channel. So for each of the five 'tree' files, five tasks are spawned: one for each 'tree' file. These files are each localized using the filename specified: 'RAxML_bipartitionsBranchLabels.tree`. This usually isn't what you want to do.</p>
<p>What you're looking for, I think, is some way to select the file called 'RAxML_bipartitionsBranchLabels.tree' from the initial collection of files. There are many ways to do this. For example if you wanted to flatten the output channel, it's possible to select the file you want using the <a href="https://www.nextflow.io/docs/latest/operator.html#first" rel="nofollow noreferrer">first</a> operator and a closure:</p>
<pre><code>bipartitionsBranchLabels = raxml_out_ch.flatten().first {
    it.name == 'RAxML_bipartitionsBranchLabels.tree'
}
</code></pre>
<p>However you should only seldom need to do this. If your pipeline requires just one of these files in a downstream process, my suggestion would be to alter the upstream output declaration to include a separate output channel for this purpose:</p>
<pre><code>process RAxML {

    output:
    path 'RAxML_*.tree' into raxml_out_ch
    path 'RAxML_bipartitionsBranchLabels.tree' into raxml_bipartitionsBranchLabels

    &quot;&quot;&quot;
    touch RAxML_bestTree.tree
    touch RAxML_bipartitions.tree
    touch RAxML_bipartitionsBranchLabels.tree
    touch RAxML_bootstrap.tree
    touch RAxML_info.tree
    &quot;&quot;&quot;
}
</code></pre>

CC BY-SA 4.0
2022-05-26T22:41:47.113Z
Thank you Steve. The last option you propose wouldn't really work with that program and I tried the others without success. What I did was to use `.collect()` in the input of the following process, this way it turns the outputs (of one channel) into an array (or tuple) and then I used `def = ...` within the script seccion to assign each file in the array to a letter.
jose lopez
CC BY-SA 4.0
2022-05-26T23:52:48.927Z
No worries @joselopez. The last option should be tool agnostic unless I'm mistaken. It's difficult to say what the right solution is here without the details. Calling collect() seems redundant, since 'channel_name' (i.e. 'raxml_out_ch') already provides an array (java.util.ArrayList). I think you could also do a `def branch_labels = yourfilelist.find { it.baseName == 'RAxML_bipartitionsBranchLabels' }` in your script block to get the file you want. Note that this solution will localize all the files in the array, which may not be what you want. Your question mentioned you only needed the one.
Steve
CC BY-SA 4.0
2022-04-20T02:46:47.447Z
2022-04-20T02:46:47.447Z
Steve
<p>In Nextflow I have a process that creates a channel that holds several files in a tuple. I'm trying to call only one of those files as input for a subsequent process.</p>
<p>So basically if I run <code>channel_name.view()</code> the channel shows <code>[/home/nextflow/work/e4/bc47bceb4569cffc01bd76e49245e9/RAxML_bestTree.tree, /home/nextflow/work/e4/bc47bceb4569cffc01bd76e49245e9/RAxML_bipartitions.tree, /home/nextflow/work/e4/bc47bceb4569cffc01bd76e49245e9/RAxML_bipartitionsBranchLabels.tree, /home/nextflow/work/e4/bc47bceb4569cffc01bd76e49245e9/RAxML_bootstrap.tree, /home/nextflow/work/e4/bc47bceb4569cffc01bd76e49245e9/RAxML_info.tree] </code>. I need just one file so I'm using the full name in the <code>input</code> section of the process.</p>
<pre><code>input:
file 'RAxML_bipartitionsBranchLabels.tree' from channel_name
</code></pre>
<p>That does not find the file. On the other hand, if I use <code>.flatten()</code>, like this:</p>
<pre><code>input:
file 'RAxML_bipartitionsBranchLabels.tree' from raxml_out_ch.flatten()
</code></pre>
<p>It works but reads some files before reaching to the one that matches and so the process results in error even after completing the task for this file properly and gives several outputs (for each file it looks into), some of them empty and one with the result.</p>
<pre><code>[7c/2971f1] Submitted process &gt; tree_visualisation (4)
[8d/dd129b] Submitted process &gt; tree_visualisation (1)
[cb/0f91f5] Submitted process &gt; tree_visualisation (5)
[6c/fb23c8] Submitted process &gt; tree_visualisation (3)
ERROR ~ Error executing process &gt; 'tree_visualisation (5)'

Caused by:
  Process `tree_visualisation (5)` terminated with an error exit status (1)

Command executed:

  Rscript tree.R RAxML_bipartitionsBranchLabels.tree phylogram.png
</code></pre>
<p>I'm looking for a way to filter this input so that the process only runs for this file and doesn't try with the others.</p>
<p>How can I do that?</p>

CC BY-SA 4.0
2022-04-19T00:23:46.187Z
Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.
Community
CC BY-SA 4.0
2022-04-19T06:59:49.273Z
Be more specific, is there a certain text pattern that this file matches? Is it always the first or the last file? Is it a file with an extension? Does the channel contain 1 tuple with multiple files or multiple file entries as separate emissions?
Pallie
<nextflow>
How can I call one file from a channel that's composed of several files in Nextflow?
# How can I call one file from a channel that's composed of several files in Nextflow?

(Asked by: username_0 on 2022-04-18)

In Nextflow I have a process that creates a channel that holds several files in a tuple. I'm trying to call only one of those files as input for a subsequent process.
So basically if I run channel_name.view() the channel shows [/home/nextflow/work/e4/bc47bceb4569cffc01bd76e49245e9/RAxML_bestTree.tree, /home/nextflow/work/e4/bc47bceb4569cffc01bd76e49245e9/RAxML_bipartitions.tree, /home/nextflow/work/e4/bc47bceb4569cffc01bd76e49245e9/RAxML_bipartitionsBranchLabels.tree, /home/nextflow/work/e4/bc47bceb4569cffc01bd76e49245e9/RAxML_bootstrap.tree, /home/nextflow/work/e4/bc47bceb4569cffc01bd76e49245e9/RAxML_info.tree] . I need just one file so I'm using the full name in the input section of the process.
input:
file 'RAxML_bipartitionsBranchLabels.tree' from channel_name

That does not find the file. On the other hand, if I use .flatten(), like this:
input:
file 'RAxML_bipartitionsBranchLabels.tree' from raxml_out_ch.flatten()

It works but reads some files before reaching to the one that matches and so the process results in error even after completing the task for this file properly and gives several outputs (for each file it looks into), some of them empty and one with the result.
[7c/2971f1] Submitted process > tree_visualisation (4)
[8d/dd129b] Submitted process > tree_visualisation (1)
[cb/0f91f5] Submitted process > tree_visualisation (5)
[6c/fb23c8] Submitted process > tree_visualisation (3)
ERROR ~ Error executing process > 'tree_visualisation (5)'

Caused by:
  Process `tree_visualisation (5)` terminated with an error exit status (1)

Command executed:

  Rscript tree.R RAxML_bipartitionsBranchLabels.tree phylogram.png

I'm looking for a way to filter this input so that the process only runs for this file and doesn't try with the others.
How can I do that?

**Tags:** nextflow
> **Comments:**
> **username_1**: Please clarify your specific problem or provide additional details to highlight exactly what you need. As it's currently written, it's hard to tell exactly what you're asking.  
> **username_2**: Be more specific, is there a certain text pattern that this file matches? Is it always the first or the last file? Is it a file with an extension? Does the channel contain 1 tuple with multiple files or multiple file entries as separate emissions?  

---

## 1 answers

### Answer by username_3 on 2022-04-20. Score: 2

If, in your input definition, you specify a string to represent your filename and provide multiple file inputs as a collection, a numerical suffix is appended to each filename:

When a target file name is defined in the input parameter and a
collection of files is received by the process, the file name will be
appended by a numerical suffix representing its ordinal position in
the list.

When you use the flatten operator, the collection is flattened such that each entry becomes a separate entry in the output channel. So for each of the five 'tree' files, five tasks are spawned: one for each 'tree' file. These files are each localized using the filename specified: 'RAxML_bipartitionsBranchLabels.tree`. This usually isn't what you want to do.
What you're looking for, I think, is some way to select the file called 'RAxML_bipartitionsBranchLabels.tree' from the initial collection of files. There are many ways to do this. For example if you wanted to flatten the output channel, it's possible to select the file you want using the first operator and a closure:
bipartitionsBranchLabels = raxml_out_ch.flatten().first {
    it.name == 'RAxML_bipartitionsBranchLabels.tree'
}

However you should only seldom need to do this. If your pipeline requires just one of these files in a downstream process, my suggestion would be to alter the upstream output declaration to include a separate output channel for this purpose:
process RAxML {

    output:
    path 'RAxML_*.tree' into raxml_out_ch
    path 'RAxML_bipartitionsBranchLabels.tree' into raxml_bipartitionsBranchLabels

    """
    touch RAxML_bestTree.tree
    touch RAxML_bipartitions.tree
    touch RAxML_bipartitionsBranchLabels.tree
    touch RAxML_bootstrap.tree
    touch RAxML_info.tree
    """
}

> **Comments:**
> **username_0**: Thank you Steve. The last option you propose wouldn't really work with that program and I tried the others without success. What I did was to use `.collect()` in the input of the following process, this way it turns the outputs (of one channel) into an array (or tuple) and then I used `def = ...` within the script seccion to assign each file in the array to a letter.  
> **username_3**: No worries @joselopez. The last option should be tool agnostic unless I'm mistaken. It's difficult to say what the right solution is here without the details. Calling collect() seems redundant, since 'channel_name' (i.e. 'raxml_out_ch') already provides an array (java.util.ArrayList). I think you could also do a `def branch_labels = yourfilelist.find { it.baseName == 'RAxML_bipartitionsBranchLabels' }` in your script block to get the file you want. Note that this solution will localize all the files in the array, which may not be what you want. Your question mentioned you only needed the one.  

---

