Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding initial version of conditional unit test WDL #29

Merged
merged 9 commits into from
Feb 5, 2025
63 changes: 63 additions & 0 deletions conditionalTest/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
# Conditional Statements WDL Workflow

## Overview
A workflow that demonstrates the usage of conditional statements in WDL. The workflow processes sample information using structs and demonstrates different types of conditional operations including if statements in scatter blocks and mutually exclusive conditional blocks.

## Workflow Components

### Struct: `SampleInfo`
Defines the structure for sample information with the following fields:
- `name`: String
- `quality_score`: Float
- `type`: String

### Workflow: `conditional_example`
The main workflow that demonstrates various conditional operations.

**Inputs:**
- `samples`: Array[SampleInfo] containing structured sample data
- `quality_threshold`: Float threshold for high-quality samples

**Outputs:**
- `final_summary`: String containing the processing summary
- `qc_report`: File containing detailed QC information for all samples

**Conditional Operations Demonstrated:**
1. If statement within scatter (processing high-quality samples)
2. Multiple mutually exclusive conditional blocks (WDL 1.0 style branching)
3. Usage of select_all() with conditional outputs
4. Usage of select_first() for mutually exclusive task outputs

### Tasks:
1. `process_high_quality`: Processes samples that meet quality threshold
2. `run_qc_report`: Generates QC report for all samples
3. `summarize`: Creates summary based on number of processed samples

## Usage
```bash
# Execute with cromwell
java -jar cromwell.jar run conditionalTest.wdl -i inputs.json

# Execute with miniwdl
miniwdl run conditionalTest.wdl -i inputs.json
```

## Purpose
This workflow serves as a test case for:
- Conditional execution in WDL 1.0
- If statements within scatter blocks
- Mutually exclusive conditional blocks
- Handling optional outputs with select_all()
- Accessing struct members
- Basic sample data processing
- Docker container usage

## Version
WDL 1.0

## Notes
- Demonstrates proper conditional statement usage in WDL 1.0
- Shows how to handle mutually exclusive execution paths
- Illustrates conditional logic within scatter blocks
- Shows proper struct member access
- Tests input parsing for struct types
124 changes: 124 additions & 0 deletions conditionalTest/conditionalTest.wdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,124 @@
version 1.0
## This workflow demonstrates the usage of conditional statements in WDL
## by selectively processing samples based on their properties

struct SampleInfo {
String name
Float quality_score
String type
}

workflow conditional_example {
input {
Array[SampleInfo] samples
Float quality_threshold
}

# Demonstrate if statement in scatter
scatter (sample in samples) {
if (sample.quality_score >= quality_threshold) {
call process_high_quality {
input:
sample = sample
}
}
}

# Create string arrays for the QC report
scatter (sample in samples) {
String sample_line = "~{sample.name},~{sample.type},~{sample.quality_score}"
}

# Demonstrate single conditional task
call run_qc_report {
input:
sample_lines = sample_line
}

# Calculate number of high quality samples
Int num_high_quality = length(select_all(process_high_quality.message))

# Demonstrate separate conditional blocks (WDL 1.0 approach instead of if/else)
Boolean has_multiple_samples = num_high_quality > 1

if (has_multiple_samples) {
call summarize {
input:
messages = select_all(process_high_quality.message),
report = "Multiple high-quality samples processed"
}
}

if (!has_multiple_samples) {
call summarize as summarize_few {
input:
messages = select_all(process_high_quality.message),
report = "Few or no high-quality samples found"
}
}

output {
String final_summary = select_first([summarize.summary, summarize_few.summary])
File qc_report = run_qc_report.report_csv
}
}

task process_high_quality {
input {
SampleInfo sample
}

command <<<
echo "Processing high quality ~{sample.type} sample ~{sample.name} (Q=~{sample.quality_score})"
>>>

output {
String message = read_string(stdout())
}

runtime {
docker: "ubuntu:noble-20241118.1"
}
}

task run_qc_report {
input {
Array[String] sample_lines
}

command <<<
echo "Quality Score Summary:"
echo "Sample Name,Type,Quality Score" > report.csv
~{sep="\n" sample_lines} >> report.csv
cat report.csv
>>>

output {
String report = read_string(stdout())
File report_csv = "report.csv"
}

runtime {
docker: "ubuntu:noble-20241118.1"
}
}

task summarize {
input {
Array[String] messages
String report
}

command <<<
echo "~{report}"
echo "Number of samples processed: ~{length(messages)}"
>>>

output {
String summary = read_string(stdout())
}

runtime {
docker: "ubuntu:noble-20241118.1"
}
}
20 changes: 20 additions & 0 deletions conditionalTest/inputs.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"conditional_example.samples": [
{
"name": "sample1",
"quality_score": 95.5,
"type": "normal"
},
{
"name": "sample2",
"quality_score": 85.3,
"type": "tumor"
},
{
"name": "sample3",
"quality_score": 92.1,
"type": "normal"
}
],
"conditional_example.quality_threshold": 90.0
}
5 changes: 5 additions & 0 deletions conditionalTest/options.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"workflow_failure_mode": "ContinueWhilePossible",
"write_to_cache": false,
"read_from_cache": false
}
Loading