Request: Add Optional() function for Objects and Maps.
See original GitHub issueHi there.
I would like to request an Optional()
function for map-like objects. If a key is not present in an object, normally a keyError returns. Optional(object.key)
will return None
when the key is not present. I could not find such a thing in the current WDL implementation (but I may have overlooked).
That would be useful in these types of situations:
task exampleTask {
String requiredVariable
String? optionalString = "sensible default here"
Int? optionalInt = 3
Boolean? optionalBool = false
command {
# insertcommandhere
}
}
workflow exampleWf {
Array[Object] objectList
scatter(exampleObject in objectList) {
call exampleTask {
input:
requiredVariable=exampleObject.requiredVariable
optionalString=Optional(exampleObject.optionalString)
optionalInt=Optional(exampleObject.optionalInt)
optionalBool=Optional(exampleObject.optionalBool)
}
}
}
Originally (without optional) your inputs.json would look like this:
{
"exampleWf.objectList":
[
{
"requiredVariable": "Sample1",
"optionalString": "someOption",
"optionalInt": 3,
"optionalBool": false
},
{
"requiredVariable": "Sample2",
"optionalString": "sensible default here",
"optionalInt": 5,
"optionalBool": false
}
]
}
But with Optional()
it can look like this:
{
"exampleWf.objectList":
[
{
"requiredVariable": "Sample1",
"optionalString": "someOption"
},
{
"requiredVariable": "Sample2",
"optionalInt": 5
}
]
}
When there are 10 optional values, this save a lot of typing and unnecessary duplication in the JSON. Why specify all these values if they have sensible defaults? There are quite some command line tools with many optional parameters that this feature seems very useful to me. Real word example:
task centrifugeDownload {
String centrifugeOutput
Array[String] domain
String? seqTaxMap
String? database = "refseq"
String? centrifugeDownloadExecutable = "centrifuge-download"
String? assemblyLevel = "Complete Genome"
String? refseqCategory = "any"
Array[String]? taxIds = ["any"]
Boolean? filterUnplaced = false
Boolean? maskLowComplexRegions = false
Boolean? downloadRnaSeqs = false
Boolean? modifyHeader = false
Boolean? downloadGiMap = false
command {
${centrifugeDownloadExecutable} \
-o ${centrifugeOutput} \
-d ${sep=',' domain} \
-a "${assemblyLevel}" \
-c ${refseqCategory} \
-t ${sep=',' taxIds} \
${true='-r' false='' downloadRnaSeqs} \
${true='-u' false='' filterUnplaced} \
${true='-m' false='' maskLowComplexRegions} \
${true='-l' false='' modifyHeader} \
${true='-g' false='' downloadGiMap} \
${database} \
${">> " + seqTaxMap}
}
}
I happen to have some experience with programming in Scala, so if you give me some pointers, I could possibly implement this myself.
Issue Analytics
- State:
- Created 6 years ago
- Comments:7 (7 by maintainers)
Top GitHub Comments
By convention map values are optional, as there are no restrictions on what the key value can be. The key error is really an access error which is what you would expect to receive in the event of a missing value.
What I think would make a better approach would be a single engine function or modifying an existing one, to test for a key in a map.
@geoffjentry @cjllanwarne has there ever been any talk of including a check like this?
The following works a bit better: