Skip to content
Snippets Groups Projects
common.wdl 2.38 KiB
Newer Older
Cats's avatar
Cats committed
task AppendToStringArray {
    Array[String] array
    String string
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    command {
Cats's avatar
Cats committed
        echo "${sep='\n' array}
        ${string}"
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
        Array[String] outArray = read_lines(stdout())
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Cats's avatar
Cats committed

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

Cats's avatar
Cats committed
# This task will fail if the MD5sum doesn't match the file.
task CheckFileMD5 {
    File file
    String MD5sum

    command {
        set -e -o pipefail
        MD5SUM=$(md5sum ${file} | cut -d ' ' -f 1)
        [ $MD5SUM = ${MD5sum} ]
    }
}

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

Ruben Vorderman's avatar
Ruben Vorderman committed
    command {
Cats's avatar
Cats committed
        set -e -o pipefail
        ${"mkdir -p $(dirname " + combinedFilePath + ")"}
        ${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 {
Cats's avatar
Cats committed
        File combinedFile = combinedFilePath
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Cats's avatar
Cats committed

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

Cats's avatar
Cats committed
task CreateLink {
    # Making this of type File will create a link to the copy of the file in the execution
    # folder, instead of the actual file.
    String inputFile
    String outputPath
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    command {
Cats's avatar
Cats committed
        ln -sf ${inputFile} ${outputPath}
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
        File link = outputPath
Cats's avatar
Cats 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 {
Cats's avatar
Cats committed
        Array[String] flattenedArray = read_lines(stdout())
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Cats's avatar
Cats committed

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

Cats's avatar
Cats 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 {
Cats's avatar
Cats committed
        String md5sum = read_string(stdout())
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Cats's avatar
Cats committed

    runtime {
        memory: 1
    }
Cats's avatar
Cats committed

task ObjectMd5 {
    Object the_object
Cats's avatar
Cats committed

Ruben Vorderman's avatar
Ruben Vorderman committed
    command {
Cats's avatar
Cats committed
        cat ${write_object(the_object)} |  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())
Ruben Vorderman's avatar
Ruben Vorderman committed
    }
Cats's avatar
Cats committed

    runtime {
        memory: 1
    }
Cats's avatar
Cats committed
task StringArrayMd5 {
    Array[String] stringArray
Cats's avatar
Cats committed
        set -eu -o pipefail
        echo ${sep=',' stringArray} | md5sum - | sed -e 's/  -//'
Cats's avatar
Cats committed
        String md5sum = read_string(stdout())
Cats's avatar
Cats committed

    runtime {
        memory: 1
    }
}