Answers.Body: <p>The documation re <a href="https://www.nextflow.io/docs/latest/process.html#conditional-scripts" rel="nofollow noreferrer">conditional scripts</a> is useful here:</p>
  <blockquote>
  <p>Process scripts can contain conditional statements by simply prefixing
  the script block with the keyword <code>script:</code>. By doing that the
  interpreter will evaluate all the following statements as a code block
  that must return the script string to be executed.</p>
  </blockquote>
  <p>But the statements don't necessarily need to be conditional. I.e. they can just be declarations like in your example. You get the error 'No signature of Method: chr()' because Nextflow interprets 'chr' as a method call when you use:</p>
  <pre><code>prefix = chr&quot;${chr_name}&quot;
  </code></pre>
  <p>If your intention is to simply add the 'chr' prefix to each chromosome name, you'd need:</p>
  <pre><code>prefix = &quot;chr${chr_name}&quot;
  </code></pre>
  <p>Notice that I changed your variable name. This is because in your code, you still need to feed in the channel of chromosome names. The easiest way to do this is to use the <a href="https://www.nextflow.io/docs/latest/process.html?highlight=script#input-repeaters" rel="nofollow noreferrer">each qualifier</a>:</p>
  <pre><code>process myprocess {
  
      input:
      tuple val(sample_name), path(bfiles) from plink_data
      each chr_name from chr_names
  
      script:
      prefix = &quot;chr${chr_name}&quot;
  
      &quot;&quot;&quot;
      echo &quot;My sample name is: <span class="math-container">${sample_name}"
      echo "My prefixed chromosome name is: $</span>{prefix}&quot;
      &quot;&quot;&quot;
  }
  </code></pre>
  <p>Unless you need chromosome names without the 'chr' prefix, another solution might be to simply add the prefix to each one initially and simply avoid having to prefix them later:</p>
  <pre><code>Channel
      .of(1..22)
      .map { &quot;chr${it}&quot; }
      .set { chr_names }
  </code></pre>
  
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-22T08:41:00.140Z
Answers.Text: It seems process 1 and 2 running in random order. Is there any way to specify that after finishing the first process, the second process will start. Because the outputs of the first process will be the input of the second process. In my case my second process shows error because it does not find an input, which is an output of the first process. Did I clarify the matter?
Answers.UserDisplayName: zillur rahman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-22T12:05:53.610Z
Answers.Text: I suspect the problem arises because you've specified two input and output channels ('step1a_out' and 'step1a_bims'). It's not clear to me why you need the two channels, since the 'step1a_bims' looks like a subset of 'step1a_out'? Please see [understanding how multiple input channels work](https://www.nextflow.io/docs/latest/process.html#process-understand-how-multiple-input-channels-work)
Answers.UserDisplayName: Steve
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-22T15:10:49.370Z
Answers.Text: Ohh! Thank you. Just one thing, How could I declare prefix of the previous process output as an input of the current process. I have chr(1-22).step1b.bed|bim|fam as output of process step1a; Now I want to declare only chr(1-22) as input in the step1b process. I want different suffix inside process step1b. I am not sure if I could clarify the issue.
Answers.UserDisplayName: zillur rahman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-22T15:37:56.560Z
Answers.Text: Does my answer to your most recent [question](https://bioinformatics.stackexchange.com/questions/15590/nextflow-ordering-the-execution-of-processes-outputs-of-process-a-are-inputs-o/15594) answer your question?
Answers.UserDisplayName: Steve
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-22T16:06:52.677Z
Answers.Text: Yes. Thank you. Still wondering how could I declare prefix (characters before first .) as input in the next process which is the output of the previous process.
Answers.UserDisplayName: zillur rahman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-23T01:51:21.167Z
Answers.Text: No worries at all @zillurrahman. If I understand correctly, the easy way would be to include it in your output tuple as an extra value for your prefix. But if it's already part of (i.e. the prefix) of another value then you could again use the [map operator](https://www.nextflow.io/docs/latest/operator.html#map) to get it back. Perhaps something like: `map { some_name, some_thing -> tuple( some_name.substring(0, some_name.indexOf('.')), some_name, some_thing ) }` ? A concrete example would be great if the above doesn't help.
Answers.UserDisplayName: Steve
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-23T07:17:00.490Z
Answers.Text: Thanks a lot @Steve. I tried different ways but failed, maybe because I am new in nextflow. My files are chr1-22.step1b.bed|bim|fam in out_ch1. I need a way to find chr1 to chr22 as prefix for the next input so I can modify the suffixes. for example input chr1-22.step1b.bed|bim|fam --some command --out chr1-22.step1c.bed|bim|fam into out_ch3.
  Also how can I use subset of the outputs channel. From above example I need only chr1-22.step1b.bim as a $bim --some command to run -out chr1-22.step1b.snp.txt. So far I tried "filter" but failed. Thanks again for helping all the way.
Answers.UserDisplayName: zillur rahman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-23T09:14:29.750Z
Answers.Text: `@Steve`, I tried to filter as: `tuple val(bim), path(bims) from step1a_bim.filter{bim -> bims=~ /*bim/}` But I am getting error `unexpected input:` Also I am still not getting the prefix correctly. Perhaps any example would be helpful. Do you know any training module to run plink, gwas in nextflow?
Answers.UserDisplayName: zillur rahman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-23T14:14:55.083Z
Answers.Text: Sorry @zillurrahman - I'm not sure I can get you a useful answer without a minimal example of exactly what you're trying to do. On file-like objects you can call `getSimpleName()` to get the prefix, see [check file attributes](https://www.nextflow.io/docs/latest/script.html#check-file-attributes). The problem is that this won't work on a tuple of files. I guess I'm confused as to why you can't just include the chromosome name in the output tuple of the first process? This way you'd avoid having to try and find the prefix in the first place.
Answers.UserDisplayName: Steve
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-23T14:19:16.093Z
Answers.Text: Using my answer above as an example, your output declaration could look like: `tuple val(sample_name), val(chr_name), path("${sample_name}.${chr_name}.step1b.{bed,bim,fam}") into step1a_out`. Also, I'm not aware of any good plink/gwas pipelines but you could try having a look here: https://github.com/nextflow-io/awesome-nextflow. HTH.
Answers.UserDisplayName: Steve
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-23T18:05:04.100Z
Answers.Text: Thanks a lot. In that case how can I declare inputs in the next process? If I use step1a_out two time (first for bfiles, and then for bim) I got error `Channel 'step1a_out' has been used twice as an input by process 'step1b'`
Answers.UserDisplayName: zillur rahman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-23T23:39:55.987Z
Answers.Text: If I understand correctly, the input declaration for the next process will be basically the same as the first processes' output declaration. If that's the case, you'd need: `tuple val(sample_name), val(chr_name), path(bfiles)`. Since the bfiles tuple will contain the bim  file as the second element, you should be able to access it directly with `${bfiles[1]}`. Alternatively, in your script block, you could unpack the bfiles: `(bed, bim, fam) = bfiles`, then just use `${bim}` as your variable. If these variables don't need to be global, consider instead: `def (bed, bim, fam) = bfiles`. HTH.
Answers.UserDisplayName: Steve
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-24T08:25:18.227Z
Answers.Text: Thanks a lot `@Steve` . It works. Just one thing. How could I specify output directory of my results? I tried `params.publish='output2'` then in each process `publishDir params.publish`. I got only link of the output files in `output2`. How could I get actual result files in my desired directory? Again thanks a lot for helping me all the way.
Answers.UserDisplayName: zillur rahman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-24T08:40:10.907Z
Answers.Text: Ohh! I got it. I just need to mention `mode: 'copy'` in `publishDir` declaration. Thanks!
Answers.UserDisplayName: zillur rahman
Answers.ContentLicense: CC BY-SA 4.0
Answers.CreationDate: 2021-03-22T01:43:30.723Z
Answers.LastActivityDate: 2021-03-22T01:43:30.723Z
Answers.UserDisplayName: Steve
Body: <p>I was trying to use plink in nextflow. My first process will split the input (single bed|bim|fam file) into 22 chromosomes (each with bed|bim|fam files) which would be used in subsequent processes. My code and error log is below. Any help?</p>
  <pre><code>params.dir='data/'
  params.publish=&quot;output2/&quot;
  Channel
  .fromFilePairs(&quot;${params.dir}*.{bed,bim,fam}&quot;,size:3)
  .set {data}
  
  Channel
  .of(1..22)
  .set {chr_names}
      
  process step1a {
  publishDir params.publish
  input:
  tuple val(sample_name), path(bfiles) from data
  output:
  tuple val(&quot;<span class="math-container">${prefix}"), path("$</span>{prefix}.step1a.{bed,bim,fam}&quot;) into step1a_results
  tuple val(&quot;<span class="math-container">${prefix}"), path("$</span>{prefix}.step1b.{bed,bim,fam}&quot;) into step1a_out
  tuple val(&quot;<span class="math-container">${prefix}"), path("$</span>{prefix}.step1b.bim&quot;) into step1a_bims
  path(&quot;<span class="math-container">${prefix}.log") into step1a_logs
  path("$</span>{prefix}.step1a.dupvar&quot;) into step1a_duplicates
  path(&quot;<span class="math-container">${prefix}.step1a.log") into step1a_log
  path("$</span>{prefix}.step1b.log&quot;) into step1_log
  script:
  prefix=chr&quot;<span class="math-container">${chr_names}"
  """
  plink --bfile "$</span>{sample_name}&quot; --chr &quot;<span class="math-container">${chr_names}" --out "$</span>{prefix}&quot; --make-bed
  plink --bfile &quot;<span class="math-container">${prefix}" --list-duplicate-vars ids-only suppress-first --out "$</span>{prefix}.step1a&quot;
  plink --bfile &quot;<span class="math-container">${prefix}" --exclude "$</span>{prefix}.step1a.dupvar&quot; --make-bed --out &quot;<span class="math-container">${prefix}.step1a"
  plink --bfile "$</span>{prefix}.step1a&quot; --snps-only just-acgt --make-bed --out &quot;<span class="math-container">${prefix}.step1b"
  """
  }
  process step1b {
  publishDir params.publish
  input:
  tuple val(sample_name), path(bfiles) from step1a_out
  tuple val(bims), path("${prefix}.step1b.bim") from step1a_bims
  output:
  tuple val("${sample_name}"), path("${sample_name}.step1c.{bed,bim,fam}") into step1b_results
  path("${sample_name}.step1c.log") into step1b_logs
  path("${sample_name}.step1b.snplist.txt") into step1b_snplist
  script:
  """
  awk '{ if ((\\\$5=="T" &amp;&amp; \\\$6=="A")||(\\\$5=="A" &amp;&amp; \\\$6=="T")||(\\\$5=="C" &amp;&amp; \\\$6=="G")||(\\\$5=="G" &amp;&amp; \\\$6=="C")) print \\\$2, "ambig" ; else print \\\$2 ;}' "${prefix}.step1b.bim" | grep ambig &gt; "${prefix}.step1b.snplist.txt"
  plink --bfile "${prefix}.step1b --exclude "${prefix}.step1b.snplist.txt" --make-bed --out "$</span>{prefix}.step1c&quot;
  &quot;&quot;&quot;
  }
  </code></pre>
  <p>The error message is:</p>
  <pre><code>N E X T F L O W  ~  version 20.10.0
  Launching `t4.hf` [zen_picasso] - revision: b0ff8db413
  [-        ] process &gt; step1a -
  [-        ] process &gt; step1b -
  Error executing process &gt; 'step1a (1)'
  
  Caused by:
  [-        ] process &gt; step1a -
  [-        ] process &gt; step1b -
  Error executing process &gt; 'step1a (1)'
  
  Caused by:
    No signature of method: chr() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [DataflowQueue(queue=[DataflowVariable(value=1), DataflowVariable(value=2), DataflowVariable(value=3), DataflowVariable(value=4), DataflowVariable(value=5), DataflowVariable(value=6), DataflowVariable(value=7), DataflowVariable(value=8), DataflowVariable(value=9), DataflowVariable(value=10), DataflowVariable(value=11), DataflowVariable(value=12), DataflowVariable(value=13), DataflowVariable(value=14), DataflowVariable(value=15), DataflowVariable(value=16), DataflowVariable(value=17), DataflowVariable(value=18), DataflowVariable(value=19), DataflowVariable(value=20), DataflowVariable(value=21), DataflowVariable(value=22), DataflowVariable(value=groovyx.gpars.dataflow.operator.PoisonPill@28c22659)])]
  Possible solutions: run(), run(), any(), is(java.lang.Object), use([Ljava.lang.Object;), tap(groovy.lang.Closure)
  
  Source block:
    prefix=chr&quot;<span class="math-container">${chr_names}"
    """
    plink --bfile "$</span>{sample_name}&quot; --chr &quot;<span class="math-container">${chr_names}" --out "$</span>{prefix}&quot; --make-bed
    plink --bfile &quot;<span class="math-container">${prefix}" --list-duplicate-vars ids-only suppress-first --out "$</span>{prefix}.step1a&quot;
    plink --bfile &quot;<span class="math-container">${prefix}" --exclude "$</span>{prefix}.step1a.dupvar&quot; --make-bed --out &quot;<span class="math-container">${prefix}.step1a"
    plink --bfile "$</span>{prefix}.step1a&quot; --snps-only just-acgt --make-bed --out &quot;${prefix}.step1b&quot;
    &quot;&quot;&quot;
  
  Tip: when you have fixed the problem you can continue the execution adding the option `-resume` to the run command line
  </code></pre>
  <p>If I use &quot;prefix=chr&quot;${chr_names}&quot; &quot; inside the code block (&quot;&quot;&quot;) it shows: unknown variable 'prefix'</p>
  
Tags: <plink><nextflow>
Title: Nextflow: No signature of Method: chr() is applicable for argument types; unknown variable
ThreadText: # Nextflow: No signature of Method: chr() is applicable for argument types; unknown variable
  
  (Asked by: username_0 on 2021-03-21)
  
  I was trying to use plink in nextflow. My first process will split the input (single bed|bim|fam file) into 22 chromosomes (each with bed|bim|fam files) which would be used in subsequent processes. My code and error log is below. Any help?
  
  ```
  params.dir='data/'
  params.publish="output2/"
  Channel
  .fromFilePairs("${params.dir}*.{bed,bim,fam}",size:3)
  .set {data}
  
  Channel
  .of(1..22)
  .set {chr_names}
      
  process step1a {
  publishDir params.publish
  input:
  tuple val(sample_name), path(bfiles) from data
  output:
  tuple val("${prefix}"), path("${prefix}.step1a.{bed,bim,fam}") into step1a_results
  tuple val("${prefix}"), path("${prefix}.step1b.{bed,bim,fam}") into step1a_out
  tuple val("${prefix}"), path("${prefix}.step1b.bim") into step1a_bims
  path("${prefix}.log") into step1a_logs
  path("${prefix}.step1a.dupvar") into step1a_duplicates
  path("${prefix}.step1a.log") into step1a_log
  path("${prefix}.step1b.log") into step1_log
  script:
  prefix=chr"${chr_names}"
  """
  plink --bfile "${sample_name}" --chr "${chr_names}" --out "${prefix}" --make-bed
  plink --bfile "${prefix}" --list-duplicate-vars ids-only suppress-first --out "${prefix}.step1a"
  plink --bfile "${prefix}" --exclude "${prefix}.step1a.dupvar" --make-bed --out "${prefix}.step1a"
  plink --bfile "${prefix}.step1a" --snps-only just-acgt --make-bed --out "${prefix}.step1b"
  """
  }
  process step1b {
  publishDir params.publish
  input:
  tuple val(sample_name), path(bfiles) from step1a_out
  tuple val(bims), path("${prefix}.step1b.bim") from step1a_bims
  output:
  tuple val("${sample_name}"), path("${sample_name}.step1c.{bed,bim,fam}") into step1b_results
  path("${sample_name}.step1c.log") into step1b_logs
  path("${sample_name}.step1b.snplist.txt") into step1b_snplist
  script:
  """
  awk '{ if ((\\\$5=="T" && \\\$6=="A")||(\\\$5=="A" && \\\$6=="T")||(\\\$5=="C" && \\\$6=="G")||(\\\$5=="G" && \\\$6=="C")) print \\\$2, "ambig" ; else print \\\$2 ;}' "${prefix}.step1b.bim" | grep ambig > "${prefix}.step1b.snplist.txt"
  plink --bfile "${prefix}.step1b --exclude "${prefix}.step1b.snplist.txt" --make-bed --out "${prefix}.step1c"
  """
  }
  
  ```
  
  The error message is:
  
  ```
  N E X T F L O W  ~  version 20.10.0
  Launching `t4.hf` [zen_picasso] - revision: b0ff8db413
  [-        ] process > step1a -
  [-        ] process > step1b -
  Error executing process > 'step1a (1)'
  
  Caused by:
  [-        ] process > step1a -
  [-        ] process > step1b -
  Error executing process > 'step1a (1)'
  
  Caused by:
    No signature of method: chr() is applicable for argument types: (org.codehaus.groovy.runtime.GStringImpl) values: [DataflowQueue(queue=[DataflowVariable(value=1), DataflowVariable(value=2), DataflowVariable(value=3), DataflowVariable(value=4), DataflowVariable(value=5), DataflowVariable(value=6), DataflowVariable(value=7), DataflowVariable(value=8), DataflowVariable(value=9), DataflowVariable(value=10), DataflowVariable(value=11), DataflowVariable(value=12), DataflowVariable(value=13), DataflowVariable(value=14), DataflowVariable(value=15), DataflowVariable(value=16), DataflowVariable(value=17), DataflowVariable(value=18), DataflowVariable(value=19), DataflowVariable(value=20), DataflowVariable(value=21), DataflowVariable(value=22), DataflowVariable(value=groovyx.gpars.dataflow.operator.PoisonPill@28c22659)])]
  Possible solutions: run(), run(), any(), is(java.lang.Object), use([Ljava.lang.Object;), tap(groovy.lang.Closure)
  
  Source block:
    prefix=chr"${chr_names}"
    """
    plink --bfile "${sample_name}" --chr "${chr_names}" --out "${prefix}" --make-bed
    plink --bfile "${prefix}" --list-duplicate-vars ids-only suppress-first --out "${prefix}.step1a"
    plink --bfile "${prefix}" --exclude "${prefix}.step1a.dupvar" --make-bed --out "${prefix}.step1a"
    plink --bfile "${prefix}.step1a" --snps-only just-acgt --make-bed --out "${prefix}.step1b"
    """
  
  Tip: when you have fixed the problem you can continue the execution adding the option `-resume` to the run command line
  
  ```
  
  If I use "prefix=chr"${chr\_names}" " inside the code block (""") it shows: unknown variable 'prefix'
  
  **Tags:** plink, nextflow
  
  
  ---
  
  ## 1 answers
  
  ### Answer by username_1 on 2021-03-22. Score: 4 | Accepted answer
  
  The documation re [conditional scripts](https://www.nextflow.io/docs/latest/process.html#conditional-scripts) is useful here:
  
  > Process scripts can contain conditional statements by simply prefixing
  > the script block with the keyword `script:`. By doing that the
  > interpreter will evaluate all the following statements as a code block
  > that must return the script string to be executed.
  
  But the statements don't necessarily need to be conditional. I.e. they can just be declarations like in your example. You get the error 'No signature of Method: chr()' because Nextflow interprets 'chr' as a method call when you use:
  
  ```
  prefix = chr"${chr_name}"
  
  ```
  
  If your intention is to simply add the 'chr' prefix to each chromosome name, you'd need:
  
  ```
  prefix = "chr${chr_name}"
  
  ```
  
  Notice that I changed your variable name. This is because in your code, you still need to feed in the channel of chromosome names. The easiest way to do this is to use the [each qualifier](https://www.nextflow.io/docs/latest/process.html?highlight=script#input-repeaters):
  
  ```
  process myprocess {
  
      input:
      tuple val(sample_name), path(bfiles) from plink_data
      each chr_name from chr_names
  
      script:
      prefix = "chr${chr_name}"
  
      """
      echo "My sample name is: ${sample_name}"
      echo "My prefixed chromosome name is: ${prefix}"
      """
  }
  
  ```
  
  Unless you need chromosome names without the 'chr' prefix, another solution might be to simply add the prefix to each one initially and simply avoid having to prefix them later:
  
  ```
  Channel
      .of(1..22)
      .map { "chr${it}" }
      .set { chr_names }
  
  ```
  
  > **Comments:**
  > **username_0**: It seems process 1 and 2 running in random order. Is there any way to specify that after finishing the first process, the second process will start. Because the outputs of the first process will be the input of the second process. In my case my second process shows error because it does not find an input, which is an output of the first process. Did I clarify the matter?  
  > **username_1**: I suspect the problem arises because you've specified two input and output channels ('step1a_out' and 'step1a_bims'). It's not clear to me why you need the two channels, since the 'step1a_bims' looks like a subset of 'step1a_out'? Please see [understanding how multiple input channels work](https://www.nextflow.io/docs/latest/process.html#process-understand-how-multiple-input-channels-work)  
  > **username_0**: Ohh! Thank you. Just one thing, How could I declare prefix of the previous process output as an input of the current process. I have chr(1-22).step1b.bed|bim|fam as output of process step1a; Now I want to declare only chr(1-22) as input in the step1b process. I want different suffix inside process step1b. I am not sure if I could clarify the issue.  
  > **username_1**: Does my answer to your most recent [question](https://bioinformatics.stackexchange.com/questions/15590/nextflow-ordering-the-execution-of-processes-outputs-of-process-a-are-inputs-o/15594) answer your question?  
  > **username_0**: Yes. Thank you. Still wondering how could I declare prefix (characters before first .) as input in the next process which is the output of the previous process.  
  > **username_1**: No worries at all @username_0. If I understand correctly, the easy way would be to include it in your output tuple as an extra value for your prefix. But if it's already part of (i.e. the prefix) of another value then you could again use the [map operator](https://www.nextflow.io/docs/latest/operator.html#map) to get it back. Perhaps something like: `map { some_name, some_thing -> tuple( some_name.substring(0, some_name.indexOf('.')), some_name, some_thing ) }` ? A concrete example would be great if the above doesn't help.  
  > **username_0**: Thanks a lot @username_1. I tried different ways but failed, maybe because I am new in nextflow. My files are chr1-22.step1b.bed|bim|fam in out_ch1. I need a way to find chr1 to chr22 as prefix for the next input so I can modify the suffixes. for example input chr1-22.step1b.bed|bim|fam --some command --out chr1-22.step1c.bed|bim|fam into out_ch3. Also how can I use subset of the outputs channel. From above example I need only chr1-22.step1b.bim as a $bim --some command to run -out chr1-22.step1b.snp.txt. So far I tried "filter" but failed. Thanks again for helping all the way.  
  > **username_0**: `@username_1`, I tried to filter as: `tuple val(bim), path(bims) from step1a_bim.filter{bim -> bims=~ /*bim/}` But I am getting error `unexpected input:` Also I am still not getting the prefix correctly. Perhaps any example would be helpful. Do you know any training module to run plink, gwas in nextflow?  
  > **username_1**: Sorry @username_0 - I'm not sure I can get you a useful answer without a minimal example of exactly what you're trying to do. On file-like objects you can call `getSimpleName()` to get the prefix, see [check file attributes](https://www.nextflow.io/docs/latest/script.html#check-file-attributes). The problem is that this won't work on a tuple of files. I guess I'm confused as to why you can't just include the chromosome name in the output tuple of the first process? This way you'd avoid having to try and find the prefix in the first place.  
  > **username_1**: Using my answer above as an example, your output declaration could look like: `tuple val(sample_name), val(chr_name), path("${sample_name}.${chr_name}.step1b.{bed,bim,fam}") into step1a_out`. Also, I'm not aware of any good plink/gwas pipelines but you could try having a look here: https://github.com/nextflow-io/awesome-nextflow. HTH.  
  > **username_0**: Thanks a lot. In that case how can I declare inputs in the next process? If I use step1a_out two time (first for bfiles, and then for bim) I got error `Channel 'step1a_out' has been used twice as an input by process 'step1b'`  
  > **username_1**: If I understand correctly, the input declaration for the next process will be basically the same as the first processes' output declaration. If that's the case, you'd need: `tuple val(sample_name), val(chr_name), path(bfiles)`. Since the bfiles tuple will contain the bim  file as the second element, you should be able to access it directly with `${bfiles[1]}`. Alternatively, in your script block, you could unpack the bfiles: `(bed, bim, fam) = bfiles`, then just use `${bim}` as your variable. If these variables don't need to be global, consider instead: `def (bed, bim, fam) = bfiles`. HTH.  
  > **username_0**: Thanks a lot `@username_1` . It works. Just one thing. How could I specify output directory of my results? I tried `params.publish='output2'` then in each process `publishDir params.publish`. I got only link of the output files in `output2`. How could I get actual result files in my desired directory? Again thanks a lot for helping me all the way.  
  > **username_0**: Ohh! I got it. I just need to mention `mode: 'copy'` in `publishDir` declaration. Thanks!  
  
  ---
  
  