-
Notifications
You must be signed in to change notification settings - Fork 308
/
SPEC.md
10794 lines (8350 loc) · 279 KB
/
SPEC.md
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
# Workflow Description Language (WDL)
This is version 1.1.2 of the Workflow Description Language (WDL) specification. It describes WDL `version 1.1`. It introduces a number of new features (denoted by the ✨ symbol) and clarifications to the [1.0](https://github.com/openwdl/wdl/blob/main/versions/1.0/SPEC.md) version of the specification. It also deprecates several aspects of the 1.0 specification that will be removed in the [next major WDL version](https://github.com/openwdl/wdl/blob/wdl-2.0/SPEC.md) (denoted by the 🗑 symbol).
## Revisions
Revisions to this specification are made periodically in order to correct errors, clarify language, or add additional examples. Revisions are released as "patches" to the specification, i.e., the third number in the specification version is incremented. No functionality is added or removed after the initial revision of the specification is ratified.
* [1.1.2](https://github.com/openwdl/wdl/tree/release-1.1.2/SPEC.md): 2024-04-12
* [1.1.1](https://github.com/openwdl/wdl/tree/release-1.1.1/SPEC.md): 2023-10-04
* [1.1.0](https://github.com/openwdl/wdl/tree/release-1.1.0/SPEC.md): 2021-01-29
## Table of Contents
- [Workflow Description Language (WDL)](#workflow-description-language-wdl)
- [Revisions](#revisions)
- [Table of Contents](#table-of-contents)
- [Introduction](#introduction)
- [An Example WDL Workflow](#an-example-wdl-workflow)
- [Executing a WDL Workflow](#executing-a-wdl-workflow)
- [Advanced WDL Features](#advanced-wdl-features)
- [WDL Language Specification](#wdl-language-specification)
- [Global Grammar Rules](#global-grammar-rules)
- [Whitespace](#whitespace)
- [Comments](#comments)
- [Reserved Keywords](#reserved-keywords)
- [Literals](#literals)
- [Types](#types)
- [Primitive Types](#primitive-types)
- [Strings](#strings)
- [Optional Types and None](#optional-types-and-none)
- [Compound Types](#compound-types)
- [Array\[X\]](#arrayx)
- [Pair\[X, Y\]](#pairx-y)
- [Map\[P, Y\]](#mapp-y)
- [🗑 Object](#-object)
- [Custom Types (Structs)](#custom-types-structs)
- [Hidden Types](#hidden-types)
- [Union](#union)
- [Type Conversion](#type-conversion)
- [Primitive Conversion to String](#primitive-conversion-to-string)
- [Type Coercion](#type-coercion)
- [Order of Precedence](#order-of-precedence)
- [Coercion of Optional Types](#coercion-of-optional-types)
- [Struct/Object coercion from Map](#structobject-coercion-from-map)
- [🗑 Limited exceptions](#-limited-exceptions)
- [Declarations](#declarations)
- [Expressions](#expressions)
- [Built-in Operators](#built-in-operators)
- [Unary Operators](#unary-operators)
- [Binary Operators on Primitive Types](#binary-operators-on-primitive-types)
- [Equality of Compound Types](#equality-of-compound-types)
- [Equality and Inequality Comparison of Optional Types](#equality-and-inequality-comparison-of-optional-types)
- [Operator Precedence Table](#operator-precedence-table)
- [Member Access](#member-access)
- [Ternary operator (if-then-else)](#ternary-operator-if-then-else)
- [Function Calls](#function-calls)
- [Expression Placeholders and String Interpolation](#expression-placeholders-and-string-interpolation)
- [Expression Placeholder Coercion](#expression-placeholder-coercion)
- [Concatenation of Optional Values](#concatenation-of-optional-values)
- [🗑 Expression Placeholder Options](#-expression-placeholder-options)
- [`sep`](#sep)
- [`true` and `false`](#true-and-false)
- [`default`](#default)
- [Static Analysis and Dynamic Evaluation](#static-analysis-and-dynamic-evaluation)
- [WDL Documents](#wdl-documents)
- [Versioning](#versioning)
- [Struct Definition](#struct-definition)
- [Import Statements](#import-statements)
- [Import URIs](#import-uris)
- [Importing and Aliasing Structs](#importing-and-aliasing-structs)
- [Task Definition](#task-definition)
- [Task Inputs](#task-inputs)
- [Task Input Localization](#task-input-localization)
- [Special Case: Versioning Filesystem](#special-case-versioning-filesystem)
- [Input Type Constraints](#input-type-constraints)
- [Optional inputs with defaults](#optional-inputs-with-defaults)
- [Private Declarations](#private-declarations)
- [Command Section](#command-section)
- [Expression Placeholders](#expression-placeholders)
- [Stripping Leading Whitespace](#stripping-leading-whitespace)
- [Task Outputs](#task-outputs)
- [Files and Optional Outputs](#files-and-optional-outputs)
- [Evaluation of Task Declarations](#evaluation-of-task-declarations)
- [Runtime Section](#runtime-section)
- [Units of Storage](#units-of-storage)
- [Mandatory `runtime` attributes](#mandatory-runtime-attributes)
- [`container`](#container)
- [`cpu`](#cpu)
- [`memory`](#memory)
- [`gpu`](#gpu)
- [`disks`](#disks)
- [`maxRetries`](#maxretries)
- [`returnCodes`](#returncodes)
- [Reserved `runtime` hints](#reserved-runtime-hints)
- [`maxCpu`](#maxcpu)
- [`maxMemory`](#maxmemory)
- [`shortTask`](#shorttask)
- [`localizationOptional`](#localizationoptional)
- [`inputs`](#inputs)
- [`outputs`](#outputs)
- [Conventions and Best Practices](#conventions-and-best-practices)
- [Metadata Sections](#metadata-sections)
- [Task Metadata Section](#task-metadata-section)
- [Parameter Metadata Section](#parameter-metadata-section)
- [Advanced Task Examples](#advanced-task-examples)
- [Example 1: HISAT2](#example-1-hisat2)
- [Example 2: GATK Haplotype Caller](#example-2-gatk-haplotype-caller)
- [Workflow Definition](#workflow-definition)
- [Workflow Elements](#workflow-elements)
- [Workflow Inputs](#workflow-inputs)
- [Workflow Outputs](#workflow-outputs)
- [Evaluation of Workflow Elements](#evaluation-of-workflow-elements)
- [Fully Qualified Names \& Namespaced Identifiers](#fully-qualified-names--namespaced-identifiers)
- [Call Statement](#call-statement)
- [Computing Call Inputs](#computing-call-inputs)
- [Scatter Statement](#scatter-statement)
- [Conditional Statement](#conditional-statement)
- [Standard Library](#standard-library)
- [Numeric Functions](#numeric-functions)
- [`floor`](#floor)
- [`ceil`](#ceil)
- [`round`](#round)
- [✨ `min`](#-min)
- [✨ `max`](#-max)
- [String Functions](#string-functions)
- [`sub`](#sub)
- [File Functions](#file-functions)
- [`basename`](#basename)
- [`glob`](#glob)
- [Non-standard Bash](#non-standard-bash)
- [`size`](#size)
- [`stdout`](#stdout)
- [`stderr`](#stderr)
- [`read_string`](#read_string)
- [`read_int`](#read_int)
- [`read_float`](#read_float)
- [`read_boolean`](#read_boolean)
- [`read_lines`](#read_lines)
- [`write_lines`](#write_lines)
- [`read_tsv`](#read_tsv)
- [`write_tsv`](#write_tsv)
- [`read_map`](#read_map)
- [`write_map`](#write_map)
- [`read_json`](#read_json)
- [`write_json`](#write_json)
- [`read_object`](#read_object)
- [`read_objects`](#read_objects)
- [`write_object`](#write_object)
- [`write_objects`](#write_objects)
- [String Array Functions](#string-array-functions)
- [`prefix`](#prefix)
- [✨ `suffix`](#-suffix)
- [✨ `quote`](#-quote)
- [✨ `squote`](#-squote)
- [✨ `sep`](#-sep)
- [Generic Array Functions](#generic-array-functions)
- [`length`](#length)
- [`range`](#range)
- [`transpose`](#transpose)
- [`cross`](#cross)
- [`zip`](#zip)
- [✨ `unzip`](#-unzip)
- [`flatten`](#flatten)
- [`select_first`](#select_first)
- [`select_all`](#select_all)
- [Map Functions](#map-functions)
- [✨ `as_pairs`](#-as_pairs)
- [✨ `as_map`](#-as_map)
- [✨ `keys`](#-keys)
- [✨ `collect_by_key`](#-collect_by_key)
- [Other Functions](#other-functions)
- [`defined`](#defined)
- [Input and Output Formats](#input-and-output-formats)
- [JSON Input Format](#json-input-format)
- [Optional Inputs](#optional-inputs)
- [Specifying / Overriding Runtime Attributes](#specifying--overriding-runtime-attributes)
- [JSON Output Format](#json-output-format)
- [JSON Serialization of WDL Types](#json-serialization-of-wdl-types)
- [Primitive Types](#primitive-types-1)
- [Array](#array)
- [Struct and Object](#struct-and-object)
- [Pair](#pair)
- [Pair to Array](#pair-to-array)
- [Pair to Struct](#pair-to-struct)
- [Map](#map)
- [Map to Struct](#map-to-struct)
- [Map to Array](#map-to-array)
- [Appendix A: WDL Value Serialization and Deserialization](#appendix-a-wdl-value-serialization-and-deserialization)
- [Primitive Values](#primitive-values)
- [Compound Values](#compound-values)
- [Array](#array-1)
- [Array serialization by delimitation](#array-serialization-by-delimitation)
- [Array serialization/deserialization using `write_lines()`/`read_lines()`](#array-serializationdeserialization-using-write_linesread_lines)
- [Array serialization/deserialization using `write_json()`/`read_json()`](#array-serializationdeserialization-using-write_jsonread_json)
- [Pair](#pair-1)
- [Homogeneous Pair serialization/deserialization as Array](#homogeneous-pair-serializationdeserialization-as-array)
- [Pair serialization/deserialization using `read_json`/`write_json`](#pair-serializationdeserialization-using-read_jsonwrite_json)
- [Map](#map-1)
- [Map serialization by delimitation](#map-serialization-by-delimitation)
- [Map serialization/deserialization using `write_map()`/`read_map()`](#map-serializationdeserialization-using-write_mapread_map)
- [Map serialization/deserialization using `write_json()`/`read_json()`](#map-serializationdeserialization-using-write_jsonread_json)
- [Struct and Object serialization/deserialization](#struct-and-object-serializationdeserialization)
- [Appendix B: WDL Namespaces and Scopes](#appendix-b-wdl-namespaces-and-scopes)
- [Namespaces](#namespaces)
- [Scopes](#scopes)
- [Global Scope](#global-scope)
- [Task Scope](#task-scope)
- [Workflow Scope](#workflow-scope)
- [Cyclic References](#cyclic-references)
- [Namespaces without Scope](#namespaces-without-scope)
- [Evaluation Order](#evaluation-order)
## Introduction
Workflow Description Language (WDL) is an open, standardized, *human readable and writable* language for expressing tasks and workflows. WDL is designed to be a general-purpose workflow language, but it is most widely used in the field of bioinformatics. There is a large community of WDL users who share their workflows and tasks on sites such as [Dockstore](https://dockstore.org/search?descriptorType=WDL&searchMode=files).
This document provides a detailed technical specification for WDL. Users who are new to WDL may appreciate a more gentle introduction, such as the [learn-wdl](https://github.com/openwdl/learn-wdl) repository.
Here is provided a short example of WDL, after which are several sections that provide the necessary details both for WDL users and for implementers of WDL execution engines:
* [Language Specification](#wdl-language-specification): a description of the WDL grammar and all the parts of the WDL document.
* [Standard Library](#standard-library): a catalog of the functions available to be called from within a WDL document.
* [Input and Output Formats](#input-and-output-formats): a description of the standard input and output formats that must be supported by all WDL implementations.
* [Appendices](#appendix-a-wdl-value-serialization-and-deserialization): Sections with more detailed information about various parts of the specification.
### An Example WDL Workflow
Below is the code for the "Hello World" workflow in WDL. This is just meant to give a flavor of WDL syntax and capabilities - all WDL elements are described in detail in the [Language Specification](#wdl-language-specification).
<details>
<summary>
Example: hello.wdl
```wdl
version 1.1
task hello_task {
input {
File infile
String pattern
}
command <<<
grep -E '~{pattern}' '~{infile}'
>>>
runtime {
container: "ubuntu:latest"
}
output {
Array[String] matches = read_lines(stdout())
}
}
workflow hello {
input {
File infile
String pattern
}
call hello_task {
input: infile, pattern
}
output {
Array[String] matches = hello_task.matches
}
}
```
</summary>
<p>
Example input:
```json
{
"hello.infile": "greetings.txt",
"hello.pattern": "hello.*"
}
```
Example output:
```json
{
"hello.matches": ["hello world", "hello nurse"]
}
```
</p>
</details>
*Note*: you can click the arrow next to the name of any example to expand it and see supplementary information, such as example inputs and outputs.
This WDL document describes a task, called `hello_task`, and a workflow, called `hello`.
* A task encapsulates a Bash script and a UNIX environment and presents them as a reusable function.
* A workflow encapsulates a (directed, acyclic) graph of task calls that transforms input data to the desired outputs.
Both workflows and tasks can accept input parameters and produce outputs. For example, `workflow hello` has two input parameters, `File infile` and `String pattern`, and one output parameter, `Array[String] matches`. This simple workflow calls `task hello_task`, passing through the workflow inputs to the task inputs, and using the results of `call hello_task` as the workflow output.
### Executing a WDL Workflow
To execute this workflow, a WDL execution engine must be used (sometimes called the "WDL runtime" or "WDL implementation"). Some popular WDL execution engines are listed in the [README](https://github.com/openwdl/wdl#execution-engines).
Along with the WDL file, the user must provide the execution engine with values for the two input parameters. While implementations may provide their own mechanisms for launching workflows, all implementations minimally accept [inputs as JSON format](#json-input-format), which requires that the input arguments be fully qualified according to the namespacing rules described in the [Fully Qualified Names & Namespaced Identifiers](#fully-qualified-names--namespaced-identifiers) section. For example:
| Variable | Value |
| ------------- | ------------- |
| hello.pattern | hello.* |
| hello.infile | greetings.txt |
Running the `hello` workflow with these inputs would yield the following command line from the call to `hello_task`:
```sh
grep -E 'hello.*' 'greetings.txt'
```
### Advanced WDL Features
WDL also provides features for implementing more complex workflows. For example, `hello_task` introduced in the previous example can be called in parallel across many different input files using the well-known [scatter-gather](https://en.wikipedia.org/wiki/Vectored_I/O#:~:text=In%20computing%2C%20vectored%20I%2FO,in%20a%20vector%20of%20buffers) pattern:
<details>
<summary>
Example: hello_parallel.wdl
```wdl
version 1.1
import "hello.wdl"
workflow hello_parallel {
input {
Array[File] files
String pattern
}
scatter (path in files) {
call hello.hello_task {
input:
infile = path,
pattern = pattern
}
}
output {
# WDL implicitly implements the 'gather' step, so the output of
# a scatter is always an array with the elements in the same
# order as the input array. Since hello_task.matches is an array,
# all the results will be gathered into an array-of-arrays.
Array[Array[String]] all_matches = hello_task.matches
}
}
```
</summary>
<p>
Example input:
```json
{
"hello_parallel.pattern": "^[a-z_]+$",
"hello_parallel.files": ["greetings.txt", "hello.txt"]
}
```
Example output:
```json
{
"hello.all_matches": [["hi_world"], ["hi_pal"]]
}
```
</p>
</details>
# WDL Language Specification
## Global Grammar Rules
WDL files are encoded in UTF-8, with no byte order mark (BOM).
### Whitespace
Whitespace may be used anywhere in a WDL document. Whitespace has no meaning in WDL, and is effectively ignored.
The following characters are treated as whitespace:
| Name | Dec | Hex |
| ----- | --- | ------ |
| Space | 32 | `\x20` |
| Tab | 9 | `\x09` |
| CR | 13 | `\x0D` |
| LF | 10 | `\x0A` |
### Comments
Comments can be used to provide helpful information such as workflow usage, requirements, copyright, etc. A comment is prepended by `#` and can be placed at the start of a line or at the end of any line of WDL code. Any text following the `#` will be completely ignored by the execution engine, with one exception: within the `command` section, *ALL* text will be included in the evaluated script - even lines prepended by `#`.
There is no special syntax for multi-line comments - simply use a `#` at the start of each line.
<details>
<summary>
Example: workflow_with_comments.wdl
```wdl
# Comments are allowed before version
version 1.1
# This is how you
# write a long
# multiline
# comment
task task_with_comments {
input {
Int number # This comment comes after a variable declaration
}
# This comment will not be included within the command
command <<<
# This comment WILL be included within the command after it has been parsed
cat ~{number * 2}
>>>
output {
Int result = read_int(stdout())
}
runtime {
container: "ubuntu:latest"
}
}
workflow workflow_with_comments {
input {
Int number
}
# You can have comments anywhere in the workflow
call task_with_comments { input: number }
output { # You can also put comments after braces
Int result = task_with_comments.result
}
}
```
</summary>
<p>
Example input:
```json
{
"workflow_with_comments.number": 1
}
```
Example output:
```json
{
"workflow_with_comments.result": 2
}
```
</p>
</details>
### Reserved Keywords
The following (case-sensitive) language keywords are reserved and cannot be used to name declarations, calls, tasks, workflows, import namespaces, struct types, or aliases.
```
Array
Boolean
File
Float
Int
Map
None
Object
Pair
String
alias
as
call
command
else
false
if
in
import
input
left
meta
object
output
parameter_meta
right
runtime
scatter
struct
task
then
true
version
workflow
```
The following keywords should also be considered as reserved - they are not used in the current version of the specification, but they will be used in a future version:
```
Directory
hints
requirements
```
### Literals
Task and workflow inputs may be passed in from an external source, or they may be specified in the WDL document itself using literal values. Input, output, and other declaration values may also be constructed at runtime using [expressions](#expressions) that consist of literals, identifiers (references to [declarations](#declarations) or [call](#call-statement) outputs), built-in [operators](#operator-precedence-table), and [standard library functions](#standard-library).
### Types
A [declaration](#declarations) is a name that the user reserves in a given [scope](#appendix-b-wdl-namespaces-and-scopes) to hold a value of a certain type. In WDL *all* declarations (including inputs and outputs) must be typed. This means that the information about the type of data that may be held by each declarations must be specified explicitly.
In WDL *all* types represent immutable values. For example, a `File` represents a logical "snapshot" of the file at the time when the value was created. It is impossible for a task to change an upstream value that has been provided as an input - even if it modifies its local copy, the original value is unaffected.
#### Primitive Types
The following primitive types exist in WDL:
* A `Boolean` represents a value of `true` or `false`.
* An `Int` represents a signed 64-bit integer (in the range `[-2^63, 2^63)`).
* A `Float` represents a finite 64-bit IEEE-754 floating point number.
* A `String` represents a unicode character string following the format described [below](#strings).
* A `File` represents a file (or file-like object).
* A `File` declaration can have a string value indicating a relative or absolute path on the local file system.
* Within a WDL file, literal values for files may only be local (relative or absolute) paths.
* An execution engine may support other ways to specify [`File` inputs (e.g. as URIs)](#input-and-output-formats), but prior to task execution it must [localize inputs](#task-input-localization) so that the runtime value of a `File` variable is a local path.
<details>
<summary>
Example: primitive_literals.wdl
```wdl
version 1.1
task write_file_task {
command <<<
printf "hello" > hello.txt
>>>
output {
File x = "hello.txt"
}
}
workflow primitive_literals {
call write_file_task
output {
Boolean b = true
Int i = 0
Float f = 27.3
String s = "hello, world"
File x = write_file_task.x
}
}
```
</summary>
<p>
Example input:
```json
{}
```
Example output:
```json
{
"primitive_literals.b": true,
"primitive_literals.i": 0,
"primitive_literals.f": 27.3,
"primitive_literals.s": "hello, world",
"primitive_literals.x": "hello.txt"
}
```
</p>
</details>
##### Strings
A string literal may contain any unicode characters between single or double-quotes, with the exception of a few special characters that must be escaped:
| Escape Sequence | Meaning | \x Equivalent | Context |
| --------------- | ------------ | ------------- | ----------------------------- |
| `\\` | `\` | `\x5C` | |
| `\n` | newline | `\x0A` | |
| `\t` | tab | `\x09` | |
| `\'` | single quote | `\x22` | within a single-quoted string |
| `\"` | double quote | `\x27` | within a double-quoted string |
| `\~` | tilde | `\x7E` | literal `"~{"` |
| `\$` | dollar sign | `\x24` | literal `"${"` |
Strings can also contain the following types of escape sequences:
* An octal escape code starts with `\`, followed by 3 digits of value 0 through 7 inclusive.
* A hexadecimal escape code starts with `\x`, followed by 2 hexadecimal digits `0-9a-fA-F`.
* A unicode code point starts with `\u` followed by 4 hexadecimal characters or `\U` followed by 8 hexadecimal characters `0-9a-fA-F`.
#### Optional Types and None
A type may have a `?` postfix quantifier, which means that its value is allowed to be undefined without causing an error. A declaration with an optional type can only be used in calls or functions that accept optional values.
WDL has a special value `None` whose meaning is "an undefined value". The `None` value has the (hidden) type [`Union`](#hidden-types), meaning `None` can be assigned to an optional declaration of any type.
An optional declaration has a default initialization of `None`, which indicates that it is undefined. An optional declaration may be initialized to any literal or expression of the correct type, including the special `None` value.
<details>
<summary>
Example: optionals.wdl
```wdl
version 1.1
workflow optionals {
input {
Int certainly_five = 5 # an non-optional declaration
Int? maybe_five_and_is = 5 # a defined optional declaration
# the following are equivalent undefined optional declarations
String? maybe_five_but_is_not
String? also_maybe_five_but_is_not = None
}
output {
Boolean test_defined = defined(maybe_five_but_is_not) # Evaluates to false
Boolean test_defined2 = defined(maybe_five_and_is) # Evaluates to true
Boolean test_is_none = maybe_five_but_is_not == None # Evaluates to true
Boolean test_not_none = maybe_five_but_is_not != None # Evaluates to false
Boolean test_non_equal = maybe_five_but_is_not == also_maybe_five_but_is_not
}
}
```
</summary>
<p>
Example input:
```json
{}
```
Example output:
```json
{
"optionals.test_defined": false,
"optionals.test_defined2": true,
"optionals.test_is_none": true,
"optionals.test_not_none": false
}
```
</p>
</details>
For more details, see the sections on [Input Type Constraints](#input-type-constraints) and [Optional Inputs with Defaults](#optional-inputs-with-defaults).
#### Compound Types
A compound type is one that contains nested types, i.e. it is *parameterized* by other types. The following compound types can be constructed. In the examples below `P` represents any of the primitive types above, and `X` and `Y` represent any valid type (including nested compound types).
##### Array[X]
An `Array` represents an ordered list of elements that are all of the same type. An array is insertion ordered, meaning the order in which elements are added to the `Array` is preserved.
An array value can be initialized with an array literal - a comma-separated list of values in brackets (`[]`). A specific zero-based index of an `Array` can be accessed by placing the index in brackets after the declaration name. Accessing a non-existent index of an `Array` results in an error.
<details>
<summary>
Example: array_access.wdl
```wdl
version 1.1
workflow array_access {
input {
Array[String] strings
Int index
}
output {
String s = strings[index]
}
}
```
</summary>
<p>
Example input:
```json
{
"array_access.strings": ["hello", "world"],
"array_access.index": 0
}
```
Example output:
```json
{
"array_access.s": "hello"
}
```
</p>
</details>
<details>
<summary>
Example: empty_array_fail.wdl
```wdl
version 1.1
workflow empty_array_fail {
Array[Int] empty = []
output {
# this causes an error - trying to access a non-existent array element
Int i = empty[0]
}
}
```
</summary>
<p>
Example input:
```json
{}
```
Example output:
```json
{}
```
Test config:
```json
{
"fail": true
}
```
</p>
</details>
An `Array` may have an empty value (i.e. an array of length zero), unless it is declared using `+`, the non-empty postfix quantifier, which represents a constraint that the `Array` value must contain one-or-more elements. For example, the following task operates on an `Array` of `String`s and it requires at least one string to function:
<details>
<summary>
Example: sum_task.wdl
```wdl
version 1.1
task sum {
input {
Array[String]+ ints
}
command <<<
printf ~{sep(" ", ints)} | awk '{tot=0; for(i=1;i<=NF;i++) tot+=$i; print tot}'
>>>
output {
Int total = read_int(stdout())
}
}
```
</summary>
<p>
Example input:
```json
{
"sum.ints": ["0", "1", "2"]
}
```
Example output:
```json
{
"sum.total": 3
}
```
</p>
</details>
Recall that a type may have an optional postfix quantifier (`?`), which means that its value may be undefined. The `+` and `?` postfix quantifiers can be combined to declare an `Array` that is either undefined or non-empty, i.e. it can have any value *except* the empty array.
Attempting to assign an empty array literal to a non-empty `Array` declaration results in an error. Otherwise, the non-empty assertion is only checked at runtime: binding an empty array to an `Array[T]+` input or function argument is a runtime error.
<details>
<summary>
Example: non_empty_optional.wdl
```wdl
version 1.1
workflow non_empty_optional {
output {
# array that must contain at least one Float
Array[Float]+ nonempty1 = [0.0]
# array that must contain at least one Int? (which may have an undefined value)
Array[Int?]+ nonempty2 = [None, 1]
# array that can be undefined or must contain at least one Int
Array[Int]+? nonempty3 = None
Array[Int]+? nonempty4 = [0]
}
}
```
</summary>
<p>
Example input:
```json
{}
```
Example output:
```json
{
"non_empty_optional.nonempty1": [0.0],
"non_empty_optional.nonempty2": [null, 1],
"non_empty_optional.nonempty3": [],
"non_empty_optional.nonempty4": [0.0]
}
```
</p>
</details>
<details>
<summary>
Example: non_empty_optional_fail.wdl
```wdl
version 1.1
workflow non_empty_optional_fail {
# these both cause an error - can't assign empty array value to non-empty Array type
Array[Boolean]+ nonempty3 = []
Array[Int]+? nonempty6 = []
}
```
</summary>
<p>
Example input:
```json
{}
```
Example output:
```json
{}
```
Test config:
```json
{
"fail": true
}
```
</p>
</details>
For more details see the section on [Input Type Constraints](#input-type-constraints).
##### Pair[X, Y]
A `Pair` represents two associated values, which may be of different types. In other programming languages, a `Pair` might be called a "two-tuple".
A `Pair` can be initialized with a pair literal - a comma-separated pair of values in parentheses (`()`). The components of a `Pair` value are accessed using its `left` and `right` accessors.
<details>
<summary>
Example: test_pairs.wdl
```wdl
version 1.1
workflow test_pairs {
Pair[Int, Array[String]] data = (5, ["hello", "goodbye"])
output {
Int five = data.left # evaluates to 5
String hello = data.right[0] # evaluates to "hello"
}
}
```
</summary>
<p>
Example input:
```json
{}
```
Example output:
```json
{
"test_pairs.five": 5,
"test_pairs.hello": "hello"
}
```
</p>
</details>
##### Map[P, Y]
A `Map` represents an associative array of key-value pairs. All of the keys must be of the same (primitive) type, and all of the values must be of the same type, but keys and values can be different types.
A `Map` can be initialized with a map literal - a comma-separated list of key-value pairs in braces (`{}`), where key-value pairs are delimited by `:`. The value of a specific key can be accessed by placing the key in brackets after the declaration name. Accessing a non-existent key of a `Map` results in an error.
<details>
<summary>
Example: test_map.wdl
```wdl
version 1.1
workflow test_map {
Map[Int, Int] int_to_int = {1: 10, 2: 11}
Map[String, Int] string_to_int = { "a": 1, "b": 2 }
Map[File, Array[Int]] file_to_ints = {
"/path/to/file1": [0, 1, 2],
"/path/to/file2": [9, 8, 7]
}
output {
Int ten = int_to_int[1] # evaluates to 10
Int b = string_to_int["b"] # evaluates to 2
Array[Int] ints = file_to_ints["/path/to/file1"] # evaluates to [0, 1, 2]
}
}
```
</summary>
<p>
Example input:
```json
{}
```
Example output:
```json
{
"test_map.ten": 10,
"test_map.b": 2,
"test_map.ints": [0, 1, 2]
}
```
</p>
</details>
<details>
<summary>
Example: test_map_fail.wdl
```wdl
version 1.1
workflow test_map_fail {
Map[String, Int] string_to_int = { "a": 1, "b": 2 }
Int c = string_to_int["c"] # error - "c" is not a key in the map
}
```
</summary>
<p>
Example input:
```json
{}
```
Example output:
```json
{}
```
Test config:
```json
{