BaseSpace Clarity LIMS Lab Logic Toolkit (LLTK) provides the evaluateDynamicExpression script, which allows for the evaluation of simple dynamic expressions.
This article provides examples that you can modify to suit the needs of your lab.
For details on script parameters and usage, and additional examples, see the Working with Lab Logic Toolkit article.
See the Setting QC Flags article.
See the Setting Next Actions article.
This example assumes that the step UDF / custom field Total samples has a default numeric value of 0:
Without a default value, the expression must set the initial value before continuing to sum:
This example demonstrates the use of step UDFs / custom fields to store temporary values in order to enable calculations between iteration.
This example checks that the container name has been changed from the default value (container LIMSID)
This example includes Groovy Closures, using both implicit variables (it) and explicit variable names (for example, currentSample).
Check the flow cell/reagent cartridge format (Illumina’s flow cell check) as follows:
The following expression results in the format: Wed Apr 03 21:28:38 EDT 2015
The following expression results in the format: 2015-04-03
This example assumes that the analyte / derived sample UDF Pool Volume (uL) has a default numeric value of 0.
This can also be done without setting a default value for the UDF:
The example below assumes the following:
The placement is alphanumeric (e.g., A:1)
The offset for the alphabetical row is 0, and the offset for the numeric column is 1
The placement order desired is horizontal: A:1 maps to 1, A:2 maps to 2, etc.
The placement of interest is the output placement
Placement is configured for a specific, known container type, and the dimensions of this container type are also known. This example uses a 96 well container configuration (12 columns are available and this value is used directly in the expression below). This value can be replaced for other container types.
Note the following:
The call to split() here will return a list of row:column, so we use [0] and [1] to access these values, respectively.
:: : ::.trim() is used to obtain the result ':' - because :: is used as a reserved character, and thus ::::: directly results in '': and errors.
See the Failing a Script article.
In some cases, special characters are not permitted in a field in the LIMS. To prevent users from entering special characters, the best practice is to include validation to check that the field contains only letters and/or numbers. Wherever possible, we recommend that you use this 'positive checking' method as it is much less error-prone. However, if this preferred method is not possible, you can use the Lab Logic Toolkit to check for the presence of special characters, and display an error message if one is found.
The following example use the Groovy matches command to check step output container names for the characters ? ( ) [ ] / \ and quotes or spaces.
The matches command
The matches command takes a regular expression (regex) as its input. Call this command on the field you want to check.
In our example, the matches command is:
If we isolate the regex, we have:
Here, we're checking for any text that contains any one of the special characters listed. It's important to note that the way regex is supported in Java (and therefore Groovy) leads to some quirks, noted in the following table.
Escaping characters Normally, in regex we would need to escape the following characters using a single backslash:
However, because of how matches works, not all of these characters need to be escaped - for example the '?' character. Characters that do still need to be escaped, need to be escaped with an additional backslash (e.g., \\).
Checking for quotes Because the command is run via Automated Informatics / Automation Worker, we also need to use a different approach for checking for quotes.
We cannot use them as we typically would when writing a regex expression (e.g., "), or escape them as we would in a call to matches (e.g., \"). Instead, we need to provide them as their unicode number, shown in our example as \u0022 and \u00.
Entry
Standard regex representation
Character being checked for
\u0022 and \u0027
' and "
Single and double quotes
?
\?
Question mark
( and )
\( and \)
Brackets
[ and ]
\[ and \]
Square brackets
/
\/
Forward slash
\
\\
Backslash
(space)
\s
Spaces
Lab scientists need to record both a start and stop date/time for an incubation. As a second evaluation of how many hours the incubation lasted, the scientists want BaseSpace Clarity LIMS to calculate the elapsed time.
The Lab Logic Toolkit evaluateDynamicExpression script can compare date/time entries and calculate elapsed hours. As Date fields in the LIMS do not display the required time component for this calculation, Text fields are needed.
The bash command uses a 'Date' function to convert the Text date/time entries into dates, and also uses a 'getTime' method to convert those dates into milliseconds since 1 January 1970 00:00:00 UTC. The difference between the two converted entries is then changed from milliseconds to hours.
Create a step level Text field for the Start Date/Time.
In this example, the field is named Incubation Start yyyy-mm-dd hh24:mi. The format is included in the name to assist the scientist entering the date/time.
Create a step level Text field for the Stop Date/Time.
In this example, the field is named Incubation Stop yyyy-mm-dd hh24:mi.
Create a step level Numeric field for the Incubation Hours. Set your preferred decimal place limit.
Create an automation and enter the following command line (if you have used different field names, edit the example command line to match):
Set the automation to be triggered by a button on the step. This allows the scientist to enter/edit the Start and Stop Date/Time before the elapsed hours are calculated.
Adjustment for the Start/Stop events taking place over the 'daylight savings change events' is not included in this example.
If you want to use a button to populate a Text field with the current date/time, then use: