how do I default to /dev/null in CommandLineTool
2
0
Entering edit mode
5.2 years ago

I need to default to /dev/null when calling an application depending on whether input File? is Null

CWL • 1.6k views
ADD COMMENT
0
Entering edit mode

This question is better suited for Stack Overflow.

ADD REPLY
1
Entering edit mode

Fyi, Biostars is an official support platform for CWL.

ADD REPLY
2
Entering edit mode
5.2 years ago

Hello Azat Badretdin,

You'll need to use a CWL Javascript Expression

Here is an example:

cwlVersion: v1.0
class: CommandLineTool

requirements:
  InlineJavascriptRequirement: {}

inputs:
  optional_file: File?

baseCommand: echo

arguments:
  - valueFrom: |
      ${
         if (inputs.optional_file) {
           return inputs.optional_file.path;
         } else {
           return "/dev/null"; }
      }

outputs: []

And how it works in practice:

$ cwltool --quiet 396625.cwl 
/dev/null
{}
$ cwltool --quiet 396625.cwl --optional_file README.md 
/tmp/tmpcpymo708/stg188757bd-0ef9-45b2-a965-0884b73de8b6/README.md
{}
ADD COMMENT
1
Entering edit mode
5.2 years ago

Another solution, using an empty file:

cwlVersion: v1.0
class: CommandLineTool

inputs:
  optional_file:
    type: File
    default:
      class: File
      size: 0
      basename: empty
      contents: "" 
    inputBinding: {}

baseCommand: [ls, -sH]

outputs: []

And the output

$ cwltool --quiet 396625-3.cwl --optional_file README.md 
4 /tmp/tmp7fc9dlpp/stg63bc390d-1944-4a54-9d30-c52210af50d8/README.md
{}
$ cwltool --quiet 396625-3.cwl 
0 /tmp/tmp9mvxth8m/stg3a4b5a05-f856-411c-ba91-f0d912f85a39/empty
{}
ADD COMMENT

Login before adding your answer.

Traffic: 2367 users visited in the last hour
Help About
FAQ
Access RSS
API
Stats

Use of this site constitutes acceptance of our User Agreement and Privacy Policy.

Powered by the version 2.3.6