Question: how do I default to /dev/null in CommandLineTool
0
gravatar for Azat Badretdin
10 months ago by
NCBI
Azat Badretdin0 wrote:

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

cwl • 373 views
ADD COMMENTlink modified 10 months ago by Michael R. Crusoe1.8k • written 10 months ago by Azat Badretdin0

This question is better suited for Stack Overflow.

ADD REPLYlink written 10 months ago by Brice Sarver3.5k
1

Fyi, Biostars is an official support platform for CWL.

ADD REPLYlink written 10 months ago by ATpoint36k
2
gravatar for Michael R. Crusoe
10 months ago by
Common Workflow Language project
Michael R. Crusoe1.8k wrote:

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 COMMENTlink written 10 months ago by Michael R. Crusoe1.8k
1
gravatar for Michael R. Crusoe
10 months ago by
Common Workflow Language project
Michael R. Crusoe1.8k wrote:

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 COMMENTlink written 10 months ago by Michael R. Crusoe1.8k
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: 1859 users visited in the last hour