Constructing a default value for a tool input

Hello,

I am looking to define a default value for a file input (metadata in the below example) in a CWL tool definition, using value of another input. I’ve seen examples for constructing string inputs using javascript but not sure if I can do something similar for File inputs.

Wanted to check if something as follows is a valid solution:

inputs:
  inputDir:
    type: Directory
    inputBinding:
      position: 1
      prefix: --inputdirectory
  metadata:
    type: File
    default: $(inputs.inputDir.path) + "something.csv" #the default location for this file if not provided by a user
    inputBinding:
      position: 2
      prefix: --sample-sheet

Thanks.
Sehrish

Hello Sehrish,

Seems like this tool description is passing an entire directory to the tool and that you want to specify a single file within it for a particular command line option.

This is a bit irregular for CWL. Ideally each individual file or groups of files would have their own inputs. Can you explain further why the Directory is used?

One can have a default value for a type: File using a class: File that has a location (URL or relative path to the CWL description) set, but I don’t think that is what you are trying to do here.

For completeness sake, here is a default File example:

  metadata:
    type: File
    default:
      class: File
      location: ./metadata.csv  # so next to this CWL description in the same directory

Hi Michael,

Thanks for the response.

The tool definition I am working on expects a directory input. metadata is one of the files inside this directory for which there can be a default value that can be extracted from the path that is specified for inputDir.

Example

If my input value for inputDir is, /foo/bar/. I’d like to define the metadata default value to be foo/bar/something.csv.
Is this something that can be done leveraging javascript?

If this input directory contains only a few files/folders and they have separate value to the workflow (either because you reuse them without the rest of the directory later, or you want to assemble this input directory from components) then you might want to consider making them explicit separate inputs and assemble them using InitialWorkDirRequirement. Then you will know the exact path to the metadata CSV and can provide that to the tool without asking the user.

Otherwise you can try this:

inputs:
  metadata_path:
    doc: path within the provided InputDir to the sample sheet CSV
    type: string?
    default: something.csv
    inputBinding:
       prefix: --sample-sheet=$(inputs.inputDir.path)/

If the tool doesn’t accept --sample-sheet with the = then try this:

inputs:
  metadata_path:
    doc: path within the provided InputDir to the sample sheet CSV
    type: string?
    default: something.csv

arguments:
  - prefix: --sample-sheet
    valueFrom: $(inputs.inputDir.path)/$(inputs.metadata_path)

Thanks a lot, Michael. For this particular tool, the second option (using arguments) would work best.

The input directory has quite a few number of files (raw sequencing data - bcls).
One of those files is something.csv for which there is always a fixed location. So I thought to rather set a default for it, instead of leaving it to the user.

1 Like