You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* adding helper function to utils.py
The helper function parses the run properties and results data so that the user doesn't need to include any parsing script in their transform script. The helper function only accepts a user-defined function that accepts an array of results data as its input and returns an array of results data matching the assay design it is used with. Also, the helper function requires that users explicitly define the run properties in their transform script, otherwise the labkey transform script parser does not recognize ${runInfo}.
* Create example transform script that uses labkey.utils.transform_helper
* Delete assay_transform_function_example.py
moving filter to /docs folder
* documentation for transform_helper function
* Update transform_helper.md
* Update transform_helper.md
* updating transform_helper to be more robust and use snake case
switched from camel case to snake case for variable naming. additionally, changed script to get file_path_in from the row beginning with "runDataUploadedFile" in runProperties file. This is to better handle results data with numerical header names, such as when the results data is a grid representing well plates.
* Update labkey/utils.py
Co-authored-by: Alan Vezina <[email protected]>
* Update utils.py
using with statements when opening files
---------
Co-authored-by: Alan Vezina <[email protected]>
This helper function provides a convenient way for users to write transform scripts for assays without requiring the user to read the results and run data before transforming the data, and it also takes care of writing the transformed data back to labkey.
4
+
5
+
### Importing and preparing the helper function
6
+
7
+
First, your script must begin with these two lines to properly use the transform helper function:
8
+
9
+
```python
10
+
from labkey.utils import transform_helper
11
+
12
+
filepath ='${runInfo}'
13
+
```
14
+
15
+
The substitution token `${runInfo}` is replaced with the runProperties file path when the transform script is run within LabKey Server.
16
+
17
+
### Write your user-defined transform function
18
+
19
+
This is an example function that could be used as an argument when using the transform_helper function:
20
+
21
+
```python
22
+
deftransform(grid):
23
+
isHeaderChecked =False
24
+
# iterate through the rows of your results data, checking for the header
25
+
for row in grid:
26
+
if isHeaderChecked ==False:
27
+
row.append('averageResult')
28
+
isHeaderChecked =True
29
+
else:
30
+
# In this example, we are taking the average of the 3rd-5th column values by row
31
+
# and appending that average value in a 6th column called "averageResult"
32
+
newValTemp =sum([float(val) for val in row[2:]])/len(row[2:])
33
+
row.append(round(newValTemp, 2))
34
+
return grid
35
+
```
36
+
37
+
As you can see in the example function, the transform function must accept only one argument, the tabular data (including headers) that needs to be transformed in an list of lists format. The user-defined transform function must also return tabular data the same list of lists format with a header row that matches the header of the results data as defined by the targeted assay design.
38
+
39
+
### Using the helper function
40
+
41
+
The last thing to do is call the transform_helper function, supplying the user-defined transfrom function as the first argument, and the file path (as defined by ${runInfo}) as the second argument.
0 commit comments