This is a test version of Biostars. For the public version, visit https://www.biostars.org.
how do I default to /dev/null in CommandLineTool

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

cwl

Fyi, Biostars is an official support platform for CWL.

2 answers

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
{}

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
{}

Log in to answer this question.