Clonal lineage trees (BCR) + clone-size repertoires (TCR / flat-BCR)#4
Merged
Conversation
…el + zero n_sample
…(n) leaves, unbiased leaf sampling
…ds + lineage_trees
…lear run_records errors, doc fixes
…mutation_count) so validation passes Lineage node Outcomes were built with an empty event ledger but a nonzero Simulation.mutation_count, causing validate_record to false-fail the mutation-count sum invariant (MutationCountSumMismatch) on mutated nodes, and build_airr_record to report zero per-segment SHM counts while n_mutations was nonzero. Fix: synthesize_shm_event_record scans sim.pool for positions where base != germline and emits one SimulationEvent::BaseChanged per mutated site into a single MUTATE_S5F EventRecord. mutation_count is then set to the net pool-mutation count. The resulting Outcome is self-consistent: build_airr_record reads the events to derive per-segment and V-subregion counts, and mutation_count matches the event count so the validator passes. Consequence: PyFamilyOutcome::airr_records no longer needs the manual pool_mutation_counts dict-overwrite path. It now delegates to build_airr_record directly, removing the PoolMutCounts struct and pool_mutation_counts helper (~90 lines net reduction).
…ch the mutated sequence
…r-cell library-prep artefacts)
…pand_clones deprecation + corruption docs
…onest sampled-tips docs
…tree leaves (extinct clones unobserved)
…, honest n_max/affinity/TCR/validation docs
…live sampling + survival guard); ARI still 1.0
…R+flat-BCR, duplicate_count collapse)
…truth trees) instead of confusing repertoire+mutate
…ge + clonal_repertoire); flag expand_clones as legacy
…ract to resolve against the published mkdocs site (site_docs/)
…ard tests for lineage + repertoire
…age/clonal_repertoire) at DSL time The duplicate-fork guards in expand_clones() and clonal_lineage() only checked a subset of the three fork step types, so stacking two different fork methods (e.g. clonal_repertoire().clonal_lineage()) slipped past the DSL guard and surfaced as a confusing 'unsupported pipeline step type' TypeError at compile(). All three guards now check all three fork types and raise the canonical 'once per pipeline' message. Adds a parametrized regression test covering every ordered pair.
MuteJester
added a commit
that referenced
this pull request
Jun 16, 2026
…e identity, gapped projection Addresses critic findings on the novel-allele slice: - #1 functional validation: synthesized V/J coding sequence is checked for an intact conserved anchor codon (Cys/Trp|Phe) and stop-free coding frame; a broken variant is rejected unless allow_nonfunctional=True (then kept + marked non-functional). Closes the 'nonfunctional emitted as productive' gap. - #2 gene identity: the novel allele's gene is taken from its NAME and must equal the base allele's gene; dropped the gene= override that left allele.gene stale. - #3 anchor: inherited from base (correct for same-length/substitution-only variants — the conserved residue does not move) and validated to remain intact; no reliance on the unavailable _native anchor resolver. - #4 name uniqueness enforced across all segments + novel set (prevents truth-table mislabeling). - #5 to_tsv now emits the 'novel' column. - #6 substitutions projected onto the gapped sequence (no stale gapped_seq). - #7 mutation positions/bases type-checked with clean ValueErrors. Tests expanded: stop/anchor rejection + allow_nonfunctional, gene-mismatch, cross-segment collision, tsv export, type-check.
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.
Replaces the star-topology
expand_cloneswith two real clonal models, plus docs and validation.What's new
clonal_lineage— BCR affinity-maturation lineage treesn_clonesis reliably produced (allow_extinctionopts out)clone_id,lineage_*, consistent pool-derived mutation counts) + per-clone ground-truth trees (to_newick/to_fasta/to_node_table_tsv)validate_records/expose_provenancesupported; BCR-only (rejects TCR loci)clonal_repertoire— TCR & flat-BCR abundance repertoiresduplicate_countexpand_clonesdeprecated (kept working). DSL ordering guards cover all three forks.Docs
clonal-lineage.md,clonal-repertoire.md(auto-published via the mkdocs deploy)clonal_lineageValidation
Two independent expert reviews of the engine + DSL drove fixes for: TCR-SHM guard, living-population sampling, live-call cache refresh, mutation-count consistency, and library-prep wiring.
Test plan
cargo test --all-features: greenpytest tests/: green (incl. clonal/lineage/repertoire suites + plan-split/ordering contracts)mkdocs build --strict: clean; docs-website contract green