Skip to content
Snippets Groups Projects

:pushpin: 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:

1. :rocket: Initialization and Authentication

  • 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.

2. :white_check_mark: Project Verification

  • Verifies the existence of a specified LabKey project

3. :books: Source Data Preparation and Import

:card_box: 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.

:stethoscope: Source Type: Patient (linked to Study)

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

4. :test_tube: Samples and Storage Hierarchy

  • 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.

5. :dividers: Creation of Sample Types and Data Population

  • 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.

6. :broom: Optional Cleanup (Commented)

  • 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.