Introduction to Building Workflows
Last updated
Was this helpful?
Last updated
Was this helpful?
Creating a workflow is easiest via the , but you can use the , dx-toolkit
, if you want to automate workflow creation or lock down your workflow. In this tutorial we will show you how to do that step by step from your local workstation.
For information on building Nextflow workflows, see .
A workflow can be created on the DNAnexus Platform from a file.
In this tutorial, we will build a workflow named "BWA MEM + Freebayes Exome Workflow." The stages
field of our JSON file holds a list of executables for the workflow. We'll add two stages to our workflow: the first one will run the app BWA-MEM FASTQ Read Mapper and the second one will run Freebayes Variant Caller. We'll also specify a name and an output folder where our results will be saved. Our dxworkflow.json
will look as follows:
Each stage in the stages
list should have an id
, which is a free-form string unique in a given workflow, and anexecutable
field, which holds either the ID/name of an app, or an ID of an applet that we want to run in that stage.
We also use the input
section of a stage to set default values for a field. We select the file hs37d5.bwa-index.tar.gz
(file-B6ZY4942J35xX095VZyQBk0v
), which is publicly available in the reference project "Apps Data: AWS US (East)" (project-BQpp3Y804Y0xbyG4GJPQ01xv
) on the DNAnexus Platform, to be the default reference file for the alignment step, align_reads
.
We can now create a workflow object in the DNAnexus Platform by following these steps:
Create a directory named "BWA MEM + Freebayes Exome Workflow" in your local workstation. The directory name does not have to be identical to the name of the workflow, but it's a good practice to keep them the same.
Place your dxworkflow.json
file in the newly created directory.
To create the workflow on the DNAnexus Platform, navigate to your directory and then enter the following commands:
You should see the ID of your resulting workflow in the command line. You can also view this workflow by logging in to your DNAnexus account on the Platform and viewing the workflow from your project's Manage page.
When we want to run a workflow, we can pass or override values to any stage inputs:
In certain situations, it may be desirable to disallow or discourage the user of our workflow to override an input to a particular stage. For example, we may want only a specific reference genome to be used for the workflow and thus lock down the reference genome input.
In order to achieve that we can add explicit fields called inputs
and outputs
to the workflow during creation, with links to inputs and outputs of specific stages. When the workflow is run, the user will be able to pass values only to the fields defined in inputs
, and all the parameters that are not visible in this workflow-level I/O interface will be unchangeable/non-overridable.
Creating locked workflows is also useful when we want to simplify the workflow execution and make it clear which inputs users are expected to provide.
This feature also makes the execution of WDL workflows on the Platform more seamless since these also explicitly specify workflow inputs and outputs.
For our example, we will create a locked down version of the workflow above and name it "BWA MEM + Freebayes Exome Workflow (locked)". Our workflow will have all inputs locked except for one in the stage align_reads
, reads_fastqgzs
. When locking workflows we always define those inputs that are not locked, by listing them in the workflow-level inputs
field. All the other inputs will be automatically locked and users will not be able to override their values when running this workflow.
To create a locked workflow we first need to add a workflow-level input specification in the inputs
field, which may look like this:
In this case the workflow will have only one input, named reads
.
Next, we should define which stage or stages will consume that input by adding a link from that stage(s) to the workflow input. We can do this by using the field workflowInputField
, as in the example below. If a file is supplied to reads
when the workflow is run, it will be directed to reads_fastqgzs
of the stage align_reads
.
Notice that the input fields genomeindex_targz
and genome_fastagz
are not put into the workflow-level input field, indicating that these fields are locked. Since the user cannot input values for locked fields, we have to set the value for these fields using each individual stage'sinput
field as above (not the workflow-level inputs
), and the workflow will only be run with the values file-B6ZY4942J35xX095VZyQBk0v
and file-B6ZY7VG2J35Vfvpkj8y0KZ01
respectively.
Any required stage inputs in a locked workflow must be specified in the dxworkflow.json
. In the example, our stages have the following required inputs:
align_reads
stage has the inputs reads_fastqgzs
and genomeindex_targz
call_variants
stage has the inputs sorted_bams
and genome_fastagz
reads_fastqgzs
is created as a workflow-level input in inputs
(so it is not locked, and the user will set the input) while the remaining inputs are locked. The values used in the locked input fields must be set by the creator of the workflow, and for our example, they have been set according to the code snippet seen above.
If the workflow-level inputs
specification is null or not specified at all, the workflow can accept inputs provided directly to the workflow stages by the user.
Multiple stages can also link to the same workflow-level input.
Optionally, we can also specify workflow-level outputs
:
The field outputSource
allows us to configure which stage-level outputs will be the outputs of the workflow. This, together with inputs
, is especially useful when we want to set a workflow as an executable within another workflow.
Our example dxworkflow.json
workflow description will look as follows:
We can then build the workflow by running this command on the directory "BWA MEM + Freebayes Exome Workflow (locked)" (which contains the dxworkflow.json
):
To run the workflow, we should pass a FASTQ input file to the workflow-level reads
input field:
Providing the input file directly to the stage, for example -ialign_reads.reads_fastqgzs=my_input_file.fastq.gz
, is not possible for locked workflows.
To find out how to run the workflow and what inputs it accepts, we can use this command:
In the online interface, the experience of running a locked workflow will resemble an app, with inputs on the left side and outputs on the right one.
To lock down an existing workflow, we get the workflow from the platform by running dx get "BWA MEM + Freebayes Exome Workflow"
, add inputs
to the downloaded dxworkflow.json
, set workflowInputField
references from stages to these inputs
as explained above, and run dx build
again.
We can add an input
field for a stage if we want to the input of that stage with an output/input of a different stage. For example, the file array input sorted_bams
of our second stage, call_variants
, will receive values from the output field sorted_bam
of the first stage, align_reads
:
You can view the names of the input and output fields of an executable (app or applet) that is defined for a stage by running the command in the command line.
A locked workflow currently cannot be edited or created in the UI; we can build it in the CLI using and then commands.