Answers.Body: <p>You would like to use the <em>sample_name</em> variable outside the <code>script</code> block, but the <code>def</code> keyword defines a variable locally. All you'd need to do is remove the <code>def</code> keyword to make it work, but usually what you'd want to do is to define your <em>sample_name</em> variable outside of your process block in your workflow block like in <a href="https://bioinformatics.stackexchange.com/a/21305/10775">my previous answer</a>. I would also call this variable something else like <em>pair_id</em>, <em>donor_name</em>, <em>case</em> or <em>patient</em> perhaps. I would say you actually have two sample names here: one tumor sample (i.e. <em>tiny_tumor</em>) and one normal sample (i.e. <em>tiny_normal</em>) from the same patient/donor/case.</p>
  <p>You may also run into issues if <em>both</em> of your input channels are <a href="https://www.nextflow.io/docs/latest/channel.html#queue-channel" rel="nofollow noreferrer">queue channels</a>. You may not notice any issues if you're testing only a single pair of samples. Try just copying your tiny files a couple of times and giving your workflow a try, for example:</p>
  <pre><code>for i in tiny_{tumor,normal}_R{1,2}.fastq.gz ; do
      for j in foo bar baz; do
          cp &quot;${i}&quot; &quot;${j}_${i#*_}&quot;
      done
  done
  </code></pre>
  <p>Most of the time what you'll 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 <a href="https://www.nextflow.io/docs/latest/channel.html#value-channel" rel="nofollow noreferrer">value channels</a> when you require <a href="https://www.nextflow.io/docs/latest/process.html#process-multiple-input-channels" rel="nofollow noreferrer">multiple input channels</a>.</p>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-14T19:25:30.133Z
Answers.Text: Thank you. I removed `def` and it worked. My apologies I didn't quite understand: `but usually what you'd want to do is to define your sample_name variable outside of your process block in your workflow block like` What do I do? the example you shared is too difficult.
Answers.UserDisplayName: Death Metal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-14T19:26:21.047Z
Answers.Text: I have seen your reply few times on my posts as well on others, I don't quite follow queue channels, values channels link. What do I use when and for what? Sorry this is complicated then I can understand or/and follow.
Answers.UserDisplayName: Death Metal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-15T04:41:26.630Z
Answers.Text: @DeathMetal A better way, I think, would be to pass your _sample_name_ variable (or  _pair_id_ or whatever) down to your _mutect2_ process. It's likely you'll need this variable later in your workflow, so defining it in your `workflow` block likely makes more sense.
Answers.UserDisplayName: Steve
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-15T04:45:53.770Z
Answers.Text: @DeathMetal I might be starting to sound like a broken record, but understanding how queue channels and value channels work should make writing workflows much easier. Queue channels can be consumed, but value channels can be read an unlimited number of times. In your example above, the intervals (targets) file and reference file should be passed in using value channels like in my previous answer. Note that value channels are implicitly created when a process is invoked with a simple value, like a `file` object.
Answers.UserDisplayName: Steve
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-19T21:56:51.277Z
Answers.Text: Hi @Steve - can you please assist me on post https://bioinformatics.stackexchange.com/questions/21338/nextflow-merge-lane-files-from-samples-forward-and-reverse-read.
Answers.UserDisplayName: Death Metal
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2023-07-14T01:31:47.550Z
Answers.LastActivityDate: 2023-07-14T01:31:47.550Z
Answers.UserDisplayName: Steve
Body: <p>I've normal-tumor human FASTQ file(s). Currently, I work with only one sample (both normal and tumor fastq R1 and R2), only.<br />
  I have alignment gatk mark duplicates, setupnmdtags, applybqsr, recalibrate steps before calling mutect2.</p>
  <p>My input files are:<br />
  tiny_tumor_R1.fastq.gz<br />
  tiny_tumor_R2.fastq.gz<br />
  tiny_normal_R1.fastq.gz<br />
  tiny_normal_R2.fastq.gz</p>
  <p>The expected output from the mutect2 is <strong>tiny.mutect2out.vcf</strong> that is ${sample_name}&quot;.mutect2out.vcf&quot;</p>
  <p>I split <code>tiny_normal</code> using nextflow split and take first element of the split array, that is tiny.</p>
  <p>However, I get error as:</p>
  <blockquote>
  <p>Caused by:   Missing value declared as output parameter: sample_name</p>
  </blockquote>
  <p>I understand that the variable was defined in the script step. How do I retrieve at the output level?</p>
  <p>Below is code of the mutect2_process.nf</p>
  <pre><code>process mutect2 {
  
          maxForks 3
          debug true
  
   memory '15 GB'
  
          input:
          tuple val(sample_id_tumor),path(bqsrbam_tumor)
          tuple val(sample_id_normal),path(bqsrbam_normal)
          
          output:
          tuple val(sample_name),path(${sample_name}&quot;.mutect2out.vcf&quot;)
          
  
          script:
          def avail_mem = task.memory ? task.memory.toGiga() : 0
                  def java_options = [
          avail_mem ? &quot;-Xmx${avail_mem}G&quot; : &quot;&quot;,
          &quot;-XX:+UseSerialGC&quot;,
      ]
          def sample_name=sample_id_normal.split('_normal')[0]
  
          &quot;&quot;&quot;
                  
          ml gatk/4.1.3.0
  gatk --java-options &quot;<span class="math-container">${java_options.join(' ')}" Mutect2 -L $</span>params.target -I <span class="math-container">${bqsrbam_tumor} -I $</span>{bqsrbam_normal} -normal <span class="math-container">${sample_name} -tumor $</span>{sample_name} --output <span class="math-container">${sample_name}".mutect2out.vcf" -R $</span>params.hg38genome
  
          &quot;&quot;&quot;
          }
  </code></pre>
  
Tags: <nextflow>
Title: Nextflow - Missing value declared as output parameter - output variable defined in script
ThreadText: # Nextflow - Missing value declared as output parameter - output variable defined in script
  
  (Asked by: username_0 on 2023-07-13)
  
  I've normal-tumor human FASTQ file(s). Currently, I work with only one sample (both normal and tumor fastq R1 and R2), only.  
  I have alignment gatk mark duplicates, setupnmdtags, applybqsr, recalibrate steps before calling mutect2.
  
  My input files are:  
  tiny\_tumor\_R1.fastq.gz  
  tiny\_tumor\_R2.fastq.gz  
  tiny\_normal\_R1.fastq.gz  
  tiny\_normal\_R2.fastq.gz
  
  The expected output from the mutect2 is **tiny.mutect2out.vcf** that is ${sample\_name}".mutect2out.vcf"
  
  I split `tiny_normal` using nextflow split and take first element of the split array, that is tiny.
  
  However, I get error as:
  
  > Caused by: Missing value declared as output parameter: sample\_name
  
  I understand that the variable was defined in the script step. How do I retrieve at the output level?
  
  Below is code of the mutect2\_process.nf
  
  ```
  process mutect2 {
  
          maxForks 3
          debug true
  
   memory '15 GB'
  
          input:
          tuple val(sample_id_tumor),path(bqsrbam_tumor)
          tuple val(sample_id_normal),path(bqsrbam_normal)
          
          output:
          tuple val(sample_name),path(${sample_name}".mutect2out.vcf")
          
  
          script:
          def avail_mem = task.memory ? task.memory.toGiga() : 0
                  def java_options = [
          avail_mem ? "-Xmx${avail_mem}G" : "",
          "-XX:+UseSerialGC",
      ]
          def sample_name=sample_id_normal.split('_normal')[0]
  
          """
                  
          ml gatk/4.1.3.0
  gatk --java-options "${java_options.join(' ')}" Mutect2 -L $params.target -I ${bqsrbam_tumor} -I ${bqsrbam_normal} -normal ${sample_name} -tumor ${sample_name} --output ${sample_name}".mutect2out.vcf" -R $params.hg38genome
  
          """
          }
  
  ```
  
  **Tags:** nextflow
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2023-07-14. Score: 1 | Accepted answer
  
  You would like to use the *sample\_name* variable outside the `script` block, but the `def` keyword defines a variable locally. All you'd need to do is remove the `def` keyword to make it work, but usually what you'd want to do is to define your *sample\_name* variable outside of your process block in your workflow block like in [my previous answer](https://bioinformatics.stackexchange.com/a/21305/10775). I would also call this variable something else like *pair\_id*, *donor\_name*, *case* or *patient* perhaps. I would say you actually have two sample names here: one tumor sample (i.e. *tiny\_tumor*) and one normal sample (i.e. *tiny\_normal*) from the same patient/donor/case.
  
  You may also run into issues if *both* of your input channels are [queue channels](https://www.nextflow.io/docs/latest/channel.html#queue-channel). You may not notice any issues if you're testing only a single pair of samples. Try just copying your tiny files a couple of times and giving your workflow a try, for example:
  
  ```
  for i in tiny_{tumor,normal}_R{1,2}.fastq.gz ; do
      for j in foo bar baz; do
          cp "${i}" "${j}_${i#*_}"
      done
  done
  
  ```
  
  Most of the time what you'll want is one [queue channel](https://www.nextflow.io/docs/latest/channel.html#queue-channel) and one or more [value channels](https://www.nextflow.io/docs/latest/channel.html#value-channel) when you require [multiple input channels](https://www.nextflow.io/docs/latest/process.html#process-multiple-input-channels).
  
  > **Comments:**
  > **username_0**: Thank you. I removed `def` and it worked. My apologies I didn't quite understand: `but usually what you'd want to do is to define your sample_name variable outside of your process block in your workflow block like` What do I do? the example you shared is too difficult.  
  > **username_0**: I have seen your reply few times on my posts as well on others, I don't quite follow queue channels, values channels link. What do I use when and for what? Sorry this is complicated then I can understand or/and follow.  
  > **username_1**: @username_0 A better way, I think, would be to pass your _sample_name_ variable (or  _pair_id_ or whatever) down to your _mutect2_ process. It's likely you'll need this variable later in your workflow, so defining it in your `workflow` block likely makes more sense.  
  > **username_1**: @username_0 I might be starting to sound like a broken record, but understanding how queue channels and value channels work should make writing workflows much easier. Queue channels can be consumed, but value channels can be read an unlimited number of times. In your example above, the intervals (targets) file and reference file should be passed in using value channels like in my previous answer. Note that value channels are implicitly created when a process is invoked with a simple value, like a `file` object.  
  > **username_0**: Hi @username_1 - can you please assist me on post https://bioinformatics.stackexchange.com/questions/21338/nextflow-merge-lane-files-from-samples-forward-and-reverse-read.  
  
  ---
  
  