{
  "filename": "plot_3.png",
  "iteration": 2,
  "description": "Test whether reported SERPINA6 pathogenic allele frequencies are compatible with the Orphanet disease prevalence of less than 1 per 1,000,000: Hardy-Weinberg expected genotype frequencies versus observed disease prevalence",
  "timestamp": "2026-11-28 09:02:26",
  "code": "\nimport numpy as np, matplotlib.pyplot as plt\n\n# ---------------------------------------------------------------\n# Allele frequencies from gnomAD v4 (retrieved this session) for the\n# three OMIM allelic variants of SERPINA6 (OMIM 122500.0001-.0003).\n# Orphanet 199247 prevalence for the disease: < 1 / 1,000,000.\n# ---------------------------------------------------------------\nPREV_ORPHANET = 1e-6\n\nalleles = {\n    \"p.Leu115His (L93H, CBG Leuven)\\nOMIM 122500.0001, rs113418909\":  2.4595e-3,\n    \"p.Asp389Asn (D367N, CBG Lyon)\\nOMIM 122500.0002, rs28929488\":    3.5811e-4,\n    \"p.Asp389Asn in Ashkenazi Jewish\\n(gnomAD asj exomes)\":            7.04e-3,\n    \"p.Trp11Ter (null)\\nOMIM 122500.0003, rs777245398\":               2.05e-6,\n    \"All 54 gnomAD pLoF alleles summed\":                              1.717e-4,\n}\n\nprint(f\"{'Allele':<52} {'q':>10} {'q^2 (biallelic)':>17} {'1 in':>14} {'excess vs 1e-6':>15}\")\nprint(\"-\"*115)\nrows = []\nfor name, q in alleles.items():\n    hom = q**2\n    rows.append((name, q, hom))\n    print(f\"{name.splitlines()[0]:<52} {q:>10.3e} {hom:>17.3e} {1/hom:>14,.0f} {hom/PREV_ORPHANET:>15.1f}x\")\n\n# Combined: probability of any biallelic genotype across Leuven + Lyon + all pLoF\nq_comb = 2.4595e-3 + 3.5811e-4 + 1.717e-4\nprint(f\"\\nCombined q (Leuven + Lyon + all pLoF)      : {q_comb:.3e}\")\nprint(f\"Expected biallelic genotype frequency q^2  : {q_comb**2:.3e}  (1 in {1/q_comb**2:,.0f})\")\nprint(f\"Expected heterozygous carrier frequency 2q : {2*q_comb:.3e}  (1 in {1/(2*q_comb):,.0f})\")\nprint(f\"Ratio to Orphanet prevalence (<1/1,000,000): {q_comb**2/PREV_ORPHANET:.0f}-fold excess\")\n\n# Observed homozygotes in gnomAD for the two OMIM missense alleles\nprint(\"\\nObserved homozygotes in gnomAD v4 (asymptomatic population reference):\")\nprint(\"  p.Leu115His : 3 homozygotes (2 exome + 1 genome)\")\nprint(\"  p.Asp389Asn : 0 homozygotes\")\nprint(\"  pLoF total  : 1 homozygote\")\n\n# Implied penetrance ceiling\npen = PREV_ORPHANET / q_comb**2\nprint(f\"\\nImplied upper bound on penetrance of biallelic genotypes\")\nprint(f\"if all diagnosed cases were ascertained: {pen*100:.2f}%\")\n\n# ------------------------- figure -------------------------\nfig, axes = plt.subplots(1, 2, figsize=(13.5, 5.2))\n\nax = axes[0]\nnames = [r[0].splitlines()[0] for r in rows]\nhoms  = [r[2] for r in rows]\ncols  = [\"#C44E52\", \"#DD8452\", \"#937860\", \"#4C72B0\", \"#55A868\"]\ny = np.arange(len(names))\nax.barh(y, homs, color=cols, edgecolor=\"black\", linewidth=0.6)\nax.axvline(PREV_ORPHANET, color=\"black\", ls=\"--\", lw=1.5)\nax.text(PREV_ORPHANET*1.3, len(names)-0.4, \"Orphanet reported\\nprevalence < 1/1,000,000\",\n        fontsize=8, va=\"top\")\nax.set_yticks(y); ax.set_yticklabels(names, fontsize=8)\nax.set_xscale(\"log\"); ax.set_xlabel(\"Expected frequency of biallelic genotype (q$^2$)\")\nax.set_title(\"A. Expected homozygote frequency of each OMIM allele\\nexceeds the reported disease prevalence\", fontsize=10)\nax.invert_yaxis()\n\nax = axes[1]\n# penetrance gap visual\nlabels = [\"Expected biallelic\\ngenotypes (q\u00b2)\", \"Reported disease\\nprevalence\"]\nvals = [q_comb**2, PREV_ORPHANET]\nax.bar(labels, vals, color=[\"#DD8452\", \"#4C72B0\"], edgecolor=\"black\", linewidth=0.6)\nax.set_yscale(\"log\"); ax.set_ylabel(\"Population frequency\")\nfor i, v in enumerate(vals):\n    ax.text(i, v*1.6, f\"1 in {1/v:,.0f}\", ha=\"center\", fontsize=10)\nax.set_ylim(1e-7, 1e-4)\nax.annotate(\"\", xy=(1, PREV_ORPHANET), xytext=(1, q_comb**2),\n            arrowprops=dict(arrowstyle=\"<->\", color=\"#C44E52\", lw=2))\nax.text(1.12, np.sqrt(PREV_ORPHANET*q_comb**2), f\"{q_comb**2/PREV_ORPHANET:.0f}-fold\\ngap\",\n        color=\"#C44E52\", fontsize=10, va=\"center\")\nax.set_title(\"B. The penetrance gap: most predicted biallelic\\ncarriers are never diagnosed\", fontsize=10)\n\nplt.tight_layout(); plt.show()\n",
  "plot_number": 3
}