common-workflow-lab/wdl-cwl-translator

WDL function select_first() is not handled

Closed this issue · 8 comments

Currently, the WDL function select_first() is not translated by the convertor. (https://github.com/openwdl/wdl/blob/main/versions/1.1/SPEC.md#x-select_firstarrayx)

A WDL workflow containing select_first() function can be found here. (https://github.com/biowdl/tasks/blob/develop/bwa.wdl#L82)

Is there a javascript equivalent for the WDL select_first() function?

could I use the find function?

Say, in the case of the example provided in (https://github.com/biowdl/tasks/blob/develop/bwa.wdl#L82):
memory: "~{select_first([memoryGb, estimatedMemoryGb])}G" would be converted to
memory: "${[memoryGb, estimatedMemoryGb].find(mem => mem != None)}G"

kinow commented

Hi @Th3nn3ss

I think in JavaScript it would have to use strings ['memoryGb', 'estimatedMemoryGb'], unless these two are variales declared previously. And the Python None does not exist in JavaScript, so maybe test for null and undefined (or check if the None mentioned in the WDL spec should be treated differently in the wdl-cwl-translator.)

Bruno

Hi @Th3nn3ss

I think in JavaScript it would have to use strings ['memoryGb', 'estimatedMemoryGb'], unless these two are variales declared previously. And the Python None does not exist in JavaScript, so maybe test for null and undefined (or check if the None mentioned in the WDL spec should be treated differently in the wdl-cwl-translator.)

Bruno

OK.
The WDL documentation actually says it returns the first non-None value of an Array with optional values. So I have to find a way for a None to be treated as a Javascript null so it can return the appropriate error message when the expression isn't successful. Errors like error! array contains only None values

mr-c commented

Hi @Th3nn3ss

I think in JavaScript it would have to use strings ['memoryGb', 'estimatedMemoryGb'], unless these two are variales declared previously. And the Python None does not exist in JavaScript, so maybe test for null and undefined (or check if the None mentioned in the WDL spec should be treated differently in the wdl-cwl-translator.)

Bruno

OK.
The WDL documentation actually says it returns the first non-None value of an Array with optional values. So I have to find a way for a None to be treated as a Javascript null so it can return the appropriate error message when the expression isn't successful. Errors like error! array contains only None values

In this case the WDL None will be a CWL/ECMAScript null. Check the existing code in main.py to see how null/existence checks are currently handled.

mr-c commented

Hi @Th3nn3ss

I think in JavaScript it would have to use strings ['memoryGb', 'estimatedMemoryGb'], unless these two are variales declared previously. And the Python None does not exist in JavaScript, so maybe test for null and undefined (or check if the None mentioned in the WDL spec should be treated differently in the wdl-cwl-translator.)

Bruno

memoryGb is an optional input in this example, so it can be referred to as inputs.memoryGb.

estimatedMemoryGb is a "WDL declaration" that isn't bound to any input, so you may want to find another example or simplify the given example for testing.

#32

Is this the required output
ramMin: ${[inputs.memoryGb].find(mem => mem !== null)}G

mr-c commented

Fixed in #150