Help needed with channels

Hi,
I am quite new to Nextflow and I came across a problem that I couldn’t solve. I am trying to modify a channel in workflow using operators and then use this modified channel as an input to a process.

This is the error message produced:

Oops... Pipeline execution stopped with the following message: No signature of method: Script_6f445ad3976f9afa$_runScript_closure1$_closure2$_closure24.call() is applicable for argument types: (ArrayList) values: [[barcode01, [HS8, HS4, HS2, HS3, HS7, HS5, HS1, HS6], [53322, 222510, 384953, 385964, ...]]]
Possible solutions: any(), any(), any(groovy.lang.Closure), each(groovy.lang.Closure), tap(groovy.lang.Closure), any(groovy.lang.Closure)
ERROR ~ Invalid method invocation `call` with arguments: [barcode01, [HS8, HS4, HS2, HS3, HS7, HS5, HS1, HS6], [53322, 222510, 384953, 385964, 534053, 847716, 1674914, 3964070]] (java.util.ArrayList) on _closure24 type

 -- Check '.nextflow.log' file for details

This is how i modify the channel using operators:

CLUSTER.out.cluster_fastas
            .map { barcode, target, clusters ->
                def total_low_count = clusters.findAll { it.countFasta() < params.min_reads_per_cluster }
                                    .sum { it.countFasta() } ?: 0
            total_low_count > 0 ? tuple(barcode, target, total_low_count) : null
            }
            .dump(pretty: true) // Only barcode/target combos with low-counts
            .filter { it != null }
            .dump(pretty: true) // Confirm filtering worked
            .groupTuple ( by: [0] ) // Group by barcode
            .dump(pretty: true) // Grouped by barcode
            .map { barcode, values -> 
                def target_counts = values.collectEntries { [it[1], it[2]] } // {target: count}
                tuple(barcode, target_counts)
                }
            .dump(pretty: true) // Final structure
            .set { low_clusters_counts }

The low_cluster_counts is then used in a process:

EXPORT_FILTER_STATS( export_stats, low_clusters_counts )

The process looks like this:

process EXPORT_FILTER_STATS {
    conda '/home/melichv/miniconda3/envs/amplicons'
    publishDir "${params.output}/${sample}/export", pattern: "*.csv", mode: 'copy'

    input:
        path export_stats
        tuple val ( sample ), val ( hs_index ), val ( low_clusters_counts )
    
    output:
        tuple val( "${sample}" ), path ( "*.csv" )

    """
        python ${export_stats} -i "${workflow.launchDir}/${params.output}" -l ${low_clusters_count} -h ${hs_index}
    """
}

The goal is that the process will run only once per barcode (but in my example there is only 1 barcode, so it is desired to run only once in total). The channel will consists of tuples with 3 elements (value of barcode, list of HS names and list of numbers)

Could someone please help me figure this one out?

I think your issue is in the 2nd map. Your first map outputs a 3-tuple [barcode, target, total_low_count], but the 2nd map is expecting a 2-tuple [barcode, values]. The groupTuple operator will take output like [ barcode, target, total_low_count] and make it [ barcode, [target1, target2, ...], [total_low_count1, total_low_count2, ...]], which is still a 3-tuple.