Merge pull request #9 from common-workflow-lab/ALuesink-patch-1
[rnaseq-cwl-training.git] / _episodes / 06-expressions.md
index 7b83de6d28c831f5b6f124f39377c0705d7df7ac..5bf1782d8010c69770a92af82fd5ce8b4ae12c84 100644 (file)
@@ -1,16 +1,18 @@
 ---
-title: "Dynamic Workflow behavior with expressions"
-teaching: 0
-exercises: 0
+title: "Dynamic Workflow Behavior"
+teaching: 20
+exercises: 10
 questions:
-- "Key question (FIXME)"
+- "What kind of custom logic can happen between steps?"
 objectives:
-- "First learning objective. (FIXME)"
+- "Customize the STAR output filename to use the input filename."
+- "Organize files into directories."
 keypoints:
-- "First key point. Brief Answer to questions. (FIXME)"
+- "CWL expressions allow you to use custom logic to determine input parameter values."
+- "CWL ExpressionTool can be used to reshape data, such as declaring directories that should contain output files."
 ---
 
-### 1. Expressions on step inputs
+# Expressions on step inputs
 
 You might have noticed that the output bam files are all named
 `Aligned.sortedByCoord.out.bam`.  This happens because because when we
@@ -20,6 +22,7 @@ During workflow execution, this is usually not a problem.  The
 workflow runner is smart enough to know that these files are different
 and keep them separate.  This can even make development easier by not
 having to worry about assigning unique file names to every file.
+Also, if we intend to discard the BAM files as intermediate results
 
 However, it is a problem for humans interpreting the output.  We can
 fix this by setting the parameter `OutFileNamePrefix` on STAR.  We
@@ -42,6 +45,7 @@ steps:
       ...
       OutFileNamePrefix: {valueFrom: "$(inputs.ForwardReads.nameroot)."}
 ```
+{: .language-yaml }
 
 The code between `$(...)` is called an "expression".  It is evaluated
 when setting up the step to run, and the expression is replaced by the
@@ -64,7 +68,7 @@ adds the remainder of the string, which just is a dot `.`.  This is to
 separate the leading part of our filename from the "Aligned.bam"
 extension that will be added by STAR.
 
-### 2. Organizing output files into Directories
+# Organizing output files into Directories
 
 You probably noticed that all the output files appear in the same
 directory.  You might prefer that each file appears in its own
@@ -92,7 +96,7 @@ assignment (`=`), which cannot include control blocks like `if` or
 `for`.  The `${}` form is a Javascript function, which can include
 control blocks, and must end in a `return` statement.
 
-Dxpressions can both appear in `valueFrom` fields as well as some
+Expressions can both appear in `valueFrom` fields as well as some
 other fields, or in an `ExpressionTool` which, like `Workflow` or
 `CommandLineTool` has explicitly defined `inputs` and `outputs`
 sections.
@@ -129,6 +133,7 @@ expression: |-
   return {"dirs": dirs};
   }
 ```
+{: .language-yaml }
 
 Then change `main.cwl`:
 
@@ -150,3 +155,19 @@ outputs:
     type: File
     outputSource: featureCounts/featurecounts
 ```
+{: .language-yaml }
+
+> ## Running the workflow
+>
+> Run the workflow.  Look at the output.  The BAM and fastqc files
+> should now be organized into directories, with better naming of the
+> bam files.
+>
+{: .challenge }
+
+> ## Episode solution
+> * <a href="../assets/answers/ep6/main.cwl">main.cwl</a>
+> * <a href="../assets/answers/ep6/alignment.cwl">alignment.cwl</a>
+> * <a href="../assets/answers/ep6/featureCounts.cwl">featureCounts.cwl</a>
+> * <a href="../assets/answers/ep6/subdirs.cwl">subdirs.cwl</a>
+{: .solution}