From 8ff16850b62499195ae344e30c882278a84e3f06 Mon Sep 17 00:00:00 2001 From: Sitapriya Moorthi <23532136+sitapriyamoorthi@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:48:54 -0800 Subject: [PATCH 1/4] Create WildcardsandConditions.wdl WDL --- .../WildcardsandConditions.wdl | 48 +++++++++++++++++++ 1 file changed, 48 insertions(+) create mode 100644 WildcardsandConditions/WildcardsandConditions.wdl diff --git a/WildcardsandConditions/WildcardsandConditions.wdl b/WildcardsandConditions/WildcardsandConditions.wdl new file mode 100644 index 0000000..c35d45c --- /dev/null +++ b/WildcardsandConditions/WildcardsandConditions.wdl @@ -0,0 +1,48 @@ +version 1.0 + +workflow WildcardsandConditions { + input { + String prefix # Required input for the file prefix (no default value) + } + + call wildcard_and_conditions_test { + input: + prefix = prefix # Explicitly pass the workflow input to the task + } + + output { + Array[File] txt_files = wildcard_and_conditions_test.txt_files + String conditional_result = wildcard_and_conditions_test.conditional_output + } +} + +task wildcard_and_conditions_test { + input { + String prefix # Required input for file creation + Boolean create_extra_file = true # Default value for conditional logic + } + + command <<< + # Create multiple .txt files to test wildcard resolution + for i in {1..3}; do + echo "File content $i" > ~{prefix}_$i.txt + done + + # Create an extra file conditionally + if [[ ~{create_extra_file} == "true" ]]; then + echo "Extra file content" > ~{prefix}_extra.txt + fi + + # Parse inputs directly in the command + echo "Parsed prefix: ~{prefix}" > parsed_output.txt + >>> + + output { + Array[File] txt_files = glob("*.txt") # Test wildcard resolution + String conditional_output = read_string("parsed_output.txt") # Verify input parsing + } + + runtime { + docker: "ubuntu:20.04" + } +} From 2ecff98d05cfc349a7ad249a6a659e08cd975c85 Mon Sep 17 00:00:00 2001 From: Sitapriya Moorthi <23532136+sitapriyamoorthi@users.noreply.github.com> Date: Wed, 15 Jan 2025 17:49:24 -0800 Subject: [PATCH 2/4] Create WildcardsandConditions.json adding json file --- WildcardsandConditions/WildcardsandConditions.json | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 WildcardsandConditions/WildcardsandConditions.json diff --git a/WildcardsandConditions/WildcardsandConditions.json b/WildcardsandConditions/WildcardsandConditions.json new file mode 100644 index 0000000..231e590 --- /dev/null +++ b/WildcardsandConditions/WildcardsandConditions.json @@ -0,0 +1,3 @@ +{ + "WildcardsandConditions.prefix": "testfile" +} From 81af9afb85ca6e9ac8f782f02419e536ecf96ee3 Mon Sep 17 00:00:00 2001 From: Sitapriya Moorthi <23532136+sitapriyamoorthi@users.noreply.github.com> Date: Wed, 15 Jan 2025 20:47:14 -0800 Subject: [PATCH 3/4] Create README.md Readme --- WildcardsandConditions/README.md | 100 +++++++++++++++++++++++++++++++ 1 file changed, 100 insertions(+) create mode 100644 WildcardsandConditions/README.md diff --git a/WildcardsandConditions/README.md b/WildcardsandConditions/README.md new file mode 100644 index 0000000..0323493 --- /dev/null +++ b/WildcardsandConditions/README.md @@ -0,0 +1,100 @@ + +# Unit Test for Wildcard Resolution and Conditional Logic (WildcardsandConditions) + +## Overview + +The `WildcardsandConditions` workflow is a unit test designed to validate the behavior of wildcard resolution and conditional logic in WDL (Workflow Description Language). It includes tests for: + +- **Wildcard Resolution**: Ensures that files matching the wildcard pattern (e.g., `*.txt`) are correctly identified and handled in the workflow. +- **Conditional Logic**: Verifies that conditional logic within the command block works properly, such as the creation of files based on boolean conditions. +- **Input Parsing**: Confirms that inputs passed to the workflow are correctly parsed and used within the command block. + +## Purpose + +This workflow serves as a test case for: +- Wildcard handling in file operations (creating and globbing files). +- Conditional logic inside the command block (such as `if` statements). +- Parsing and using workflow inputs in commands. +- Validation of input parameters (required and default inputs). + +## Workflow Components + +### Workflow: `WildcardsandConditions` + +This workflow demonstrates wildcard handling, conditional file creation, and input parsing in a WDL task. + +**Inputs:** +- `prefix`: String - The prefix used to create files (e.g., `sample`) (required). +- `create_extra_file`: Boolean - A flag to control the conditional creation of an extra file (optional, defaults to `true`). + +**Outputs:** +- `txt_files`: Array[File] - A list of `.txt` files created in the task, resolved using a wildcard. +- `conditional_result`: String - The content of the file that shows the parsed `prefix` input. + +### Tasks + +#### Task: `wildcard_and_conditions_test` +- **Purpose**: Creates `.txt` files using a wildcard pattern, conditionally creates an extra file, and parses the `prefix` input. +- **Key Operations**: + - Create `.txt` files with a dynamic name using a loop and wildcard. + - Conditionally create an additional file based on the `create_extra_file` input. + - Output the parsed `prefix` in a file to verify input parsing. + +**Runtime Requirements:** +- **Docker Image**: `ubuntu:20.04` +- **CPU**: 1 core +- **Memory**: 1 GB + +--- + +## Usage + +### Input JSON + +To run the workflow, you need to specify the required `prefix` input in an `inputs.json` file. Here's an example: + +```json +{ + "WildcardsandConditions.prefix": "testfile", + "WildcardsandConditions.create_extra_file": true +} +``` + +You can run the workflow with the following command: + +```bash +# Using Cromwell +java -jar cromwell.jar run WildcardsandConditions.wdl -i inputs.json + +# Using MiniWDL +miniwdl run WildcardsandConditions.wdl prefix="testfile" create_extra_file=true +``` + +### Expected Output Files + +1. **txt_files**: This output will contain a list of `.txt` files matching the wildcard pattern (`*.txt`) created during the task execution, including the ones with the prefix provided. + + Example: + - `testfile_1.txt` + - `testfile_2.txt` + - `testfile_3.txt` + - If `create_extra_file` is `true`, there will also be `testfile_extra.txt`. + +2. **conditional_result**: This output will contain the content of the file created by the task that verifies the parsing of the `prefix` input. + + Example: + - Content of `parsed_output.txt`: `"Parsed prefix: testfile"` + +--- + +## Version +- **WDL Version**: 1.0 + +--- + +## Additional Notes +- This workflow demonstrates the usage of wildcards in WDL, which can be particularly useful when working with large datasets where files follow a consistent naming pattern. +- The conditional logic in this test checks whether a specific file is created based on the value of the input parameter `create_extra_file`. +- The workflow also tests how inputs are parsed and used in the command block, allowing for dynamic file creation and manipulation based on workflow parameters. +- If no value for `prefix` is provided, the workflow will fail with an error message, as the input is required. You can provide a default value in the `input` block if you want to make it optional. + From 7bd89306b3ae5119e6a02f7ba1c1ca75411a71a5 Mon Sep 17 00:00:00 2001 From: Sitapriya Moorthi <23532136+sitapriyamoorthi@users.noreply.github.com> Date: Wed, 22 Jan 2025 12:18:47 -0800 Subject: [PATCH 4/4] Rename WildcardsandConditions.json to inputs.json Changing name to inputs.json for JSON --- .../{WildcardsandConditions.json => inputs.json} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename WildcardsandConditions/{WildcardsandConditions.json => inputs.json} (100%) diff --git a/WildcardsandConditions/WildcardsandConditions.json b/WildcardsandConditions/inputs.json similarity index 100% rename from WildcardsandConditions/WildcardsandConditions.json rename to WildcardsandConditions/inputs.json