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

CC BY-SA 4.0
2023-07-14T19:25:30.133Z
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.
Death Metal
CC BY-SA 4.0
2023-07-14T19:26:21.047Z
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.
Death Metal
CC BY-SA 4.0
2023-07-15T04:41:26.630Z
@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.
Steve
CC BY-SA 4.0
2023-07-15T04:45:53.770Z
@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.
Steve
CC BY-SA 4.0
2023-07-19T21:56:51.277Z
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.
Death Metal
CC BY-SA 4.0
2023-07-14T01:31:47.550Z
2023-07-14T01:31:47.550Z
Steve
<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>

<nextflow>
Nextflow - Missing value declared as output parameter - output variable defined in script
# 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. 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. 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 and one or more value channels when you require 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**: @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.  
> **username_1**: @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.  
> **username_0**: 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.  

---

