Skip to content

Cartridge genotype plane: persist population genotype priors on a cartridge - #7

Merged
MuteJester merged 16 commits into
masterfrom
genotype-cartridge-plane
Jun 17, 2026
Merged

Cartridge genotype plane: persist population genotype priors on a cartridge#7
MuteJester merged 16 commits into
masterfrom
genotype-cartridge-plane

Conversation

@MuteJester

Copy link
Copy Markdown
Owner

Summary

Adds a donor-population germline prior ("population genotype model") as a top-level cartridge plane (DataConfig.genotype_priors), so Genotype.sample(cfg) can draw per-individual genotypes from a cartridge-authored prior instead of a uniform synthetic one. Follow-on #2 of the genotype roadmap (after V1 #5 and population priors #6).

Python-only — zero engine_rs/ changes. The plane is consumed entirely in Genotype.sample, which already lowers a fully-specified genotype through the existing SampleGenotypePass; population novel alleles reuse the existing effective-refdata injection. No Experiment API change.

What's included

  • genotype_priors.pyPopulationGenotypeModel + PopulationNovelAllele: per-segment/gene allele frequencies, per-gene haplotype-deletion probabilities, chromosome weights, population novel alleles, and identity (model_id/source/version/description). Catalogue-free validate() (shape, numeric bounds, DNA, ChainType-normalized D-on-VJ rejection) + canonical content_checksum().
  • PopulationGenotypeModel.from_genotypes(...) — pure estimator from observed Genotypes: per-chromosome allele counts (homozygous=2 / hemizygous=1), deletion prob = deleted_haplotypes / (2·n_subjects), pseudocount on catalogue alleles only, with completeness / copy-number / subject-id / input-type guards.
  • DataConfig.genotype_priors — fifth top-level plane; legacy-pickle fallback; None-pop checksum shim (unused plane → byte-identical cartridge checksum; a real plane → distinct identity); models.genotype_priors manifest block (robust against malformed direct-attached planes).
  • Genotype.sample — per-input source resolution with use_cartridge_priors opt-out; candidate-vs-carried novel injection (include_cartridge_novel_alleles); genotype-level prior_provenance + to_metadata() (base + effective refdata hashes); order-independent draws.
  • Builderset_genotype_priors (catalogue-aware + functional novel validation) and chainable estimate_genotype_priors.
  • Docs — new "Population genotype models on a cartridge" guide section; all examples executed live.

Invariants

  • No-genotype-prior cartridges keep a byte-identical compute_checksum(); a real plane is part of cartridge identity.
  • Plane novels are candidate alleles for the draw, but only carried novels reach effective_dataconfig() / AIRR projection — uncarried candidates never leak.
  • Backward compatible: no plane attached ⇒ behavior unchanged.

Test plan

  • New tests/test_genotype_cartridge_plane.py (45 tests): validation, checksum invariant + canonicality, serialization round-trip, manifest, sampler provenance/opt-out/mixed-sourcing, candidate-vs-carried novel injection, estimator statistics + guards, builder set/estimate, input-type hardening, end-to-end truth-call carriage.
  • Full Python suite green (2425 passed).
  • No engine_rs/ changes (compiled engine byte-identical).
  • Reviewed across four rounds (spec-compliance + adversarial API/statistics + two external critic passes); 19 findings triaged and fixed with regression tests.

… round)

- from_genotypes: validate pseudocount (finite >=0, reject bool); reject unknown
  carried alleles; reject copy_count>1 single-entry slots; validate model before return
- Genotype.sample: validate a directly-attached plane before use
- manifest: report genotype_priors 'valid' flag, never leak NaN numerics
- to_metadata: add effective_refdata_hash for carried-novel genotypes
…nd 2)

- manifest: never crash on a garbage/invalid direct-attached plane (type-check,
  guard content_checksum/float, defensive dict access)
- Genotype.sample: require use_cartridge_priors to be a real bool
- from_genotypes: require include_novel bool; validate min_subjects (int>=1) and
  segments (non-empty unique V/D/J labels present in cfg; reject bare string)
@MuteJester
MuteJester merged commit 8b0c237 into master Jun 17, 2026
13 checks passed
@MuteJester
MuteJester deleted the genotype-cartridge-plane branch June 17, 2026 12:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant