Skip to content

Commit cf44b9d

Browse files
authored
Add support for plate metadata in assay saveBatch API #31
2 parents f9c65de + 067cebb commit cf44b9d

File tree

3 files changed

+78
-1
lines changed

3 files changed

+78
-1
lines changed

labkey/experiment.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,7 @@ def __init__(self, **kwargs):
186186
self.material_inputs = kwargs.pop('material_inputs', kwargs.pop('materialInputs', []))
187187
self.material_outputs = kwargs.pop('material_outputs', kwargs.pop('materialOutputs', []))
188188
self.object_properties = kwargs.pop('object_properties', kwargs.pop('objectProperties', []))
189+
self.plate_metadata = kwargs.pop('plate_metadata', None)
189190

190191
# TODO: initialize protocol
191192
# self._protocol = None
@@ -212,6 +213,7 @@ def to_json(self):
212213
data['filePathRoot'] = self.file_path_root
213214
data['materialInputs'] = self.material_inputs
214215
data['materialOutputs'] = self.material_outputs
216+
data['plateMetadata'] = self.plate_metadata
215217

216218
return data
217219

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
#
2+
# Copyright (c) 2018 LabKey Corporation
3+
#
4+
# Licensed under the Apache License, Version 2.0 (the "License");
5+
# you may not use this file except in compliance with the License.
6+
# You may obtain a copy of the License at
7+
#
8+
# http://www.apache.org/licenses/LICENSE-2.0
9+
#
10+
# Unless required by applicable law or agreed to in writing, software
11+
# distributed under the License is distributed on an "AS IS" BASIS,
12+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
# See the License for the specific language governing permissions and
14+
# limitations under the License.
15+
#
16+
from __future__ import unicode_literals
17+
18+
from labkey.utils import create_server_context
19+
from labkey.experiment import Batch, Run, load_batch, save_batch
20+
21+
labkey_server = 'localhost:8080'
22+
project_name = 'assays' # Project folder name
23+
context_path = 'labkey'
24+
server_context = create_server_context(labkey_server, project_name, context_path, use_ssl=False)
25+
26+
assay_id = 310 # provide one from your server
27+
28+
###################
29+
# Save an Assay batch
30+
###################
31+
32+
# Generate the Run object(s)
33+
runTest = Run()
34+
runTest.name = 'python upload'
35+
runTest.data_rows = [{
36+
# ColumnName: Value
37+
'ParticipantId' : '1234',
38+
'VisitId' : 111,
39+
'WellLocation' : 'A1'
40+
}, {
41+
'ParticipantId' : '5678',
42+
'VisitId' : 222,
43+
'WellLocation' : 'B11'
44+
}, {
45+
'ParticipantId' : '9123',
46+
'VisitId' : 333,
47+
'WellLocation' : 'F12'
48+
}]
49+
50+
# Assays that are configured for plate support have a required run property for the plate template, this is the plate template lsid
51+
runTest.properties['PlateTemplate'] = 'urn:lsid:labkey.com:PlateTemplate.Folder-6:d8bbec7d-34cd-1038-bd67-b3bd777822f8'
52+
53+
# The assay plate metadata is a specially formatted JSON object to map properties to the well groups
54+
runTest.plate_metadata = {
55+
'control' : {
56+
'positive' : {'dilution': 0.005},
57+
'negative' : {'dilution': 1.0}
58+
},
59+
'sample' : {
60+
'SA01' : {'dilution': 1.0, 'Barcode' : 'BC_111', 'Concentration' : 0.0125},
61+
'SA02' : {'dilution': 2.0, 'Barcode' : 'BC_222'},
62+
'SA03' : {'dilution': 3.0, 'Barcode' : 'BC_333'},
63+
'SA04' : {'dilution': 4.0, 'Barcode' : 'BC_444'}
64+
}
65+
}
66+
67+
# Generate the Batch object(s)
68+
batch = Batch()
69+
batch.runs = [runTest]
70+
batch.name = 'python batch'
71+
batch.properties['PropertyName'] = 'Property Value'
72+
73+
# Execute save api
74+
saved_batch = save_batch(server_context, assay_id, batch)
75+

test/test_experiment_api.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ def setUp(self):
104104
self.service = MockSaveBatch()
105105
self.expected_kwargs = {
106106
'expected_args': [self.service.get_server_url()],
107-
'data': '{"assayId": 12345, "batches": [{"batchProtocolId": 0, "comment": null, "created": null, "createdBy": null, "modified": null, "modifiedBy": null, "name": null, "properties": {"PropertyName": "Property Value"}, "runs": [{"comment": null, "created": null, "createdBy": null, "dataInputs": [], "dataRows": [], "experiments": [], "filePathRoot": null, "materialInputs": [], "materialOutputs": [], "modified": null, "modifiedBy": null, "name": "python upload", "properties": {"RunFieldName": "Run Field Value"}}]}]}',
107+
'data': '{"assayId": 12345, "batches": [{"batchProtocolId": null, "comment": null, "created": null, "createdBy": null, "modified": null, "modifiedBy": null, "name": null, "properties": {"PropertyName": "Property Value"}, "runs": [{"comment": null, "created": null, "createdBy": null, "dataInputs": [], "dataRows": [], "experiments": [], "filePathRoot": null, "materialInputs": [], "materialOutputs": [], "modified": null, "modifiedBy": null, "name": "python upload", "plateMetadata": null, "properties": {"RunFieldName": "Run Field Value"}}]}]}',
108108
'headers': {'Content-type': 'application/json', 'Accept': 'text/plain'},
109109
'timeout': 300
110110
}

0 commit comments

Comments
 (0)