This is a test version of Biostars. For the public version, visit https://www.biostars.org.
Filter array of files to one file

One step in my workflow produces File[] and I need to filter to grab just one File for the next step. I am trying to use glob without much success. Any hints?

cwl

2 answers

Michael R. Crusoe point out a couple of solutions:

At workflow level:

in:
  single_file:
    source: other_step/array_of_files
    valueFrom: $(self[0])

So this was something already answered by @Michael in one of the other posts? Generally good to link to the original when you do this.

Also accept your answer (green check mark) to provide closure to this question.

valueFrom: $( self.filter(file => !!file.basename.match(/^.*.ids.txt$/)).pop() )

Add an ExpressionTool step to filter:

cwlVersion: v1.0
class: ExpressionTool

requirements: { InlineJavascriptRequirement: {} }

inputs:
  files:
    type: File[]

expression: |
    ${ return {"ids": inputs.files.filter(file => !!file.basename.match(/^.*\.ids\.txt$/)).pop()}; }

outputs:
  ids:
    type: File

Log in to answer this question.