This lesson is still being designed and assembled (Pre-Alpha version)

Adding your own script to a step

Overview

Teaching: 0 min
Exercises: 0 min
Questions
  • How to include and run a script in a step at runtime?

  • Which requirements need to be specified?

  • How to capture output of a script?

Objectives
  • Include and run a script in a step at runtime

  • Capture output of a script

By the end of this episode, learners should be able to include and run their own script in a step at runtime

Exercise 1:

Which Requirment from the following options is used to create a script at runtime?

A. InlineJavascriptRequirement
B. InitialWorkDirRequirement
C. ResourceRequirement
D. DockerRequirement

Solution

B. InitialWorkDirRequirement

Exercise 2:

Using the template below, add the missing instructions so that a script named script.sh with the specified contents is created at runtime.

InitialWorkDirRequirement:
  listing:
    - ------: script.sh
      ------: |
        echo "*Documenting input*" && \
        echo "Input received: $(inputs.message)" && \
        echo "Exit"

inputs:
  message:
    type: string

Solution:

InitialWorkDirRequirement:
  listing:
    - entryname: script.sh
      entry: |
        echo "*Documenting input*" && \
        echo "Input received: $(inputs.message)" && \
        echo "Exit"

inputs:
  message:
    type: string

Exercise 3:

Since we are using echo in the script (as shown below) - what is the appropriate type in the outputs section of following code block to capture standard output?

class: CommandLineTool
cwlVersion: v1.1
requirements:
  DockerRequirement:
    dockerPull: 'debian:stable'
  InitialWorkDirRequirement:
    listing:
      - entryname: script.sh
        entry: |
          echo "*Documenting input*" && \
          echo "Input received: $(inputs.message)" && \
          echo "Exit"

inputs:
  message:
    type: string

stdout: "message.txt"

outputs:
 message:
   type: ----

Your options are: A. File B. Directory C. stdout D. string

Solution:

C. stdout

Exercise 4:

Fix the baseCommand in following code snippet to execute the script we have created in previous exercises.

baseCommand: []

Solution:

baseCommand: [ sh, script.sh ]

Exercise 5:

CHALLENGE question. Extend the outputs section of the following CWLtool definition to capture the script we have created along with tools’ standard output.

This will help you inspect the generated script and is useful in more complex situations to troubleshoot related issues.

class: CommandLineTool
cwlVersion: v1.1
requirements:
  DockerRequirement:
    dockerPull: 'debian:stable'
  InitialWorkDirRequirement:
    listing:
      - entryname: script.sh
        entry: |
          echo "*Documenting input*" && \
          echo "Input received: $(inputs.message)" && \
          echo "Exit"

inputs:
  message:
    type: string

stdout: "message.txt"
baseCommand: ["sh", "script.sh"]

outputs:
  message:
    type: stdout

Solution:

class: CommandLineTool
cwlVersion: v1.1
requirements:
  DockerRequirement:
    dockerPull: 'debian:stable'
  InitialWorkDirRequirement:
    listing:
      - entryname: script.sh
        entry: |
          echo "*Documenting input*" && \
          echo "Input received: $(inputs.message)" && \
          echo "Exit"

inputs:
  message:
    type: string

stdout: "message.txt"
baseCommand: ["sh", "script.sh"]

outputs:
  message:
    type: stdout
  script:
    type: File
    outputBinding:
      glob: "script.sh"

Key Points

  • First key point. Brief Answer to questions. (FIXME)