# Compute Replicate Average

The Clarity LIMS NGS Extensions Package v5.14 includes the *computeReplicateAverage* script, which automates calculation of replicate (referred to as derivatives in the LIMS) average values. The script can also optionally calculate standard deviation and %CV values.

This section provides details on the script, its parameters, and LIMS configuration requirements.

## Script Overview

The *computeReplicateAverage* script uses data stored in a source UDF / custom field (specified by the src parameter) to calculate the average across replicates, and writes the resulting value to a destination UDF / custom field (specified by the dest parameter).

* The script assumes the step has input analytes / derived samples with replicated per-input results / measurements.
* The script groups the per-input results / measurements by their parent analyte / derived sample.
* For each group, the script calculates the average of the result UDFs / measurement custom fields specified by the src parameter, ignoring any results that:
  * Are missing *src* values, or
  * Have an *exclude* field set to true
* The resulting averages are written back into the parent analyte / derived sample field specified by the *dest* parameter for each group.
* The *exclude* parameter is optional and no exclusions are performed if it is missing.

The script can also be used to calculate standard deviation and %CV values and add these results back to the corresponding UDF / field in the parent analyte / derived sample. The names of the Standard Deviation and %CV UDFs must be given to the script for it to update the values.

## Script Parameters

| **Parameter**                                               | **Description**                                       |
| ----------------------------------------------------------- | ----------------------------------------------------- |
| <p>-u {username}<br>-username {username}</p>                | (Required) LIMS login username                        |
| <p>-p {password}<br>-password {password}</p>                | (Required) LIMS login password                        |
| <p>-i {stepURI:v2}<br>-stepURI {stepURI:v2}</p>             | (Required) LIMS step URI                              |
| <p>-log {logFileLIMSID}<br>-logFileName {logFileLIMSID}</p> | (Required) LIMS ID of the log file placeholder        |
| <p>-src \<srcUDF><br>-srcUDF \<srcUDF></p>                  | (Required) Source UDF / custom field name             |
| <p>-dest \<destUDF><br>-destUDF \<destUDF></p>              | (Required) Destination UDF / custom field name        |
| <p>-exclude \<excludeUDF><br>-excludeUDF \<excludeUDF></p>  | (Optional) Exclude UDF / custom field name            |
| <p>-sd \<sdUDF><br>-stdDevUDF \<sdUDF></p>                  | (Optional) Standard deviation UDF / custom field name |
| <p>-cv \<cvUDF><br>-cvUDF \<cvUDF></p>                      | (Optional) %CV UDF / custom field name                |

## Command Line Example

When working with the *computeReplicateAverage* script, the automation command line must be constructed as follows:

{% code overflow="wrap" %}

```markup
bash -l -c "/opt/gls/clarity/bin/java -jar \
/opt/gls/clarity/extensions/ngs-common/v5/EPP/ngs-extensions.jar \
-i {stepURI:v2} \
-u {username} \
-p {password} \
script:computeReplicateAverage \
-src '' \
-dest '' \
-exclude ''
-log {}"
```

{% endcode %}

<details>

<summary>Example 1</summary>

{% code overflow="wrap" %}

```markup
script:computeReplicateAverage \
-src 'Concentration' \
-dest 'Avg Concentration' \
-exclude 'Ignore' \
-log {compoundOutputFileLuid0}"
```

{% endcode %}

In this example, the script will:

1. Average the values captured in the replicate *Concentration* fields. Replicates whose *Ignore* field value is set to True will be excluded from the calculation.
2. Copy the result to the *Avg Concentration* field configured on the parent derived sample.

</details>

<details>

<summary>Example 2</summary>

{% code overflow="wrap" %}

```markup
script:computeReplicateAverage \
-src 'Concentration' \
-dest 'Avg Concentration' \
-sd 'Std Dev' \
-cv '%CV' \
-exclude 'Ignore' \
-log {compoundOutputFileLuid0}"
```

{% endcode %}

In this example, the script will:

1. Average the values captured in the replicate *Concentration* fields. Replicates whose *Ignore* field value is set to True will be excluded from the calculation.
2. Copy the replicate average result to the *Avg Concentration* field configured on the parent derived sample.
3. Calculate standard deviation and %CV values.
4. Copy the standard deviation and %CV results to the *Std Dev* and *%CV* fields configured on the parent derived sample.

</details>

<details>

<summary>Example 3</summary>

{% code overflow="wrap" %}

```markup
script:computeReplicateAverage \
-src 'Raw CP' \
-dest 'Raw CP' \
-log {compoundOutputFileLuid0}"
```

{% endcode %}

In this example, the script will:

1. Average the values captured in the replicate *Raw CP* fields. No replicates will be excluded from the calculation.
2. Copy the result to the *Raw CP* field configured on the parent derived sample. No values will be ignored.

</details>

## Configuration

The inputs to the step must have values for the analyte UDF / derived sample custom field to be used as the source field. There must be an additional analyte UDF / derived sample custom field configured as the destination field - to capture the calculated replicate average. Both field types must be Numeric.

The following table provides example field configuration details.The field names used correspond to those used in the command line Example 1 shown above.

*Configured on ResultFile in LIMS v4.2.x and Measurement in LIMS v5.x & later*

| **Field Name**                                                                                   | **Field Type**                                                  | **Field Constraints / Options**                       | **Preset Values / Additional Options** |
| ------------------------------------------------------------------------------------------------ | --------------------------------------------------------------- | ----------------------------------------------------- | -------------------------------------- |
| <p>Concentration<br>In example 1, this is the field specified by the <em>-src</em> parameter</p> | Numeric                                                         | <ul><li>Required: Yes</li><li>Read Only: No</li></ul> | Decimal Places Displayed: 2            |
| <p>Ignore<br>In example 1, this is the field specified by the <em>-exclude</em> parameter</p>    | <ul><li>Boolean (v4.2.x)</li><li>Toggle Switch (v5.x)</li></ul> | <ul><li>Required: No</li><li>Read Only: No</li></ul>  | Default: None Set                      |

\
\&#xNAN;*Configured on Analyte in LIMS v4.2.x and Derived Sample in LIMS v5.x & later*

| **Field Name**                                                                                        | **Field Type** | **Field Constraints / Options** | **Preset Values / Additional Options** |
| ----------------------------------------------------------------------------------------------------- | -------------- | ------------------------------- | -------------------------------------- |
| <p>Avg Concentration<br>In example 1, this is the field specified by the <em>-dest</em> parameter</p> | Numeric        | Required: Yes Read Only: No     | Decimal Places Displayed: 2            |
