1 # Writing a tool wrapper
3 It is time to add the last step in the analysis.
5 This will use the "featureCounts" tool from the "subread" package.
9 Create a new file "featureCounts.cwl"
11 Start with this header
15 class: CommandLineTool
18 ### 2. Command line tool inputs
20 A CommandLineTool describes a single invocation of a command line program.
22 It consumes some input parameters, runs a program, and produce output
25 Here is the original shell command:
28 featureCounts -T $cores -s 2 -a $gtf -o $counts $counts_input_bam
31 The variables used in the bash script are `$cores`, `$gtf`, `$counts` and `$counts_input_bam`.
35 This gives us two file inputs, `gtf` and `counts_input_bam` which we can declare in our `inputs` section:
40 counts_input_bam: File
43 ### 3. Specifying the program to run
45 Give the name of the program to run in `baseCommand`.
48 baseCommand: featureCounts
51 ### 4. Command arguments
53 The easiest way to describe the command line is with an `arguments`
54 section. This takes a comma-separated list of command line arguments.
56 Input variables are included on the command line as
57 `$(inputs.name_of_parameter)`. When the tool is executed, these input
58 parameter values are substituted for these variable.
60 Special variables are also available. The runtime environment
61 describes the resources allocated to running the program. Here we use
62 `$(runtime.cores)` to decide how many threads to request.
65 arguments: [-T, $(runtime.cores),
67 -o, featurecounts.tsv,
68 $(inputs.counts_input_bam)]
71 ### 5. Outputs section
73 In CWL, you must explicitly identify the outputs of a program. This
74 associates output parameters with specific files, and enables the
75 workflow runner to know which files must be saved and which files can
78 In the previous section, we told the featureCounts program the name of
79 our output files should be `featurecounts.tsv`.
81 We can declare an output parameter called `featurecounts` that will
82 have that output file as its value.
84 The `outputBinding` section describes how to determine the value of
85 the parameter. The `glob` field tells it to search for a file in the
86 output directory called `featurecounts.tsv`
93 glob: featurecounts.tsv
96 ### 6. Running in a container
98 In order to run the tool, it needs to be installed.
99 Using software containers, a tool can be pre-installed into a
100 compatible runtime environment, and that runtime environment (called a
101 container image) can be downloaded and run on demand.
103 Many bioinformatics tools are already available as containers. One
104 resource is the BioContainers project. Let's find the "subread" software:
106 1. Visit https://biocontainers.pro/
107 2. Click on "Registry"
108 3. Search for "subread"
109 4. Click on the search result for "subread"
110 5. Click on the tab "Packages and Containers"
111 6. Choose a row with type "docker", then on the right side of the "Full
112 Tag" column for that row, click the "copy to clipboard" button.
114 To declare that you want to run inside a container, create a section
115 called `hints` with a subsection `DockerRequirement`. Under
116 `DockerRequirement`, paste the text your copied in the above step.
117 Replace the text `docker pull` to `dockerPull:` and indent it so it is
118 in the `DockerRequirement` section.
123 dockerPull: quay.io/biocontainers/subread:1.5.0p3--0
126 ### 7. Running a tool on its own
128 When creating a tool wrapper, it is helpful to run it on its own to test it.
130 The input to a single tool is the same kind of input parameters file
131 that we used as input to a workflow in the previous lesson.
138 location: Aligned.sortedByCoord.out.bam
141 location: rnaseq/reference_data/chr1-hg19_genes.gtf
144 The invocation is also the same:
147 cwl-runner featureCounts.cwl featureCounts.yaml
150 ### 8. Adding it to the workflow
152 Now that we have confirmed that it works, we can add it to our workflow.
153 We add it to `steps`, connecting the output of samtools to
154 `counts_input_bam` and the `gtf` taking the workflow input of the same
164 run: featureCounts.cwl
166 counts_input_bam: samtools/bam_sorted_indexed
171 We will add the result from featurecounts to the output:
178 outputSource: featureCounts/featurecounts
181 You should now be able to re-run the workflow and it will run the
182 "featureCounts" step and include "featurecounts" in the output.