Examples
Examples to use the SDK
Create a record
Create a entry
# init the labii sdk
from labii_sdk.sdk import LabiiObject
labii = LabiiObject(api_key="xxx", organization__sid="xxx")
# 1. get entry table
et = labii.Table.list(query="name_singular=entry", serializer="name")["results"][0]
# 2. get the project
project = labii.Project.list(query="name=Sample Project", serializer="name")["results"][0]
# 3. create the entry
et1 = labii.Record.create({
"name": "Demo template",
"projects": [{"sid": project["sid"], "name": "Sample Project"}],
"is_template": True
}, query=f"table__sid={et['sid']}")
Create a sample
# init the labii sdk
from labii_sdk.sdk import LabiiObject
labii = LabiiObject(api_key="xxx", organization__sid="xxx")
# 1. get sample table
sp = labii.Table.list(query="name_singular=sample", serializer="name")["results"][0]
# 2. get the project
project = labii.Project.list(query="name=Sample Project", serializer="name")["results"][0]
# 3. get the columns
columns = labii.get_columns(f"table__sid={sg['sid']}&name__in=volume,concentration,storage")
# 4. get the storage information
sg3 = labii.Record.list(query=f"table__name_singular=storage&uid=SG3", serializer="name")["results"][0]
# 5. create the sample
sp1 = labii.Record.create({
"name": "Demo sample",
"projects": [{"sid": project["sid"], "name": "Sample Project"}],
columns["volume"]: 100,
columns["concentration"]: 10,
columns["storage"]: {"sid": sg3["sid"], "name": sg3["name"]},
}, query=f"table__sid={sp['sid']}")
Create a section
# init the labii sdk
from labii_sdk.sdk import LabiiObject
labii = LabiiObject(api_key="xxx", organization__sid="xxx")
# 1. get record
ep1 = labii.Record.list(query=f"table__name_singular=experiment&uid=EP1", serializer="name")["results"][0]
# 2. add a Procedure section with CKEditor Classic widget
labii.Section.create({
"data": {
"html": "<h4>Procedure</h4><ol><li>Prepare the PCR solution based on the protocol: {protocol}</li><li>Based on the below table, the PCR cycle is used</li></ol><figure class=\"table\"><table><tbody><tr><td>#</td><td>Plant</td><td>Anneal Temp (°C)</td><td>Extension Time</td></tr><tr><td>1</td><td>xrn2-1</td><td>58</td><td>60s</td></tr><tr><td>2</td><td>xrn2-2</td><td>58</td><td>60s</td></tr></tbody></table></figure><p> </p><p> </p><p> </p><p> </p>"
},
"name": "Procedure",
"widget": {"sid": "0cfi0a40x3abglqvAFK", "name": "CKEditor Classic"}
}, query=f"row__sid={et1['sid']}")
Import RT-PCR CT Range
# init the labii sdk
from labii_sdk.sdk import LabiiObject
labii = LabiiObject(api_key="xxx", organization__sid="xxx")
# prepare data
table = labii.Table.list(query="name_singular=qPCR CT Range", serializer="name")["results"][0]
project = labii.Project.list(query="name=Sample Project", serializer="name")["results"][0]
columns = labii.get_columns(f"table__sid={table['sid']}&name__in=CT_low_start,CT_low_end,CT_medium_start,CT_medium_end,CT_high,recommended_treatment,antibiotic_resistance")
# import file
with open("qPCR_CT_Range.tsv", 'r') as file:
for line in file:
if not "CT_low_start" in line: # skip the first line
data = line.split("\t")
print(f"Importing {data[0]}...")
labii.Record.create({
"name": data[0].strip(),
"projects": [{"sid": project["sid"], "name": "Sample Project"}],
columns["CT_low_start"]: data[1].strip(),
columns["CT_low_end"]: data[2].strip(),
columns["CT_medium_start"]: data[3].strip(),
columns["CT_medium_end"]: data[4].strip(),
columns["CT_high"]: data[5].strip(),
columns["recommended_treatment"]: data[6].strip(),
columns["antibiotic_resistance"]: data[7].strip()
}, query=f"table__sid={table['sid']}")
Last updated