diff --git a/common.wdl b/common.wdl index d80d47e6d5a964b4ba2637741eeb62b51cecc2f2..863421dc299425d62291943b585e58f457caf861 100644 --- a/common.wdl +++ b/common.wdl @@ -1,12 +1,14 @@ -task objectMd5 { - Object the_object +task AppendToStringArray { + Array[String] array + String string command { - cat ${write_object(the_object)} | md5sum - | sed -e 's/ -//' + echo "${sep='\n' array} + ${string}" } output { - String md5sum = read_string(stdout()) + Array[String] outArray = read_lines(stdout()) } runtime { @@ -14,15 +16,33 @@ task objectMd5 { } } -task mapMd5 { - Map[String,String] map +# This task will fail if the MD5sum doesn't match the file. +task CheckFileMD5 { + File file + String MD5sum command { - cat ${write_map(map)} | md5sum - | sed -e 's/ -//' + set -e -o pipefail + MD5SUM=$(md5sum ${file} | cut -d ' ' -f 1) + [ $MD5SUM = ${MD5sum} ] + } +} + +task ConcatenateTextFiles { + Array[File] fileList + String combinedFilePath + Boolean? unzip = false + Boolean? zip = false + + command { + set -e -o pipefail + ${"mkdir -p $(dirname " + combinedFilePath + ")"} + ${true='zcat' false= 'cat' unzip} ${sep=' ' fileList} \ + ${true="| gzip -c" false="" zip} > ${combinedFilePath} } output { - String md5sum = read_string(stdout()) + File combinedFile = combinedFilePath } runtime { @@ -30,38 +50,32 @@ task mapMd5 { } } -task stringArrayMd5 { - Array[String] stringArray +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 command { - set -eu -o pipefail - echo ${sep=',' stringArray} | md5sum - | sed -e 's/ -//' + ln -sf ${inputFile} ${outputPath} } output { - String md5sum = read_string(stdout()) - } - - runtime { - memory: 1 + File link = outputPath } } -task concatenateTextFiles { - Array[File] fileList - String combinedFilePath - Boolean? unzip=false - Boolean? zip=false +# inspired by https://gatkforums.broadinstitute.org/wdl/discussion/9616/is-there-a-way-to-flatten-arrays +task FlattenStringArray { + Array[Array[String]] arrayList command { - set -e -o pipefail - ${"mkdir -p $(dirname " + combinedFilePath + ")"} - ${true='zcat' false= 'cat' unzip} ${sep=' ' fileList} \ - ${true="| gzip -c" false="" zip} > ${combinedFilePath} + for line in $(echo ${sep=', ' arrayList}) ; \ + do echo $line | tr -d '"[],' ; done } output { - File combinedFile = combinedFilePath + Array[String] flattenedArray = read_lines(stdout()) } runtime { @@ -69,17 +83,15 @@ task concatenateTextFiles { } } -# inspired by https://gatkforums.broadinstitute.org/wdl/discussion/9616/is-there-a-way-to-flatten-arrays -task flattenStringArray { - Array[Array[String]] arrayList +task MapMd5 { + Map[String,String] map command { - for line in $(echo ${sep=', ' arrayList}) ; \ - do echo $line | tr -d '"[],' ; done + cat ${write_map(map)} | md5sum - | sed -e 's/ -//' } output { - Array[String] flattenedArray = read_lines(stdout()) + String md5sum = read_string(stdout()) } runtime { @@ -87,17 +99,16 @@ task flattenStringArray { } } -task appendToStringArray { - Array[String] array - String string + +task ObjectMd5 { + Object the_object command { - echo "${sep='\n' array} - ${string}" + cat ${write_object(the_object)} | md5sum - | sed -e 's/ -//' } output { - Array[String] out_array = read_lines(stdout()) + String md5sum = read_string(stdout()) } runtime { @@ -105,17 +116,19 @@ task appendToStringArray { } } -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 +task StringArrayMd5 { + Array[String] stringArray command { - ln -sf ${inputFile} ${outputPath} + set -eu -o pipefail + echo ${sep=',' stringArray} | md5sum - | sed -e 's/ -//' } output { - File link = outputPath + String md5sum = read_string(stdout()) } -} \ No newline at end of file + + runtime { + memory: 1 + } +}