# Renaming Samples to Add an Internal ID

When a lab takes in samples, they are named by the lab scientist who supplies them. As such, samples may be named in any way imaginable. Conversely, the research facilities processing the samples often have strict naming conventions.

When these two situations occur, there is a need for the sample to renamed with the strict nomenclature of the processing lab. However, in order for the final data to be meaningful for the scientist who supplied the samples, the original name must also be retained.

### Solution

In this example, the attached script may be used to rename samples, while retaining their original names in a separate field.

* The original name of the sample is saved in a user-defined field (UDF) called **Customer's Sample Name**, .
* The **Sample Name** for the submitted sample is overwritten, using the specific naming convention of the customer.

It is recommended that the script be launched by a process/protocol step as early as possible in the sample lifecycle.

#### Parameters

The script is invoked with just three parameters:

<table data-header-hidden><thead><tr><th width="122"></th><th></th></tr></thead><tbody><tr><td>-l</td><td>The limsid of the process invoking the script (Required)</td></tr><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></tbody></table>

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

{% code overflow="wrap" %}

```
/usr/bin/python /opt/gls/clarity/customextensions/renameSamples.py -l 2-1234 -u admin -p securepassword
```

{% endcode %}

### About the Code

Once the command-line parameters have been harvested, and the API object set up ready to handle API requests, the **renameSamples()** method is called.

This method implements the following pseudo code:

```
step 1: get the inputs to this process

for each input:

   step 2: get the URI of the submitted sample associated with the inputs

   step 3: get the sample

   step 4: update the sample

   step 5: save the sample
```

### Assumptions and Notes

* Both of the attached files are placed on the Clarity LIMS server, in the **/opt/gls/clarity/customextensions** folder.
* A user defined field, named **Customer's Sample Name** has been created at the analyte (sample) level.
* The **Customer's Sample Name** field is visible within the LabLink **Collaborations Interface**.
* You will need to update the HOSTNAME global variable such that it points to your Clarity LIMS server.
* You will need to implement your own logic to apply the new sample name in Step 4 of the script.
* 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

renameSamples.py:

{% file src="/files/7ka7TqQli3QHXQY9zUe4" %}


---

# 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.connected.illumina.com/clarity-lims/api-and-database/api-docs/application-examples/page-12/renaming-samples-to-add-an-internal-id.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.
