{"metadata":{"image":[],"title":"","description":""},"api":{"url":"","auth":"required","settings":"","results":{"codes":[]},"params":[]},"next":{"description":"","pages":[]},"title":"Bring Your Own Tool(s) to CAVATICA","type":"basic","slug":"bring-your-own-tools-to-cavatica-1","excerpt":"","body":"[block:callout]\n{\n  \"type\": \"info\",\n  \"body\": \"* [Creating, testing and scaling CWL workflows](#section-creating-testing-and-scaling-cwl-workflows)\\n* [Introduction to the Seven Bridges Software Development Kit](#section-introduction-to-seven-bridges-software-development-kit)\\n* [Creating a development project](#section-creating-a-development-project)\\n* [Outlining your workflow](#section-outlining-your-workflow) \\n* [Wrapping your tool](#section-wrapping-your-tool)\\n* [Extending into a workflow](#section-extending-into-a-workflow)\\n* [Scaling up your analysis](#section-scaling-up-your-analysis)\\n* [Creating a tool from a script](#section-creating-a-tool-from-a-script)\\n* [Additional resources](#section-additional-resources)\"\n}\n[/block]\nReproducibility and portability in data analysis is vital in order to make scientific research as accurate, efficient, and cost-effective as possible. Seven Bridges and CAVATICA promote FAIR (Findability, Accessibility, Interoperability, Reusability) guidelines by utilizing Docker-based, reproducible, and portable tools written in [The Common Workflow Language (CWL)](https://www.commonwl.org/). CWL is an open-source, community-driven specification and emerging standard for describing how to run computational analyses with command-line tools in short, human- and machine-readable text files. Seven Bridges has been instrumental in developing and implementing CWL specifications, and supports its use in all of our environments. Because CWL tracks code version, inputs, outputs, and more, researchers can use CWL for debugging errors and validating results, ensuring reproducibility. Additionally, CWL’s inherent portability allows researchers to reproduce their method(s) with exactly the same software, dependencies, and configurations regardless of the execution environment.\n\nThere are hundreds of commonly used bioinformatics tools pre-installed on CAVATICA. Use our [Public Apps Gallery](https://cavatica.sbgenomics.com/public/apps) to browse and utilize hundreds of CWL tools, which are continually maintained by the Seven Bridges team. You can also bring in CWL tools from [Dockstore](https://dockstore.org/). **However, many researchers will want to work with pipelines that do not currently have a CWL version, or wish to edit existing CWL pipelines**. This guide provides step-by-step instructions for how to bring your own tools to the CAVATICA ecosystem. To learn more about working with CWL on CAVATICA, see our CWL blog post [here](https://www.sevenbridges.com/cwl-seven-bridges-platforms/). To learn more about adding your own tools to the CAVATICA Public Apps Gallery, see [here](https://docs.cavatica.org/docs/publish-your-app).\n\n## Creating, Testing, and Scaling CWL Workflows\n\nIn this section, the reader will first learn how the Seven Bridges Software Development Kit (SDK) enables the easy creation of CWL workflows that will benefit the greater community. We will review the benefits of the SDK and then walk through an example of workflow creation, testing, and scaling. There are also links to more detailed resources for further reading.\n\n***Helpful Terms to Know on Seven Bridges:***\n\n* **Wrapping**: The process of describing a command-line tool or custom script in Common Workflow Language (CWL) so that it can be easily run in multiple cloud environments, dynamically scale compute requirements based on inputs, and be inserted into distinct analysis pipelines.\n* **Tool**: A CWL description of a reusable piece of software that performs one specific function. An example is the bwa read alignment tool which can be applied to multiple workflows in different contexts. Tools need to have several things specified in the CWL description that includes Docker image, Linux base command, input files (or parameters), and output files. Tools can be used in completely disparate workflows and can be thought of as building blocks.  \n* **Workflow**: Chains of connected tools to accomplish a full analysis. Tools are often connected in a specific way to enable maximum computational efficiency and are also constructed to accomplish a specific analysis goal. Whereas tools describe a single software step (e.g. alignment or read sorting), a workflow describes a full analysis (e.g. variant discovery, differential expression, or multiple variant association tests).\n* **App**: An app is a general term to refer to both tools and workflows. The platform user will typically only see the term “app” in reference to mixed groups of tools and workflows, such as in the Public Apps Gallery, the Apps collection tab, or within a workspace.\n\n## Introduction to Seven Bridges Software Development Kit\n\n*For the Seven Bridges Software Development Kit documentation, please see the following: [https://docs.cavatica.org/docs/sdk-overview](https://docs.cavatica.org/docs/sdk-overview)*.\n\nCAVATICA provides a full Software Development Kit (SDK) that enables users to easily create CWL apps that can be tested and scaled up to production level directly on the platform. The SDK consists of a tool editor and a workflow editor. Both are based on the open-source project **Rabix**, a portmanteau of \"Reproducible Analyses for Bioinformatics\" (for more information, see [rabix.io](https://rabix.io/)). The SDK guides the user through the process of creating fully functional analytical workflows that can be tested, the scaled up to population-scale analysis, and shared with the research community. The SDK also has built-in version control at the tool and workflow level to enable full reproducibility of previous versions.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/d29b3e4-image23.png\",\n        \"image23.png\",\n        1600,\n        755,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 1. Overview of tool wrapping process\"\n    }\n  ]\n}\n[/block]\nThe Tool Editor guides the user through the creation of a portable CWL description by linking a pre-built Docker image (see platform documentation section on [Docker](https://docs.cavatica.org/docs/docker-basics)) to a command-line or script that will be run inside the container. The above image shows the tool wrapping process. The Tool Editor enables users to easily create CWL by specifying the tool details through the visual interface (Figure 2). \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/7d64663-image5.png\",\n        \"image5.png\",\n        1541,\n        1041,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 2. The Visual Editor\"\n    }\n  ]\n}\n[/block]\nIn this above figure, the numbered orange icons denote the following:\n[1] Tabs for tool editor views (App Info, Visual Editor, Code).\n[2] Commands available for apps (Revision history, Save, Run, and additional actions where you can export your app to CWL in JSON or YAML format). \n[3] Tool editor pane.\n[4] Object inspector, showing properties of an input port of the tool being described in the tool editor. The items shown here vary depending on the object that has been selected, and in some cases, on other selections in the object inspector.\n[5] Preview pane, showing a preview of the command that is being built up in the tool editor.\n[6] Tool status bar, showing the CWL version and a toggle to show and hide the error state and the Command-Line pane.\n\nThis GUI template simplifies the technical aspects of this process and makes it as easy as possible for users to get their tools set up on the platform. The CWL code can also be edited directly in the tool editor if that is desired. For users working with JavaScript, JavaScript dynamic expressions can be tested without having to leave the tool editor.\n\nThe Workflow Editor enables users to create full pipelines by linking together multiple discrete tools, as shown in Figure 3 below. The workflow editor is a drag-and-drop visual interface that makes it easy to build even the most complex pipelines.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/48400b4-image6.png\",\n        \"image6.png\",\n        1999,\n        1070,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 3. The Workflow Editor’s visual interface for the creation and editing of CWL workflows.\"\n    }\n  ]\n}\n[/block]\nBefore we dive into more detail on how to use the Tool Editor and the Workflow Editor, it is important to understand the distinction between tools and workflows. The distinction is only present in the CWL, and it is an important one. Wrapping a tool requires knowledge of Docker and Linux command-lines. The Tool Editor helps the user get past even the most technical and dynamic of command-line and script issues, with the goal being the creation of a reusable and shareable component. For building workflows, the Docker and Linux command-lines are abstracted away to enable less-technical users to build full analytical pipelines. We can refer to this as “separation of concerns.” Each tool should be designed to handle one functional aspect, and therefore will be able to operate in multiple analytical pipelines.\n\nLinking together multiple tools into a full computational pipeline can have many advantages. It is important to understand the benefits of building a full and robust workflow that includes each of the analysis steps. The most apparent benefit is that it makes the entire pipeline easier to share, as there will only be one resulting CWL file. The CWL file is a human-readable text file that can be distributed digitally in multiple ways, such as through Dockstore, Seven Bridges, GitHub, or over email. A novice user can easily reproduce the full analysis using the one file. They can also use the SDK to make adjustments if necessary, or even decompose the workflow to get at the constituent tools for use in other contexts.\n\nCAVATICA has built-in optimizations to execute a workflow for maximum efficiency and cost savings. For example, workflows only save final output files back to the project. Since intermediate files from earlier steps in the workflow are not saved, they do not accumulate cloud storage costs, saving funds that would otherwise be used for intermediate file object storage. Users can still make use of intermediate files for subsequent reruns of a task by simply turning on “memoization” for that task and intermediate files will be re-used where appropriate.\n\nFinally, linking multiple tools together also has the added benefit of increasing computational efficiency. When running workflows, multiple tools can use the same compute instance if multiple CPU cores are available. This saves time and funds, and increases the ability to run jobs in parallel with no additional configurations.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/95ddeec-image19.png\",\n        \"image19.png\",\n        1999,\n        916,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 4. Example workflow showing how three tools can be connected together into one workflow\"\n    }\n  ]\n}\n[/block]\nIn the following sections, we will build the workflow in Figure 4. Here, we can visually see the importance of creating a workflow: running each of these tools separately would require more steps from the user and require more unnecessary data to be moved back and forth from the cloud computational instance to the user’s workspace. Therefore, running as a single workflow achieves the best efficiency.  \n\n## Creating A Development Project\n\nBefore getting started with this section, we recommend first creating a development workspace (project) to house the new tool(s) and workflow(s) while they are being created and tested. Please see the “Get Started” tab [here](https://docs.cavatica.org/docs/getting-started) for detailed instructions and tutorials on topics ranging from how to create projects to cloud infrastructure pricing. \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/b56457d-image13.png\",\n        \"image13.png\",\n        1187,\n        1191,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 5. Create a project on CAVATICA\"\n    }\n  ]\n}\n[/block]\nFigure 5 shows all the options available when creating a project including selecting the Billing Group.\n\n## Outlining Your Workflow\n\nFor the purposes of this tutorial, we will create a Next Generation Sequencing (NGS) alignment Quality Control (QC) workflow as an example problem. Researchers should outline their pipeline into individual steps. These steps should correspond to individual software executables (i.e. bwa, samtools) or scripts (i.e. R, python, shell).\n\nA great place to outline your tool is in your development project description, shown below in Figure 6:  \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/328a1b2-image24.png\",\n        \"image24.png\",\n        642,\n        797,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 6. Project description space can be used to outline tool\"\n    }\n  ]\n}\n[/block]\nIt is important to determine if there are tools (steps in your outline) that have already been wrapped and are published in either Dockstore or the CAVATICA Public Apps Gallery. This reduces the time in porting analytical workflows to the cloud because these steps will not have to be re-validated or re-benchmarked. This also promotes developing with “separation of concerns.” This means that every tool (step) can be versioned, tested and improved without adversely affecting the entire workflow.\n\nWe recommend searching the CAVATICA Public Apps Gallery to find validated and reusable components. Tools from the Public Apps Gallery can be easily imported directly into your project. These apps have been validated and optimized for the cloud. By re-using existing tools, the development time is dramatically reduced.\n\nSearching the Public Apps Gallery reveals that CWL tools are available for Fastqc and Picard CollectWgsMetrics. Therefore, the only tool that needs to be wrapped is MultiQC.\n\n## Wrapping Your Tool\n\nAs described previously, the process of describing a command-line tool or script in CWL so that it can be run in a cloud environment either by itself or in a larger workflow is known as wrapping. Let us proceed with wrapping our MultiQC tool. The first step is to either (1) create a Docker image from a Docker build file or (2) find one available to us on a hosted repository. Next, we should run the Docker locally to test out the basic command line. If a Docker image was previously created and hosted for us we can use that to save time. On the other hand, if the software programs are not available in a single Docker image you will need to build it. Please see the section on Working with Docker for more information on creating images.\n\nFor this example, a MultiQC Docker image is available for us via biocontainers.pro with the image specially hosted at [quay.io/biocontainers/multiqc:1.9--pyh9f0ad1d_0](https://quay.io/biocontainers/multiqc:1.9--pyh9f0ad1d_0).\n\nTo use the SDK tool editor to wrap MultiQC, we will follow these steps in the development project:\n\n**Step 1**: In the development project, click on the Apps tab and select “Add app.”\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/9bb52d3-image12.png\",\n        \"image12.png\",\n        1212,\n        390,\n        \"#333\"\n      ]\n    }\n  ]\n}\n[/block]\n**Step 2**: On the next screen, select “Create New App,” then select “Create a Tool.” \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/1b7fdb5-image3.png\",\n        \"image3.png\",\n        822,\n        726,\n        \"#333\"\n      ]\n    }\n  ]\n}\n[/block]\n**Step 3**: Name your tool “MultiQC” and create a version of CWL 1.0 tool from the options on the dropdown menu. Next, click the Create button. This will automatically take you to the visual Tool Editor.\n\n**Step 4**: To complete our wrapping of MultiQC, we need to fill in the Docker Image, Base Command, Input Ports, and Outputs sections in the Visual Editor.  \n\nThe Docker image/repository is quay.io/biocontainers/multiqc:1.9--pyh9f0ad1d_0.\nFor this example, the base command (see screenshot below) is simply: MultiQC multiqc (See *Creating a tool from a script* for how this will look for your own custom script).\nFor this example, we just need one input port which is an array of our quality control files from the upstream apps. We do not need any additional parameters for this example. If you are wrapping your own custom script, you can configure multiple input ports of different types.\nPlease see Figure 7 for where to fill in the details.\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/e8ad199-image14.png\",\n        \"image14.png\",\n        1245,\n        386,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 7. Fill out details for MultiQC tool\"\n    }\n  ]\n}\n[/block]\nBe sure to create an input of type “array” which has items of type “File.” The MultiQC executable does not require that inputs of different types be prefaced with any flags or indicators. When wrapping an executable that requires distinguishing inputs (e.g. “--arg1 --arg2”), multiple inputs would need to be added.\n\nThe tool editor gives the user a preview of the resulting command-line:  \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/6828fb1-image27.png\",\n        \"image27.png\",\n        1191,\n        106,\n        \"#333\"\n      ]\n    }\n  ]\n}\n[/block]\nThis is a relatively simple one and the arguments are just the full paths in the input file array. Features such as file metadata and JavaScript expression can be used to create a more sophisticated Linux command-line for other tools.\n\nThe output port is the comprehensive MultiQC report (Figure 8) that the software tool creates. For this output we will use a wildcard inside the “glob” field. The “[glob](page:glob)” is simply how the tool will select which files to keep from the current working directory. The user can create as many output ports as necessary. Since MultiQC is a simplification and summarization tool we will only have the one HTML report which can be acquired using a glob of “*.html.” \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/e1da197-image10.png\",\n        \"image10.png\",\n        822,\n        846,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 8. MultiQC report as output port\"\n    }\n  ]\n}\n[/block]\nThe output “glob” field (like all fields in the tool editor) has the ability to use JavaScript expressions to dynamically search for files in a very specific manner such as the full path that is based on the input files or to scan through a deep folder structure.    \n\nThe completed tool is shown in Figure 9.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/223ffd1-image8.png\",\n        \"image8.png\",\n        1999,\n        988,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 9. Completed Tool\"\n    }\n  ]\n}\n[/block]\nFinally, we should consider the Computational Resources section of the Tool Editor (Figure 10). Here it is important to specify the minimum compute required. Because our example tool is not compute-intensive we can require a minimal amount of RAM and CPU. Through JavaScript dynamic expressions we can customize these computational requirements to scale with either the input file sizes or user input parameters. The Seven Bridges job scheduler will select the appropriate cloud instance(s) based on these constraints.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/799edc2-image14.png\",\n        \"image14.png\",\n        1245,\n        386,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 10. Computational Resources section of Tool Editor\"\n    }\n  ]\n}\n[/block]\nTools can be tested by themselves, but in some cases it makes more sense to test the tool in the context of the complete workflow. For simplicity, we will add MultiQC to the workflow and use the output from the tool upstream of MultiQC in the workflow to test the MultiQC tool.\n\nFinding appropriate test data is key to testing tools and workflows. When possible, we recommend working with data that is small in size to test tools and workflows. Small in size generally means a small size on disk and usually correlates to a smaller number of NGS reads, smaller number of variants, or smaller number of samples. Sometimes this small data is referred to as a “toy” dataset or a “subset” of data. Testing the tool wrapper will generally require multiple test runs using this small data set.\n\nCAVATICA hosts a number of test files in the [Public Files Gallery](https://cavatica.sbgenomics.com/public/apps) that range from reference files to test size input data. Users can link these test files to their project instead of uploading their own test data to avoid storage costs. One of these test files is the human whole exome sequencing sample **merged-normal.bam** which we will use for testing here. You can view the provenance of this test file by clicking on the file name and then on “metadata”:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/383b617-image16.png\",\n        \"image16.png\",\n        1864,\n        234,\n        \"#333\"\n      ]\n    }\n  ]\n}\n[/block]\nThis file is a “subset” of the whole exome data and is therefore a good choice for testing since the cost per analysis will be less than if data from all chromosomes were used. Tools should always be tested separately. When wrapping a tool the user should obtain access to data they can use for testing. The above metadata description also tells us the exact reference that was used for the read alignment. CAVATICA also has the same reference files in the Public Files Gallery here: \n\n* [https://cavatica.sbgenomics.com/public/files/5772b6d8507c1752674486e6/](https://cavatica.sbgenomics.com/public/files/5772b6d8507c1752674486e6/)\n* [https://cavatica.sbgenomics.com/public/files/578cf949507c17681a3117e2/](https://cavatica.sbgenomics.com/public/files/578cf949507c17681a3117e2/)\n\nMake sure to copy both testing files to your development project. Because these files are hosted in the Public Files Gallery, linking these files to your project will not lead to any additional storage costs. \n\n## Extending Into A Workflow\n\nThe next step is to add our tool to a workflow with the upstream QC tools. We will use the pipeline editor to do this.\n\n**Step 1**. The first step is to create a new “blank canvas” in the workflow editor. Go to the Apps tab in the development project and click on “Add app”. This time select “Create New App,” and then “Create a workflow”.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/20f4e4a-image2.png\",\n        \"image2.png\",\n        811,\n        924,\n        \"#333\"\n      ]\n    }\n  ]\n}\n[/block]\n**Step 2**. After creating the workflow, the next screen is a blank canvas in the Workflow Editor. From here, we can add multiple QC apps that are compatible with MultiQC to the canvas directly from the Public Apps Gallery. Search for “fastqc” and then for “picard alignment metrics” and use the mouse to drag them onto the workflow canvas.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/b0f8f1c-image17.png\",\n        \"image17.png\",\n        1600,\n        739,\n        \"#333\"\n      ]\n    }\n  ]\n}\n[/block]\nAdd the MultiQC CWL tool from the current project in the “My Projects” tab. The screen will look like this:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/86ff401-image25.png\",\n        \"image25.png\",\n        1600,\n        867,\n        \"#333\"\n      ]\n    }\n  ]\n}\n[/block]\nThe next step is to connect the apps together. The nodes that are displayed on the workflow canvas represent apps. The input and output ports are represented by small circles on the perimeter of the node. Circles on the left of the node represent input ports whereas the ones on the right indicate output ports. Use the mouse to connect the wire frame together. The completed workflow will look like this:\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/dfb3bb5-image7.png\",\n        \"image7.png\",\n        1999,\n        835,\n        \"#333\"\n      ]\n    }\n  ]\n}\n[/block]\nThis simple workflow highlights several advantages of the workflow editor. Notice that the “input file” input port node which represents an aligned bam file for this workflow feeds into both the Picard CollectWgsMetrics and FastQC tools. This means that the end user only needs to specify this input one time when running the task and that the alignment metrics and FastQC tools will run in parallel, conserving time and funds.  \n\nTake note that one of the FastQC outputs is not connected to any downstream tool. In this case, this output port creates a zip file of the raw report data. However, the MultiQC tool does not need this output file and therefore it does not need to be moved or persisted outside the Docker container of the FastQC tool. In addition, although the CollectWgsMetrics and FastQC nodes feed into MultiQC, they do not have output nodes for themselves. This workflow has only 1 output which is the MultiQC html report. The intermediate reports will be saved temporarily in case the tool needs to be re-run, but will not persist in the file page of the user’s workspace, highlighting another way the workflow conserves funding.\n\nWe can test the workflow directly on the platform using the reference files in the Public Gallery. A completed task of the workflow will have one interactive report as an output. See the completed task in Figure 11.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/cd231db-image1.png\",\n        \"image1.png\",\n        1999,\n        488,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 11. Completed Task page where users can access output files\"\n    }\n  ]\n}\n[/block]\nThe output of MultiQC is an interactive report that is viewable directly on the platform (Figure 12).\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/1b8abdd-image8.png\",\n        \"image8.png\",\n        1999,\n        988,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 12. Interactive report from MultiQC tool\"\n    }\n  ]\n}\n[/block]\nFor more information about the workflow editor and for other examples please refer to the following pages:\n\n* [about the workflow editor](doc:about-the-workflow-editor)\n* [create a workflow](doc:create-a-workflow)\n* [workflow editor tutorial](doc:workflow-editor-tutorial)\n\n## Scaling up your analysis \n\nThere are two easy ways to scale your workflows on CAVATICA. We refer to these as “batching” and “scattering.” Batch analysis separates files into batches or groups when running your analysis. The batching is done according to the specified metadata criteria of your input files or according to a files list you provide. Batch analyses can be defined at run time with no special setup in the tool. However, each batch is run on a separate instance. For more information on batch analyses, please see [here](doc:about-batch-analyses).\n\nUsing our NGS QC workflow example we can create a batch task for every file in the input file port, as shown in Figure 13. This batch task will create 1 child task for each input bam file.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/5626a8e-image11.png\",\n        \"image11.png\",\n        1185,\n        1027,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 13. Creating a batch task\"\n    }\n  ]\n}\n[/block]\nWe can use another method called “scattering,” which operates inside a single task. This means that a workflow can utilize multiple cores in a single compute instance, which is often more efficient than using multiple instances. Scattering can only be used at the workflow level, not at the tool level. To use scattering, we need to edit our workflow. We make the input file of type “array” and the array type “file” as shown in Figure 14. \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/af6dc8a-image21.png\",\n        \"image21.png\",\n        1999,\n        1364,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 14. Input file settings for scatter\"\n    }\n  ]\n}\n[/block]\nClick on each of our QC tools and select “Step.” In the “step” panel select the appropriate input to scatter on. In this case we scatter by “input_bam” for the Picard Collect WGS Metrics tool (Figure 15) and by “input_fastq” for the FastQC tool (Figure 16). When the workflow is run, the user can select multiple input files and each of them will be processed in parallel on separate compute nodes.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/29b0262-image20.png\",\n        \"image20.png\",\n        1536,\n        1155,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 15. Scatter by input_bam for Picard tool\"\n    }\n  ]\n}\n[/block]\n\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/4f5fa10-image9.png\",\n        \"image9.png\",\n        1528,\n        1136,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 16. Scatter by input_fastq for FastQC tool\"\n    }\n  ]\n}\n[/block]\nThis was a brief introduction to the powerful scatter ability of the workflow editor. For more information, see our [documentation](doc:about-the-workflow-editor). \n\nWhen running your custom workflow, you can define computational requirements so that there is enough memory and CPUs to run multiple jobs in parallel. For example, if your tool requires 4GB of RAM and you select an instance with 8 CPUs and 32G RAM, you will see that 8 jobs are running in parallel when you run your workflow as shown in Figure 17.\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/e864a92-image22.png\",\n        \"image22.png\",\n        1604,\n        685,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 17. Scatter\"\n    }\n  ]\n}\n[/block]\nIf you have followed this guide, your tool has now been wrapped and added to a workflow. It has also been tested on a “toy” dataset and validated against real data for your project. \n\n## Creating a tool from a script\n\nNot all tools need to be command-line binaries. Many researchers bring their shell scripts, Python and R scripts to Seven Bridges and this is all possible using the Tool Editor.   \n\nFor example, if we wanted to run an R script using the GENESIS Docker image we could do that without having to recreate the Docker image. To run a specific script that is not included in the Docker image, use the “File requirements” field shown in Figure 18. Specify a name for your file and paste in the file contents. \n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/5bd8e20-image4.png\",\n        \"image4.png\",\n        1999,\n        746,\n        \"#333\"\n      ],\n      \"caption\": \"Figure 18. File Requirements box\"\n    }\n  ]\n}\n[/block]\nThen enter the name of the file in the “Base command” section along with the command required to execute it (e.g. Rscript):\n[block:image]\n{\n  \"images\": [\n    {\n      \"image\": [\n        \"https://files.readme.io/374c078-image15.png\",\n        \"image15.png\",\n        1015,\n        174,\n        \"#333\"\n      ]\n    }\n  ]\n}\n[/block]\nSimilarly, if you were using a python script the base command would be “Python.”  Using the files requirements section of the Tool Editor we can execute any type of script without having to create a new Docker container.  \n\nAfter completing this guide, you will have learned to create CWL workflows using Seven Bridges Software Development Kit (SDK) as well as methods for testing and scaling these workflows. For detailed information regarding the use of the Cancer Genomics Cloud platform that is beyond the scope of this guide, please see the rest of our [CAVATICA documentation](https://docs.cavatica.org/docs/getting-started). Lastly, see the *Additional Resources* section below for links to other helpful guides and tutorials. \n\n## Additional resources\n\n  * [SevenBridges Introduction to tool wrapping](https://docs.cavatica.org/docs/introduction-to-tool-wrapping)\n  * [Troubleshooting](https://docs.cavatica.org/docs/troubleshoot-a-failed-task)\n  * [CWL User Guide](https://www.commonwl.org/user_guide/)","updates":[],"order":1,"isReference":false,"hidden":false,"sync_unique":"","link_url":"","link_external":false,"_id":"60a6453dd1428802899e0026","createdAt":"2021-05-20T11:17:17.433Z","user":"5767bc73bb15f40e00a28777","category":{"sync":{"isSync":false,"url":""},"pages":[],"title":"Tutorials","slug":"tutorials","order":1,"from_sync":false,"reference":false,"_id":"6024033e2b2f6f004dfe994c","createdAt":"2021-02-10T16:01:02.224Z","version":"5773dcfc255e820e00e1cd50","project":"5773dcfc255e820e00e1cd4d","__v":0},"version":{"version":"1.0","version_clean":"1.0.0","codename":"","is_stable":true,"is_beta":false,"is_hidden":false,"is_deprecated":false,"categories":["5773dcfc255e820e00e1cd51","5773df36904b0c0e00ef05ff","577baf92451b1e0e006075ac","577bb183b7ee4a0e007c4e8d","577ce77a1cf3cb0e0048e5ea","577d11865fd4de0e00cc3dab","578e62792c3c790e00937597","578f4fd98335ca0e006d5c84","578f5e5c3d04570e00976ebb","57bc35f7531e000e0075d118","57f801b3760f3a1700219ebb","5804d55d1642890f00803623","581c8d55c0dc651900aa9350","589dcf8ba8c63b3b00c3704f","594cebadd8a2f7001b0b53b2","59a562f46a5d8c00238e309a","5a2aa096e25025003c582b58","5a2e79566c771d003ca0acd4","5a3a5166142db90026f24007","5a3a52b5bcc254001c4bf152","5a3a574a2be213002675c6d2","5a3a66bb2be213002675cb73","5a3a6e4854faf60030b63159","5c8a68278e883901341de571","5cb9971e57bf020024523c7b","5cbf1683e2a36d01d5012ecd","5dc15666a4f788004c5fd7d7","5eaff69e844d67003642a020","5eb00899b36ba5002d35b0c1","5eb0172be179b70073dc936e","5eb01b42b36ba5002d35ebba","5eb01f202654a20136813093","5eb918ef149186021c9a76c8","5f0839d3f4b24e005ebbbc29","5f893e508c9862002d0614a9","6024033e2b2f6f004dfe994c","60a7a12f9a06c70052b7c4db","60a7ab97266a4700161507c4","60b0c84babba720010a8b0b5"],"_id":"5773dcfc255e820e00e1cd50","__v":39,"createdAt":"2016-06-29T14:36:44.812Z","releaseDate":"2016-06-29T14:36:44.812Z","project":"5773dcfc255e820e00e1cd4d"},"project":"5773dcfc255e820e00e1cd4d","__v":0,"parentDoc":null}

