OCDocker.DB.DB module

Sets of classes and functions that are used for creating everything required for the database.

Usage:

import OCDocker.DB.DB as ocdb

OCDocker.DB.DB.create_tables(engine=None)[source]

Create all ORM tables bound to the provided engine.

If no engine is provided, attempts to resolve the engine from OCDocker.Initialise (and creates one from db_url if necessary).

Parameters:

engine (Engine | None) –

Return type:

None

OCDocker.DB.DB.export_db_to_csv(session, output_format='dataframe', output_file=None, drop_na=True, batch_size=1000)[source]

Merge data from Complexes, Ligands, and Receptors tables and export.

Parameters:
  • session (sqlalchemy.orm.session.Session) – The session object to use for querying the database.

  • output_format ({'dataframe','json','csv'}) – Output format. If ‘dataframe’, returns a DataFrame; for ‘json’/’csv’ returns a string unless output_file is provided (then returns None).

  • output_file (str | None) – Optional path to write the result to disk.

  • drop_na (bool) – If True, drops rows with missing values. Defaults to True.

  • batch_size (int) – Streaming batch size for DB row iteration. Defaults to 1000.

Returns:

DataFrame or serialized string depending on output_format; None when writing to output_file.

Return type:

pandas.DataFrame | str | None

OCDocker.DB.DB.export_table_to_csv(model, filename, session, batch_size=1000)[source]

Export a single ORM model’s rows to CSV.

Parameters:
  • model (type[Base]) – ORM model class to export.

  • filename (str) – Output CSV file path.

  • session (sqlalchemy.orm.session.Session) – SQLAlchemy session bound to the database engine.

  • batch_size (int) – Streaming batch size for DB row iteration. Defaults to 1000.

Return type:

None

OCDocker.DB.DB.setup_database()[source]

Ensure the database exists, create a new Engine, and create tables.

Returns:

Live engine connected to the configured database URL.

Return type:

sqlalchemy.engine.base.Engine