<center><img src="https://i.imgur.com/BWehQrf.png" alt="drawing" width="700"/></center>
# IBA - Compose and run a simple workflow in usegalaxy.no
:::success
Tools in **Galaxy** can be run interactively, one by one, or combined into multi-step workflows that can be executed as a single analysis. If compatible, the output from one tool act as input for the next tool.
<center><img src="https://i.imgur.com/jNsRnMI.png" alt="drawing" width="700"/></center>
In this hands-on exercise, you will import data from NeLS and create your first workflow.
Read more about creating workflows in general at the official Galaxy pages [here](https://galaxyproject.org/learn/advanced-workflow/)
:::
<br/>
:::info
:information_source: **Note:** Names of files, folders, commands, and other functionality elements will be highlighted through the exercises in the following way: `file_name_example.txt`. User specific (and thus variable) character strings as for example user_name will be written between `<` and `>` as `<user_name>` to indicate the meaning.
:::
## Import exercise data
:::success
The data for this exercise is stored in the shared project folder in NeLS.
:::
<br/>
I. In usegalaxy.no, create a new history and rename it to `My first workflow`
<br/>
II. Expand the `Get Data` tool category and select `Get files from NeLS storage`
<br/>
II. This will redirect you to the NeLS portal (you might need to log in). Under `Projects`, browse to the directory `IBA_ELIXIR_2021/usegalaxy_workflow/`
<br/>
III. Select the two files in the `usegalaxy_workflow` folder and press `Send to Galaxy`
<br/>
IV. This will redirect you back to usegalaxy.no. Make sure that the data you imported are present in your current history. There should be two text files named `file1` and `file2`
## Create the workflow
:::success
In this part, you will create a very simple workflow by connecting tools in the proper order so that the output from the previous tool act as input for the next one. You will also set the parameters correctly for each tool, and run it on a simple data set.
This workflow is only meant for exercise purposes, as it will only produce meaningful results with the text files you imported from NeLS.
The workflow will consist of several tools (in bold below) that perform simple **text manipulation** operations on the data:
1. Import two datasets (tabulated text files) using **Input datasets**
2. Sort the data in each file numerically in ascending order based on the values in the first column using **Sort data**
3. Cut the 4th column from each file using **Cut**
4. Select the first 9 rows (lines) from the first file using **Select first**
5. Select the last 9 rows (lines) from the first file using **Select last**
6. Concatenate the two datasets using **Concatenate dataset**
7. Print only the output from the last tool
#### In addition:
* Add a tag named "workshop"
* The workflow should only generate a result file from the last step of of the workflow (**Select first lines**)
The workflow you are about to create will end up looking like this:
<br/>
<center><img src="https://i.imgur.com/ODaGVmG.png" alt="drawing" width="800"/></center>
:::
<br/>
:::info
:information_source: Tags can be useful for searching and for providing brief, single-word descriptions of the workflow, like e.g. "ChIP-seq" or "RNA-seq" or "metagenomics".
The annotation can give a slightly longer description of the workflow but this will not be shown in your workflow list. However, it will be shown behind the workflow name in the "Published workflows" list if you decide to share it.
:::
<br/>
I. Navigate to the top menu and select `Workflow` section [1]. Create a workflow by clicking on `+ Create` button [2] in the right top of the workflow panel and name the new workflow `my first workflow` [3]. Save [4] the new (empty) workflow
<br/>
<center><img src="https://i.imgur.com/OKohrbm.png" alt="drawing" width="500"/></center>
<br/>
II. An empty **Workflow editor** will appear. You can add tools to your workflow by browsing the **Tools** menu [1] and selecting the tool [2] you want to include. The selected to will appear in the **Workflow editor** [3].
:::info
:information_source: **Tip:** Using the search function in the **Tools** menu will make it easier to find tools. Start typing the name of the tool in the search field [4] and tools in the **Tools** menu will be filtered accordingly [5]
:::
<br/>
<center><img src="https://i.imgur.com/MLzWZmA.png" alt="drawing" width="800"/></center>
<br/>
III. Now you can start adding tools and connecting them as outlined below. **Remember that each individual tool has its separate parameter settings that you need to adjust.**
<br/>
IV. Start by adding "**Input file**" twice! Add the label "Input file 1" for the first input and "Input file 2" for the second input
<br/>
V. Add the tool "**Sort**" and adjust the parameters so that the tool will:
* label "Sort file 1"
* sort on column 1
* Numerical sort
* ascending order
<br/>
VI. Add the tool "**Sort**" again and adjust the parameters so that the tool will:
* label "Sort file 2"
* column 1
* Numerical sort
* ascending order
VII. Add the tool "**Cut**" and adjust the parameters so that the tool will:
* label "Cut file 1"
* cut column c4
<br/>
VII. Add the tool "**Cut**" again and adjust the parameters so that the tool will:
* label "Cut file 2"
* cut column c4
<br/>
VIII. Add the tool **Select first** and adjust the parameters so that the tool will:
* keep the first 9 lines
<br/>
IX. Add the tool **Select last** and adjust the parameters so that the tool will:
* keep the last 9 lines
X. Add the tool "**Concatenate**" and adjust the parameters so that the tool will:
* accept two input files
* select the output from **Select first** as the first input dataset and the output from **Select last** as the second dataset
<br/>
XI: Connect the tools so that the output from "**Input file 1**" is the input for "**Sort file 1**" and so on. File 1 and 2 will converge at "**Concatenate**"
XII. By default each tool write output files to you history. Change this so that only the output from the last tool is written to your history.
<br/>
:::warning
:warning: Remember to save the workflow before closing the **Workflow editor**
:::
XIII. Make sure you are still in the history with the two text files you imported from NeLS and try to run the workflow
<br/>
<center><img src="https://i.imgur.com/BsEwXFm.png" alt="drawing" width="800"/></center>
<br/>
XVI. You will not see any input files because the workflow only accept the data type `tabular`
XV. Change data type of the text files in your history by pressing the `Edit attributes` icon [1]. Select `Datatypes` in the new window that appears and start typing `tabular` [3] in the text field [2]. A drop-down menu will appear and you can select the data type from here [4]. Press `Change datatype` [5] to complete, and repeat for the second file.
<br/>
<center><img src="https://i.imgur.com/OSZ3XGs.png" alt="drawing" width="800"/></center>
<br/>
XVI. Try to run the workflow again and have a look at the output from the final tool.
<br/>
:::success
:+1: That was the end of this practical.
:::