Bring Your Own Tool(s) to CAVATICA


[block:callout] { "type": "info", "body": "* [Creating, testing and scaling CWL workflows](#section-creating-testing-and-scaling-cwl-workflows)\n* [Introduction to the Seven Bridges Software Development Kit](#section-introduction-to-seven-bridges-software-development-kit)\n* [Creating a development project](#section-creating-a-development-project)\n* [Outlining your workflow](#section-outlining-your-workflow) \n* [Wrapping your tool](#section-wrapping-your-tool)\n* [Extending into a workflow](#section-extending-into-a-workflow)\n* [Scaling up your analysis](#section-scaling-up-your-analysis)\n* [Creating a tool from a script](#section-creating-a-tool-from-a-script)\n* [Additional resources](#section-additional-resources)" } [/block] Reproducibility and portability in data analysis is vital in order to make scientific research as accurate, efficient, and cost-effective as possible. Seven Bridges and CAVATICA promote FAIR (Findability, Accessibility, Interoperability, Reusability) guidelines by utilizing Docker-based, reproducible, and portable tools written in [The Common Workflow Language (CWL)](https://www.commonwl.org/). CWL is an open-source, community-driven specification and emerging standard for describing how to run computational analyses with command-line tools in short, human- and machine-readable text files. Seven Bridges has been instrumental in developing and implementing CWL specifications, and supports its use in all of our environments. Because CWL tracks code version, inputs, outputs, and more, researchers can use CWL for debugging errors and validating results, ensuring reproducibility. Additionally, CWL’s inherent portability allows researchers to reproduce their method(s) with exactly the same software, dependencies, and configurations regardless of the execution environment. There are hundreds of commonly used bioinformatics tools pre-installed on CAVATICA. Use our [Public Apps Gallery](https://cavatica.sbgenomics.com/public/apps) to browse and utilize hundreds of CWL tools, which are continually maintained by the Seven Bridges team. You can also bring in CWL tools from [Dockstore](https://dockstore.org/). **However, many researchers will want to work with pipelines that do not currently have a CWL version, or wish to edit existing CWL pipelines**. This guide provides step-by-step instructions for how to bring your own tools to the CAVATICA ecosystem. To learn more about working with CWL on CAVATICA, see our CWL blog post [here](https://www.sevenbridges.com/cwl-seven-bridges-platforms/). To learn more about adding your own tools to the CAVATICA Public Apps Gallery, see [here](https://docs.cavatica.org/docs/publish-your-app). ## Creating, Testing, and Scaling CWL Workflows In this section, the reader will first learn how the Seven Bridges Software Development Kit (SDK) enables the easy creation of CWL workflows that will benefit the greater community. We will review the benefits of the SDK and then walk through an example of workflow creation, testing, and scaling. There are also links to more detailed resources for further reading. ***Helpful Terms to Know on Seven Bridges:*** * **Wrapping**: The process of describing a command-line tool or custom script in Common Workflow Language (CWL) so that it can be easily run in multiple cloud environments, dynamically scale compute requirements based on inputs, and be inserted into distinct analysis pipelines. * **Tool**: A CWL description of a reusable piece of software that performs one specific function. An example is the bwa read alignment tool which can be applied to multiple workflows in different contexts. Tools need to have several things specified in the CWL description that includes Docker image, Linux base command, input files (or parameters), and output files. Tools can be used in completely disparate workflows and can be thought of as building blocks. * **Workflow**: Chains of connected tools to accomplish a full analysis. Tools are often connected in a specific way to enable maximum computational efficiency and are also constructed to accomplish a specific analysis goal. Whereas tools describe a single software step (e.g. alignment or read sorting), a workflow describes a full analysis (e.g. variant discovery, differential expression, or multiple variant association tests). * **App**: An app is a general term to refer to both tools and workflows. The platform user will typically only see the term “app” in reference to mixed groups of tools and workflows, such as in the Public Apps Gallery, the Apps collection tab, or within a workspace. ## Introduction to Seven Bridges Software Development Kit *For the Seven Bridges Software Development Kit documentation, please see the following: [https://docs.cavatica.org/docs/sdk-overview](https://docs.cavatica.org/docs/sdk-overview)*. CAVATICA provides a full Software Development Kit (SDK) that enables users to easily create CWL apps that can be tested and scaled up to production level directly on the platform. The SDK consists of a tool editor and a workflow editor. Both are based on the open-source project **Rabix**, a portmanteau of "Reproducible Analyses for Bioinformatics" (for more information, see [rabix.io](https://rabix.io/)). The SDK guides the user through the process of creating fully functional analytical workflows that can be tested, the scaled up to population-scale analysis, and shared with the research community. The SDK also has built-in version control at the tool and workflow level to enable full reproducibility of previous versions. [block:image] { "images": [ { "image": [ "https://files.readme.io/d29b3e4-image23.png", "image23.png", 1600, 755, "#333" ], "caption": "Figure 1. Overview of tool wrapping process" } ] } [/block] The Tool Editor guides the user through the creation of a portable CWL description by linking a pre-built Docker image (see platform documentation section on [Docker](https://docs.cavatica.org/docs/docker-basics)) to a command-line or script that will be run inside the container. The above image shows the tool wrapping process. The Tool Editor enables users to easily create CWL by specifying the tool details through the visual interface (Figure 2). [block:image] { "images": [ { "image": [ "https://files.readme.io/7d64663-image5.png", "image5.png", 1541, 1041, "#333" ], "caption": "Figure 2. The Visual Editor" } ] } [/block] In this above figure, the numbered orange icons denote the following: [1] Tabs for tool editor views (App Info, Visual Editor, Code). [2] Commands available for apps (Revision history, Save, Run, and additional actions where you can export your app to CWL in JSON or YAML format). [3] Tool editor pane. [4] Object inspector, showing properties of an input port of the tool being described in the tool editor. The items shown here vary depending on the object that has been selected, and in some cases, on other selections in the object inspector. [5] Preview pane, showing a preview of the command that is being built up in the tool editor. [6] Tool status bar, showing the CWL version and a toggle to show and hide the error state and the Command-Line pane. This GUI template simplifies the technical aspects of this process and makes it as easy as possible for users to get their tools set up on the platform. The CWL code can also be edited directly in the tool editor if that is desired. For users working with JavaScript, JavaScript dynamic expressions can be tested without having to leave the tool editor. The Workflow Editor enables users to create full pipelines by linking together multiple discrete tools, as shown in Figure 3 below. The workflow editor is a drag-and-drop visual interface that makes it easy to build even the most complex pipelines. [block:image] { "images": [ { "image": [ "https://files.readme.io/48400b4-image6.png", "image6.png", 1999, 1070, "#333" ], "caption": "Figure 3. The Workflow Editor’s visual interface for the creation and editing of CWL workflows." } ] } [/block] Before we dive into more detail on how to use the Tool Editor and the Workflow Editor, it is important to understand the distinction between tools and workflows. The distinction is only present in the CWL, and it is an important one. Wrapping a tool requires knowledge of Docker and Linux command-lines. The Tool Editor helps the user get past even the most technical and dynamic of command-line and script issues, with the goal being the creation of a reusable and shareable component. For building workflows, the Docker and Linux command-lines are abstracted away to enable less-technical users to build full analytical pipelines. We can refer to this as “separation of concerns.” Each tool should be designed to handle one functional aspect, and therefore will be able to operate in multiple analytical pipelines. Linking together multiple tools into a full computational pipeline can have many advantages. It is important to understand the benefits of building a full and robust workflow that includes each of the analysis steps. The most apparent benefit is that it makes the entire pipeline easier to share, as there will only be one resulting CWL file. The CWL file is a human-readable text file that can be distributed digitally in multiple ways, such as through Dockstore, Seven Bridges, GitHub, or over email. A novice user can easily reproduce the full analysis using the one file. They can also use the SDK to make adjustments if necessary, or even decompose the workflow to get at the constituent tools for use in other contexts. CAVATICA has built-in optimizations to execute a workflow for maximum efficiency and cost savings. For example, workflows only save final output files back to the project. Since intermediate files from earlier steps in the workflow are not saved, they do not accumulate cloud storage costs, saving funds that would otherwise be used for intermediate file object storage. Users can still make use of intermediate files for subsequent reruns of a task by simply turning on “memoization” for that task and intermediate files will be re-used where appropriate. Finally, linking multiple tools together also has the added benefit of increasing computational efficiency. When running workflows, multiple tools can use the same compute instance if multiple CPU cores are available. This saves time and funds, and increases the ability to run jobs in parallel with no additional configurations. [block:image] { "images": [ { "image": [ "https://files.readme.io/95ddeec-image19.png", "image19.png", 1999, 916, "#333" ], "caption": "Figure 4. Example workflow showing how three tools can be connected together into one workflow" } ] } [/block] In the following sections, we will build the workflow in Figure 4. Here, we can visually see the importance of creating a workflow: running each of these tools separately would require more steps from the user and require more unnecessary data to be moved back and forth from the cloud computational instance to the user’s workspace. Therefore, running as a single workflow achieves the best efficiency. ## Creating A Development Project Before getting started with this section, we recommend first creating a development workspace (project) to house the new tool(s) and workflow(s) while they are being created and tested. Please see the “Get Started” tab [here](https://docs.cavatica.org/docs/getting-started) for detailed instructions and tutorials on topics ranging from how to create projects to cloud infrastructure pricing. [block:image] { "images": [ { "image": [ "https://files.readme.io/b56457d-image13.png", "image13.png", 1187, 1191, "#333" ], "caption": "Figure 5. Create a project on CAVATICA" } ] } [/block] Figure 5 shows all the options available when creating a project including selecting the Billing Group. ## Outlining Your Workflow For the purposes of this tutorial, we will create a Next Generation Sequencing (NGS) alignment Quality Control (QC) workflow as an example problem. Researchers should outline their pipeline into individual steps. These steps should correspond to individual software executables (i.e. bwa, samtools) or scripts (i.e. R, python, shell). A great place to outline your tool is in your development project description, shown below in Figure 6: [block:image] { "images": [ { "image": [ "https://files.readme.io/328a1b2-image24.png", "image24.png", 642, 797, "#333" ], "caption": "Figure 6. Project description space can be used to outline tool" } ] } [/block] It is important to determine if there are tools (steps in your outline) that have already been wrapped and are published in either Dockstore or the CAVATICA Public Apps Gallery. This reduces the time in porting analytical workflows to the cloud because these steps will not have to be re-validated or re-benchmarked. This also promotes developing with “separation of concerns.” This means that every tool (step) can be versioned, tested and improved without adversely affecting the entire workflow. We recommend searching the CAVATICA Public Apps Gallery to find validated and reusable components. Tools from the Public Apps Gallery can be easily imported directly into your project. These apps have been validated and optimized for the cloud. By re-using existing tools, the development time is dramatically reduced. Searching the Public Apps Gallery reveals that CWL tools are available for Fastqc and Picard CollectWgsMetrics. Therefore, the only tool that needs to be wrapped is MultiQC. ## Wrapping Your Tool As described previously, the process of describing a command-line tool or script in CWL so that it can be run in a cloud environment either by itself or in a larger workflow is known as wrapping. Let us proceed with wrapping our MultiQC tool. The first step is to either (1) create a Docker image from a Docker build file or (2) find one available to us on a hosted repository. Next, we should run the Docker locally to test out the basic command line. If a Docker image was previously created and hosted for us we can use that to save time. On the other hand, if the software programs are not available in a single Docker image you will need to build it. Please see the section on Working with Docker for more information on creating images. For this example, a MultiQC Docker image is available for us via biocontainers.pro with the image specially hosted at [quay.io/biocontainers/multiqc:1.9--pyh9f0ad1d_0](https://quay.io/biocontainers/multiqc:1.9--pyh9f0ad1d_0). To use the SDK tool editor to wrap MultiQC, we will follow these steps in the development project: **Step 1**: In the development project, click on the Apps tab and select “Add app.” [block:image] { "images": [ { "image": [ "https://files.readme.io/9bb52d3-image12.png", "image12.png", 1212, 390, "#333" ] } ] } [/block] **Step 2**: On the next screen, select “Create New App,” then select “Create a Tool.” [block:image] { "images": [ { "image": [ "https://files.readme.io/1b7fdb5-image3.png", "image3.png", 822, 726, "#333" ] } ] } [/block] **Step 3**: Name your tool “MultiQC” and create a version of CWL 1.0 tool from the options on the dropdown menu. Next, click the Create button. This will automatically take you to the visual Tool Editor. **Step 4**: To complete our wrapping of MultiQC, we need to fill in the Docker Image, Base Command, Input Ports, and Outputs sections in the Visual Editor. The Docker image/repository is quay.io/biocontainers/multiqc:1.9--pyh9f0ad1d_0. For this example, the base command (see screenshot below) is simply: MultiQC multiqc (See *Creating a tool from a script* for how this will look for your own custom script). For this example, we just need one input port which is an array of our quality control files from the upstream apps. We do not need any additional parameters for this example. If you are wrapping your own custom script, you can configure multiple input ports of different types. Please see Figure 7 for where to fill in the details. [block:image] { "images": [ { "image": [ "https://files.readme.io/e8ad199-image14.png", "image14.png", 1245, 386, "#333" ], "caption": "Figure 7. Fill out details for MultiQC tool" } ] } [/block] Be sure to create an input of type “array” which has items of type “File.” The MultiQC executable does not require that inputs of different types be prefaced with any flags or indicators. When wrapping an executable that requires distinguishing inputs (e.g. “--arg1 --arg2”), multiple inputs would need to be added. The tool editor gives the user a preview of the resulting command-line: [block:image] { "images": [ { "image": [ "https://files.readme.io/6828fb1-image27.png", "image27.png", 1191, 106, "#333" ] } ] } [/block] This is a relatively simple one and the arguments are just the full paths in the input file array. Features such as file metadata and JavaScript expression can be used to create a more sophisticated Linux command-line for other tools. The output port is the comprehensive MultiQC report (Figure 8) that the software tool creates. For this output we will use a wildcard inside the “glob” field. The “[glob](page:glob)” is simply how the tool will select which files to keep from the current working directory. The user can create as many output ports as necessary. Since MultiQC is a simplification and summarization tool we will only have the one HTML report which can be acquired using a glob of “*.html.” [block:image] { "images": [ { "image": [ "https://files.readme.io/e1da197-image10.png", "image10.png", 822, 846, "#333" ], "caption": "Figure 8. MultiQC report as output port" } ] } [/block] The output “glob” field (like all fields in the tool editor) has the ability to use JavaScript expressions to dynamically search for files in a very specific manner such as the full path that is based on the input files or to scan through a deep folder structure. The completed tool is shown in Figure 9. [block:image] { "images": [ { "image": [ "https://files.readme.io/223ffd1-image8.png", "image8.png", 1999, 988, "#333" ], "caption": "Figure 9. Completed Tool" } ] } [/block] Finally, we should consider the Computational Resources section of the Tool Editor (Figure 10). Here it is important to specify the minimum compute required. Because our example tool is not compute-intensive we can require a minimal amount of RAM and CPU. Through JavaScript dynamic expressions we can customize these computational requirements to scale with either the input file sizes or user input parameters. The Seven Bridges job scheduler will select the appropriate cloud instance(s) based on these constraints. [block:image] { "images": [ { "image": [ "https://files.readme.io/799edc2-image14.png", "image14.png", 1245, 386, "#333" ], "caption": "Figure 10. Computational Resources section of Tool Editor" } ] } [/block] Tools can be tested by themselves, but in some cases it makes more sense to test the tool in the context of the complete workflow. For simplicity, we will add MultiQC to the workflow and use the output from the tool upstream of MultiQC in the workflow to test the MultiQC tool. Finding appropriate test data is key to testing tools and workflows. When possible, we recommend working with data that is small in size to test tools and workflows. Small in size generally means a small size on disk and usually correlates to a smaller number of NGS reads, smaller number of variants, or smaller number of samples. Sometimes this small data is referred to as a “toy” dataset or a “subset” of data. Testing the tool wrapper will generally require multiple test runs using this small data set. CAVATICA hosts a number of test files in the [Public Files Gallery](https://cavatica.sbgenomics.com/public/apps) that range from reference files to test size input data. Users can link these test files to their project instead of uploading their own test data to avoid storage costs. One of these test files is the human whole exome sequencing sample **merged-normal.bam** which we will use for testing here. You can view the provenance of this test file by clicking on the file name and then on “metadata”: [block:image] { "images": [ { "image": [ "https://files.readme.io/383b617-image16.png", "image16.png", 1864, 234, "#333" ] } ] } [/block] This file is a “subset” of the whole exome data and is therefore a good choice for testing since the cost per analysis will be less than if data from all chromosomes were used. Tools should always be tested separately. When wrapping a tool the user should obtain access to data they can use for testing. The above metadata description also tells us the exact reference that was used for the read alignment. CAVATICA also has the same reference files in the Public Files Gallery here: * [https://cavatica.sbgenomics.com/public/files/5772b6d8507c1752674486e6/](https://cavatica.sbgenomics.com/public/files/5772b6d8507c1752674486e6/) * [https://cavatica.sbgenomics.com/public/files/578cf949507c17681a3117e2/](https://cavatica.sbgenomics.com/public/files/578cf949507c17681a3117e2/) Make sure to copy both testing files to your development project. Because these files are hosted in the Public Files Gallery, linking these files to your project will not lead to any additional storage costs. ## Extending Into A Workflow The next step is to add our tool to a workflow with the upstream QC tools. We will use the pipeline editor to do this. **Step 1**. The first step is to create a new “blank canvas” in the workflow editor. Go to the Apps tab in the development project and click on “Add app”. This time select “Create New App,” and then “Create a workflow”. [block:image] { "images": [ { "image": [ "https://files.readme.io/20f4e4a-image2.png", "image2.png", 811, 924, "#333" ] } ] } [/block] **Step 2**. After creating the workflow, the next screen is a blank canvas in the Workflow Editor. From here, we can add multiple QC apps that are compatible with MultiQC to the canvas directly from the Public Apps Gallery. Search for “fastqc” and then for “picard alignment metrics” and use the mouse to drag them onto the workflow canvas. [block:image] { "images": [ { "image": [ "https://files.readme.io/b0f8f1c-image17.png", "image17.png", 1600, 739, "#333" ] } ] } [/block] Add the MultiQC CWL tool from the current project in the “My Projects” tab. The screen will look like this: [block:image] { "images": [ { "image": [ "https://files.readme.io/86ff401-image25.png", "image25.png", 1600, 867, "#333" ] } ] } [/block] The next step is to connect the apps together. The nodes that are displayed on the workflow canvas represent apps. The input and output ports are represented by small circles on the perimeter of the node. Circles on the left of the node represent input ports whereas the ones on the right indicate output ports. Use the mouse to connect the wire frame together. The completed workflow will look like this: [block:image] { "images": [ { "image": [ "https://files.readme.io/dfb3bb5-image7.png", "image7.png", 1999, 835, "#333" ] } ] } [/block] This simple workflow highlights several advantages of the workflow editor. Notice that the “input file” input port node which represents an aligned bam file for this workflow feeds into both the Picard CollectWgsMetrics and FastQC tools. This means that the end user only needs to specify this input one time when running the task and that the alignment metrics and FastQC tools will run in parallel, conserving time and funds. Take note that one of the FastQC outputs is not connected to any downstream tool. In this case, this output port creates a zip file of the raw report data. However, the MultiQC tool does not need this output file and therefore it does not need to be moved or persisted outside the Docker container of the FastQC tool. In addition, although the CollectWgsMetrics and FastQC nodes feed into MultiQC, they do not have output nodes for themselves. This workflow has only 1 output which is the MultiQC html report. The intermediate reports will be saved temporarily in case the tool needs to be re-run, but will not persist in the file page of the user’s workspace, highlighting another way the workflow conserves funding. We can test the workflow directly on the platform using the reference files in the Public Gallery. A completed task of the workflow will have one interactive report as an output. See the completed task in Figure 11. [block:image] { "images": [ { "image": [ "https://files.readme.io/cd231db-image1.png", "image1.png", 1999, 488, "#333" ], "caption": "Figure 11. Completed Task page where users can access output files" } ] } [/block] The output of MultiQC is an interactive report that is viewable directly on the platform (Figure 12). [block:image] { "images": [ { "image": [ "https://files.readme.io/1b8abdd-image8.png", "image8.png", 1999, 988, "#333" ], "caption": "Figure 12. Interactive report from MultiQC tool" } ] } [/block] For more information about the workflow editor and for other examples please refer to the following pages: * [about the workflow editor](doc:about-the-workflow-editor) * [create a workflow](doc:create-a-workflow) * [workflow editor tutorial](doc:workflow-editor-tutorial) ## Scaling up your analysis There are two easy ways to scale your workflows on CAVATICA. We refer to these as “batching” and “scattering.” Batch analysis separates files into batches or groups when running your analysis. The batching is done according to the specified metadata criteria of your input files or according to a files list you provide. Batch analyses can be defined at run time with no special setup in the tool. However, each batch is run on a separate instance. For more information on batch analyses, please see [here](doc:about-batch-analyses). Using our NGS QC workflow example we can create a batch task for every file in the input file port, as shown in Figure 13. This batch task will create 1 child task for each input bam file. [block:image] { "images": [ { "image": [ "https://files.readme.io/5626a8e-image11.png", "image11.png", 1185, 1027, "#333" ], "caption": "Figure 13. Creating a batch task" } ] } [/block] We can use another method called “scattering,” which operates inside a single task. This means that a workflow can utilize multiple cores in a single compute instance, which is often more efficient than using multiple instances. Scattering can only be used at the workflow level, not at the tool level. To use scattering, we need to edit our workflow. We make the input file of type “array” and the array type “file” as shown in Figure 14. [block:image] { "images": [ { "image": [ "https://files.readme.io/af6dc8a-image21.png", "image21.png", 1999, 1364, "#333" ], "caption": "Figure 14. Input file settings for scatter" } ] } [/block] Click on each of our QC tools and select “Step.” In the “step” panel select the appropriate input to scatter on. In this case we scatter by “input_bam” for the Picard Collect WGS Metrics tool (Figure 15) and by “input_fastq” for the FastQC tool (Figure 16). When the workflow is run, the user can select multiple input files and each of them will be processed in parallel on separate compute nodes. [block:image] { "images": [ { "image": [ "https://files.readme.io/29b0262-image20.png", "image20.png", 1536, 1155, "#333" ], "caption": "Figure 15. Scatter by input_bam for Picard tool" } ] } [/block] [block:image] { "images": [ { "image": [ "https://files.readme.io/4f5fa10-image9.png", "image9.png", 1528, 1136, "#333" ], "caption": "Figure 16. Scatter by input_fastq for FastQC tool" } ] } [/block] This was a brief introduction to the powerful scatter ability of the workflow editor. For more information, see our [documentation](doc:about-the-workflow-editor). When running your custom workflow, you can define computational requirements so that there is enough memory and CPUs to run multiple jobs in parallel. For example, if your tool requires 4GB of RAM and you select an instance with 8 CPUs and 32G RAM, you will see that 8 jobs are running in parallel when you run your workflow as shown in Figure 17. [block:image] { "images": [ { "image": [ "https://files.readme.io/e864a92-image22.png", "image22.png", 1604, 685, "#333" ], "caption": "Figure 17. Scatter" } ] } [/block] If you have followed this guide, your tool has now been wrapped and added to a workflow. It has also been tested on a “toy” dataset and validated against real data for your project. ## Creating a tool from a script Not all tools need to be command-line binaries. Many researchers bring their shell scripts, Python and R scripts to Seven Bridges and this is all possible using the Tool Editor. For example, if we wanted to run an R script using the GENESIS Docker image we could do that without having to recreate the Docker image. To run a specific script that is not included in the Docker image, use the “File requirements” field shown in Figure 18. Specify a name for your file and paste in the file contents. [block:image] { "images": [ { "image": [ "https://files.readme.io/5bd8e20-image4.png", "image4.png", 1999, 746, "#333" ], "caption": "Figure 18. File Requirements box" } ] } [/block] Then enter the name of the file in the “Base command” section along with the command required to execute it (e.g. Rscript): [block:image] { "images": [ { "image": [ "https://files.readme.io/374c078-image15.png", "image15.png", 1015, 174, "#333" ] } ] } [/block] Similarly, if you were using a python script the base command would be “Python.” Using the files requirements section of the Tool Editor we can execute any type of script without having to create a new Docker container. After completing this guide, you will have learned to create CWL workflows using Seven Bridges Software Development Kit (SDK) as well as methods for testing and scaling these workflows. For detailed information regarding the use of the Cancer Genomics Cloud platform that is beyond the scope of this guide, please see the rest of our [CAVATICA documentation](https://docs.cavatica.org/docs/getting-started). Lastly, see the *Additional Resources* section below for links to other helpful guides and tutorials. ## Additional resources * [SevenBridges Introduction to tool wrapping](https://docs.cavatica.org/docs/introduction-to-tool-wrapping) * [Troubleshooting](https://docs.cavatica.org/docs/troubleshoot-a-failed-task) * [CWL User Guide](https://www.commonwl.org/user_guide/)