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

Demonstrate use of conditional with conditional secondary file #5

Open
pvanheus opened this issue May 24, 2021 · 1 comment
Open

Demonstrate use of conditional with conditional secondary file #5

pvanheus opened this issue May 24, 2021 · 1 comment

Comments

@pvanheus
Copy link

pvanheus commented May 24, 2021

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_stdout

where 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.owl

or (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.owl
@pvanheus
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant