# 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="/files/vWKoZGuLbcYGFvrKREZ8" 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](/api-and-database/api-docs/rest.md).

### 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="/files/QV7PNE99vAPZArJeT2Ga" %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://help.claritylims.illumina.com/api-and-database/api-docs/application-examples/page-15/routing-output-artifacts-to-specific-workflows-stages.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
