To celebrate the release of GATK 4.0, we are giving away free credits for running the GATK4 Best Practices pipelines in FireCloud, our secure online analysis portal. It’s first come first serve, so sign up now to claim your free credits worth $250. Sponsored by Google Cloud. Learn more at https://software.broadinstitute.org/firecloud/documentation/freecredits

scatter across Array[Pair[]]

NicoBxlNicoBxl Member
edited February 2 in Ask the 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.