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.3.2.tar.gz (11.3 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.3.2-py3-none-any.whl (12.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: evoseer_utils-0.3.2.tar.gz
  • Upload date:
  • Size: 11.3 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.3.2.tar.gz
Algorithm Hash digest
SHA256 31f972cb9d14a60d825dbfa5ebdb47daa900acb263709488195d672b0c260f74
MD5 eb2bf9e969682ee34588425c277e9c8f
BLAKE2b-256 f0a7181097e766b3fcc960dcbddd1f69d963666ae1a0f8ffd322a6a31097e7bc

See more details on using hashes here.

File details

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

File metadata

  • Download URL: evoseer_utils-0.3.2-py3-none-any.whl
  • Upload date:
  • Size: 12.2 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.3.2-py3-none-any.whl
Algorithm Hash digest
SHA256 e716767486c411a21f73f0ac16d86deefe42b00008ed8ff69b6b7cd1172aadf5
MD5 a6f066ab9965f56af3418087a1a21ace
BLAKE2b-256 9accae18060b8714370b17e170dae164e7bb8d245ad1d1d6275d5385fbe8f9e7

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