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.

Best way to have set an optional file argument based on a boolean value?

jonnjonn Member, Broadie, Dev admin
edited December 2018 in Ask the Cromwell + WDL Team

I'm working on a validation WDL and I'm looking for a way to pass in an optional interval file to my tasks based on whether a boolean value is true. I can't make the file optional at the workflow level.

I'm currently doing the following:

Boolean isUsingIntervals = sub(inputBaseName, "Pond.*", "") != "Nex"
File? garbageFile
File? interval_list_final = if !isUsingIntervals then interval_list else garbageFile

This way the interval_list_final gets set to the empty optional File garbageFile in the case I don't want to use it.

However, this seems like I'm doing something wrong. Is there a better way to do this?


  • RuchiRuchi Member, Broadie, Moderator, Dev admin

    Hey @jonn

    Question -- why cant be intervals file be optional?

    Usually, I would recommend the logic to be simply an optional intervals file, where passing in a value for it means to run a workflow using those intervals, and the lack of that file is an indicator to run the workflow without it.

    workflow w {
    File? intervals 
    call someTask { 
        intervalsFile = intervals 
    task someTask {
      File? intervalsFile
      String cmd = if(defined(intervalsFile)) { "--intervals ${intervalsFile}" } else ""
      command {
      echo ${cmd}

    Let me know if this doesn't help your exact case...

  • ChrisLChrisL Cambridge, MAMember, Broadie, Dev admin

    @jonn for now, your garbage file might well be the best solution.

    Hopefully an upcoming new version of WDL will have a better placeholder for empty optionals: None (see https://github.com/openwdl/wdl/pull/263 - and if you watch that PR then you can vote to approve it for the upcoming version of the SPEC when it opens for public voting)

Sign In or Register to comment.