f3c9779dae1f1ce5c072d9ab97edf6f3e29aa52d
[rnaseq-cwl-training.git] / _episodes / 03-running.md
1 ---
2 title: "Running and Debugging a Workflow"
3 teaching: 10
4 exercises: 20
5 questions:
6 - "How do I provide input to run a workflow?"
7 - "What should I do if the workflow fails?"
8 objectives:
9 - "Write an input parameter file."
10 - "Execute the workflow."
11 - "Diagnose workflow errors."
12 keypoints:
13 - "The input parameter file is a YAML file with values for each input parameter."
14 - "A common reason for a workflow step fails is insufficient RAM."
15 - "Use ResourceRequirement to set the amount of RAM to be allocated to the job."
16 - "Output parameter values are printed as JSON to standard output at the end of the run."
17 ---
18
19 # The input parameter file
20
21 CWL input values are provided in the form of a YAML or JSON file.
22 create a called file
23
24 This file gives the values for parameters declared in the `inputs`
25 section of our workflow.  Our workflow takes `fq`, `genome` and `gtf`
26 as input parameters.
27
28 When setting inputs, Files and Directories are given as an object with
29 `class: File` or `class: Directory`.  This distinguishes them from
30 plain strings that may or may not be file paths.
31
32 Note: if you don't have example sequence data or the STAR index files, see [setup](/setup.html).
33
34 main-input.yaml
35
36 ```
37 fq:
38   class: File
39   location: rnaseq/raw_fastq/Mov10_oe_1.subset.fq
40   format: http://edamontology.org/format_1930
41 genome:
42   class: Directory
43   location: hg19-chr1-STAR-index
44 gtf:
45   class: File
46   location: rnaseq/reference_data/chr1-hg19_genes.gtf
47 ```
48 {: .language-yaml }
49
50 > ## Running the workflow
51 >
52 > Type this into the terminal:
53 >
54 > ```
55 > cwl-runner main.cwl main-input.yaml
56 > ```
57 >
58 > This may take a few minutes to run, and will print some amount of
59 > logging.  The logging you see, how access other logs, and how to
60 > track workflow progress will depend on your CWL runner platform.
61 >
62 > {: .language-bash }
63 {: .challenge }
64
65 # Debugging the workflow
66
67 Depending on whether and how your workflow platform enforces memory
68 limits, your workflow may fail.  Let's talk about what to do when a
69 workflow fails.
70
71 A workflow can fail for many reasons: some possible reasons include
72 bad input, bugs in the code, or running out memory.  In our example,
73 the STAR workflow may fail with an out of memory error.
74
75 To help diagnose these errors, the workflow runner produces logs that
76 record what happened, either in the terminal or the web interface.
77
78 Some errors you might see in the logs that would indicate an out of
79 memory condition:
80
81 ```
82 EXITING: fatal error trying to allocate genome arrays, exception thrown: std::bad_alloc
83 Possible cause 1: not enough RAM. Check if you have enough RAM 5711762337 bytes
84 Possible cause 2: not enough virtual memory allowed with ulimit. SOLUTION: run ulimit -v 5711762337
85 ```
86
87 or
88
89 ```
90 Container exited with code: 137
91 ```
92
93 (Exit code 137 most commonly occurs when a container goes "out of memory" and is terminated by the operating system).
94
95 If this happens, you will need to request more RAM.
96
97 # Setting runtime RAM requirements
98
99 By default, a step is allocated 256 MB of RAM.  From the STAR error message:
100
101 > Check if you have enough RAM 5711762337 bytes
102
103 We can see that STAR requires quite a bit more RAM than 256 MB.  To
104 request more RAM, add a "requirements" section with
105 "ResourceRequirement" to the "STAR" step:
106
107 ```
108   STAR:
109     requirements:
110       ResourceRequirement:
111         ramMin: 9000
112     run: bio-cwl-tools/STAR/STAR-Align.cwl
113         ...
114 ```
115 {: .language-yaml }
116
117 Resource requirements you can set include:
118
119 * coresMin: CPU cores
120 * ramMin: RAM (in megabytes)
121 * tmpdirMin: temporary directory available space
122 * outdirMin: output directory available space
123
124 After setting the RAM requirements, re-run the workflow.
125
126 # Workflow results
127
128 The CWL runner will print a results JSON object to standard output.  It will look something like this (it may include additional fields).
129
130 ```
131 {
132     "bam_sorted_indexed": {
133         "location": "file:///home/username/rnaseq-cwl-training-exercises/Aligned.sortedByCoord.out.bam",
134         "basename": "Aligned.sortedByCoord.out.bam",
135         "class": "File",
136         "size": 25370707,
137         "secondaryFiles": [
138             {
139                 "basename": "Aligned.sortedByCoord.out.bam.bai",
140                 "location": "file:///home/username/rnaseq-cwl-training-exercises/Aligned.sortedByCoord.out.bam.bai",
141                 "class": "File",
142                 "size": 176552,
143             }
144         ]
145     },
146     "qc_html": {
147         "location": "file:///home/username/rnaseq-cwl-training-exercises/Mov10_oe_1.subset_fastqc.html",
148         "basename": "Mov10_oe_1.subset_fastqc.html",
149         "class": "File",
150         "size": 383589
151     }
152 }
153 ```
154 {: .language-yaml }
155
156 This has a similar structure as `main-input.yaml`.  The each output
157 parameter is listed, with the `location` field of each `File` object
158 indicating where the output file can be found.