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

Uploaded Python 3

File details

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

File metadata

  • Download URL: evoseer_utils-0.3.0.tar.gz
  • Upload date:
  • Size: 11.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.3.0.tar.gz
Algorithm Hash digest
SHA256 bd6bdb87578daa287fd854bd3accea862290222283bd759ab841acfab623beb1
MD5 a19fff13daa4781f89187b850fc449bb
BLAKE2b-256 a83606961ff9c8a2f813949c448cc7668e881a9b335f1533daeec20e9189f19d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: evoseer_utils-0.3.0-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.0-py3-none-any.whl
Algorithm Hash digest
SHA256 514295db033309b461fc49da728c1a52a3c0d93610ed38c74521c4654400aea1
MD5 4a6db6ef95f8842dc9e06d455f63697e
BLAKE2b-256 ed54b5bcb47c4e6085ee788f182321fe83b8a1a0f60b49f4b824fe89679186f4

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