Handling optional workflow input

Hello. Here is the simple example of workflow with optional input:

workflow wf {
    String? inn
    call tsk_grep { input: input_381012639=inn }
    }

task tsk_grep {
    String? input_381012639
    command { ps aux | grep j${"a" + input_381012639}
    }
}

When i do not specify any input for workflow(json file below):

{
}

i get an the error:
wdl4s.WdlExpressionException: Could not resolve inn as a scatter variable, namespace, call, or declaration

But when my workflow looks like this:

workflow wf {
    call tsk_grep
    }

task tsk_grep {
    String? input_381012639
    command { ps aux | grep j${"a" + input_381012639}
    }
}

Cromwell works as expected executing ps aux | grep j.
Is this a bug or i can only use optional variables inside of task scope?

Answers

  • KateNKateN Cambridge, MAMember, Broadie, Moderator

    Optional variables, at this time, can only be used in the task scope. You can declare the value of the optional task-level variable directly from your json, using:

    {
    "wf.tsk_grep.input_381012639" : "value"
    }
    

    Or, specify a blank json to not use a value for the optional input. This method requires deleting the inn variable entirely.

    A second option allows you to either pass in a fixed workflow level variable or not. Declare inn without the optional modifier, ?, then you can call your task with or without specifying the input value:

    call tsk_grep{ input : input_381012639=inn }
    call tsk_grep
    

    In this method, you would have to declare a value for inn in your json, but not one for the input_381012639.

Sign In or Register to comment.