Skip to main content

Shared library for mutation management across modules

Project description

Mutation Library

Shared library for mutation management across modules.

Components

DbConnection - Singleton DB connection

from libs import DbConnection

DbConnection.set_db_path("mutations.db")
conn = DbConnection.get_connection()

Mutation - Pydantic model with DB integration

States

  • "full": Has both id and (chrom, pos, ref, alt)
  • "miss_id": Has coordinates, missing id
  • "miss_attributes": Has id, missing coordinates

Creation patterns

# With coordinates (lazy load id)
mut = Mutation(chrom=17, pos=7577548, ref="C", alt="T")

# With id (lazy load attributes)
mut = Mutation(id=123)

# With both
mut = Mutation(id=123, chrom=17, pos=7577548, ref="C", alt="T")

Methods

Instance methods:

mut.fetch_id_from_db()           # Get id from coordinates
mut.fetch_attributes_from_db()   # Get coordinates from id
mut.ensure_in_db()              # Create if missing, return id

Class methods (batch):

Mutation.fetch_ids_from_db_batch(mutations)
Mutation.fetch_attributes_from_db_batch(mutations)
Mutation.ensure_in_db_batch(mutations)

Usage in modules with OutputDescription (fully automatic)

OutputDescription is a base class that provides automatic DB insertion for module outputs.

from pydantic import Field
from typing import ClassVar, List
from libs import OutputDescription, DbConnection, Mutation

class MyModuleOutput(OutputDescription):
    table_name: ClassVar[str] = "tool_mymodule"
    db_fields: ClassVar[List[str]] = ["my_score", "my_prediction"]

    my_score: float = Field(..., description="Module score")
    my_prediction: str = Field(..., description="Prediction")

# Setup
DbConnection.set_db_path("mutations.db")

# Single insertion (automatic table creation + mutation insertion)
output = MyModuleOutput(
    mutation=Mutation(chrom=17, pos=7577548, ref="C", alt="T"),
    version="1.0.0",  # Required field (free text)
    my_score=0.85,
    my_prediction="pathogenic"
)
output.insert_to_db()  # Creates table if needed, ensures mutation exists, inserts

# Batch insertion
outputs = [...]
MyModuleOutput.insert_batch_to_db(outputs)

What happens automatically:

  • Table creation with correct SQL types (inferred from Python types)
  • Mutation insertion/lookup
  • Index creation on mutation_id
  • version field automatically added to table and insertion
  • INSERT OR REPLACE (idempotent)

Note: version field is required in all OutputDescription subclasses. Format is free text.

Chromosome encoding

  • Autosomes: 1-22
  • X: 23
  • Y: 24

Helper functions:

from libs.src.mutations import chrom_to_int, int_to_chrom

chrom_to_int("chr17")  # 17
chrom_to_int("chrX")  # 23
int_to_chrom(23)  # "chrX"

Tests

# From project root
.venv/bin/python3 libs/tests/test_mutations_lib.py

# Or use the test runner
libs/tests/run_tests.sh

Examples

python3 example_mutations_lib.py
python3 modules/boostdm/output_description_example.py

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

evoseer_utils-0.1.3.tar.gz (9.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

evoseer_utils-0.1.3-py3-none-any.whl (9.8 kB view details)

Uploaded Python 3

File details

Details for the file evoseer_utils-0.1.3.tar.gz.

File metadata

  • Download URL: evoseer_utils-0.1.3.tar.gz
  • Upload date:
  • Size: 9.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.14 Linux/5.10.0-22-amd64

File hashes

Hashes for evoseer_utils-0.1.3.tar.gz
Algorithm Hash digest
SHA256 f7a6652bcaba6106e021969ff48f3e2ea57c11ae722c8c6497e8bb4cfa741320
MD5 1077c5f47354cb7368cc5f30882c7490
BLAKE2b-256 974a69780a0a0ef77ef2bf3b4c96ed1d68fd8b8dbdf40b3300969bd79a4373ee

See more details on using hashes here.

File details

Details for the file evoseer_utils-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: evoseer_utils-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 9.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.5 CPython/3.11.14 Linux/5.10.0-22-amd64

File hashes

Hashes for evoseer_utils-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 d34ffd695d4f0c0e662dca8c2e4f55228624ff37e09e1e1bfa68f6fb0dd952d0
MD5 b9827cd1887f3b6198a618e0a2bd701a
BLAKE2b-256 8fd0fcb2270e045920a51dc267c8d3b66ebe47b4e111d1c48aee0b63be27d352

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page