{
  "filename": "plot_6.png",
  "iteration": 5,
  "description": "Final synthesis: temporal windows, HPO system profiles and the constraint-driven allelic spectrum",
  "timestamp": "2026-11-26 22:39:12",
  "code": "\nimport numpy as np, pandas as pd, matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\n\nfig = plt.figure(figsize=(16.5, 9.2))\ngs = fig.add_gridspec(2, 2, height_ratios=[1, 1.15], hspace=0.38, wspace=0.26)\n\n# ---------------- Panel A: temporal windows of the three entities ----------------\naxA = fig.add_subplot(gs[0, :])\nent = [\n    (\"ATP6AP2-CDG (OMIM 301045)\\nmissense: G62E, R71H, L98S\", 0.0, 3.0, \"#b2182b\",\n     \"neonatal jaundice, cholestasis -> cirrhosis, cutis laxa, infections\"),\n    (\"MRXSH (OMIM 300423)\\nsplicing: c.321C>T, c.168+6T>A, c.301-11_-10del\", 0.3, 60, \"#ef8a62\",\n     \"DD/ID from infancy -> epilepsy -> cerebral atrophy -> parkinsonism in adulthood\"),\n    (\"XPDS (OMIM 300911)\\nsplicing: c.345C>T\", 14, 65, \"#4393c3\",\n     \"juvenile spasticity in some; parkinsonism onset juvenile to middle age\"),\n]\nfor i, (lab, a, b, c, note) in enumerate(ent):\n    y = 2 - i\n    axA.add_patch(Rectangle((a, y-0.3), b-a, 0.6, color=c, alpha=0.8))\n    axA.text(-1.0, y, lab, ha=\"right\", va=\"center\", fontsize=9)\n    axA.text(b+1.0, y, note, ha=\"left\", va=\"center\", fontsize=8.6, color=\"#333333\")\naxA.set_xlim(-30, 118); axA.set_ylim(-0.5, 2.8)\naxA.set_xticks([0, 1, 5, 10, 20, 30, 40, 50, 60])\naxA.set_xlabel(\"age (years), 0 = birth\", fontsize=10)\naxA.set_yticks([])\nfor s in [\"top\", \"right\", \"left\"]: axA.spines[s].set_visible(False)\naxA.axvline(0, color=\"#888888\", lw=0.8, ls=\"--\")\naxA.set_title(\"A  Temporal windows: allele class sets both the organ and the onset age\",\n              fontsize=11.5, loc=\"left\")\n\n# ---------------- Panel B: HPO frequency by organ system ----------------\naxB = fig.add_subplot(gs[1, 0])\n# counts of annotated HPO terms per system, per OMIM entity (from ontology.jax.org)\nsysdf = pd.DataFrame({\n    \"MRXSH\\n(31 terms)\":  {\"Nervous system\":22, \"Head and neck\":2, \"Growth/onset\":4,\n                            \"Hepatobiliary\":0, \"Immunology\":0, \"Genitourinary\":0, \"Integument\":0},\n    \"XPDS\\n(13 terms)\":   {\"Nervous system\":8,  \"Head and neck\":1, \"Growth/onset\":4,\n                            \"Hepatobiliary\":0, \"Immunology\":0, \"Genitourinary\":0, \"Integument\":0},\n    \"CDG2R\\n(17 terms)\":  {\"Nervous system\":0,  \"Head and neck\":2, \"Growth/onset\":2,\n                            \"Hepatobiliary\":7, \"Immunology\":3, \"Genitourinary\":1, \"Integument\":1},\n}).T\nsysdf.plot(kind=\"barh\", stacked=True, ax=axB, width=0.68,\n           color=[\"#2166ac\", \"#92c5de\", \"#bdbdbd\", \"#b2182b\", \"#ef8a62\", \"#fddbc7\", \"#f7f7f7\"],\n           edgecolor=\"#666666\", linewidth=0.4)\naxB.set_xlabel(\"number of annotated HPO terms\", fontsize=10)\naxB.legend(fontsize=8, ncol=2, frameon=False, loc=\"lower right\")\naxB.set_title(\"B  HPO annotation profiles are almost disjoint\\n\"\n              \"(53 distinct terms; 0 disease-specific overlap between CDG2R and the two neurological entities)\",\n              fontsize=10.5, loc=\"left\")\nfor s in [\"top\", \"right\"]: axB.spines[s].set_visible(False)\n\n# ---------------- Panel C: constraint vs allelic spectrum ----------------\naxC = fig.add_subplot(gs[1, 1])\ncats = [\"observed LoF\\nin gnomAD v4\", \"expected LoF\\nin gnomAD v4\",\n        \"ClinVar P/LP\\nsmall variants\", \"ClinVar VUS\"]\nvals = [1, 23.42, 6, 134]\ncols = [\"#2166ac\", \"#92c5de\", \"#b2182b\", \"#fddbc7\"]\nbars = axC.bar(cats, vals, color=cols, edgecolor=\"#555555\", linewidth=0.5)\naxC.set_yscale(\"log\"); axC.set_ylabel(\"count (log scale)\", fontsize=10)\nfor b, v in zip(bars, vals):\n    axC.text(b.get_x()+b.get_width()/2, v*1.15, f\"{v:g}\", ha=\"center\", fontsize=9.5)\naxC.set_title(\"C  LoF intolerance (pLI 0.9999, LOEUF 0.203, o/e 0.043)\\n\"\n              \"explains a hypomorph-only allelic spectrum and a large VUS backlog\",\n              fontsize=10.5, loc=\"left\")\naxC.tick_params(axis=\"x\", labelsize=8.6)\nfor s in [\"top\", \"right\"]: axC.spines[s].set_visible(False)\n\nplt.show()\n\nprint(\"Depletion of LoF alleles: observed 1 / expected 23.42 = %.3f (90%% CI 0.0152-0.2026)\" % (1/23.42))\nprint(\"VUS to P/LP ratio among single-gene small variants: %.1f to 1\" % (134/6))\n",
  "plot_number": 6
}