Attention:
The frontline support team will be unavailable to answer questions on April 15th and 17th 2019. We will be back soon after. Thank you for your patience and we apologize for any inconvenience!

scatter across Array[Pair[]]

NicoBxlNicoBxl Member
edited February 2018 in Ask the Cromwell + WDL Team

Hi,

I've three String arrays that I put in a Array[Pair[]]. I would like to call a task on each of the elements of the new Array[Pair[]] as :

workflow test{
    Array[String] a
    Array[String] b
    Array[String] c
    Array[Pair[String,String,String]] x = zip(a,b,c) 
    scatter (y in x ) {
        call stuff{
            input :
                a=lane.a
                b=lane.b
                c=lane.c
        }
    }   
}

task stuff{
    String a
    String b
    String c
    command {
        echo ${a}" "${b}" "${c}
    }
}

In this example the lines in the call stuff{} will not work (e.g. a=lane.a)

Is there a way to do that ? Or maybe an other design than using Array[Pair[]] to group three arrays ?

Thank you

Answers

  • kshakirkshakir Broadie, Dev ✭✭

    A Pair only contains two members left and right. One can zip-a-zip though to create a structure with three elements.

    For example:

    workflow zip3 {
        Array[String] a = ["1a", "2a", "3a"]
        Array[String] b = ["1b", "2b", "3b"]
        Array[String] c = ["1c", "2c", "3c"]
        Array[Pair[String,String]] inner = zip(b,c)
        Array[Pair[String,Pair[String,String]]] outer = zip(a,inner)
    
        scatter (element in outer) {
    
            # Create a variable to access the "inner" pair
            Pair[String, String] right_pair = element.right
    
            call stuff {
                input:
                    a = element.left,
                    b = right_pair.left,
                    c = right_pair.right
            }
        }
    }
    
    task stuff {
        String a
        String b
        String c
        command {
            echo ${a} ${b} ${c}
        }
        output { String out = read_string(stdout()) }
    }
    
Sign In or Register to comment.