Same-haplotype receptor revision: genotype-aware V replacement - #9
Merged
Conversation
…didates, exclude-current, replay validation, signature)
…sed, same-hap, both-hap, novel)
…ent contracts; correct run_cohort docstring
…resh stale revision docs; pin cross-chromosome revision
… requirements comment
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Makes
receptor_revision()genotype-aware: when a genotype is attached, the post-recombination V replacement is drawn from the genotype's carried V alleles on the drawn rearrangement chromosome (same_haplotype=True, default), excluding the current V — and thegenotype + receptor_revisionrejection is lifted. Follow-on #5 (final) of the genotype roadmap, and the first to touch the engine.This is haplotype-aware V replacement, not a full model of receptor editing (no genomic V order / RSS / upstream-availability realism); it guarantees the replacement is an allele the individual carries on the relevant chromosome.
What's included
Engine (Rust):
AlleleInstance.haplotype: Option<u8>(0/1-asserted) — the drawn rearrangement chromosome, stamped on V/D/J bySampleGenotypePass(per-pass traces are isolated, so the chromosome is threaded through the IR).ReceptorRevisionPass(GenotypeVConstraint): per-haplotype carried-V candidates aggregated byAlleleId, current-V excluded, same-length filtered;same_haplotypetrue (drawn chromosome) / false (both, a synthetic control). Coin always consumed (RNG parity);applied = coin AND eligible-nonempty(strict errors / permissiveapplied=falseon empty).commit_replacementpreserves the original rearrangement chromosome even undersame_haplotype=False. Full replay tamper-set validation + constraint-digestparameter_signature. Strict post-event contracts honored (parity with the non-genotype path), fresh and replay.push_genotype_receptor_revisionPyO3 builder with boundary validation (prob, V pool, haplotype, allele-id range, weight finiteness/positivity, copies, mass).Python (DSL):
receptor_revision(prob=..., same_haplotype=True)(bool-validated); genotype-aware lowering against the effective refdata (carried novel V alleles are valid targets).genotype + receptor_revisionrejection in bothcompile()andrun_cohort();genotype + clonal-forkstays rejected.Docs: "Receptor revision with a genotype" guide section; removed from Limitations.
Invariants
receptor_revisionis byte-identical to today (genotype_v=None dispatch; non-genotypecommit_replacementcalls passhaplotype=None).original_v_call/receptor_revision_appliedAIRR fields unchanged;v_call/truth_v_callare post-revision.Test plan
AlleleInstancefield/assert — candidate restriction, exclude-current, both-haplotype, empty (strict/permissive), replay tamper set (incl. unresolvable id →missing_allele), strict post-event contract rejection (fresh + replay), signature. cargo green across 6 binaries.same_haplotype=False, novel-allele target, cohort + revision, bool validation, lifted rejections; no-genotype path unchanged.