String expanding to array after scatter block

I am puzzled by the way scatter works, and especially how it seems to expand a string variable into an array. Here is an example of the code that got me confused:

workflow wf {
  scatter (bam in FastqToBam.out_bam) {
    String sub_strip_path = "/my_hardcoded_path/.*/"
    call do_something{input: in_bam=bam}

  call task2 {
    input: in = do_something.out,
    basename = sub(do_something.out, sub_strip_path, "")  ### <- Oooops, string got expanded b/c scatter

  String sub_strip_path = "/my_hardcoded_path/.*/"  ### Ooops, re-assigning a variable is not allowed

So first of all, I was stupid and defined the sub_strip_path inside the scope of the scatter block and then tried to access it from outside the scope. That sub_strip_path is globally defined is surprising enough, but more so, that the string is expanded into an array after exiting the scatter scope. Then I tried just to re-assign the variable but this is not allowed...

Would I get the expected behaviour of sub_strip_path staying as a string if I had defined it outside the scatter scope? And also should it really be possible to access sub_strip_path outside the scatter scope? This seems like a breach of normal scoping rules.


Best Answer


Sign In or Register to comment.