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.

Optional WDL Inputs to Toggle Flag

Hi,

The WDL Spec describes a situation similar to what I'm trying to do here:

https://github.com/broadinstitute/wdl/blob/develop/SPEC.md#prepending-a-string-to-an-optional-parameter

In this case, I assume that Cromwell knows that it should do the "--val" here because of the concatenation with the val parameters contents. However, my problem is that I do not want to concatenate the contents of val, because my flag is a toggle that does not take a parameter. So what I want is that if val is specified, I just want:

python script.py --val

and if it is not, I want

python script.py

How can I accomplish this with the constraints of the WDL language?

Answers

  • danbdanb Member, Broadie ✭✭✭

    You can accomplish this by declaring a boolean flag and then running a bash if statement,

    if [ ${flag} ]
    then
      python script.py --val
    else
      python script.py
    fi
    
  • amr@broadinstitute.orge[email protected] Member, Broadie
    edited March 2018

    Sorry, I neglected to mention that my "python script.py" is wrapped inside a command line python call within the command block of the WDL task, so bash won't work, and apparently command line python doesn't accept expressions, only statements.

  • danbdanb Member, Broadie ✭✭✭

    Could you paste your command?

    so bash won't work, and apparently command line python doesn't accept expressions, only statements.

    I don't think these statements are accurate as ultimately the command is a bash statement, and can be parameterized via an expression.

  • RuchiRuchi Member, Broadie, Moderator, Dev admin

    Alternatively, you could also try:

    task test {
      String? val
      command <<<
        python script.py ${"--val=" + val}
      >>>
    }
    
  • ChrisLChrisL Cambridge, MAMember, Broadie, Dev admin
    edited March 2018

    @Ruchi I think that won't help because the val isn't wanted. Luckily the WDL if then else should help:

    EDIT: Oops, I think you wanted the --val to be --${val}? I think this should work:

    task test {
      String? val
      String cmdLineVal = if isDefined(val) then "--${val}" else ""
      command <<<
        python script.py ${cmdLineVal}
      >>>
    }
    
Sign In or Register to comment.