|
| 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 | + |
0 commit comments