Bioinformatics Asked by Xophmeister on July 5, 2021
I want to get the array of keys from a map data structure, so I can perform array-based functions against the map in subsequent tasks. I am limited to draft-2
Workflow Description Language (WDL), so I don’t have access to the newer spec’s extraction functions. I thought I could achieve this by writing a task:
task extract_keys {
Map[String, String] map
command {
cut -f1 ${write_map(map)}
}
output {
Array[String] keys = read_lines(stdout())
}
}
This task works just fine and, as far as I can tell, returns the array of map keys. However, when I try to feed this array into subsequent tasks, I get an error:
workflow test {
Map[String, String] my_map = {
"a": "foo",
"b": "bar",
"c": "quux"
}
call extract_keys { input: map = my_map }
scatter (k in extract_keys.keys) {
call task_foo { input: k = k, s = my_map[k] }
}
}
Call input and runtime attributes evaluation failed for task_foo
I don’t have access to the full error message or the logs, unfortunately. The frontend I’m using hides these away.
(Incidentally, I’m aware that you can scatter over maps, although it’s undocumented, per https://github.com/openwdl/wdl/issues/106#issuecomment-356047538. This code is just illustrative; I wish to do other things, such as length
and cross
, that only accept arrays.)
Is it not possible to scatter over the output of a previous task?
I seem to have solved this myself by virtue of the linked undocumented feature (scattering over a map). It turns out you don't need a separate task at all. This works:
workflow test {
Map[String, String] my_map = {
"a": "foo",
"b": "bar",
"c": "quux"
}
scatter (pairs in my_map) {
String keys = pairs.left
# String values = pairs.right
}
scatter (k in keys) {
call task_foo { input: k = k, s = my_map[k] }
}
}
Correct answer by Xophmeister on July 5, 2021
Get help from others!
Recent Questions
Recent Answers
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP