Demonstrate use of conditional with conditional secondary file
pvanheus opened this issue · 1 comments
pvanheus commented
Below is a simple workflow that conditionally creates an index file for a FASTA reference file before using it as an input to a CWL tool.
#!/usr/bin/env bash
if ! [ -f data/reference.fa.sa ]; then
bwa index data/reference.fa
fi
for sample in samples; do
bwa mem data/reference.fa $sample > outputs/$sample.sam
done
# we have limited storage space so we
# cleanup indices once we are done
rm -f data/reference.fa.*
The step in this script that creates an index is in a conditional. In the beginner tutorial this script is presented without the conditional but this gives us an opportunity to introduce conditional steps in the intermediate tutorial.
Here is an example workflow using conditional:
#!/usr/bin/env cwl-runner
cwlVersion: v1.2
class: Workflow
requirements:
InlineJavascriptRequirement: {}
StepInputExpressionRequirement: {}
MultipleInputFeatureRequirement: {}
inputs:
reference:
type: File
reads:
type: File[]
outputs:
mapped:
type: File
outputSource: map/reads_stdout
steps:
index:
run: bwa/BWA-Index.cwl
in:
InputFile: reference
IndexName:
valueFrom: $(inputs.InputFile.basename)
out:
- index
when:
$( typeof inputs.InputFile.secondaryFiles === 'undefined' || inputs.InputFile.secondaryFiles.length != 4 )
map:
run: bwa/BWA-Mem.cwl
in:
InputFile: reads
Index:
source:
- index/index
- reference
pickValue: first_non_null
out:
- reads_stdoutwhere the input can either be:
reference:
class: File
path: /home/pvh/Data/fasta/MN908947_3_Wuhan-Hu-1.fasta
format: edam:format_1929
reads:
- class: File
path: /home/pvh/Data/fastq/foss_caseB_single.fastq.gz
format: edam:format_1931
$namespaces:
edam: http://edamontology.org/
$schemas:
- http://edamontology.org/EDAM_1.18.owlor (if the index is pre-computed)
reference:
class: File
path: /home/pvh/Data/fasta/MN908947_3_Wuhan-Hu-1.fasta.bwt
format: edam:format_1929
secondaryFiles:
- class: File
path: /home/pvh/Data/fasta/MN908947_3_Wuhan-Hu-1.fasta.ann
- class: File
path: /home/pvh/Data/fasta/MN908947_3_Wuhan-Hu-1.fasta.amb
- class: File
path: /home/pvh/Data/fasta/MN908947_3_Wuhan-Hu-1.fasta.pac
- class: File
path: /home/pvh/Data/fasta/MN908947_3_Wuhan-Hu-1.fasta.sa
reads:
- class: File
path: /home/pvh/Data/fastq/foss_caseB_single.fastq.gz
format: edam:format_1931
$namespaces:
edam: http://edamontology.org/
$schemas:
- http://edamontology.org/EDAM_1.18.owlpvanheus commented
Note - the above required some modifications to the BWA tools to run. Perhaps best to resolve common-workflow-library/bio-cwl-tools#95 and then come back to this example.