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.4.tar.gz (9.9 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.4-py3-none-any.whl (10.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: evoseer_utils-0.1.4.tar.gz
  • Upload date:
  • Size: 9.9 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.4.tar.gz
Algorithm Hash digest
SHA256 ac9a0ae91a556ce9f4c84e6ea4ec0716869fc2ab8b598d83e803350b866be0f4
MD5 858662cc3cf604b99d61cd007b073619
BLAKE2b-256 1f01a4aa1960c5cc603e308b9ab21beaaa7ae98cc2adf8bb00c9aecc5fa47a0f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: evoseer_utils-0.1.4-py3-none-any.whl
  • Upload date:
  • Size: 10.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.4-py3-none-any.whl
Algorithm Hash digest
SHA256 d0fe622865d0d3fae20caf996e84110ca3d767d93c67f38e884e49c449dbdbed
MD5 44c9719c74ffc80eb9f7b3f7b813e8ce
BLAKE2b-256 1b89fca63e2f59f467b0074d3ecc999d35c5395edd018533c03a26836c1b9e7a

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