It consumes some input parameters, runs a program, and produce output
values.
-Here's the original bash script
+Here is the original shell command:
```
featureCounts -T $cores -s 2 -a $gtf -o $counts $counts_input_bam
counts_input_bam: File
```
-4. The base command
+4. Specifying the program to run
-This one is easy. This is the name of program to run:
+Give the name of the program to run in `baseCommand`.
```
baseCommand: featureCounts
```
-5. The command arguments
+5. Command arguments
The easiest way to describe the command line is with an `arguments`
section. This takes a comma-separated list of command line arguments.
describes the resources allocated to running the program. Here we use
`$(runtime.cores)` to decide how many threads to request.
-File variables can also yield a partial filename, by adding
-`.nameroot`. This is the filename with the final dot-extension
-stripped off.
-
```
arguments: [-T, $(runtime.cores),
-a, $(inputs.gtf),
- -o, $(inputs.counts_input_bam.nameroot)_featurecounts.txt,
+ -o, featurecounts.tsv,
$(inputs.counts_input_bam)]
```
-6. The outputs section
+6. Outputs section
In CWL, you must explicitly identify the outputs of a program. This
-associates output parameters with specific files, and allows the
+associates output parameters with specific files, and enables the
workflow runner to know which files must be saved and which files can
be discarded.
In the previous section, we told the featureCounts program the name of
-our output files should be
-`$(inputs.counts_input_bam.nameroot)_featurecounts.txt`.
+our output files should be `featurecounts.tsv`.
We can declare an output parameter called `featurecounts` that will
have that output file as its value.
The `outputBinding` section describes how to determine the value of
the parameter. The `glob` field tells it to search for a file in the
-output directory with the
-`$(inputs.counts_input_bam.nameroot)_featurecounts.txt`
+output directory called `featurecounts.tsv`
```
outputs:
featurecounts:
type: File
outputBinding:
- glob: $(inputs.counts_input_bam.nameroot)_featurecounts.txt
+ glob: featurecounts.tsv
+```
+
+7. Running in a container
+
+In order to run the tool, it needs to be installed.
+Using software containers, a tool can be pre-installed into a
+compatible runtime environment, and that runtime environment (called a
+container image) can be downloaded and run on demand.
+
+Many bioinformatics tools are already available as containers. One
+resource is the BioContainers project. Let's find the "subread" software:
+
+ 1. Visit https://biocontainers.pro/
+ 2. Click on "Registry"
+ 3. Search for "subread"
+ 4. Click on the search result for "subread"
+ 5. Click on the tab "Packages and Containers"
+ 6. Choose a row with type "docker", then on the right side of the "Full
+Tag" column for that row, click the "copy to clipboard" button.
+
+To declare that you want to run inside a container, create a section
+called `hints` with a subsection `DockerRequirement`. Under
+`DockerRequirement`, paste the text your copied in the above step.
+Replace the text `docker pull` to `dockerPull:` and indent it so it is
+in the `DockerRequirement` section.
+
+```
+hints:
+ DockerRequirement:
+ dockerPull: quay.io/biocontainers/subread:1.5.0p3--0
+```
+
+8. Running a tool on its own
+
+When creating a tool wrapper, it is helpful to run it on its own to test it.
+
+The input to a single tool is the same kind of input parameters file
+that we used as input to a workflow in the previous lesson.
+
+featureCounts.yaml:
+
+```
+counts_input_bam:
+ class: File
+ location: Aligned.sortedByCoord.out.bam
+gtf:
+ class: File
+ location: rnaseq/reference_data/chr1-hg19_genes.gtf
```
-N.
+The invocation is also the same:
-The most portable way to run a tool is to wrap it in a Docker
-container. (Some CWL platforms, such as Arvados, require it). Many
-bioinformatics tools are already available as containers. One
-resource is the BioContainers project.
+```
+cwl-runner featureCounts.cwl featureCounts.yaml
+```
-Visit https://biocontainers.pro/
+9. Adding it to the workflow
-Click on "Registry"
+Now that we have confirmed that it works, we can add it to our workflow.
+We add it to `steps`, connecting the output of samtools to
+`counts_input_bam` and the `gtf` taking the workflow input of the same
+name.
-Search for "subread"
+```
+steps:
+ ...
+ featureCounts:
+ requirements:
+ ResourceRequirement:
+ ramMin: 500
+ run: featureCounts.cwl
+ in:
+ counts_input_bam: samtools/bam_sorted_indexed
+ gtf: gtf
+ out: [featurecounts]
+```
-Click on the search result for "subread"
+We will add the result from featurecounts to the output:
-Click on the tab "Packages and Containers"
+```
+outputs:
+ ...
+ featurecounts:
+ type: File
+ outputSource: featureCounts/featurecounts
+
+```
-Choose a row with type "docker", then click the "copy to clipboard"
-button on the right side of the"Full Tag" column for that row.
+You should now be able to re-run the workflow and it will run the
+"featureCounts" step and include "featurecounts" in the output.