2 title: "Analyzing Multiple Samples"
6 - "How can you run the same workflow over multiple samples?"
8 - "Modify the workflow to process multiple samples, then perform a joint analysis."
10 - "Separate the part of the workflow that you want to run multiple times into a subworkflow."
11 - "Use a scatter step to run the subworkflow over a list of inputs."
12 - "The result of a scatter is an array, which can be used in a combine step to get a single result."
15 In the previous lesson, we completed converting the function of the
16 original source shell script into CWL. This lesson expands the scope
17 by demonstrating what changes to make to the workflow to be able to
18 analyze multiple samples in parallel.
22 In addition to running command line tools, a workflow step can also
23 execute another workflow.
25 First, copy `main.cwl` to `alignment.cwl`.
27 Next, open `main.cwl` for editing. We are going to replace the `steps` and `outputs` sections.
29 Remove all the steps and replace them with a single `alignment` step
30 which invokes the `alignment.cwl` we just copied.
40 out: [qc_html, bam_sorted_indexed, featurecounts]
44 In the `outputs` section, all the output sources are from the alignment step:
50 outputSource: alignment/qc_html
53 outputSource: alignment/bam_sorted_indexed
56 outputSource: alignment/featurecounts
60 We also need add "SubworkflowFeatureRequirement" to tell the workflow
61 runner that we are using subworkflows:
65 SubworkflowFeatureRequirement: {}
69 > ## Running the workflow
71 > Run this workflow. You should get exactly the same results as
72 > before, as all we have done so far is to wrap the inner workflow with
79 The "wrapper" step lets us do something useful. We can modify the
80 outer workflow to accept a list of files, and then invoke the inner
81 workflow step for every one of those files. We will need to modify
82 the `inputs`, `steps`, `outputs`, and `requirements` sections.
84 First we change the `fq` parameter to expect a list of files:
94 Next, we add `scatter` to the alignment step. The means we want to
95 run run `alignment.cwl` for each value in the list in the `fq`
107 out: [qc_html, bam_sorted_indexed, featurecounts]
111 Because the scatter produces multiple outputs, each output parameter
112 becomes a list as well:
118 outputSource: alignment/qc_html
121 outputSource: alignment/bam_sorted_indexed
124 outputSource: alignment/featurecounts
128 We also need add "ScatterFeatureRequirement" to tell the workflow
129 runner that we are using scatter:
133 SubworkflowFeatureRequirement: {}
134 ScatterFeatureRequirement: {}
138 # Input parameter lists
140 The `fq` parameter needs to be a list. You write a list in yaml by
141 starting each list item with a dash. Example `main-input.yaml`
146 location: rnaseq/raw_fastq/Mov10_oe_1.subset.fq
147 format: http://edamontology.org/format_1930
149 location: rnaseq/raw_fastq/Mov10_oe_2.subset.fq
150 format: http://edamontology.org/format_1930
152 location: rnaseq/raw_fastq/Mov10_oe_3.subset.fq
153 format: http://edamontology.org/format_1930
155 location: rnaseq/raw_fastq/Irrel_kd_1.subset.fq
156 format: http://edamontology.org/format_1930
158 location: rnaseq/raw_fastq/Irrel_kd_2.subset.fq
159 format: http://edamontology.org/format_1930
161 location: rnaseq/raw_fastq/Irrel_kd_3.subset.fq
162 format: http://edamontology.org/format_1930
165 location: hg19-chr1-STAR-index
168 location: rnaseq/reference_data/chr1-hg19_genes.gtf
172 > ## Running the workflow
174 > Run this workflow. You will now get results for each one of the
181 Each instance of the alignment workflow produces its own
182 `featurecounts.tsv` file. However, to be able to compare results
183 easily, we would like single file with all the results.
185 We can modify the workflow to run `featureCounts` once at the end of
186 the workflow, taking all the bam files listed on the command line.
188 We will need to change a few things.
190 First, in `featureCounts.cwl` we need to modify it to accept either a
191 single bam file or list of bam files.
202 Second, in `alignment.cwl` we need to remove the `featureCounts` step from alignment.cwl, as well as the `featurecounts` output parameter.
204 Third, in `main.cwl` we need to remove `featurecounts` from the `alignment` step
205 outputs, and add a new step:
216 out: [qc_html, bam_sorted_indexed]
221 run: featureCounts.cwl
223 counts_input_bam: alignment/bam_sorted_indexed
229 Last, we modify the `featurecounts` output parameter. Instead of a
230 list of files produced by the `alignment` step, it is now a single
231 file produced by the new `featureCounts` step.
238 outputSource: featureCounts/featurecounts
242 > ## Running the workflow
244 > Run this workflow. You will still have separate results from fastq
245 > and and STAR, but now you will only have a single
246 > `featurecounts.tsv` file with a column for each bam file.