<p>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:</p>
<pre><code>workflow test {
  Map[String, String] my_map = {
    &quot;a&quot;: &quot;foo&quot;,
    &quot;b&quot;: &quot;bar&quot;,
    &quot;c&quot;: &quot;quux&quot;
  }

  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] }
  }
}
</code></pre>

CC BY-SA 4.0
2021-06-09T16:52:39.277Z
2021-06-09T16:52:39.277Z
Xophmeister
<p>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 <code>draft-2</code> 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:</p>
<pre><code>task extract_keys {
  Map[String, String] map
  
  command {
    cut -f1 ${write_map(map)}
  }

  output {
    Array[String] keys = read_lines(stdout())
  }
}
</code></pre>
<p>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:</p>
<pre><code>workflow test {
  Map[String, String] my_map = {
    &quot;a&quot;: &quot;foo&quot;,
    &quot;b&quot;: &quot;bar&quot;,
    &quot;c&quot;: &quot;quux&quot;
  }

  call extract_keys { input: map = my_map }

  scatter (k in extract_keys.keys) {
    call task_foo { input: k = k, s = my_map[k] }
  }
}
</code></pre>
<blockquote>
<p>Call input and runtime attributes evaluation failed for task_foo</p>
</blockquote>
<p>I don't have access to the full error message or the logs, unfortunately. The frontend I'm using hides these away.</p>
<p>(Incidentally, I'm aware that you can scatter over maps, although it's undocumented, per <a href="https://github.com/openwdl/wdl/issues/106#issuecomment-356047538" rel="nofollow noreferrer">https://github.com/openwdl/wdl/issues/106#issuecomment-356047538</a>. This code is just illustrative; I wish to do other things, such as <code>length</code> and <code>cross</code>, that <em>only</em> accept arrays.)</p>
<p>Is it not possible to scatter over the output of a previous task?</p>

<wdl>
Extracting WDL map keys as a task
# Extracting WDL map keys as a task

(Asked by: username_0 on 2021-06-09)

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?

**Tags:** wdl

---

## 1 answers

### Answer by username_0 on 2021-06-09. Score: 4 | Accepted answer

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] }
  }
}


---

