text: user3839: Hi I was trying to use plink in nextflow and getting the error mentioned in the subject. Here is my code, any help what I am missing. I am new in nextflow, it was ok when input was a single file, but for grouped files, I am getting lost.
  params.dir='data/'
  params.publish="output/"
  Channel
  .fromFilePairs("${params.dir}*.{bed,fam,bim}",size:3){file -> file.baseName}
  .set {plink-data}
      
  process test1{
  publishDir params.publish
  input:
  set t1,file(plk1) from plink-data
  output:
  file "${t1}.{bed,fam,bim}" into test1_results
  script:
  output_file = "${t1}"
  base = plk1[0].baseName
  """
  module load plink
  plink --bfile $t1 --maf 0.05 --make-bed --out ${output_file}
  """
  }
  process test2{
  publishDir params.publish
  input:
  set file(bed), file(fam), file(bim) from test1_results.collect()
  output:
  set t2,file '${plk2}.{bed,fam,bim}' into test2_results
  script:
  output_file = "{t2}"
  base = plk2[0].baseName
  """
  plink --bfile $t2 --maf 0.01 --make-bed --out ${output_file}
  """
  }
  
  
  user10775: Channel names must consist only alphanumeric characters including underscores. Your channel called 'plink-data' contains a hyphen. This is problematic because it is interpreted as a minus() operation to remove 'data' from 'plink'. You get a NullPointerException since 'plink' hasn't been defined. You can test this easily with the following example:
  Channel
      .of(1..23, 'X', 'Y')
      .set { chr-names }
  
  chr-names.view()
  
  Results:
  Cannot invoke method minus() on null object
  
  The solution is to just use an underscore instead of a hyphen:
  Channel
      .of(1..23, 'X', 'Y')
      .set { chr_names }
  
  chr_names.view()
  
  
  Follow-up issues:
  I think if you want to use the bfiles plink option (and I think this is reasonable), I think it makes the most sense to just keep your bfiles in a tuple:
  Channel
      .fromFilePairs( "${params.input_dir}/*.{bed,bim,fam}", size: 3 )
      .set { plink_data }
  
  
  process test1{
  
      publishDir params.publish_dir
  
      module 'plink'
  
      input:
      tuple val(sample_name), path(bfiles) from plink_data
  
      output:
      tuple val("${sample_name}-t1"), path("${sample_name}-t1.{bed,bim,fam}") into test1_results
  
      """
      plink \\
          --bfile "${sample_name}" \\
          --maf 0.05 \\
          --make-bed \\
          --out "${sample_name}-t1"
      """
  }
  
  process test2{
  
      publishDir params.publish_dir
  
      module 'plink'
  
      input:
      tuple val(sample_name), path(bfiles) from test1_results
  
      output:
      tuple val("${sample_name}-t2"), path("${sample_name}-t2.{bed,bim,fam}") into test2_results
  
      """
      plink \\
          --bfile "${sample_name}" \\
          --maf 0.01 \\
          --make-bed \\
          --out "${sample_name}-t2"
      """
  }
  
  If you need to reference each bfile separately, you could just unpack the tuple and reference each file accordingly:
  Channel
      .fromFilePairs( "${params.input_dir}/*.{bed,bim,fam}", size: 3 )
      .map { group_key, files -> tuple( group_key, *files ) }
      .set { plink_data }
  
  
  process test1{
  
      publishDir params.publish_dir
  
      module 'plink'
  
      input:
      tuple val(sample_name), path(bed), path(bim), path(fam) from plink_data
  
      output:
      tuple val("${sample_name}-t1"), path("${sample_name}-t1.{bed,bim,fam}") into test1_results
  
      """
      plink \\
          --bed "${bed}" \\
          --bim "${bim}" \\
          --fam "${fam}" \\
          --maf 0.05 \\
          --make-bed \\
          --out "${sample_name}-t1"
      """
  }
  
  process test2{
  
      publishDir params.publish_dir
  
      module 'plink'
  
      input:
      tuple val(sample_name), path(bed), path(bim), path(fam) from test1_results
  
      output:
      tuple val("${sample_name}-t2"), path("${sample_name}-t2.{bed,bim,fam}") into test2_results
  
      """
      plink \\
          --bed "${bed}" \\
          --bim "${bim}" \\
          --fam "${fam}" \\
          --maf 0.01 \\
          --make-bed \\
          --out "${sample_name}-t2"
      """
  }
  
  Note that in the first example, bfiles could be replaced with "*" since no reference is made to the tuple of bfiles anyway. Also note that the list of files produced using the fromFilesPairs operator are returned in lexicographic order.
  
