-
Ankit Izardar authoredAnkit Izardar authored
- 📌 LabKey Sample Manager Data Import Automation Script
- 1. 🚀 Initialization and Authentication
- 2. ✅ Project Verification
- 3. 📚 Source Data Preparation and Import
- 🗃️ Source Type: Study
- 🩺 Source Type: Patient (linked to Study)
- 4. 🧪 Samples and Storage Hierarchy
- 5. 🗂️ Creation of Sample Types and Data Population
- 6. 🧹 Optional Cleanup (Commented)
README.md 2.21 KiB

LabKey Sample Manager Data Import Automation Script

The Python script automates the creation, organization, and population of data in a Sample Manager using data from Excel files. The script performs following set of tasks:

Initialization and Authentication
1. 
-
Imports necessary Python libraries (
labkey
,pandas
,urllib3
, etc.). -
Connects to the LabKey server (
labkey-pro-dev.scicore.unibas.ch
) using LabKey’s API. -
Authenticates securely by retrieving login credentials from a
.netrc
file.

Project Verification
2. 
- Verifies the existence of a specified LabKey project

Source Data Preparation and Import
3. 

Source Type: Study

-
Reads study data from the file
Study.xlsx
. -
Creates a DataClass named
Study
within LabKey. -
Imports study data into the newly created
Study
DataClass.

Source Type: Patient (linked to Study)

-
Reads patient data from
Patient.xlsx
. -
Creates a DataClass named
Patient
, which references the previously createdStudy
DataClass. - Imports patient data, linking each patient entry explicitly to a study.

Samples and Storage Hierarchy
4. 
-
Reads and processes sample data from
Samples.xlsx
. - Parses complex hierarchical storage location information from the data (Building → Floor → Freezer → Shelf → Rack → Box → Coordinates). Note: By defualt boxes of size 10x10 are created. Always confimr with user about the box size.
- Programmatically creates a structured hierarchy of physical storage locations within LabKey, mirroring the data’s structure.
- Associates each sample with the correct storage coordinates within LabKey.

Creation of Sample Types and Data Population
5. 
- Identifies unique Sample Types from the sample data.
- Creates corresponding "Sample Type" domains in LabKey dynamically.
- Inserts sample entries into respective Sample Type domains, linking each sample to its appropriate storage location and patient.

Optional Cleanup (Commented)
6. 
- Provides optional code (commented out) to clean up by deleting all created sample types and their data in LabKey if required for testing or reset purposes.