Nextflow: Singleton list conversion cause quirk behaviour

Created on 11 Dec 2018  路  7Comments  路  Source: nextflow-io/nextflow

Bug report

Minimal example:

    input:
    file input_files from featureCounts_to_merge.collect()

    output:
    file 'merged_gene_counts.txt'

    script:
    //if we only have 1 file, just use cat and pipe output to csvtk. Else join all files first, and then remove unwanted column names.
    def single = input_files instanceof Path ? 1 : input_files.size()
    def merge = (single == 1) ? 'cat' : 'csvtk join -t -f "Geneid,Start,Length,End,Chr,Strand,gene_name"'
    """
    $merge $input_files | csvtk cut -t -f "-Start,-Chr,-End,-Length,-Strand" | sed 's/Aligned.sortedByCoord.out.markDups.bam//g' > merged_gene_counts.txt
    """

Expected behavior and actual behavior

I expect input_files.size() to return the size of the list, e.g. having n elements.

Actually, this depends:

  • if its just one element, it returns a Path object, so path.size() returns the length of the path as a String
  • if its multiple elements, it returns the list size, as expected

Steps to reproduce the problem

See above testcase

Program output

Environment

  • Nextflow version: 18.10.1
  • Java version: 1.8
  • Operating system: no-arch
kinenhancement stale

All 7 comments

What is bla in your example? do you mean input_files ?

Updated the post, yes that's what I meant :-)

OK, this is the problem we discussed right. Therefore with input_files instanceof Path ? 1 : input_files.size() you get the list size, right?

Exactly, I used this now for the RNAseq pipeline in that way :-)

OK. being so I will change the title because it's misleading. The problem is not the File.size method but the fact that a list containing a single value is implicitly converted to the element value, causing that quirk behaviour.

Yes of course :-)

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

Was this page helpful?
0 / 5 - 0 ratings