We've moved!
For WDL questions, see the WDL specification and WDL docs.
For Cromwell questions, see the Cromwell docs and please post any issues on Github.

appending a string to optinal parameters

Hi, I'm trying to append --covar ${var} to an optional list of variables. What do you suggest for syntax?

Below seems like it probably wouldn't give me the correct output...

task test {
   File input
   File output
   Array[String]? covariates

   command {
      mytool --in ${input}${" --covar " + sep=" " covariates} --out ${output}

   output {
      File out = ${output}.txt

Best Answers


  • KateNKateN Cambridge, MAMember, Broadie, Moderator admin

    To add an element to an array, you will likely need to implement an entirely separate task. Below is a sample task that uses python to join together two arrays:

    task append_array {
      Array[Int] input_array
      Array[Int] elements_to_add
      command {
        python <<CODE
        for x in [${sep="," input_array}]:
        for x in [${sep="," elements_to_add}]:
      output {
        Array[Int] new_array = read_lines(stdout())
    workflow w {
      call append_array { input:

    You can use a task like this to concatenate your optional array with --covar ${var}.

  • pradeepnpradeepn MGHMember

    Thanks for the prompt reply!

    I tried running the example above but it didn't seem to recognize the inputs even though they are specified in the wdl.

    pradeep% cromwell run append_array.wdl
    [2016-04-27 14:40:04,319] [info] Slf4jLogger started
    [2016-04-27 14:40:04,341] [info] RUN sub-command
    [2016-04-27 14:40:04,341] [info]   WDL file: append_array.wdl
    [2016-04-27 14:40:04,342] [info]   Inputs: append_array.inputs
    ERROR: Unable to process inputs
    Inputs does not exist: append_array.inputs
    pradeep% java -jar /Applications/wdltool/wdltool0.1.jar inputs append_array.wdl
  • KateNKateN Cambridge, MAMember, Broadie, Moderator admin

    After a second look through your question, I believe I have answered the wrong question in my above response. You have an Array of optional variables, covariates, and you want it to add --covar in front of each item in the array as it passes the array in to your command. The syntax for that is:

    ${sep=' --covar ' covariates}

    Thus, if your array is ["a", "b", "c"], Cromwell will translate the above script into --covar a --covar b --covar c

  • KateNKateN Cambridge, MAMember, Broadie, Moderator admin

    Ah, and your problem when running the above WDL is that you need to specify an inputs file. As all the actual input variables are declared and defined within the task/workflow, the inputs json will be empty, but you do still need it. Run wdltool.jar inputs to generate the empty json file.

Sign In or Register to comment.