Answers.Body: <p>With <code>output: path(pair_id)</code>, you're telling Nextflow to expect a file or directory with the value of <em>pair_id</em> in the process working directory when the command exits (successfully). <a href="https://github.com/cihga39871/Atria" rel="nofollow noreferrer">Atria</a> outputs all files to a directory specified using <code>-o PATH</code><sup><a href="https://github.com/cihga39871/Atria/blob/v3.2.1/docs/2.Atria_trimming_methods_and_usages.md#usage" rel="nofollow noreferrer">1</a></sup>. This directory is created if it doesn't already exist. Note that the output directory defaults to the current working directory if <code>-o</code> is not specified. If you'd like to write the results to a sub-directory, you could try:</p>
  <pre><code>process TRIM {
  
      tag { pair_id }
  
      publishDir &quot;${params.outdir}/TRIM&quot;, mode: 'copy'
  
      cpus 1
  
      input:
      tuple val(pair_id), path(reads)
  
      output:
      tuple val(pair_id), path(trimmed_reads), emit: trimmed_fastqs
      path &quot;${pair_id}/*.atria.log*&quot;, emit: logs
  
      script:
      def (r1, r2) = reads
  
      trimmed_reads = reads.collect {
          &quot;<span class="math-container">${pair_id}/$</span>{it.baseName}.atria.fastq&quot;
      }
  
      &quot;&quot;&quot;
      atria \\
          -r &quot;<span class="math-container">${r1}" \\
          -R "$</span>{r2}&quot; \\
          -o &quot;<span class="math-container">${pair_id}" \\
          -t $</span>{task.cpus} \\
          -l 12 \\
          -q 30
      &quot;&quot;&quot;
  }
  </code></pre>
  <p>In the above, we used the <a href="https://www.nextflow.io/docs/latest/dsl2.html#process-named-output" rel="nofollow noreferrer">emit</a> option in the process output definition to assign a name identifier to each declaration. We can use this feature to reference the desired channel in the workflow block. For example:</p>
  <pre><code>workflow {
  
      read_pairs_ch = Channel.fromFilePairs( params.reads, checkIfExists:true )
  
      trim_out = TRIM(read_pairs_ch)
  
      trim_out.trimmed_fastqs.view()
  }
  </code></pre>
  <p>Results:</p>
  <pre><code>$ nextflow run main.nf 
  N E X T F L O W  ~  version 22.10.0
  Launching `main.nf` [distraught_dalembert] DSL2 - revision: aea2d37092
  executor &gt;  local (3)
  [5f/78908b] process &gt; TRIM (A) [100%] 3 of 3 ✔
  [B, [/path/to/work/6a/440a50e9a0725c18f9eede80549cb8/B/B_1.atria.fastq, /path/to/work/6a/440a50e9a0725c18f9eede80549cb8/B/B_2.atria.fastq]]
  [A, [/path/to/work/5f/78908b96adee8b8d663d9b4eb4faba/A/A_1.atria.fastq, /path/to/work/5f/78908b96adee8b8d663d9b4eb4faba/A/A_2.atria.fastq]]
  [C, [/path/to/work/b0/a3bb3024a4c05fffec555cce5097a7/C/C_1.atria.fastq, /path/to/work/b0/a3bb3024a4c05fffec555cce5097a7/C/C_2.atria.fastq]]
  </code></pre>
  <hr />
  <p>To input the trimmed reads into a downstream process, just ensure that the input tuple matches the input set cardinality declared by the process. If the input declaration is not the same, you may need to apply one or more <a href="https://www.nextflow.io/docs/latest/operator.html" rel="nofollow noreferrer">operators</a> to your channel to make it fit. For your alignment process, you might not need to make any changes. Also, if your alignment process needs to declare one or more reference files, just make sure these are <a href="https://www.nextflow.io/docs/latest/channel.html#value-channel" rel="nofollow noreferrer">value channels</a>. Most of the time, what you want is one <a href="https://www.nextflow.io/docs/latest/channel.html#queue-channel" rel="nofollow noreferrer">queue channel</a> and one or more value channels when you require multiple input channels, otherwise you might observe unusual behavior (e.g. see <a href="https://stackoverflow.com/q/74537223/751863">this question</a>). The section on <a href="https://www.nextflow.io/docs/latest/process.html#process-multiple-input-channels" rel="nofollow noreferrer">multiple input channels</a> in the docs is well worth taking the time to read in my opinion.</p>
  <p>A dummy alignment process might look like:</p>
  <pre><code>process ALIGN {
  
      tag { sample }
  
      debug true
  
      input:
      tuple val(sample), path(reads)
      path fasta
      path gtf
  
      script:
      def (r1, r2) = reads
  
      &quot;&quot;&quot;
      ls -g &quot;<span class="math-container">${r1}"
      ls -g "$</span>{r2}&quot;
      ls -g &quot;<span class="math-container">${fasta}"
      ls -g "$</span>{gtf}&quot;
      &quot;&quot;&quot;
  }
  </code></pre>
  <p>And the updated workflow:</p>
  <pre><code>workflow {
  
      read_pairs_ch = Channel.fromFilePairs( params.reads, checkIfExists:true )
  
      transcriptome = file( params.transcriptome_file )
      gtf = file( params.gtf_file )
  
      TRIM( read_pairs_ch )
  
      ALIGN( TRIM.out.trimmed_fastqs, transcriptome, gtf )
  }
  </code></pre>
  <p>Results:</p>
  <pre><code>$ nextflow run main.nf 
  N E X T F L O W  ~  version 22.10.0
  Launching `main.nf` [extravagant_lattes] DSL2 - revision: 29b5315739
  executor &gt;  local (6)
  [51/e4e261] process &gt; TRIM (A)  [100%] 3 of 3 ✔
  [cc/72c53d] process &gt; ALIGN (A) [100%] 3 of 3 ✔
  lrwxrwxrwx 1 users 57 Dec 14 00:21 C_1.atria.fastq -&gt; ../../c1/9a85e19c601f2ab2c4af9c6fd203f0/C/C_1.atria.fastq
  lrwxrwxrwx 1 users 57 Dec 14 00:21 C_2.atria.fastq -&gt; ../../c1/9a85e19c601f2ab2c4af9c6fd203f0/C/C_2.atria.fastq
  lrwxrwxrwx 1 users 40 Dec 14 00:21 Glycine_max.cdna.all.fasta -&gt; ../../../data/Glycine_max.cdna.all.fasta
  lrwxrwxrwx 1 users 29 Dec 14 00:21 Glycine_max.gtf -&gt; ../../../data/Glycine_max.gtf
  
  lrwxrwxrwx 1 users 57 Dec 14 00:21 B_1.atria.fastq -&gt; ../../3f/16747fbd2c9bc4c0dc945b24873cca/B/B_1.atria.fastq
  lrwxrwxrwx 1 users 57 Dec 14 00:21 B_2.atria.fastq -&gt; ../../3f/16747fbd2c9bc4c0dc945b24873cca/B/B_2.atria.fastq
  lrwxrwxrwx 1 users 40 Dec 14 00:21 Glycine_max.cdna.all.fasta -&gt; ../../../data/Glycine_max.cdna.all.fasta
  lrwxrwxrwx 1 users 29 Dec 14 00:21 Glycine_max.gtf -&gt; ../../../data/Glycine_max.gtf
  
  lrwxrwxrwx 1 users 57 Dec 14 00:21 A_1.atria.fastq -&gt; ../../51/e4e261d019c65377d63826963b19b1/A/A_1.atria.fastq
  lrwxrwxrwx 1 users 57 Dec 14 00:21 A_2.atria.fastq -&gt; ../../51/e4e261d019c65377d63826963b19b1/A/A_2.atria.fastq
  lrwxrwxrwx 1 users 40 Dec 14 00:21 Glycine_max.cdna.all.fasta -&gt; ../../../data/Glycine_max.cdna.all.fasta
  lrwxrwxrwx 1 users 29 Dec 14 00:21 Glycine_max.gtf -&gt; ../../../data/Glycine_max.gtf
  
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-13T13:15:41.163Z
Answers.Text: I appreciate your reply so much and I am very thankful for it. I wanted to confirm one more thing as I just started using nextflow. How do I input these trimmed_fastqs into a new process, say, for alignment? Do I use trim_out.trimmed_fastqs channel as input for the alignment process?
Answers.UserDisplayName: pubsurfted
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-13T14:27:24.277Z
Answers.Text: @pubsurfted Correct. I've tried to give an example above of what you might need. Please let me know if I've missed anything, thanks!
Answers.UserDisplayName: Steve
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2022-12-13T10:10:11.750Z
Answers.LastActivityDate: 2022-12-13T14:22:48.330Z
Answers.LastEditDate: 2022-12-13T14:22:48.330Z
Answers.UserDisplayName: Steve
Body: <p>I have the following simple nextflow script, that takes fastq paired reads and runs them through the atria adapter trimming.</p>
  <pre><code>// Declare syntax version
  nextflow.enable.dsl=2
  
  /* 
   * pipeline input parameters 
   */
  
  
  params.reads = &quot;<span class="math-container">$projectDir/data/*_{1,2}.fastq"
  params.transcriptome_file = "$</span>projectDir/data/Glycine_max.cdna.all.fasta&quot;
  params.gtf_file = &quot;$projectDir/data/Glycine_max.gtf&quot;
  params.outdir = &quot;results&quot;
  
  
  /*
   * define the `TRIM` process that creates trimmed.reads.fastq files
   * given the reads.fastq file. 
   */
   
  process TRIM {
  
      tag &quot;$pair_id&quot;
  
      input:
      tuple val(pair_id), path(reads)
  
      output:
      path(pair_id)
  
      script:
      &quot;&quot;&quot;
      atria -r <span class="math-container">${reads[0]} -R $</span>{reads[1]} -t 1 -l 12 -q 30 -o $pair_id
      &quot;&quot;&quot;
  }
  
  workflow {
  
      read_pairs_ch = Channel.fromFilePairs( params.reads, checkIfExists:true )
  
      trim_ch=TRIM(read_pairs_ch)
  
  }
  </code></pre>
  <p>Next what I want to achieve is input the atria.trimmed.fastq files generated by the trim process into a channel so that I could use it as an input for other process. But atria trimming tool also creates two additional log files along with atria.trimmed.fastq. How do i exclude those additional files and only input the trimmed files into a channel for later use.</p>
  <p>Best wishes.</p>
  
Comments.ContentLicense: CC BY-SA 4.0
Comments.CreationDate: 2022-12-13T15:17:45.683Z
Comments.Text: Cross posted here: https://stackoverflow.com/questions/74780770/how-to-include-only-the-trimmed-fastq-files-into-a-nextflow-channel-and-exclude
Comments.UserDisplayName: Steve
Tags: <nextflow>
Title: How to include only the trimmed fastq files into a nextflow channel and exclude any secondary log files created?
ThreadText: # How to include only the trimmed fastq files into a nextflow channel and exclude any secondary log files created?
  
  (Asked by: username_0 on 2022-12-13)
  
  I have the following simple nextflow script, that takes fastq paired reads and runs them through the atria adapter trimming.
  
  ```
  // Declare syntax version
  nextflow.enable.dsl=2
  
  /* 
   * pipeline input parameters 
   */
  
  params.reads = "$projectDir/data/*_{1,2}.fastq"
  params.transcriptome_file = "$projectDir/data/Glycine_max.cdna.all.fasta"
  params.gtf_file = "$projectDir/data/Glycine_max.gtf"
  params.outdir = "results"
  
  /*
   * define the `TRIM` process that creates trimmed.reads.fastq files
   * given the reads.fastq file. 
   */
   
  process TRIM {
  
      tag "$pair_id"
  
      input:
      tuple val(pair_id), path(reads)
  
      output:
      path(pair_id)
  
      script:
      """
      atria -r ${reads[0]} -R ${reads[1]} -t 1 -l 12 -q 30 -o $pair_id
      """
  }
  
  workflow {
  
      read_pairs_ch = Channel.fromFilePairs( params.reads, checkIfExists:true )
  
      trim_ch=TRIM(read_pairs_ch)
  
  }
  
  ```
  
  Next what I want to achieve is input the atria.trimmed.fastq files generated by the trim process into a channel so that I could use it as an input for other process. But atria trimming tool also creates two additional log files along with atria.trimmed.fastq. How do i exclude those additional files and only input the trimmed files into a channel for later use.
  
  Best wishes.
  
  **Tags:** nextflow
  
  > **Comments:**
  > **username_1**: Cross posted here: https://stackoverflow.com/questions/74780770/how-to-include-only-the-trimmed-fastq-files-into-a-nextflow-channel-and-exclude  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2022-12-13. Score: 2 | Accepted answer
  
  With `output: path(pair_id)`, you're telling Nextflow to expect a file or directory with the value of *pair\_id* in the process working directory when the command exits (successfully). [Atria](https://github.com/cihga39871/Atria) outputs all files to a directory specified using `-o PATH`[1](https://github.com/cihga39871/Atria/blob/v3.2.1/docs/2.Atria_trimming_methods_and_usages.md#usage). This directory is created if it doesn't already exist. Note that the output directory defaults to the current working directory if `-o` is not specified. If you'd like to write the results to a sub-directory, you could try:
  
  ```
  process TRIM {
  
      tag { pair_id }
  
      publishDir "${params.outdir}/TRIM", mode: 'copy'
  
      cpus 1
  
      input:
      tuple val(pair_id), path(reads)
  
      output:
      tuple val(pair_id), path(trimmed_reads), emit: trimmed_fastqs
      path "${pair_id}/*.atria.log*", emit: logs
  
      script:
      def (r1, r2) = reads
  
      trimmed_reads = reads.collect {
          "${pair_id}/${it.baseName}.atria.fastq"
      }
  
      """
      atria \\
          -r "${r1}" \\
          -R "${r2}" \\
          -o "${pair_id}" \\
          -t ${task.cpus} \\
          -l 12 \\
          -q 30
      """
  }
  
  ```
  
  In the above, we used the [emit](https://www.nextflow.io/docs/latest/dsl2.html#process-named-output) option in the process output definition to assign a name identifier to each declaration. We can use this feature to reference the desired channel in the workflow block. For example:
  
  ```
  workflow {
  
      read_pairs_ch = Channel.fromFilePairs( params.reads, checkIfExists:true )
  
      trim_out = TRIM(read_pairs_ch)
  
      trim_out.trimmed_fastqs.view()
  }
  
  ```
  
  Results:
  
  ```
  $ nextflow run main.nf 
  N E X T F L O W  ~  version 22.10.0
  Launching `main.nf` [distraught_dalembert] DSL2 - revision: aea2d37092
  executor >  local (3)
  [5f/78908b] process > TRIM (A) [100%] 3 of 3 ✔
  [B, [/path/to/work/6a/440a50e9a0725c18f9eede80549cb8/B/B_1.atria.fastq, /path/to/work/6a/440a50e9a0725c18f9eede80549cb8/B/B_2.atria.fastq]]
  [A, [/path/to/work/5f/78908b96adee8b8d663d9b4eb4faba/A/A_1.atria.fastq, /path/to/work/5f/78908b96adee8b8d663d9b4eb4faba/A/A_2.atria.fastq]]
  [C, [/path/to/work/b0/a3bb3024a4c05fffec555cce5097a7/C/C_1.atria.fastq, /path/to/work/b0/a3bb3024a4c05fffec555cce5097a7/C/C_2.atria.fastq]]
  
  ```
  
  ---
  
  To input the trimmed reads into a downstream process, just ensure that the input tuple matches the input set cardinality declared by the process. If the input declaration is not the same, you may need to apply one or more [operators](https://www.nextflow.io/docs/latest/operator.html) to your channel to make it fit. For your alignment process, you might not need to make any changes. Also, if your alignment process needs to declare one or more reference files, just make sure these are [value channels](https://www.nextflow.io/docs/latest/channel.html#value-channel). Most of the time, what you want is one [queue channel](https://www.nextflow.io/docs/latest/channel.html#queue-channel) and one or more value channels when you require multiple input channels, otherwise you might observe unusual behavior (e.g. see [this question](https://stackoverflow.com/q/74537223/751863)). The section on [multiple input channels](https://www.nextflow.io/docs/latest/process.html#process-multiple-input-channels) in the docs is well worth taking the time to read in my opinion.
  
  A dummy alignment process might look like:
  
  ```
  process ALIGN {
  
      tag { sample }
  
      debug true
  
      input:
      tuple val(sample), path(reads)
      path fasta
      path gtf
  
      script:
      def (r1, r2) = reads
  
      """
      ls -g "${r1}"
      ls -g "${r2}"
      ls -g "${fasta}"
      ls -g "${gtf}"
      """
  }
  
  ```
  
  And the updated workflow:
  
  ```
  workflow {
  
      read_pairs_ch = Channel.fromFilePairs( params.reads, checkIfExists:true )
  
      transcriptome = file( params.transcriptome_file )
      gtf = file( params.gtf_file )
  
      TRIM( read_pairs_ch )
  
      ALIGN( TRIM.out.trimmed_fastqs, transcriptome, gtf )
  }
  
  ```
  
  Results:
  
  ```
  $ nextflow run main.nf 
  N E X T F L O W  ~  version 22.10.0
  Launching `main.nf` [extravagant_lattes] DSL2 - revision: 29b5315739
  executor >  local (6)
  [51/e4e261] process > TRIM (A)  [100%] 3 of 3 ✔
  [cc/72c53d] process > ALIGN (A) [100%] 3 of 3 ✔
  lrwxrwxrwx 1 users 57 Dec 14 00:21 C_1.atria.fastq -> ../../c1/9a85e19c601f2ab2c4af9c6fd203f0/C/C_1.atria.fastq
  lrwxrwxrwx 1 users 57 Dec 14 00:21 C_2.atria.fastq -> ../../c1/9a85e19c601f2ab2c4af9c6fd203f0/C/C_2.atria.fastq
  lrwxrwxrwx 1 users 40 Dec 14 00:21 Glycine_max.cdna.all.fasta -> ../../../data/Glycine_max.cdna.all.fasta
  lrwxrwxrwx 1 users 29 Dec 14 00:21 Glycine_max.gtf -> ../../../data/Glycine_max.gtf
  
  lrwxrwxrwx 1 users 57 Dec 14 00:21 B_1.atria.fastq -> ../../3f/16747fbd2c9bc4c0dc945b24873cca/B/B_1.atria.fastq
  lrwxrwxrwx 1 users 57 Dec 14 00:21 B_2.atria.fastq -> ../../3f/16747fbd2c9bc4c0dc945b24873cca/B/B_2.atria.fastq
  lrwxrwxrwx 1 users 40 Dec 14 00:21 Glycine_max.cdna.all.fasta -> ../../../data/Glycine_max.cdna.all.fasta
  lrwxrwxrwx 1 users 29 Dec 14 00:21 Glycine_max.gtf -> ../../../data/Glycine_max.gtf
  
  lrwxrwxrwx 1 users 57 Dec 14 00:21 A_1.atria.fastq -> ../../51/e4e261d019c65377d63826963b19b1/A/A_1.atria.fastq
  lrwxrwxrwx 1 users 57 Dec 14 00:21 A_2.atria.fastq -> ../../51/e4e261d019c65377d63826963b19b1/A/A_2.atria.fastq
  lrwxrwxrwx 1 users 40 Dec 14 00:21 Glycine_max.cdna.all.fasta -> ../../../data/Glycine_max.cdna.all.fasta
  lrwxrwxrwx 1 users 29 Dec 14 00:21 Glycine_max.gtf -> ../../../data/Glycine_max.gtf
  
  ```
  
  > **Comments:**
  > **username_0**: I appreciate your reply so much and I am very thankful for it. I wanted to confirm one more thing as I just started using nextflow. How do I input these trimmed_fastqs into a new process, say, for alignment? Do I use trim_out.trimmed_fastqs channel as input for the alignment process?  
  > **username_1**: @username_0 Correct. I've tried to give an example above of what you might need. Please let me know if I've missed anything, thanks!  
  
  ---
  
  