This is a test version of Biostars. For the public version, visit https://www.biostars.org.
How to import environment variables from the system running it (like Ubuntu) to CWL?

Does anyone know if CWL is capable of create a random number to an output file, like the environment variable $RANDOM in UNIX? Or how to import the environment variables of one's system, like in Ubuntu, to CWL?

cwl

1 answer

If you just need a random number i would recommend solving this through a javascript expression.

As an expression tool, this might look like:

cwlVersion: v1.0
class: ExpressionTool

requirements:
  InlineJavascriptRequirement: {}

inputs:
  min:
    type: int
  max:
    type: int

outputs:
  random_integer:
    type: int

expression: |
  ${
    var randomInt;
    var min = Math.ceil(inputs.min);
    var max = Math.floor(inputs.max);
    randomInt = Math.floor(Math.random() * (max - min + 1)) + min;
    return {"random_integer": randomInt};
  }

You can also just add a javascript expression directly into your tool or workflow, without the overhead of an expression tool. The javascript math is plucked from stackoverflow, but it looks like it should provide random integers.

Log in to answer this question.