Get file in Directory

Hi,
I am giving a directory as input and I want the first (and only) file in this directory as its final value. (This because the filename can be different but the location is more standardized.)

This worked with CWL 1.0 not in CWL 1.2:

  indexfolder:
    type: Directory
    doc: "Folder with kallisto index file"
    inputBinding:
      prefix: '--index='
      separate: false
      # Return kallisto index .idx file in the given folder.
      valueFrom: $(self.listing[0].path)

The error I get with CWL 1.2:

60 var self = {
61     "class": "Directory",
62     "location": "file:///home/bart/Projects/UNLOCK/CWL/kallisto/kallisto",
63     "basename": "kallisto",
64     "listing": [
65         {
66             "class": "File",
67             "location": "file:///home/bart/Projects/UNLOCK/CWL/kallisto/kallisto/n402_kallisto.idx",
68             "basename": "n402_kallisto.idx",
69             "size": 346717278,
70             "path": "/tmp/tmpu12jkvjz/stg65a835ae-2df1-4577-b9d1-3682a8853177/kallisto/n402_kallisto.idx",
71             "dirname": "/tmp/tmpu12jkvjz/stg65a835ae-2df1-4577-b9d1-3682a8853177/kallisto",
72             "nameroot": "n402_kallisto",
73             "nameext": ".idx"
74         }
75     ],
76     "path": "/tmp/tmpu12jkvjz/stg65a835ae-2df1-4577-b9d1-3682a8853177/kallisto",
77     "dirname": "/tmp/tmpu12jkvjz/stg65a835ae-2df1-4577-b9d1-3682a8853177"
78 };
79 var runtime = {
80     "cores": 1,
81     "ram": 1024,
82     "tmpdirSize": 1024,
83     "outdirSize": 1024,
84     "tmpdir": "/tmp/tmp1nfrfwpl",
85     "outdir": "/tmp/9z8o6fk4"
86 };
87 (function(){return ((self.path.listing[0]));})()
stdout was: ''
stderr was: 'evalmachine.<anonymous>:87
(function(){return ((self.path.listing[0]));})()
                                      ^

TypeError: Cannot read property '0' of undefined
    at evalmachine.<anonymous>:87:39
    at evalmachine.<anonymous>:87:47
    at Script.runInContext (vm.js:133:20)
    at Script.runInNewContext (vm.js:139:17)
    at Object.runInNewContext (vm.js:322:38)
    at Socket.<anonymous> ([eval]:11:57)
    at Socket.emit (events.js:198:13)
    at addChunk (_stream_readable.js:288:12)
    at readableAddChunk (_stream_readable.js:265:13)
    at Socket.Readable.push (_stream_readable.js:224:10)'

What has changed in 1.2 that it doesn’t work anymore?

(This was inspired from the bowtie2-align.cwl: https://github.com/common-workflow-library/bio-cwl-tools/blob/5f8208fb8b9eb640cec3102a475c0a857748d647/bowtie2/bowtie2_align.cwl)

Hello @bartn. For CWL v1.1+ you will need to use the following https://www.commonwl.org/v1.1/CommandLineTool.html#LoadListingRequirement

I think the following should work for you

requirements:
  LoadListingRequirement:
    loadListing: shallow_listing

Thanks! That indeed works and makes sense

1 Like