### WDL Workflow Input and Output JSON Source: https://github.com/openwdl/docs/blob/main/getting-started/quickstart.md Examples of the JSON format used to provide inputs to a WDL workflow and the resulting JSON structure returned by the execution engine. ```json { "main.name": "world" } ``` ```json { "messages": [ "Hello, world!", "Hallo, world!", "Hej, world!" ] } ``` -------------------------------- ### Define WDL Tasks and Workflows Source: https://github.com/openwdl/docs/blob/main/getting-started/quickstart.md Demonstrates the structure of a WDL task with input, command, and output sections, and a workflow that uses scatter-gather and conditional logic to execute the task. ```wdl version 1.3 task say_hello { input { String greeting String name } command <<< echo "~{greeting}, ~{name}!" >>> output { String message = read_string(stdout()) } requirements { container: "ubuntu:latest" } } workflow main { input { String name Boolean is_pirate = false } Array[String] greetings = select_all([ "Hello", "Hallo", "Hej", ( if is_pirate then "Ahoy" else None ), ]) scatter (greeting in greetings) { call say_hello { greeting, name, } } output { Array[String] messages = say_hello.message } } ``` -------------------------------- ### Install and Run WDL Documentation Project (Bash) Source: https://github.com/openwdl/docs/blob/main/README.md Commands to install project dependencies, run a development server, and create a production build for the WDL documentation. Requires pnpm or npm. ```bash # Install the project. pnpm install # Run a development server. pnpm run docs:dev # Create a production build in the `.vitepress/dist` folder. pnpm run docs:build ``` -------------------------------- ### WDL Task Output Section Example Source: https://github.com/openwdl/docs/blob/main/language-guide/tasks.md Demonstrates the 'output' section of a WDL task, showing how to declare outputs. Examples include reading from files using standard library functions like 'read_int' and 'glob' to gather files, and evaluating boolean expressions. ```wdl task run { # ... output { # Reads an integer from a file called `threshold.txt`. Int threshold = read_int("threshold.txt") # Gathers a list of CSV files from the task's execution directory. Array[File]+ csvs = glob("*.csv") # Examines an existing variable to evaluate a boolean expression. Boolean two_csvs = length(csvs) == 2 } } ``` -------------------------------- ### File Functions: Glob, Basename, and Size Source: https://context7.com/openwdl/docs/llms.txt Provides examples of common file system operations: matching files with glob patterns, extracting filenames, and calculating file sizes. ```wdl task file_operations { command <<< touch output1.csv output2.csv output3.csv >>> output { # Match files with glob pattern Array[File] csv_files = glob("*.csv") # Get filename without path String name = basename("/path/to/file.txt") # Get filename without extension String stem = basename("/path/to/file.txt", ".txt") # Get file size in GiB Float size_gib = size("large_file.bin", "GiB") } } ``` -------------------------------- ### Full Workflow Example: Calculating Circle Area Source: https://github.com/openwdl/docs/blob/main/design-patterns/linear-chaining/index.md A complete WDL workflow example that calculates the value of Pi in one task and uses that output to compute the area of a circle in a second task. ```wdl version 1.3 task calculate_pi { command <<< python3 -c "import math; print(math.pi)" >>> output { Float pi = read_float(stdout()) } } task calculate_circle_area { input { Float pi Float radius = 5.0 } command <<< bc -l <<< "~{pi} * ~{radius} ^ 2" >>> output { Float area = read_float(stdout()) } } workflow hello { call calculate_pi call calculate_circle_area { input: pi = calculate_pi.pi } output { Float area = calculate_circle_area.area } } ``` -------------------------------- ### WDL Task Requirements Section Example Source: https://github.com/openwdl/docs/blob/main/language-guide/tasks.md Shows the 'requirements' section of a WDL task, used to specify runtime needs. This example includes setting a container image, CPU cores, and memory, highlighting common resource specifications. ```wdl task run { # ... requirements { # Constrain the container within which this task should run. container: "ubuntu:latest", # Ensure that 8 cores are requisitioned. cpu: 8, # Request 16 gibibytes of random-access memory. memory: "16 GiB", } } ``` -------------------------------- ### WDL Task Definition Example Source: https://github.com/openwdl/docs/blob/main/language-guide/tasks.md A representative example of a simple WDL task, including input, command, output, and requirements sections. This demonstrates the basic structure of a WDL task. ```wdl task say_hello { input { String greeting String name } command <<< echo "~{greeting}, ~{name}!" >>> output { String message = read_string(stdout()) } requirements { container: "ubuntu:latest" } } ``` -------------------------------- ### Splitting and merging VCF files using Picard in WDL Source: https://github.com/openwdl/docs/blob/main/design-patterns/multiple-io/index.md A practical example showing a task that produces multiple output files from a single input, and a subsequent task that consumes those multiple outputs to perform a merge operation. ```wdl version 1.3 task split_vcf { input { File vcf } command <<< java -jar picard.jar SplitVcfs I="~{vcf}" SNP_OUTPUT="snp.vcf" INDEL_OUTPUT="indel.vcf" STRICT=false >>> output { File snp_vcf = "snp.vcf" File indel_vcf = "indel.vcf" } } task merge_vcfs { input { File snp_vcf; File indel_vcf } command <<< java -jar picard.jar MergeVcfs I="~{snp_vcf}" I="~{indel_vcf}" O="combined.vcf" >>> output { File combined = "combined.vcf" } } workflow run { input { File vcf } call split_vcf { input: vcf } call merge_vcfs { input: snp_vcf = split_vcf.snp_vcf, indel_vcf = split_vcf.indel_vcf, } output { File combined = merge_vcfs.combined } } ``` -------------------------------- ### Define a WDL Workflow with Conditional Logic and Scatter-Gather Source: https://context7.com/openwdl/docs/llms.txt This example shows how to define a WDL workflow, including inputs, conditional execution, scattering tasks, and gathering results. ```wdl version 1.3 workflow run { input { String name Boolean is_pirate = false } Array[String] greetings = select_all([ "Hello", "Hallo", "Hej", (if is_pirate then "Ahoy" else None), ]) scatter (greeting in greetings) { call say_hello { greeting, name } } output { Array[String] messages = say_hello.message } } ``` -------------------------------- ### Transform and Combine Arrays in WDL Source: https://context7.com/openwdl/docs/llms.txt Provides examples of array transformation using zip, cross, and flatten functions. These are useful for creating paired inputs or flattening nested data structures during workflow execution. ```wdl task array_operations { output { Array[Int] xs = [1, 2, 3] Array[String] ys = ["a", "b", "c"] Array[Pair[Int, String]] zipped = zip(xs, ys) Array[Pair[Int, String]] crossed = cross(xs, ys) Array[Array[Int]] nested = [[1, 2], [3], [4, 5]] Array[Int] flat = flatten(nested) } } ``` -------------------------------- ### WDL Task Command Section Example Source: https://github.com/openwdl/docs/blob/main/language-guide/tasks.md Illustrates the 'command' section of a WDL task, which contains the bash script to be executed. It shows how WDL variables can be interpolated into the script using the '~{variable_name}' syntax. ```wdl task say_hello { input { String greeting String name } command <<< echo "~{greeting}, ~{name}!" >>> # ... } ``` -------------------------------- ### Structs for Custom Data Types Source: https://context7.com/openwdl/docs/llms.txt Defines custom data structures to package complex information. Includes examples of nested structs and checking for the presence of optional fields. ```wdl struct Address { Int street_number String street_address String city String state } struct ContactInformation { String first_name String last_name Address address String? email_address } workflow run { output { ContactInformation john = ContactInformation { first_name: "John", last_name: "Smith", address: Address { street_number: 123, street_address: "Main Street", city: "Somewhere", state: "Foobar", }, } Boolean has_email = defined(john.email_address) } } ``` -------------------------------- ### Call tasks and subworkflows in WDL Source: https://github.com/openwdl/docs/blob/main/language-guide/workflows.md Demonstrates how to invoke tasks within a workflow using the call statement. Includes examples of passing inputs and using the 'as' keyword for task aliasing to avoid naming collisions. ```wdl task stepA { # ... } task stepB { # ... } workflow run { # You can instruct the workflow to run `stepA` by `call`-ing it. call stepA {} # If there are inputs, you can include them within the brackets. call stepB { input: foo = bar } # Normally, if you wanted to call `stepA` again, there would be # a name conflict because the identifier `stepA` would be brought # into the workflow's scope twice. You can use the `as` keyword # to assign the task an alias. call stepA as stepA_again {} } ``` -------------------------------- ### range Function Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/array.md Creates an array of sequential integers starting from 0 up to the specified length. Returns an empty array if the length is 0. ```APIDOC ## range Function ### Description Creates an array of the given length containing sequential integers starting from 0. The length must be >= 0. If the length is 0, an empty array is returned. ### Method N/A (Function Call) ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```wdl Array[Int] indexes = range(5) # `indexes` now contains `[0, 1, 2, 3, 4]`. ``` ### Response #### Success Response (200) - **Array[Int]**: An array containing integers `0..(N-1)`. #### Response Example ```json { "result": [0, 1, 2, 3, 4] } ``` ``` -------------------------------- ### Branch and merge VCF filtering workflow in WDL Source: https://github.com/openwdl/docs/blob/main/design-patterns/branch-and-merge/index.md A practical example of splitting a VCF file, filtering SNPs and INDELs in parallel branches, and merging the results. It utilizes Picard and GATK tools to demonstrate real-world bioinformatics pipeline logic. ```wdl version 1.3 task split_vcf { input { File vcf } command <<< picard SplitVcfs I="~{vcf}" SNP_OUTPUT="snp.vcf" INDEL_OUTPUT="indel.vcf" STRICT=false >>> output { File snp_vcf = "snp.vcf", File indel_vcf = "indel.vcf" } } task filter_snps { input { File vcf } command <<< gatk VariantFiltration -V ~{vcf} -O filtered.vcf --filter-expression "QD < 2.0 || FS > 60.0 || MQ < 40.0 || MQRankSum < -12.5 || ReadPosRankSum < -8.0" --filter-name "snp_filter" >>> output { File filtered_vcf = "filtered.vcf" } } task filter_indels { input { File vcf } command <<< gatk VariantFiltration -V ~{vcf} -O filtered.vcf --filter-expression "QD < 2.0 || FS > 200.0 || ReadPosRankSum <-20.0" --filter-name "indel_filter" >>> output { File filtered_vcf = "filtered.vcf" } } task merge_vcfs { input { File snp_vcf, File indel_vcf } command <<< picard MergeVcfs I="~{snp_vcf}" I="~{indel_vcf}" O="combined.vcf" >>> output { File combined = "combined.vcf" } } workflow run { input { File vcf } call split_vcf { input: vcf } call filter_snps { input: vcf = split_vcf.snp_vcf } call filter_indels { input: vcf = split_vcf.indel_vcf } call merge_vcfs { input: snp_vcf = filter_snps.filtered_vcf, indel_vcf = filter_indels.filtered_vcf } output { File combined = merge_vcfs.combined } } ``` -------------------------------- ### WDL Task Aliasing Example Source: https://github.com/openwdl/docs/blob/main/design-patterns/task-aliasing/index.md This WDL code snippet demonstrates how to use task aliasing to call the same task ('stepA') multiple times within a workflow. It shows how to assign aliases ('first', 'second') and connect their outputs to subsequent tasks ('stepB', 'stepC'). ```wdl # ... task definitions ... workflow run { # `taskA` is run twice—this is enabled using task aliasing. call stepA as first {} call stepA as second {} # `taskB` takes in the output from the `first` task. call stepB { input: in = first.out } # `taskC` takes in the output from the `second` task. call stepC { input: in = second.out } } ``` -------------------------------- ### Explicit vs. Implicit Enum Typing (WDL) Source: https://github.com/openwdl/docs/blob/main/language-guide/enumerations.md Demonstrates how enums can be explicitly typed (e.g., `[Float]`) or implicitly typed by WDL inferring the type from the assigned values. An example of an invalid enum due to mixed types is also shown. ```wdl version 1.3 # Explicitly typed as Float—the Int value 3 coerces to Float enum ExplicitFloat[Float] { Three = 3, Pi = 3.14159 } # Implicitly typed—WDL infers Float from the values enum ImplicitFloat { Three = 3.0, Pi = 3.14159 } # Implicitly typed as String (the default when no values are provided) enum Status { Pending, Running, Complete } # ERROR: Int and String don't coerce to a common type enum Invalid { Number = 42, Text = "hello" } ``` -------------------------------- ### Create sequential integer array with range - WDL Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/array.md The `range` function generates an array of sequential integers starting from 0 up to (but not including) the specified length. The input must be a non-negative integer. An empty array is returned if the length is 0. ```wdl Array[Int] indexes = range(5) # `indexes` now contains `[0, 1, 2, 3, 4]`. ``` -------------------------------- ### Get Map Values with `values` (WDL) Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/map.md The `values` function extracts all values from an input Map and returns them as an Array. It requires WDL v1.2 or later. If the input Map is empty, an empty Array is returned. The order of values in the output Array corresponds to the order of elements in the input Map. ```wdl Array[Y] values(Map[P, Y]) ``` ```wdl Map[String, Int] x = {"a": 1, "b": 2, "c": 3} Array[Int] result = values(x) # `result` now contains [1, 2, 3]. ``` -------------------------------- ### File Functions: Line-based I/O Source: https://context7.com/openwdl/docs/llms.txt Demonstrates reading and writing files as arrays of strings using read_lines and write_lines. ```wdl task process_lines { input { File input_file } command <<< cat ~{input_file} >>> output { Array[String] lines = read_lines("~{input_file}") } } task write_output { output { Array[String] lines = ["first", "second", "third"] File result = write_lines(lines) } } ``` -------------------------------- ### Chaining tasks with multiple I/O in WDL Source: https://github.com/openwdl/docs/blob/main/design-patterns/multiple-io/index.md Demonstrates the syntax for calling tasks and mapping multiple outputs from one task to the specific inputs of a subsequent task. ```wdl workflow run { call stepA {} call stepB { input: in = stepA.out } call stepC { input: in1 = stepB.out1, in2 = stepB.out2 } } ``` -------------------------------- ### Importing WDL Modules Source: https://context7.com/openwdl/docs/llms.txt Demonstrates how to import external WDL files using local paths, URLs, and namespace aliasing to share tasks and workflows. ```wdl # Import from local file with default namespace import "foo.wdl" # Import with custom namespace alias import "bar.wdl" as baz # Import struct with alias import "person.wdl" alias Person as Individual # Import from URL import "http://example.com/lib/stdlib.wdl" ``` -------------------------------- ### Get Basename of File or Directory Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/file.md The basename function returns the name of a file or directory after the last directory separator. It can optionally remove a specified suffix from the filename if it exists. ```wdl String bn = basename("/path/to/file.txt") // `bn` contains "file.txt". String bn = basename("/path/to/file.txt", ".txt") // `bn` contains "file". ``` -------------------------------- ### Define a WDL Task with Inputs, Command, Outputs, and Requirements Source: https://context7.com/openwdl/docs/llms.txt This snippet demonstrates the structure of a WDL task, including defining inputs, the command to execute, expected outputs, and runtime requirements like container images. ```wdl version 1.3 task say_hello { input { String greeting String name } command <<< echo "~{greeting}, ~{name}!" >>> output { String message = read_string(stdout()) } requirements { container: "ubuntu:latest" } } ``` -------------------------------- ### WDL Linear Chaining Pattern for Sequential Task Execution Source: https://context7.com/openwdl/docs/llms.txt Demonstrates the linear chaining pattern in WDL, where the output of one task is directly used as the input for the next task in a sequence. ```wdl version 1.3 task calculate_pi { command <<< python3 -c "import math; print(math.pi)" >>> output { Float pi = read_float(stdout()) } } task calculate_circle_area { input { Float pi Float radius = 5.0 } command <<< bc -l <<< "~{pi} * ~{radius} ^ 2" >>> output { Float area = read_float(stdout()) } } workflow hello { call calculate_pi call calculate_circle_area { input: pi = calculate_pi.pi } output { Float area = calculate_circle_area.area } } ``` -------------------------------- ### Linear Task Chaining in WDL Source: https://github.com/openwdl/docs/blob/main/design-patterns/linear-chaining/index.md Demonstrates the basic syntax for chaining tasks linearly by mapping the output of a previous task to the input of a subsequent task within a workflow block. ```wdl workflow run { call stepA {} call stepB { input: in = stepA.out } call stepC { input: in = stepB.out } } ``` -------------------------------- ### Define WDL Task Outputs from Files and Standard Output Source: https://context7.com/openwdl/docs/llms.txt Shows how to declare outputs for a WDL task, including reading values from files, capturing standard output, and using glob patterns to gather multiple files. ```wdl task run_analysis { command <<< echo "42" > threshold.txt touch results_001.csv results_002.csv >>> output { # Read an integer from a file Int threshold = read_int("threshold.txt") # Gather files matching a glob pattern Array[File]+ csvs = glob("*.csv") # Compute derived values Boolean two_csvs = length(csvs) == 2 } } ``` -------------------------------- ### Define WDL Task Inputs with Defaults and Optional Values Source: https://context7.com/openwdl/docs/llms.txt Illustrates how to define input variables for a WDL task, including required inputs, inputs with default values, and optional inputs that can be null. ```wdl task process_data { input { # Required input - must be supplied by caller File input_file # Input with default value - can be overridden Int threads = 4 # Optional input - may be None if not provided String? sample_name } command <<< process --input ~{input_file} --threads ~{threads} >>> } ``` -------------------------------- ### Get Enum Value - WDL Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/enum.md The 'value' function in WDL returns the underlying value associated with an enum choice. It takes an enum choice of any type as input and returns its corresponding value. This is useful for accessing the raw data represented by an enum. ```wdl enum Color { Red = "#FF0000", Green = "#00FF00", Blue = "#0000FF" } enum Priority { Low = 1, Medium = 5, High = 10 } workflow example { Color color = Color.Red Priority priority = Priority.High String choice_name = "~{color}" # "Red" String hex_value = value(color) # "#FF0000" Int priority_num = value(priority) # 10 } ``` -------------------------------- ### Importing WDL files and components Source: https://github.com/openwdl/docs/blob/main/language-guide/imports.md Demonstrates various import strategies in WDL, including local file imports, namespace aliasing, struct aliasing, and remote URI imports. These techniques help organize workflows and prevent naming collisions. ```wdl # Importing from a file `foo.wdl` with the namespace `foo`. import "foo.wdl" # Importing form a file `bar.wdl` but defining its namespace as `baz`. import "bar.wdl" as baz # Importing the `Person` struct from `person.wdl` directly into the # current namespace with the name `Individual`.. import "person.wdl" alias Person as Individual # Importing from a URI. import "http://example.com/lib/stdlib.wdl" ``` -------------------------------- ### Perform String Manipulation with WDL Source: https://context7.com/openwdl/docs/llms.txt Demonstrates common string operations in WDL including substitution, splitting, pattern matching, and searching. These functions are essential for parsing file paths and processing text-based data within tasks. ```wdl task string_operations { output { String original = "I like chocolate" String modified = sub(original, "like", "love") String csv = "a,b,c" Array[String] parts = split(csv, ",") String? match = find("Hello, world!", "e..o") Boolean has_r1 = matches("sample1234_R1.fastq", "_R1") } } ``` -------------------------------- ### File Functions: JSON Serialization Source: https://context7.com/openwdl/docs/llms.txt Shows how to serialize and deserialize JSON data, including mapping JSON content directly into WDL structs. ```wdl struct Person { String name Int age } task json_io { input { File json_file } output { # Read JSON into struct Person person = read_json(json_file) # Write struct to JSON Array[Person] people = [ Person { name: "Jane Doe", age: 29 }, Person { name: "John Doe", age: 28 } ] File output_json = write_json(people) } } ``` -------------------------------- ### Document WDL Tasks with Metadata Source: https://context7.com/openwdl/docs/llms.txt Illustrates how to add meta and parameter_meta blocks to WDL tasks to provide documentation, author information, and help text for pipeline parameters. ```wdl task documented_task { input { File input_file } command <<< process ~{input_file} >>> output { File result = "output.txt" } meta { authors: ["Jane Doe "], description: "This task processes input files and produces results." } parameter_meta { input_file: { help: "The input file to process" }, result: { help: "The processed output file" } } } ``` -------------------------------- ### Specify WDL Task Runtime Requirements for Resources and Containers Source: https://context7.com/openwdl/docs/llms.txt Demonstrates how to define runtime requirements for a WDL task, such as specifying a container image, CPU cores, memory, and disk space. ```wdl task compute_intensive { command <<< heavy_computation >>> requirements { # Container for portability container: "ubuntu:latest" # Request 8 CPU cores cpu: 8 # Request 16 GiB of RAM memory: "16 GiB" # Request 100 GiB of disk space disk: "100 GiB" } } ``` -------------------------------- ### File Functions: Primitive I/O Source: https://context7.com/openwdl/docs/llms.txt Covers reading primitive values (String, Int, Float) from files or standard output streams within a task. ```wdl task capture_output { command <<< echo "Hello, World!" > message.txt echo "42" > count.txt echo "3.14159" > pi.txt >>> output { String message = read_string("message.txt") Int count = read_int("count.txt") Float pi = read_float("pi.txt") # Read from stdout/stderr String stdout_content = read_string(stdout()) } } ``` -------------------------------- ### Handle Optional Values with WDL Array Functions Source: https://context7.com/openwdl/docs/llms.txt Utilizes select_first and select_all to manage optional types (T?) within arrays. These functions help in providing default values or filtering out null entries in pipeline configurations. ```wdl task optional_handling { output { Int? maybe_five = 5 Int? maybe_none = None Int? maybe_three = 3 Int first = select_first([maybe_none, maybe_five, maybe_three]) Int with_default = select_first([], 42) Array[Int] non_null = select_all([maybe_five, maybe_none, maybe_three]) } } ``` -------------------------------- ### Use Utility Functions for Validation and Measurement Source: https://context7.com/openwdl/docs/llms.txt Demonstrates the use of defined() to check for the presence of optional values and length() to determine the size of arrays, maps, or strings. ```wdl task utility_operations { input { String? optional_name } output { Boolean has_name = defined(optional_name) Array[Int] xs = [1, 2, 3] Map[String, Int] m = {"a": 1, "b": 2} String s = "ABCDE" Int arr_len = length(xs) Int map_len = length(m) Int str_len = length(s) } } ``` -------------------------------- ### Define and Use WDL Structs (WDL) Source: https://github.com/openwdl/docs/blob/main/language-guide/structs.md Demonstrates the definition of custom struct types 'Address' and 'ContactInformation' in WDL. It also shows how to instantiate and use these structs within a WDL workflow, including nested structs and optional fields. ```wdl # Create a custom type named `Address`. struct Address { Int street_number String street_address Array[Int] zip_code String city String state Array[Int]+? gate_code } # Create a custom type named `ContactInformation`. It can contain # other structs, like it does here with the `address` field. struct ContactInformation { String first_name String last_name Address address String? email_address } # An example workflow using these structs. workflow run { output { ContactInformation john = ContactInformation { first_name: "John", last_name: "Smith", address: Address { street_number: 123, street_address: "Main Street", zip_code: [0, 1, 2, 3, 4 ], city: "Somewhere", state: "Foobar", gate_code: None, }, } Boolean has_email = defined(john.email_address) } } ``` -------------------------------- ### Define meta and parameter_meta in WDL Source: https://github.com/openwdl/docs/blob/main/language-guide/tasks.md Demonstrates the structure of meta and parameter_meta sections within a WDL task. The meta section provides general task information, while parameter_meta provides specific help text for task inputs and outputs. ```wdl task run { # ... meta { authors: ["Foo Bar ", "Baz Quux "], description: "This is a task that accomplishes ...", } parameter_meta { in: { help: "The `in` parameter defines an input file that is used to ..." }, out: { help: "The `out` parameter defines an output file that contains ..." } } # ... } ``` -------------------------------- ### Branch and Merge Pattern in WDL Source: https://context7.com/openwdl/docs/llms.txt Illustrates parallel execution by splitting a task into multiple branches and merging the results back into a single output. This pattern is essential for optimizing pipeline performance. ```wdl version 1.3 workflow run { input { File vcf } call split_vcf { input: vcf } # Branch: filter SNPs and INDELs in parallel call filter_snps { input: vcf = split_vcf.snp_vcf } call filter_indels { input: vcf = split_vcf.indel_vcf } # Merge: combine filtered results call merge_vcfs { input: snp_vcf = filter_snps.filtered_vcf, indel_vcf = filter_indels.filtered_vcf, } output { File combined = merge_vcfs.combined } } ``` -------------------------------- ### Variables and Types in WDL Source: https://context7.com/openwdl/docs/llms.txt Shows the declaration of primitive and compound types, including required inputs, default values, and optional variables. It also demonstrates private variable binding. ```wdl workflow run { input { # Unbound declaration - required input Int radius # Bound declaration - default value Float pi = 3.14 # Optional variable - may be None File? reference } # Private bound declaration Int three = 1 + 2 output { Float six = 2 * three } } ``` -------------------------------- ### WDL Scatter-Gather Pattern for Parallel Task Execution Source: https://context7.com/openwdl/docs/llms.txt Shows the scatter-gather pattern in WDL, where a task is executed in parallel for each item in an array, and the results are collected into a single array. ```wdl workflow run { input { Array[File] files } # Scatter: run stepA for each file in parallel scatter(file in files) { call stepA { input: in = file } } # Gather: stepA.out is automatically coerced to Array call stepB { input: files = stepA.out } } ``` -------------------------------- ### Implement basic branching and merging in WDL Source: https://github.com/openwdl/docs/blob/main/design-patterns/branch-and-merge/index.md Demonstrates the fundamental structure of a WDL workflow where a single task output feeds into two parallel tasks, which are then merged into a final task. This pattern ensures the final task waits for both parallel branches to complete. ```wdl workflow run { call stepA {} call stepB { input: in = stepA.out } call stepC { input: in = stepA.out } call stepD { input: in1 = stepB.out, in2 = stepC.out } } ``` -------------------------------- ### File Functions: TSV Operations Source: https://context7.com/openwdl/docs/llms.txt Illustrates reading tab-separated value files into objects and writing arrays of arrays as TSV files. ```wdl task tsv_operations { output { # Read TSV with header into objects Array[Object] objects = read_tsv("data.tsv", true) # Write array of arrays as TSV Array[Array[String]] data = [ ["one", "two", "three"], ["un", "deux", "trois"] ] File result = write_tsv(data) } } ``` -------------------------------- ### Implement Scatter-Gather Workflow in WDL Source: https://github.com/openwdl/docs/blob/main/design-patterns/scatter-gather/index.md This WDL workflow demonstrates the scatter-gather pattern by scattering a task across an array of input files and gathering the resulting outputs into a subsequent task. The scatter block automatically collects outputs into an array, which is then passed as input to the gather step. ```wdl workflow run { inputs { Array[File] files } # Perform `stepA` for each of the inputs in parallel (scatter). scatter(file in files) { call stepA { input: in = file } } # Collect the results from the scatter (gather). # # Note that the outputs from `stepA` are automatically coerced # into an `Array` that you can pass in elsewhere. call stepB { input: files = stepA.out } } ``` -------------------------------- ### Define Workflow JSON Inputs and Outputs Source: https://context7.com/openwdl/docs/llms.txt Shows the standard JSON structure used to provide inputs to a WDL workflow and the resulting output format produced after execution. ```json // Input JSON { "main.name": "world", "main.is_pirate": true } // Output JSON { "messages": [ "Hello, world!", "Hallo, world!", "Hej, world!", "Ahoy, world!" ] } ``` -------------------------------- ### Select First Non-None Value (WDL) Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/array.md The `select_first` function finds the first non-`None` value in an array of optional values. An optional default value can be provided, which is returned if the array is empty or contains only `None`s. If no default is given and such a condition occurs, an error is raised. It accepts a non-empty array of optional values or an array and a default value. ```wdl X select_first(Array[X?]+) ``` ```wdl X select_first(Array[X?], X) ``` ```wdl Int? maybe_five = 5 Int? maybe_none = None Int? maybe_three = 3 Int result1 = select_first([maybe_five, maybe_none, maybe_three]) # `result1` now contains `5`. Int result2 = select_first([maybe_none, maybe_five, maybe_three]) # `result2` now contains `5`. Int result3 = select_first([], 42) # `result3` now contains `42`. ``` -------------------------------- ### Calculate file or directory size in WDL Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/file.md Calculates the size of a file, directory, or compound structure in bytes or a specified unit. Returns a Float representing the total size. ```wdl Float size = size("foo.txt") ``` -------------------------------- ### WDL Call Statement for Executing Tasks and Subworkflows Source: https://context7.com/openwdl/docs/llms.txt Illustrates the WDL `call` statement, used to execute tasks or subworkflows and connect their outputs to subsequent steps. It also shows aliasing tasks. ```wdl workflow run { # Call a task with no inputs call stepA {} # Call with inputs specified call stepB { input: foo = bar } # Use alias to avoid naming conflicts call stepA as stepA_again {} } ``` -------------------------------- ### Implement conditional logic in WDL workflows Source: https://github.com/openwdl/docs/blob/main/language-guide/workflows.md Shows how to use if/else statements to control the execution of tasks based on workflow inputs or previous task outputs. Demonstrates the use of select_first to handle optional outputs from conditional branches. ```wdl task stepA { } task stepA_alternate { } task stepB { } workflow run { input { Boolean alternate_execution_mode } if (alternate_execution_mode) { call stepA_alternate {} } else { call stepA {} } if (select_first([ stepA.qc_passed, stepA_alternate.qc_passed, ])) { call stepB {} } } ``` -------------------------------- ### Write Array of Strings to File (WDL) Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/file.md The `write_lines` function takes an array of strings and writes them to a file, with each string becoming a line terminated by a newline character ('\n'). If the input array is empty, an empty file is created. The function returns a File object representing the newly created file. ```wdl File write_lines(Array[String]) # Example: Array[String] lines = ["first", "second", "third"] File result = write_lines(lines) ``` -------------------------------- ### WDL v1.3: New split Standard Library Function Source: https://github.com/openwdl/docs/blob/main/reference/upgrade-guide.md Introduces the `split` function to divide a string into an array of substrings using a specified delimiter pattern. A native alternative to external tools like `awk` or `cut` for string manipulation. ```wdl Array[String] parts = split("a,b,c", ",") # ["a", "b", "c"] ``` -------------------------------- ### Capture standard output and error streams in WDL Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/file.md Functions to retrieve the standard output or standard error of a command as a File. These files are typically stored in temporary directories to prevent naming conflicts. ```wdl String message = read_string(stdout()) String err = read_string(stderr()) ``` -------------------------------- ### Combine elements from two arrays with zip - WDL Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/array.md The `zip` function creates an array of pairs by combining elements from two input arrays at the same index. Both input arrays must have identical lengths, or an error will be raised. Empty input arrays yield an empty result. ```wdl Array[Int] xs = [1, 2, 3] Array[String] ys = ["a", "b", "c"] Array[Pair[Int, String]] result = zip(xs, ys) # `result` now contains [(1, "a"), (2, "b"), (3, "c")]. ``` -------------------------------- ### Join Paths into an Absolute Path Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/file.md The join_paths function combines two or more path components into a single absolute path. It supports joining a base path with a single string, a base path with an array of strings, or an array of path components. ```wdl File path = join_paths(["/usr", "bin", "env"]) // `path` points to `/usr/bin/env`. ``` -------------------------------- ### Read File Lines as Array of Strings (WDL) Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/file.md The `read_lines` function reads a file line by line, removing trailing newline characters, and returns each line as an element in a String array. If the file is empty, an empty array is returned. The order of lines in the output array matches their order in the file. ```wdl Array[String] read_lines(File) # Example: Array[String] lines = read_lines("foo.txt") ``` -------------------------------- ### Declare WDL workflow variables Source: https://github.com/openwdl/docs/blob/main/language-guide/variables.md Demonstrates how to define input, private, and output variables within a WDL workflow. It covers bound declarations with default values, unbound declarations requiring caller input, and optional file types. ```wdl workflow run { input { Int radius Float pi = 3.14 File? reference } Int three = 1 + 2 output { Float six = 2 * three } } ``` -------------------------------- ### Glob Files Matching a Pattern Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/file.md The glob function returns an array of files that match a given glob string pattern. The pattern is evaluated relative to the task's execution directory, similar to Bash's glob expansion. ```wdl Array paths = glob("*.py") // `paths` contains all files with the `.py` extension in the current directory. ``` -------------------------------- ### Branching Logic with Else and Else If in WDL Source: https://github.com/openwdl/docs/blob/main/design-patterns/conditional-statement/index.md Shows how to implement complex branching logic using else if and else clauses. This is useful for selecting specific analysis modes based on input parameters. ```wdl workflow run { input { String mode } if (mode == "fast") { call fast_analysis {} } else if (mode == "thorough") { call thorough_analysis {} } else { call standard_analysis {} } } ``` -------------------------------- ### Separate elements of paired array with unzip - WDL Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/array.md The `unzip` function takes an array of pairs and returns a pair of arrays, separating the left and right elements of each pair. This is the inverse operation of `zip`. An empty input array results in a pair of empty arrays. ```wdl Array[Pair[Int, String]] int_str_arr = [(0, "hello"), (42, "goodbye")] Pair[Array[Int], Array[String]] result = unzip(int_str_arr) # `result` now contains ([0, 42], ["hello", "goodbye"]). ``` -------------------------------- ### Select All Non-None Values (WDL) Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/array.md The `select_all` function filters an array of optional values, returning a new array containing only the non-`None` elements. The order of elements is preserved from the original array. If the input array is empty or contains only `None` values, an empty array is returned. The function takes an `Array[X?]` and returns an `Array[X]`. ```wdl Array[X] select_all(Array[X?]) ``` ```wdl Int? maybe_five = 5 Int? maybe_none = None Int? maybe_three = 3 Array[Int] result = select_all([maybe_five, maybe_none, maybe_three]) # `result` now contains [5, 3]. ``` -------------------------------- ### unzip Function Source: https://github.com/openwdl/docs/blob/main/reference/stdlib/array.md Creates a Pair of Arrays by separating the left and right elements from an array of Pairs. This is the inverse of the zip function. Returns a pair of empty arrays if the input array is empty. ```APIDOC ## unzip Function ### Description Creates a `Pair` of `Arrays`, the first containing the elements from the `left` members of an `Array` of `Pair`s, and the second containing the `right` members. If the array is empty, a pair of empty arrays is returned. This is the inverse of the `zip` function. ### Method N/A (Function Call) ### Endpoint N/A (Function Call) ### Parameters #### Path Parameters None #### Query Parameters None #### Request Body None ### Request Example ```wdl Array[Pair[Int, String]] int_str_arr = [(0, "hello"), (42, "goodbye")] Pair[Array[Int], Array[String]] result = unzip(int_str_arr) # `result` now contains ([0, 42], ["hello", "goodbye"]) ``` ### Response #### Success Response (200) - **Pair[Array[X], Array[Y]]**: A pair where each element is an array of length N. #### Response Example ```json { "result": {"left": [0, 42], "right": ["hello", "goodbye"]} } ``` ```