| name | cwl-understand-workflow |
| description | Understand CWL Workflow class structures for chaining multiple processing steps. Learn how to
connect outputs to inputs, manage data flow between steps, and create complex multi-step
workflows. Use when building workflows that chain multiple processes together.
|
| license | Apache-2.0 |
| compatibility | Requires understanding of CWL CommandLineTool basics. Supports CWL v1.0, v1.1, v1.2. |
| metadata | {"author":"fmigneault"} |
Understand CWL Workflows
Learn to create and understand CWL Workflow class structures for chaining multiple processing steps.
When to Use
- Building multi-step data processing pipelines
- Chaining multiple tools together
- Understanding workflow execution order
- Debugging workflow step connections
- Optimizing data flow between steps
Workflow Basics
Workflow vs CommandLineTool
CommandLineTool: Single process execution
class: CommandLineTool
baseCommand: [process]
Workflow: Chain multiple steps
class: Workflow
steps:
step1: ...
step2: ...
Simple Workflow Example
cwlVersion: v1.2
class: Workflow
inputs:
input_file: File
threshold: float
outputs:
final_output:
type: File
outputSource: step2/output
steps:
step1:
run: preprocess.cwl
in:
input: input_file
out: [processed]
step2:
run: analyze.cwl
in:
data: step1/processed
threshold: threshold
out: [output]
Workflow Components
1. Inputs
Workflow-level inputs that can be used by any step:
inputs:
input_files:
type: File[]
parameter:
type: string
default: "default_value"
optional_param:
type: string?
2. Outputs
Final outputs from the workflow:
outputs:
result:
type: File
outputSource: final_step/output
intermediate:
type: File
outputSource: step1/output
3. Steps
Individual processing steps:
steps:
step_name:
run:
class: CommandLineTool
baseCommand: [echo]
in:
step_input: workflow_input
another: some_step/output
out: [output1, output2]
The run can also reference an external CWL file.
⚠️ WARNING: The referenced tool.cwl should be a corresponding pre-existing process (where ID would be tool) for
this CWL to succeed Weaver deployment.
steps:
step_name:
run: tool.cwl
Data Flow Patterns
Sequential Processing
steps:
download:
run: download.cwl
in: {url: input_url}
out: [file]
process:
run: process.cwl
in: {input: download/file}
out: [result]
upload:
run: upload.cwl
in: {file: process/result}
out: [location]
Parallel Processing
steps:
process_a:
run: tool-a.cwl
in: {input: input_file}
out: [output_a]
process_b:
run: tool-b.cwl
in: {input: input_file}
out: [output_b]
merge:
run: merge.cwl
in:
file_a: process_a/output_a
file_b: process_b/output_b
out: [merged]
Scatter/Gather Pattern
steps:
process_many:
run: process-one.cwl
scatter: input_file
in:
input_file: input_files
out: [output]
combine:
run: combine.cwl
in:
files: process_many/output
out: [combined]
Advanced Workflow Features
ScatterMethod
steps:
process:
run: tool.cwl
scatter: [input1, input2]
scatterMethod: dotproduct
in:
input1: files_a
input2: files_b
out: [output]
Conditional Execution (CWL v1.2+)
steps:
optional_step:
run: tool.cwl
when: $(inputs.do_process)
in:
do_process: run_optional
input: data
out: [output]
SubWorkflows
steps:
sub_workflow:
run: another-workflow.cwl
in:
workflow_input: my_input
out: [workflow_output]
Common Workflow Patterns
Preprocessing Pipeline
steps:
validate:
run: validate.cwl
in: {input: raw_data}
out: [validated]
clean:
run: clean.cwl
in: {input: validate/validated}
out: [cleaned]
transform:
run: transform.cwl
in: {input: clean/cleaned}
out: [transformed]
analyze:
run: analyze.cwl
in: {data: transform/transformed, params: parameters}
out: [results]
Map-Reduce Pattern
steps:
map:
run: mapper.cwl
scatter: item
in: {item: input_items}
out: [mapped]
reduce:
run: reducer.cwl
in: {items: map/mapped}
out: [result]
Debugging Workflows
Visualize Workflow
cwltool --print-dot workflow.cwl | dot -Tpng > workflow.png
Check Step Connections
cwltool --validate workflow.cwl
cwltool --print-deps workflow.cwl inputs.json
Test Individual Steps
cwltool step1.cwl step1-inputs.json
cwltool step2.cwl step2-inputs.json
Enable Debug Output
cwltool --debug workflow.cwl inputs.json
Requirements for Workflows
Subworkflow Feature
requirements:
SubworkflowFeatureRequirement: {}
Scatter Feature
requirements:
ScatterFeatureRequirement: {}
Multiple Input Feature
requirements:
MultipleInputFeatureRequirement: {}
Step Input Expression
requirements:
StepInputExpressionRequirement: {}
steps:
process:
run: tool.cwl
in:
computed_input:
valueFrom: $(inputs.x + inputs.y)
Weaver Workflow Example
Complete workflow for data processing:
cwlVersion: v1.2
class: Workflow
requirements:
ScatterFeatureRequirement: {}
inputs:
netcdf_files: File[]
region: string
outputs:
statistics:
type: File
outputSource: compute_stats/output
steps:
subset:
run: subset-by-region.cwl
scatter: input_file
in:
input_file: netcdf_files
region: region
out: [subset_file]
compute_stats:
run: compute-statistics.cwl
in:
input_files: subset/subset_file
out: [output]
Related Skills
Documentation
Best Practices
- Keep steps modular - Each step should do one thing well
- Use descriptive names - Clear step and variable names
- Document data flow - Comment complex connections
- Test incrementally - Verify each step works before chaining
- Handle errors - Consider what happens if a step fails
- Optimize scatter - Use appropriate scatterMethod for your use case
- Version control - Track workflow changes