import uuid from typing import Any from app.db import SessionLocal from app.models import Case, CasePhenotype, GenePhenotype, Job, JobStatus, Prediction, Variant VARIANT_DEFAULTS: dict[str, Any] = { "chrom": "22", "pos": 1, "ref": "A", "alt": "G", "gene": "NF2", "impact": "HIGH", "consequence": "frameshift_variant", "gnomad_af": None, "annotations": {}, } async def seed_case( *, phenotypes: list[tuple[str, str]] | None = None, variants: list[dict[str, Any]] | None = None, gene_terms: dict[str, list[tuple[str, str]]] | None = None, status: JobStatus = JobStatus.succeeded, name: str | None = None, ) -> tuple[uuid.UUID, uuid.UUID]: """Insert a case, its phenotypes, a job and its variants. Returns (case_id, job_id). `variants` entries override VARIANT_DEFAULTS; a "score" key becomes a Prediction. """ async with SessionLocal() as s: case = Case( name=name or f"case-{uuid.uuid4()}", vcf_uri="gs://bucket/proband.vcf.gz", assembly="GRCh38", phenotypes=[CasePhenotype(hpo_id=hpo, label=label) for hpo, label in (phenotypes or [])], ) job = Job(case=case, status=status, vep_version="113.0") s.add_all([case, job]) for gene, terms in (gene_terms or {}).items(): s.add_all( GenePhenotype(gene_symbol=gene, hpo_id=hpo, hpo_name=label) for hpo, label in terms ) for spec in variants or []: fields = VARIANT_DEFAULTS | spec score = fields.pop("score", None) variant = Variant(job=job, **fields) s.add(variant) if score is not None: await s.flush() s.add(Prediction(variant_id=variant.id, model_name="rarelens-pathogenicity", model_version="demo", score=float(score))) await s.commit() return case.id, job.id