Repository navigation
feat(sandbox): traits, reported as odds rather than answers - #33
Merged
Merged
Conversation
A trait takes a genome and an environment and returns a distribution, never a single value. For most traits a single value would be false, and a sandbox that reported "blue eyes" would be teaching the school model with better graphics. Two lessons ship, chosen because they teach opposite things. Sickle cell anaemia is the clean case. The first thirteen codons here are the real HBB coding sequence, so the sixth codon of the mature protein is GAG at base 18 and changing its middle A to T makes GTG. Glutamate to valine, verifiable by anyone. The explanation is derived rather than recited. An amino acid table carries Kyte and Doolittle hydropathy and formal charge, and substitution_effect works out that the residue loses a negative charge and goes from hydrophilic to hydrophobic, which puts a sticky patch on a protein surface. The same reasoning then works for a substitution a student invents. Eye colour is the correction. The brown-dominant, blue-recessive model is not a simplification of the biology, it is wrong, and the sandbox says so in the output rather than in a footnote. Roughly 16 genes contribute and the largest, rs12913832, is not in a pigment gene: it sits in a regulatory region of HERC2 and controls OCA2 expression. A test asserts that no combination of modelled variants reaches 95 percent, because if one did, someone had tuned an effect size until a demo looked convincing and the lesson had inverted into the model it corrects. A test caught a real bug in the odds arithmetic. A genome carrying no variants came back with its own baseline distorted: 55/30/15 became 67/23/10. Odds are a two-class idea, and converting each of three mutually exclusive classes to odds against everything else and then renormalising is not the identity. Effects are additive on the log probability scale, where adding to one class and renormalising multiplies its odds against every other class by exp(effect), so with two outcomes it is exactly the log-odds shift the literature reports. The same fix made a rare baseline shiftable again, which it had not been. What the model leaves out is reported alongside what it includes: the other thirteen genes, the diploid nature of real genomes, and the fact that rs12913832 acts through regulation rather than by changing a protein. Sickle cell says the same about recessiveness, since this sandbox holds one copy of each gene and one copy of that variant gives trait rather than disease.
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.
A trait takes a genome and an environment and returns a distribution, never a single value. For most traits a single value would be false, and a sandbox that reported "blue eyes" would be teaching the school model with better graphics.
Two lessons ship, chosen because they teach opposite things.
Sickle cell: the clean case
The first thirteen codons here are the real HBB coding sequence, so the sixth codon of the mature protein is
GAGat base 18 and changing its middle A to T givesGTG. Glutamate to valine, checkable by anyone.Truncating the gene is a simplification; moving the variant would have been an error, so the position is exact and the length is not. A test asserts the substitution is
Glu6Valand nothing else, which is what catches a coordinate drifting.The explanation is derived, not recited. An amino acid table carries Kyte and Doolittle hydropathy and formal charge, and
substitution_effectworks out what changed:Because it comes from the table, the same reasoning works for a substitution a student invents.
Eye colour: the correction
Subplan 33 was specific that the school model must not be reproduced. The brown-dominant, blue-recessive model is not a simplification of the biology, it is wrong, and this says so in the output rather than in a footnote:
Roughly 16 genes contribute, and the largest, rs12913832, is not in a pigment gene at all: it sits in a regulatory region of HERC2 and controls OCA2 expression.
test_eye_colour_is_never_certainchecks all eight variant combinations exhaustively and fails if any reaches 95 percent. That is the test most likely to matter later: if one ever did, someone had tuned an effect size until a demo looked convincing, and the lesson would have inverted into the model it exists to correct.The bug a test caught
A genome carrying no variants came back with its own baseline distorted: 55/30/15 became 67/23/10.
Odds are a two-class idea. Converting each of three mutually exclusive classes to odds against "everything else" and then renormalising is not the identity. Effects are additive on the log probability scale, where adding to one class and renormalising multiplies its odds against every other class by
exp(effect), so with two outcomes it is exactly the log-odds shift the literature reports.The same fix made a rare baseline shiftable again. With log odds, a baseline clamped at 1e-6 sat at -13.8 while the other class sat at +13.8, so a +20 effect moved it to 0.05 percent.
test_a_genome_with_no_variants_reproduces_the_baselinenow guards the identity directly.What is reported as missing
Alongside every result, not in documentation: the other thirteen eye colour genes, the diploid nature of real genomes, and the fact that rs12913832 acts through regulation rather than by changing a protein. Sickle cell carries the same note about recessiveness, since this sandbox holds one copy of each gene and one copy of that variant gives sickle cell trait rather than the disease.
Self-review
Traitis aProtocollikeProcess, with a test asserting a student class needs no base class.mypy --strict, ruff, and the voice check clean.Not in this PR
The drug design puzzle from subplan 33, which needs the permanent
Uncalibratedmarker wired through before anything is scored. Huntington's repeat-count dose response, which is the natural third lesson and needs repeat expansion inSequencefirst.