I have this output which is going to do bwa next which is from join operator

[DF122_SO11378_A03, DF122_SO11378, DF122_SO11378_A03.norm.merged.fq, DF122_SO11378_A03.final.gfa, DF122_SO11378_A03.final.fasta]

in this case, pair_id is DF122_SO11378_A03, plate_id is DF122_SO11378, fq is DF122_SO11378_A03.norm.merged.fq, DF122_SO11378_A03.final.gfa is gfa DF122_SO11378_A03.final.fasta is fa

I have following code like this

process bwa {

     tuple val(pair_id), val(plate_id), path(fq), path(gfa), path(fa) from align_in

     path "*bam" into bam
     tuple val(pair_id), val(plate_id), path ("*.csv") into metrics

     if [ -s $fa ]; then
     bwa index $fa

     bwa mem $fa $fq \
      | samtools view -bh -F2048 - \
      | samtools sort > ${pair_id}.bam

     samtools depth -a ${pair_id}.bam > ${pair_id}.depth.csv
     samtools view -c ${pair_id}.bam >${pair_id}.count.csv
     touch ${pair_id}.depth.csv
     touch ${pair_id}.count.csv
     touch ${pair_id}.bam

However, now my upstream work flow changed a little, for some sample they have more than one gfa and fasta output like this

[DF122_SO11378_A04, DF122_SO11378, DF122_SO11378_A04.norm.merged.fq, [DF122_SO11378_A04.2.final.gfa, DF122_SO11378_A04.final.gfa], [DF122_SO11378_A04.2.final.fasta, DF122_SO11378_A04.final.fasta]]

in this case, pair_id is DF122_SO11378_A04, plate_id is DF122_SO11378, fq is DF122_SO11378_A04.norm.merged.fq, [DF122_SO11378_A04.2.final.gfa, DF122_SO11378_A04.final.gfa] is gfa, [DF122_SO11378_A04.2.final.fasta, DF122_SO11378_A04.final.fasta] is fa

But some samples still have one gfa and fasta as shown earlier.

How can I adapt my bwa process to handle such situations?

I am using DSL1.

  • $\begingroup$ I think I can use transpose operator to make the list flat, and use the downstream pipeline. So the problem is currently solved. $\endgroup$
    – cautree
    Apr 7, 2023 at 12:44
  • $\begingroup$ You can put the details in an answer, and then accept your own answer as the solution. That'll help anyone in the same situation later. $\endgroup$
    – Jesse
    Apr 7, 2023 at 13:04
  • $\begingroup$ Note that there's no reference to the GFA file in the script block of the process. Also, testing if the FASTA file is empty is probably unnecessary. Ideally, this should be performed upstream so as to not execute tasks that just create empty (placeholder) files. $\endgroup$
    – Steve
    Apr 7, 2023 at 13:44

1 Answer 1


If you're looking for the transposition, you could use the transpose operator to get what you want. But to handle the variable output, you would need to first check what types you have. For this, you could use something like the following for example:

    .map { pair_id, plate_id, fastq, gfa, fasta ->

        def gfa_files = gfa instanceof Path ? [gfa] : gfa
        def fasta_files = fasta instanceof Path ? [fasta] : fasta

        tuple( pair_id, plate_id, fastq, gfa_files, fasta_files )

Note that the old DSL1 is no longer supported.


Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.