Answers.Body: <p><strong>TLDR</strong>, use:</p>
  <pre><code>nextflow.enable.dsl=2
  
  workflow {
  
      Channel.fromFilePairs('/path/to/adsp/cram/snd10000/A-CUHS-CU000*.cram{,.crai}')
          | view()
  }
  </code></pre>
  <p>Results:</p>
  <pre><code>N E X T F L O W  ~  version 20.10.0
  Launching `xscript.nf` [special_caravaggio] - revision: a4e53657a0
  [A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1, [/path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram, /path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram.crai]]
  [A-CUHS-CU000194-BL-COL-38470BL1_vcpa1.1, [/path/to/adsp/cram/snd10000/A-CUHS-CU000194-BL-COL-38470BL1_vcpa1.1.cram, /path/to/adsp/cram/snd10000/A-CUHS-CU000194-BL-COL-38470BL1_vcpa1.1.cram.crai]]
  [A-CUHS-CU000018-BL-COL-46250BL1_vcpa1.1, [/path/to/adsp/cram/snd10000/A-CUHS-CU000018-BL-COL-46250BL1_vcpa1.1.cram, /path/to/adsp/cram/snd10000/A-CUHS-CU000018-BL-COL-46250BL1_vcpa1.1.cram.crai]]
  [A-CUHS-CU000387-BL-COL-38200BL2_vcpa1.1, [/path/to/adsp/cram/snd10000/A-CUHS-CU000387-BL-COL-38200BL2_vcpa1.1.cram, /path/to/adsp/cram/snd10000/A-CUHS-CU000387-BL-COL-38200BL2_vcpa1.1.cram.crai]]
  [A-CUHS-CU000563-BL-COL-47451BL1_vcpa1.1, [/path/to/adsp/cram/snd10000/A-CUHS-CU000563-BL-COL-47451BL1_vcpa1.1.cram, /path/to/adsp/cram/snd10000/A-CUHS-CU000563-BL-COL-47451BL1_vcpa1.1.cram.crai]]
  </code></pre>
  <hr />
  <hr />
  <p>When using the <a href="https://www.nextflow.io/docs/latest/channel.html#fromfilepairs" rel="nofollow noreferrer">fromFilePairs</a> factory method, the trick is to ensure that the pattern you provide can return a <em>common</em> prefix in order for the files to be grouped as expected. An easy way to check to see if this is working as expected is to directly call the <a href="https://github.com/nextflow-io/nextflow/blob/v21.10.6/modules/nextflow/src/main/groovy/nextflow/Channel.groovy#L523-L585" rel="nofollow noreferrer">readPrefix</a> helper function. For example:</p>
  <pre><code>test_cram = file('/path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram')
  test_crai = file('/path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram.crai')
  
  pattern = '/path/to/adsp/cram/snd10000/A-CUHS-CU000*.{cram,crai}'
  
  println(&quot;My CRAM prefix is: <span class="math-container">${Channel.readPrefix(test_cram, pattern)}")
  println("My CRAI prefix is: $</span>{Channel.readPrefix(test_crai, pattern)}&quot;)
  </code></pre>
  <p>You can see that these results do <em>not</em> produce a common prefix:</p>
  <pre><code>N E X T F L O W  ~  version 20.10.0
  Launching `script.nf` [lonely_jang] - revision: 428df7e55e
  My CRAM prefix is: A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1
  My CRAI prefix is: A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram
  </code></pre>
  <p>But if you change your pattern definition to:</p>
  <pre><code>pattern = '/path/to/adsp/cram/snd10000/A-CUHS-CU000*.cram{,.crai}'
  </code></pre>
  <p>We can check that it returns a common prefix:</p>
  <pre><code>N E X T F L O W  ~  version 20.10.0
  Launching `script.nf` [maniac_volta] - revision: a8acf7b03f
  My CRAM prefix is: A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1
  My CRAI prefix is: A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-16T17:50:41.633Z
Answers.Text: Thanks, @Steve. Very helpful. The `Channel.readPrefix(...)` is a nice test.
Answers.UserDisplayName: Mark Ebbert
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-03-16T05:45:54.960Z
Answers.LastActivityDate: 2022-03-16T05:45:54.960Z
Answers.UserDisplayName: Steve
Body: <p>I'm remarkably still struggling with some basic <code>Nextflow</code> concepts. I'm simply trying to collect all pairs of <code>.cram</code> and <code>.crai</code> files from a directory using <code>Channel.fromFilePairs(...)</code>, but I get no output when I try to <code>view()</code> the <code>Channel</code>.</p>
  <p><strong>Question:</strong> Why does my <code>Channel.fromFilePairs(...)</code> command not return file pairs, but I get a list of files when using <code>Channel.fromPath(...)</code>?</p>
  <p>As far as I can tell, I'm following the same pattern from the following examples:</p>
  <ol>
  <li><a href="https://www.nextflow.io/docs/latest/channel.html#fromfilepairs" rel="nofollow noreferrer">Nextflow fromFilePairs</a></li>
  <li><a href="https://github.com/nextflow-io/patterns/blob/master/docs/process-per-file-pairs.adoc" rel="nofollow noreferrer">.bam/.bai example</a> (except without the extra code)</li>
  </ol>
  <h3>Code</h3>
  <pre><code>nextflow.enable.dsl=2
  
  workflow {
  
      /*
       * Channel.fromPath returns the expected files and prints them to
       * terminal.
       */
      Channel.fromPath('/path/to/adsp/cram/snd10000/A-CUHS-CU000*.cram')
          | view()
   
      /*
       * Channel.fromFilePairs does not print anything to terminal.
       */
      Channel.fromFilePairs('/path/to/adsp/cram/snd10000/A-CUHS-CU000*.{cram,crai}')
          | view()
  }
  </code></pre>
  <h3>Output (note, no file tuples/pairs)</h3>
  <pre><code>N E X T F L O W  ~  version 21.04.3
  Launching `pairs.nf` [pensive_plateau] - revision: f917a5c41b
  /path/to/adsp/cram/snd10000/A-CUHS-CU000563-BL-COL-47451BL1_vcpa1.1.cram.crai
  /path/to/adsp/cram/snd10000/A-CUHS-CU000387-BL-COL-38200BL2_vcpa1.1.cram.crai
  /path/to/adsp/cram/snd10000/A-CUHS-CU000018-BL-COL-46250BL1_vcpa1.1.cram.crai
  /path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram
  /path/to/adsp/cram/snd10000/A-CUHS-CU000563-BL-COL-47451BL1_vcpa1.1.cram
  /path/to/adsp/cram/snd10000/A-CUHS-CU000387-BL-COL-38200BL2_vcpa1.1.cram
  /path/to/adsp/cram/snd10000/A-CUHS-CU000194-BL-COL-38470BL1_vcpa1.1.cram
  /path/to/adsp/cram/snd10000/A-CUHS-CU000194-BL-COL-38470BL1_vcpa1.1.cram.crai
  /path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram.crai
  /path/to/adsp/cram/snd10000/A-CUHS-CU000018-BL-COL-46250BL1_vcpa1.1.cram
  </code></pre>
  
Tags: <nextflow>
Title: Nextflow: cannot get file pairs from Channel.fromFilePairs
ThreadText: # Nextflow: cannot get file pairs from Channel.fromFilePairs
  
  (Asked by: username_0 on 2022-03-15)
  
  I'm remarkably still struggling with some basic `Nextflow` concepts. I'm simply trying to collect all pairs of `.cram` and `.crai` files from a directory using `Channel.fromFilePairs(...)`, but I get no output when I try to `view()` the `Channel`.
  
  **Question:** Why does my `Channel.fromFilePairs(...)` command not return file pairs, but I get a list of files when using `Channel.fromPath(...)`?
  
  As far as I can tell, I'm following the same pattern from the following examples:
  
  1. [Nextflow fromFilePairs](https://www.nextflow.io/docs/latest/channel.html#fromfilepairs)
  2. [.bam/.bai example](https://github.com/nextflow-io/patterns/blob/master/docs/process-per-file-pairs.adoc) (except without the extra code)
  
  ### Code
  
  ```
  nextflow.enable.dsl=2
  
  workflow {
  
      /*
       * Channel.fromPath returns the expected files and prints them to
       * terminal.
       */
      Channel.fromPath('/path/to/adsp/cram/snd10000/A-CUHS-CU000*.cram')
          | view()
   
      /*
       * Channel.fromFilePairs does not print anything to terminal.
       */
      Channel.fromFilePairs('/path/to/adsp/cram/snd10000/A-CUHS-CU000*.{cram,crai}')
          | view()
  }
  
  ```
  
  ### Output (note, no file tuples/pairs)
  
  ```
  N E X T F L O W  ~  version 21.04.3
  Launching `pairs.nf` [pensive_plateau] - revision: f917a5c41b
  /path/to/adsp/cram/snd10000/A-CUHS-CU000563-BL-COL-47451BL1_vcpa1.1.cram.crai
  /path/to/adsp/cram/snd10000/A-CUHS-CU000387-BL-COL-38200BL2_vcpa1.1.cram.crai
  /path/to/adsp/cram/snd10000/A-CUHS-CU000018-BL-COL-46250BL1_vcpa1.1.cram.crai
  /path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram
  /path/to/adsp/cram/snd10000/A-CUHS-CU000563-BL-COL-47451BL1_vcpa1.1.cram
  /path/to/adsp/cram/snd10000/A-CUHS-CU000387-BL-COL-38200BL2_vcpa1.1.cram
  /path/to/adsp/cram/snd10000/A-CUHS-CU000194-BL-COL-38470BL1_vcpa1.1.cram
  /path/to/adsp/cram/snd10000/A-CUHS-CU000194-BL-COL-38470BL1_vcpa1.1.cram.crai
  /path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram.crai
  /path/to/adsp/cram/snd10000/A-CUHS-CU000018-BL-COL-46250BL1_vcpa1.1.cram
  
  ```
  
  **Tags:** nextflow
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-03-16. Score: 3 | Accepted answer
  
  **TLDR**, use:
  
  ```
  nextflow.enable.dsl=2
  
  workflow {
  
      Channel.fromFilePairs('/path/to/adsp/cram/snd10000/A-CUHS-CU000*.cram{,.crai}')
          | view()
  }
  
  ```
  
  Results:
  
  ```
  N E X T F L O W  ~  version 20.10.0
  Launching `xscript.nf` [special_caravaggio] - revision: a4e53657a0
  [A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1, [/path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram, /path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram.crai]]
  [A-CUHS-CU000194-BL-COL-38470BL1_vcpa1.1, [/path/to/adsp/cram/snd10000/A-CUHS-CU000194-BL-COL-38470BL1_vcpa1.1.cram, /path/to/adsp/cram/snd10000/A-CUHS-CU000194-BL-COL-38470BL1_vcpa1.1.cram.crai]]
  [A-CUHS-CU000018-BL-COL-46250BL1_vcpa1.1, [/path/to/adsp/cram/snd10000/A-CUHS-CU000018-BL-COL-46250BL1_vcpa1.1.cram, /path/to/adsp/cram/snd10000/A-CUHS-CU000018-BL-COL-46250BL1_vcpa1.1.cram.crai]]
  [A-CUHS-CU000387-BL-COL-38200BL2_vcpa1.1, [/path/to/adsp/cram/snd10000/A-CUHS-CU000387-BL-COL-38200BL2_vcpa1.1.cram, /path/to/adsp/cram/snd10000/A-CUHS-CU000387-BL-COL-38200BL2_vcpa1.1.cram.crai]]
  [A-CUHS-CU000563-BL-COL-47451BL1_vcpa1.1, [/path/to/adsp/cram/snd10000/A-CUHS-CU000563-BL-COL-47451BL1_vcpa1.1.cram, /path/to/adsp/cram/snd10000/A-CUHS-CU000563-BL-COL-47451BL1_vcpa1.1.cram.crai]]
  
  ```
  
  ---
  
  ---
  
  When using the [fromFilePairs](https://www.nextflow.io/docs/latest/channel.html#fromfilepairs) factory method, the trick is to ensure that the pattern you provide can return a *common* prefix in order for the files to be grouped as expected. An easy way to check to see if this is working as expected is to directly call the [readPrefix](https://github.com/nextflow-io/nextflow/blob/v21.10.6/modules/nextflow/src/main/groovy/nextflow/Channel.groovy#L523-L585) helper function. For example:
  
  ```
  test_cram = file('/path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram')
  test_crai = file('/path/to/adsp/cram/snd10000/A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram.crai')
  
  pattern = '/path/to/adsp/cram/snd10000/A-CUHS-CU000*.{cram,crai}'
  
  println("My CRAM prefix is: ${Channel.readPrefix(test_cram, pattern)}")
  println("My CRAI prefix is: ${Channel.readPrefix(test_crai, pattern)}")
  
  ```
  
  You can see that these results do *not* produce a common prefix:
  
  ```
  N E X T F L O W  ~  version 20.10.0
  Launching `script.nf` [lonely_jang] - revision: 428df7e55e
  My CRAM prefix is: A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1
  My CRAI prefix is: A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1.cram
  
  ```
  
  But if you change your pattern definition to:
  
  ```
  pattern = '/path/to/adsp/cram/snd10000/A-CUHS-CU000*.cram{,.crai}'
  
  ```
  
  We can check that it returns a common prefix:
  
  ```
  N E X T F L O W  ~  version 20.10.0
  Launching `script.nf` [maniac_volta] - revision: a8acf7b03f
  My CRAM prefix is: A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1
  My CRAI prefix is: A-CUHS-CU000169-BL-COL-57413BL1_vcpa1.1
  
  ```
  
  > **Comments:**
  > **username_0**: Thanks, @username_1. Very helpful. The `Channel.readPrefix(...)` is a nice test.  
  
  ---
  
  