pydetecdiv.persistence.sqlalchemy.orm

Creation of global mapper_registry and Base class for database access. Main DAO class for accessing data in SQL Tables. Subclasses are responsible for providing the domain layer with lists of compatible records for the creation of domain-specific objects.

class pydetecdiv.persistence.sqlalchemy.orm.main.DAO(session: <module 'sqlalchemy.orm.session' from '/data1/EM2/miniconda3/envs/pyDetecDiv/lib/python3.11/site-packages/sqlalchemy/orm/session.py'>)

Bases: object

Data Access Object class defining methods common to all DAOs. This class is not meant to be used directly. Actual DAOs should inherit of this class first in order to inherit the __init__ method.

insert(rec: dict[str, Any]) int

Inserts data in SQL database for a newly created object

Parameters:

rec – the record representing the object

Returns:

the primary key of the newly created object

update(rec: dict[str, Any]) int

Updates data in SQL database for the object corresponding to the record, which should contain the id of the modified object

Parameters:

rec – the record representing the object

Returns:

the primary key of the updated object

get_records(where_clause) list[dict]

A method to get from the SQL database, all records verifying the specified where clause

Example of use: roi_records = roidao.get_records((ROIdao.fov == FOVdao.id_) & (FOVdao.name == 'fov1')) retrieves all ROI records associated with FOV whose name is ‘fov1’

Parameters:

where_clause – the selection ‘where clause’ that can be specified using DAO classes or tables

Returns:

a list of records as dictionaries

static translate_record(record: dict, exclude: list[str], translate: dict) dict

The actual translation engine reading the record fields and translating or excluding them if they occur in the translate or exclude variables

Parameters:
  • record – the record to be translated

  • exclude – a list of fields that must not be passed to the SQL engine

  • translate – a list of fields that must be translated and the corresponding columns

Returns:

the translated record

property record: dict

Template for method converting a DAO row dictionary into a DSO record

Returns:

a DSO record

Access to FOV data

class pydetecdiv.persistence.sqlalchemy.orm.FOVdao.FOVdao(session)

Bases: DAO, Base

DAO class for access to FOV records from the SQL database

image_resources(fov_id: int) list[dict[str, object]]

A method returning the list of ImageResource records whose parent FOV has id_ == fov_id

Parameters:

fov_id – the id of the FOV

Returns:

a list of ImageResource records whose parent FOV has id_ == fov_id

property record: dict[str, object]

A method creating a DAO record dictionary from a fov row dictionary. This method is used to convert the SQL table columns into the FOV record fields expected by the domain layer

Returns:

a FOV record as a dictionary with keys() appropriate for handling by the domain layer

roi_list(fov_id: int) list[dict[str, object]]

A method returning the list of ROI records whose parent FOV has id == fov_id

Parameters:

fov_id – the id of the FOV

Returns:

a list of ROI records with parent FOV id == fov_id

Access to ROI data

class pydetecdiv.persistence.sqlalchemy.orm.ROIdao.ROIdao(session)

Bases: DAO, Base

DAO class for access to ROI records from the SQL database

property record: dict[str, Any]

A method creating a record dictionary from a roi row dictionary. This method is used to convert the SQL table columns into the ROI record fields expected by the domain layer

Returns:

a ROI record as a dictionary with keys() appropriate for handling by the domain layer

data(roi_id: int) list[dict[str, Any]]

Returns a list of DataDao objects linked to the ROIdao object with the specified id_

Parameters:

roi_id – the id_ of the ROI

Returns:

the list of Data records linked to the ROI

entities(roi_id: int) list[dict[str, object]]

A method returning the list of Entity records whose parent ROI has id_ == roi_id

Parameters:

roi_id – the id of the ROI

Returns:

a list of Entity records with parent ROI id_ == roi_id

Access to data relative to Data file (images, tables, etc.)

class pydetecdiv.persistence.sqlalchemy.orm.DataDao.DataDao(session)

Bases: DAO, Base

DAO class for access to data records from the SQL database

property record: dict[str, object]

A method creating a record dictionary from a data row dictionary. This method is used to convert the SQL table columns into the data record fields expected by the domain layer