original_text: 3839: <p>Hi I was trying to use plink in nextflow and getting the error mentioned in the subject. Here is my code, any help what I am missing. I am new in nextflow, it was ok when input was a single file, but for grouped files, I am getting lost.</p>
  <pre><code>params.dir='data/'
  params.publish=&quot;output/&quot;
  Channel
  .fromFilePairs(&quot;${params.dir}*.{bed,fam,bim}&quot;,size:3){file -&gt; file.baseName}
  .set {plink-data}
      
  process test1{
  publishDir params.publish
  input:
  set t1,file(plk1) from plink-data
  output:
  file &quot;<span class="math-container">${t1}.{bed,fam,bim}" into test1_results
  script:
  output_file = "$</span>{t1}&quot;
  base = plk1[0].baseName
  &quot;&quot;&quot;
  module load plink
  plink --bfile <span class="math-container">$t1 --maf 0.05 --make-bed --out $</span>{output_file}
  &quot;&quot;&quot;
  }
  process test2{
  publishDir params.publish
  input:
  set file(bed), file(fam), file(bim) from test1_results.collect()
  output:
  set t2,file '<span class="math-container">${plk2}.{bed,fam,bim}' into test2_results
  script:
  output_file = "{t2}"
  base = plk2[0].baseName
  """
  plink --bfile $</span>t2 --maf 0.01 --make-bed --out ${output_file}
  &quot;&quot;&quot;
  }
  </code></pre>
   10775: <p>Channel names must consist only alphanumeric characters including underscores. Your channel called 'plink-data' contains a hyphen. This is problematic because it is interpreted as a minus() operation to remove 'data' from 'plink'. You get a NullPointerException since 'plink' hasn't been defined. You can test this easily with the following example:</p>
  <pre><code>Channel
      .of(1..23, 'X', 'Y')
      .set { chr-names }
  
  chr-names.view()
  </code></pre>
  <p>Results:</p>
  <pre><code>Cannot invoke method minus() on null object
  </code></pre>
  <p>The solution is to just use an underscore instead of a hyphen:</p>
  <pre><code>Channel
      .of(1..23, 'X', 'Y')
      .set { chr_names }
  
  chr_names.view()
  </code></pre>
  <hr />
  <p><strong>Follow-up issues:</strong></p>
  <p>I think if you want to use the bfiles plink option (and I think this is reasonable), I think it makes the most sense to just keep your bfiles in a tuple:</p>
  <pre><code>Channel
      .fromFilePairs( &quot;${params.input_dir}/*.{bed,bim,fam}&quot;, size: 3 )
      .set { plink_data }
  
  
  process test1{
  
      publishDir params.publish_dir
  
      module 'plink'
  
      input:
      tuple val(sample_name), path(bfiles) from plink_data
  
      output:
      tuple val(&quot;<span class="math-container">${sample_name}-t1"), path("$</span>{sample_name}-t1.{bed,bim,fam}&quot;) into test1_results
  
      &quot;&quot;&quot;
      plink \\
          --bfile &quot;<span class="math-container">${sample_name}" \\
          --maf 0.05 \\
          --make-bed \\
          --out "$</span>{sample_name}-t1&quot;
      &quot;&quot;&quot;
  }
  
  process test2{
  
      publishDir params.publish_dir
  
      module 'plink'
  
      input:
      tuple val(sample_name), path(bfiles) from test1_results
  
      output:
      tuple val(&quot;<span class="math-container">${sample_name}-t2"), path("$</span>{sample_name}-t2.{bed,bim,fam}&quot;) into test2_results
  
      &quot;&quot;&quot;
      plink \\
          --bfile &quot;<span class="math-container">${sample_name}" \\
          --maf 0.01 \\
          --make-bed \\
          --out "$</span>{sample_name}-t2&quot;
      &quot;&quot;&quot;
  }
  </code></pre>
  <p>If you need to reference each bfile separately, you could just unpack the tuple and reference each file accordingly:</p>
  <pre><code>Channel
      .fromFilePairs( &quot;${params.input_dir}/*.{bed,bim,fam}&quot;, size: 3 )
      .map { group_key, files -&gt; tuple( group_key, *files ) }
      .set { plink_data }
  
  
  process test1{
  
      publishDir params.publish_dir
  
      module 'plink'
  
      input:
      tuple val(sample_name), path(bed), path(bim), path(fam) from plink_data
  
      output:
      tuple val(&quot;<span class="math-container">${sample_name}-t1"), path("$</span>{sample_name}-t1.{bed,bim,fam}&quot;) into test1_results
  
      &quot;&quot;&quot;
      plink \\
          --bed &quot;<span class="math-container">${bed}" \\
          --bim "$</span>{bim}&quot; \\
          --fam &quot;<span class="math-container">${fam}" \\
          --maf 0.05 \\
          --make-bed \\
          --out "$</span>{sample_name}-t1&quot;
      &quot;&quot;&quot;
  }
  
  process test2{
  
      publishDir params.publish_dir
  
      module 'plink'
  
      input:
      tuple val(sample_name), path(bed), path(bim), path(fam) from test1_results
  
      output:
      tuple val(&quot;<span class="math-container">${sample_name}-t2"), path("$</span>{sample_name}-t2.{bed,bim,fam}&quot;) into test2_results
  
      &quot;&quot;&quot;
      plink \\
          --bed &quot;<span class="math-container">${bed}" \\
          --bim "$</span>{bim}&quot; \\
          --fam &quot;<span class="math-container">${fam}" \\
          --maf 0.01 \\
          --make-bed \\
          --out "$</span>{sample_name}-t2&quot;
      &quot;&quot;&quot;
  }
  </code></pre>
  <p>Note that in the first example, <code>bfiles</code> could be replaced with <code>&quot;*&quot;</code> since no reference is made to the tuple of bfiles anyway. Also note that the list of files produced using the <a href="https://www.nextflow.io/docs/latest/channel.html#fromfilepairs" rel="nofollow noreferrer">fromFilesPairs operator</a> are returned in lexicographic order.</p>
  