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.0.tar.gz (7.5 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.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: evoseer_utils-0.1.0.tar.gz
  • Upload date:
  • Size: 7.5 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.0.tar.gz
Algorithm Hash digest
SHA256 daf4bc86c7bba76f0208e7fca83a554abbb773541896e6f3fbc7079c84b0579d
MD5 9eed3f4f3926d20bbacea73135f41441
BLAKE2b-256 7f6ae61b11e0d27d0feec139d60dfcc75a9aa6758d51abf92b0ce4c7f385ef92

See more details on using hashes here.

File details

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

File metadata

  • Download URL: evoseer_utils-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 365d6f8eab38cb944c41a45d972a7bcc134eba768ae2881d573f3ce097ca91f4
MD5 c8d7518beda20065715145ad0ef7dadf
BLAKE2b-256 efd46edf3a828e24fc41d3ea40a38042939969970b3b7c2f3debbcbb9855c68e

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