Skip to content

sanger/biosero-sql

Repository files navigation

CherryTrack SQL

Scripts to create/update the schema required for the cherrytrack database.

Table of Contents

Schema diagram

Alt text

List of tables and views

DEPRECATED: USE CHERRYTRACK REPOSITORY

Tables

  • configurations - one row per configuration key value pair per system
  • automation_systems - one row per automation system
  • automation_system_runs - one row per run
  • run_events - one row per event on a run (error or other)
  • run_configurations - one row per run to record the configuration used
  • source_plate_wells - one row per pickable sample plate well
  • control_plate_wells - one row per pickable control plate well (as defined in configurations table)
  • destination_plate_wells - one row per destination plate well

Views

  • Run level view - one row per run
  • Sample level view - one row per picked sample

Table and view descriptions can be found here: table_and_view_descriptions.md.

List of stored procedures

DEPRECATED: USE CHERRYTRACK REPOSITORY

Stored procedures

Database creation

DEPRECATED: USE CHERRYTRACK REPOSITORY

The easiest way to create the database (and associated views and stored procedures) is via the python scripts here: Python Scripts

Alternatively you can use the database creation scripts are found in database_script.sql. NB. Change the 'database name' placeholder.

Table creation script

DEPRECATED: USE CHERRYTRACK REPOSITORY

The required table creation scripts are found in tables_script.sql.

View creation scripts

DEPRECATED: USE CHERRYTRACK REPOSITORY

The required view creation scripts are found in:

Example SQL

Configurations

See example insert sql script here:

This example select query fetches the configuration key value pairs for a workcell called 'CPA':

SELECT asys.automation_system_name, conf.config_key, conf.config_value, conf.description, conf.created_at
FROM `configurations` conf
JOIN `automation_systems` asys
  ON conf.automation_system_id = asys.id
WHERE asys.automation_system_name = 'CPA';

Example JSON representation of the configuration for a workcell called 'CPA':

{
    "configuration": {
        "CPA": {
            "version": 1,
            "change_description": "moved the positive control",
            "change_user_id": "ab1",
            "control_coordinate_positive": "A1",
            "control_coordinate_negative": "H12",
            "control_excluded_destination_wells": "B5, B6",
            "bv_barcode_prefixes_control": "DN, DM",
            "bv_barcode_prefixes_destination prefixes": "HT, HS",
            "bv_deck_barcode_control": "DECKC123",
            "bv_deck_barcode_destination": "DECKP123"
        }
    }
}

Select unpicked wells for a source barcode

This query selects unpicked source plate wells for a source plate barcode e.g. if the source is a partial i.e. it has rows on the source_plate_wells table that are not in the destination_plate_wells table.

SELECT
    dpw.id AS destination_id,
    spw.id,
    spw.barcode,
    spw.coordinate,
    spw.sample_id,
    spw.rna_id,
    spw.lab_id
FROM
    `source_plate_wells` spw
LEFT OUTER JOIN `destination_plate_wells` dpw
    ON spw.id = dpw.source_plate_well_id
WHERE
    spw.barcode = <source_barcode>
    AND dpw.id IS NULL
ORDER BY spw.id;

Select empty well coordinates in a destination plate barcode

SELECT dpw.coordinate
FROM `destination_plate_wells` dpw
WHERE
    barcode = '<destination plate barcode>'
    AND source_plate_well_id IS NULL
    AND control_plate_well_id IS NULL
ORDER BY dpw.id;

Example usage queries for use case 1 from the URS

This use case picks a positive and negative control from a Control plate, and then from 2 Source plates (with 1 and 93 pickable samples) to create a full destination plate.

See file use_case_1.sql

Example use of views

  • Example select from Run level View
SELECT
    *
FROM
    `run_level_view`
WHERE
    automation_system_run_id = 1
;
  • Example select from Sample level View
SELECT
    *
FROM
    `sample_level_view`
WHERE
    automation_system_run_id = 1
ORDER BY automation_system_run_id, destination_barcode, destination_coordinate
;

Python Scripts

Environment

Scripts in this repo depend on certain pip packages to be installed. To facilitate this, a pipenv environment has been configured to run the scripts in. From the root of the repo:

pipenv install
pipenv shell

Within this shell, you can navigate to the python_scripts directory to run them.

Note that the scripts require access to external services. To provide the details to connect to these, duplicate the file at /python_scripts/config/defaults.template.py removing the .template part of the filename and put credentials in there.

List of scripts

A python script has been included to demonstrate use of the stored procedures during a typical run to create test data here: generate_test_data.py.

A python script has been included to act as an integration test for both use of the stored procedures and calls to the lighthouse API during a typical run here: generate_test_data.py

DEPRECATED: USE CHERRYTRACK REPOSITORY

A python script has been included to reset the database(CARE!) here: reset_database.py.

Miscellaneous

Updating the Table of Contents

To update the table of contents after adding things to this README you can use the markdown-toc node module. To run:

npx markdown-toc -i README.md

About

No description, website, or topics provided.

Resources

Contributing

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages