# Invoking bcl2fastq from BCL Conversion and Demultiplexing Step

Illumina sequencing protocols include a **BCL Conversion and Demultiplexing** step. This stage allows you to select the command options for running bcl2fastq2. The bcl2fastq must be initiated through a command-line call on the BCL server.

This example allows you to initiate the bcl2fastq2 conversion software by the selection of a button in BaseSpace Clarity LIMS.

**Step Configuration**

The "out of the box" step is configured to include the following UDFs / custom fields. You can select these options on the **Record Details** screen. You can also configure additional custom options.

### About the Code

**The main method in the script is convertData(). This method performs several operations:**

1. The script determines the run folder. The link to the run folder is attached as a result file to the sequencing step.
   * The script searches for the appropriate sequencing step and downloads the result file containing the link.
   * The script changes directories into the run folder.
2. The script gathers all the step level UDFs / custom fields from the **BCL Conversion and Demultiplexing** step.
3. Using the information gathered, the script builds the command that is executed on the BCL server. The command consists of two parts: cd (changing directory) into the run folder.
   * Executing the bcl2fastq command with the selected options.

#### Script Configuration

This script must be copied to the BCL server because the script is executed on the BCL server remote Automated Informatics (AI) / Automation Worker (AW) node.

By default, the remote AI / AW node does not come with a custom extensions folder. Therefore, if this script is the first script on the server you can create a **customextensions** folder in **/opt/gls/**.

{% hint style="info" %}
It is not recommended to have the **customextensions** folder in the **remoteai** folder as the **remoteaifolder** can get overwritten.
{% endhint %}

**When uploading the script, ensure the following:**

* The path to the bcl2fastq application is correct (line 17)
* The sequencing process type matches exactly the name of the process type / master step the artifact went through (the **-d** parameter)
* The customextensions folder contains both glsapiutil.py and glsfileutil.py modules. See [#assumptions-and-notes](#assumptions-and-notes "mention").

**Parameters**

The script accepts the following parameters:

<table data-header-hidden><thead><tr><th width="114"></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><tr><td>-d</td><td>The display name of the sequencing step (Required)</td></tr></tbody></table>

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

{% code overflow="wrap" %}

```
/usr/bin/python /opt/gls/customextensions/ kickoff_bcl2fastq2.py -u {username} -p {password} -s {stepURI:v2} -d 'Illumina Sequencing (Illumina SBS) 5.0'
```

{% endcode %}

### Assumptions and Notes

* You are running a version of Python supported by Clarity LIMS, as documented in the *Clarity LIMS Technical Requirements*.
* The attached files are 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 the [GitHub](https://github.com/Illumina/BaseSpace_Clarity_LIMS) page.
* The example code is provided for illustrative purposes only. It does not contain sufficient exception handling for use 'as is' in a production environment.

#### Attachments

kickoff\_bcl2fastq2.py:

{% file src="<https://2084401275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfjuebS41N49G1Eh55hP7%2Fuploads%2Fgit-blob-fbd893097815003aa579bf66a79ddcb6ded2b549%2Fkickoff_bcl2fastq2.py?alt=media&token=be3108a0-c082-4c26-9f44-5534cf1adba8>" %}

glsfileutil.py:

{% file src="<https://2084401275-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FfjuebS41N49G1Eh55hP7%2Fuploads%2Fgit-blob-461a54a978af06eb0a5f40bb10b80e3c0b1a98e9%2Fglsfileutil.py?alt=media&token=70066665-7958-411e-b74e-97261b3a35e3>" %}
