Question: Filter array of files to one file
0
gravatar for eduardo
6 days ago by
eduardo0
eduardo0 wrote:

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 • 90 views
ADD COMMENTlink modified 6 days ago • written 6 days ago by eduardo0
1
gravatar for eduardo
6 days ago by
eduardo0
eduardo0 wrote:

Michael R. Crusoe point out a couple of solutions:

At workflow level:

in:
  single_file:
    source: other_step/array_of_files
    valueFrom: $(self[0])
ADD COMMENTlink written 6 days ago by eduardo0

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.

ADD REPLYlink modified 6 days ago • written 6 days ago by genomax37k

I tried to acknowledge Michael R. Crusoe, but I didn't found a way to link to a specific gitter message. Or were referring to this other post? Converting stdout (File) to string

I made another post because Converting stdout (File) to string was about converting a file to string. The solution is similar.

ADD REPLYlink modified 6 days ago • written 6 days ago by eduardo0

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

ADD REPLYlink written 6 days ago by eduardo0
1
gravatar for eduardo
6 days ago by
eduardo0
eduardo0 wrote:

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
ADD COMMENTlink written 6 days ago by eduardo0
Please log in to add an answer.

Help
Access

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.
Powered by Biostar version 2.3.0
Traffic: 1658 users visited in the last hour