Skip to content

Commit ca856c2

Browse files
committed
new task for adding integers
1 parent 381cc32 commit ca856c2

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

wdl/tasks/Utility/GeneralUtils.wdl

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -245,6 +245,32 @@ task ConcatenateFiles {
245245
}
246246
}
247247

248+
task AddIntegers {
249+
meta {
250+
description:
251+
"Add an array of integers."
252+
warn:
253+
"Be cautious with large arrays and/or arrays with very large values due to potential integer overflow."
254+
}
255+
input {
256+
Array[Int] integers
257+
}
258+
output {
259+
Int sum = read_int("result.txt")
260+
}
261+
command <<<
262+
set -euxo pipefail
263+
264+
echo ~{sep=' ' integers} \
265+
| awk '{s=0; for(i=1;i<=NF;i++)s+=$i; print s}' \
266+
> result.txt
267+
>>>
268+
runtime {
269+
disks: "local-disk 10 HDD"
270+
docker: "marketplace.gcr.io/google/ubuntu2404:latest"
271+
}
272+
}
273+
248274
struct HelperStructForUnzip {
249275
Array[Pair[String, String]] contents
250276
}

0 commit comments

Comments
 (0)