Skip to content
Snippets Groups Projects
common.wdl 2 KiB
Newer Older
Ruben Vorderman's avatar
Ruben Vorderman committed
task objectMd5 {
    Object the_object
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    command {
        cat ${write_object(the_object)} |  md5sum - | sed -e 's/  -//'
    }
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    output {
        String md5sum = read_string(stdout())
    }
Cats's avatar
Cats committed

    runtime {
        memory: 1
    }
Ruben Vorderman's avatar
Ruben Vorderman committed
}

task mapMd5 {
    Map[String,String] map
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    command {
Cats's avatar
Cats committed
        cat ${write_map(map)} | md5sum - | sed -e 's/  -//'
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    output {
        String md5sum = read_string(stdout())
    }
Cats's avatar
Cats committed

    runtime {
        memory: 1
    }
Ruben Vorderman's avatar
Ruben Vorderman committed
}

task stringArrayMd5 {
    Array[String] stringArray
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    command {
Cats's avatar
Cats committed
        set -eu -o pipefail
        echo ${sep=',' stringArray} | md5sum - | sed -e 's/  -//'
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    output {
Cats's avatar
Cats committed
        String md5sum = read_string(stdout())
    }

    runtime {
        memory: 1
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
}

task concatenateTextFiles {
    Array[File] fileList
    String combinedFilePath
    Boolean? unzip=false
    Boolean? zip=false
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    command {
        set -e -o pipefail
        ${"mkdir -p $(dirname " + combinedFilePath + ")"}
Ruben Vorderman's avatar
Ruben Vorderman committed
        ${true='zcat' false= 'cat' unzip} ${sep=' ' fileList} \
        ${true="| gzip -c" false="" zip} > ${combinedFilePath}
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    output {
        File combinedFile = combinedFilePath
    }
Cats's avatar
Cats committed

    runtime {
        memory: 1
    }
Ruben Vorderman's avatar
Ruben Vorderman committed
}

# inspired by https://gatkforums.broadinstitute.org/wdl/discussion/9616/is-there-a-way-to-flatten-arrays
task flattenStringArray {
    Array[Array[String]] arrayList
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    command {
Cats's avatar
Cats committed
        for line in $(echo ${sep=', ' arrayList}) ; \
        do echo $line | tr -d '"[],' ; done
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    output {
        Array[String] flattenedArray = read_lines(stdout())
    }
Cats's avatar
Cats committed

    runtime {
        memory: 1
    }
Ruben Vorderman's avatar
Ruben Vorderman committed
}

task appendToStringArray {
    Array[String] array
    String string
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    command {
        echo "${sep='\n' array}
        ${string}"
    }
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    output {
        Array[String] out_array = read_lines(stdout())
    }
Cats's avatar
Cats committed

    runtime {
        memory: 1
    }
}

task createLink {
    File inputFile
    String outputPath

    command {
        ln -sf ${inputFile} ${outputPath}
    }

    output {
        File link = outputPath
    }
Ruben Vorderman's avatar
Ruben Vorderman committed
}