Returns:

a data record as a dictionary with keys() appropriate for handling by the domain layer

fov_list(data_id: int) list[dict[str, object]]

A method returning the list of FOV records whose parent Data has id_ == data_id

Parameters:

data_id – the id of the Data

Returns:

a list of FOV records with parent Data has id_ == data_id

roi_list(data_id: int) list[dict[str, object]]

A method returning the list of ROI records whose parent Data has id_ == data_id

Parameters:

data_id – the id of the Data

Returns:

a list of FOV records with parent Data has id_ == data_id

Access to Dataset data

class pydetecdiv.persistence.sqlalchemy.orm.DatasetDao.DatasetDao(session)

Bases: DAO, Base

DAO class for access to dataset records from the SQL database

data_list(dataset_id: int) list[dict[str, object]]

A method returning the list of Data records whose parent Dataset has id_ == dataset_id

Parameters:

dataset_id – the id of the Dataset

Returns:

a list of Data records whose parent Dataset has id_ == dataset_id

property record: dict[str, object]

A method creating a record dictionary from a dataset row dictionary. This method is used to convert the SQL table columns into the dataset record fields expected by the domain layer

Returns:

a dataset record as a dictionary with keys() appropriate for handling by the domain layer

Access to ImageResourceData data

class pydetecdiv.persistence.sqlalchemy.orm.ImageResourceDao.ImageResourceDao(session)

Bases: DAO, Base

DAO class for access to ImageResource records from the SQL database

data_list(image_res_id: int) list[dict[str, object]]

A method returning the list of Data records whose parent Dataset has id_ == dataset_id

Parameters:

dataset_id – the id of the Dataset

Returns:

a list of Data records whose parent Dataset has id_ == dataset_id

property record: dict[str, object]

A method creating a DAO record dictionary from a fov row dictionary. This method is used to convert the SQL table columns into the FOV record fields expected by the domain layer

Returns:

a FOV record as a dictionary with keys() appropriate for handling by the domain layer

Access to ROI data

class pydetecdiv.persistence.sqlalchemy.orm.RunDao.RunDao(session)

Bases: DAO, Base

DAO class for access to Run records from the SQL database

property record: dict[str, Any]

A method creating a record dictionary from a dataset row dictionary. This method is used to convert the SQL table columns into the dataset record fields expected by the domain layer

Returns:

a Run record as a dictionary with keys() appropriate for handling by the domain layer

Access to ROI data

class pydetecdiv.persistence.sqlalchemy.orm.ExperimentDao.ExperimentDao(session)

Bases: DAO, Base

DAO class for access to Experiment records from the SQL database

property record: dict[str, object]

A method creating a record dictionary from a data row dictionary. This method is used to convert the SQL table columns into the data record fields expected by the domain layer

Returns:

a data record as a dictionary with keys() appropriate for handling by the domain layer

ORM classes describing associations between DAOs/tables

class pydetecdiv.persistence.sqlalchemy.orm.associations.Linker

Bases: object

A class providing methods for linking two Data access objects.

static association(class1_name: str, class2_name: str) relationship

Defines the possible associations between DAO classes and returns the one corresponding to the classes passed as arguments.

Creates a link between the specified objects, calling the appropriate association object link method, as provided by the associations() method above.

Parameters:
  • obj1 – the first object to link

  • obj2 – the second object to link

class pydetecdiv.persistence.sqlalchemy.orm.associations.ROIdata(**kwargs)

Bases: Base

Association many to many between ROI and Image data

static roi_to_data() relationship

Defines and returns the relationship from ROI to ImageData tables

Returns:

the relationship between ROI and ImageData

static data_to_roi() relationship

Defines and returns the relationship from ImageData to ROI tables

Returns:

the relationship between ImageData and ROI

Checks there the existence of a link between the specified ROIdao and DataDao objects and creates a link (calling the _link method) only if there is no preexisting link.

Parameters:
  • obj1 – the first object to link

  • obj2 – the second object to link

property record: dict[str, Column]

A method creating a record dictionary from a ROIdata row dictionary.

Returns:

a ROIdata record as a dictionary with keys() appropriate for handling by the domain layer