Nextflow error: can not invoke method minus () on null object 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=&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;${t1}.{bed,fam,bim}" into test1_results
script:
output_file = "${t1}&quot;
base = plk1[0].baseName
&quot;&quot;&quot;
module load plink
plink --bfile $t1 --maf 0.05 --make-bed --out ${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 '${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}
&quot;&quot;&quot;
}
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( &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;${sample_name}-t1"), path("${sample_name}-t1.{bed,bim,fam}&quot;) into test1_results

    &quot;&quot;&quot;
    plink \\
        --bfile &quot;${sample_name}" \\
        --maf 0.05 \\
        --make-bed \\
        --out "${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;${sample_name}-t2"), path("${sample_name}-t2.{bed,bim,fam}&quot;) into test2_results

    &quot;&quot;&quot;
    plink \\
        --bfile &quot;${sample_name}" \\
        --maf 0.01 \\
        --make-bed \\
        --out "${sample_name}-t2&quot;
    &quot;&quot;&quot;
}

If you need to reference each bfile separately, you could just unpack the tuple and reference each file accordingly:
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;${sample_name}-t1"), path("${sample_name}-t1.{bed,bim,fam}&quot;) into test1_results

    &quot;&quot;&quot;
    plink \\
        --bed &quot;${bed}" \\
        --bim "${bim}&quot; \\
        --fam &quot;${fam}" \\
        --maf 0.05 \\
        --make-bed \\
        --out "${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;${sample_name}-t2"), path("${sample_name}-t2.{bed,bim,fam}&quot;) into test2_results

    &quot;&quot;&quot;
    plink \\
        --bed &quot;${bed}" \\
        --bim "${bim}&quot; \\
        --fam &quot;${fam}" \\
        --maf 0.01 \\
        --make-bed \\
        --out "${sample_name}-t2&quot;
    &quot;&quot;&quot;
}

Note that in the first example, bfiles could be replaced with &quot;*&quot; 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.