# Routing Output Artifacts to Specific Workflows/Stages

Samples progressing through workflows can branch off and must be directed to different workflows or stages within a workflow.

Example: If it is not known at the initiation of a workflow if a sample is to be sequenced on a HiSeq or MiSeq. Rerouting the derived samples could be necessary.

### Solution <a href="#h_97bf4507-5925-4e70-8b3d-cb9bbd7643f8" id="h_97bf4507-5925-4e70-8b3d-cb9bbd7643f8"></a>

This example provides the user with the opportunity to route samples individually to the HiSeq, MiSeq, or both stages from the **Record Details** screen.

#### Step Configuration <a href="#h_08163378-105f-4f1b-a1ec-5cb41c7827a0" id="h_08163378-105f-4f1b-a1ec-5cb41c7827a0"></a>

The step is configured to display two checkbox analyte UDFs / derived sample custom fields. The fields are used to select the destination workflow/stages for each derived sample. You can choose to queue the sample for HiSeq, MiSeq, or both.

In this example, you select the following:

* Two samples to be queued for HiSeq
* Two samples for MiSeq
* Two that are not routed
* Two samples for both HiSeq and MiSeq

<figure><img src="https://2084401275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfjuebS41N49G1Eh55hP7%2Fuploads%2Fgit-blob-f20aa431fab2852ea91144d60c4188e1f351a0d6%2FRoutingOutputArtifactstoWorkflow_swCL.png?alt=media" alt=""><figcaption></figcaption></figure>

#### Parameters <a href="#h_205d1e9b-aa93-4344-bf56-00e9bf8bf06b" id="h_205d1e9b-aa93-4344-bf56-00e9bf8bf06b"></a>

The script accepts the following parameters:

<table data-header-hidden><thead><tr><th width="115"></th><th></th></tr></thead><tbody><tr><td>-u</td><td>The username of the current user (Required)</td></tr><tr><td>-p</td><td>The password of the current user (Required)</td></tr><tr><td>-s</td><td>The URI of the step that launches the script - the {stepURI:v2} token (Required)</td></tr></tbody></table>

An example of the full syntax to invoke the script is as follows:

{% code overflow="wrap" %}

```
bash -c "/usr/bin/python /opt/gls/clarity/customextensions/Route_to_HiSeq_MiSeq.py -u {username} -p {password} -s {stepURI:v2}"
```

{% endcode %}

### User Interaction <a href="#h_beae2a76-642a-436f-b67a-245be0205f8b" id="h_beae2a76-642a-436f-b67a-245be0205f8b"></a>

On the **Record Details** screen, you use the analyte UDF / derived sample custom field checkboxes to decide which workflow/stage combination to send each derived sample.

### About the Code <a href="#h_1b2af6d6-1572-4d79-9534-cf5676dc62d0" id="h_1b2af6d6-1572-4d79-9534-cf5676dc62d0"></a>

The first important piece of information required is the URI of the destination stage.

A stage URI can change across LIMS instances (such as switching from Dev to Prod). Therefore, the script gathers the stage URI from the **workflow and stage name**. This process occurs even when the workflows are identical.

The main method in the script is **routeAnalytes**. This method in turn carries out several operations:

* Gathers the information for the process / master step that triggered the script, including output analytes.
* For each analyte, evaluates which UDFs / custom fields have been set, and adds the analyte to a list of analytes to route.
* Creates the XML message for each stage.
* Does a POST to the REST API in order to add the analytes to the queue in Clarity LIMS.

**Modifications**

This script can be modified to look for a process level UDF (master step custom field), in which case all outputs from the step would be routed to the same step.

This example also serves to demonstrate a more general concept. Routing artifacts is valuable in any situation where a sample needs to be queued for a stage outside of the usual order of a workflow - or even routing newly submitted samples to the first stage in a workflow.

For more information about how to use the **artifact/route** endpoint, see [rest](https://help.connected.illumina.com/clarity-lims/api-and-database/api-docs/rest "mention").

### Assumptions and Notes <a href="#h_8f62e899-445c-4427-9316-c15b039c8495" id="h_8f62e899-445c-4427-9316-c15b039c8495"></a>

* You are running a version of Python that is supported by Clarity LIMS, as documented in the *Clarity LIMS Technical Requirements*.
* The attached file is placed on the LIMS server, in the **/opt/gls/clarity/customextensions** folder.
* The Python API Library (glsapiutil.py) is placed on the Clarity LIMS server, in the **/opt/gls/clarity/customextensions** folder. You can download the latest glsapiutil library from our [GitHub page](https://github.com/Illumina/BaseSpace_Clarity_LIMS).
* The example code is provided for illustrative purposes only. It does not contain sufficient exception handling for use 'as is' in a production environment.
* Samples can be inadvertently duplicated in the next step. This duplication occurs if:

  * The sample is being routed at the last step of a protocol and;
  * If the action of next steps is Mark Protocol as Complete.

  This duplication is due to:

  * The next step is routing the artifact to its default destination and;
  * The script is routing the same artifact.

  The solution here is to set the default next steps action to **Remove from Workflow** instead. This solution can be automated using Lab Logic Toolkit or the API.

### Attachments <a href="#h_c187a998-2336-41bd-8beb-469e45f22d93" id="h_c187a998-2336-41bd-8beb-469e45f22d93"></a>

Route\_to\_HiSeq\_MiSeq.py:

{% file src="<https://2084401275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfjuebS41N49G1Eh55hP7%2Fuploads%2Fgit-blob-b4c24d38d9913ce072499f6af3ad1a4fa39681a5%2FRoute_to_HiSeq_MiSeq.py?alt=media&token=36dc49a4-851f-465f-8d11-7b42ad97c21b>" %}
