{
  "filename": "plot_4.png",
  "iteration": 2,
  "description": "Compare the observed SERPINA6 carrier frequency in the southern Italian founder village with the gnomAD-derived population expectation, and assemble the full allelic series of reported human CBG variants",
  "timestamp": "2026-11-28 09:07:43",
  "code": "\nimport numpy as np, matplotlib.pyplot as plt\nfrom scipy import stats\n\n# ------------------------------------------------------------------\n# A. Founder enrichment test\n# Cizza et al. 2011 (PMID 21795453): field survey of the southern Italian\n# village from which the original null/Lyon kindred emigrated.\n# ------------------------------------------------------------------\nn_village, n_carriers = 495, 18          # 6 null + 12 Lyon, all heterozygous\np_village = n_carriers / n_village\n\n# gnomAD-derived expectation for the same two allele classes (this session):\nq_lyon, q_null = 3.5811e-4, 1.717e-4      # Lyon AF; all pLoF AF summed\np_expect = 2 * (q_lyon + q_null)          # heterozygote frequency, 2q\n\nres = stats.binomtest(n_carriers, n_village, p_expect, alternative=\"greater\")\nci = res.proportion_ci(confidence_level=0.95)\n\nprint(\"=== Founder enrichment in the southern Italian village ===\")\nprint(f\"Observed carriers            : {n_carriers}/{n_village} = {p_village:.4f} (3.6%)\")\nprint(f\"95% CI on observed frequency : {ci.low:.4f} - {ci.high:.4f}\")\nprint(f\"gnomAD expectation 2q        : {p_expect:.6f} (1 in {1/p_expect:,.0f})\")\nprint(f\"Enrichment                   : {p_village/p_expect:.0f}-fold\")\nprint(f\"Exact binomial P (one-sided) : {res.pvalue:.3e}\")\n\n# ------------------------------------------------------------------\n# B. Phenotype within carriers (no non-carrier denominator published)\n# ------------------------------------------------------------------\nprint(\"\\n=== Phenotype among the 18 carriers (Cizza 2011) ===\")\nfor lab, n, pain, oa in [(\"Lyon (D367N) het\", 12, 8, 5), (\"Null het\", 6, 3, 4)]:\n    print(f\"{lab:<18} n={n:<3} chronic widespread pain {pain}/{n} ({pain/n:.0%})\"\n          f\"   osteoarthritis with pain {oa}/{n} ({oa/n:.0%})\")\nprint(f\"{'Combined':<18} n=18  chronic widespread pain 11/18 ({11/18:.0%})\")\nprint(\"Note: the abstract reports no non-carrier comparison rates, so this is\")\nprint(\"a within-carrier description, not an effect size.\")\n\n# ------------------------------------------------------------------\n# C. Allelic series of reported human SERPINA6 variants\n# mature numbering (precursor = mature + 22)\n# ------------------------------------------------------------------\nseries = [\n    # name,                 protein,            class,     CBG level %ref, affinity %ref\n    (\"CBG null (Melbourne)\", \"c.121delT fs\",     \"quantity\",  50,  100),\n    (\"CBG Santiago\",         \"p.Leu5CysfsX26\",   \"quantity\",  50,  100),\n    (\"CBG Montevideo\",       \"haploinsufficiency\",\"quantity\", 50,  100),\n    (\"CBG Trp11Ter\",         \"p.Trp11Ter\",       \"quantity\",  50,  100),\n    (\"CBG Lyon\",             \"D367N / D389N\",    \"quality\",  100,   15),\n    (\"CBG Leuven\",           \"L93H / L115H\",     \"quality\",  100,   50),\n    (\"CBG Athens\",           \"W371S / W393S\",    \"quality\",  100,    0),\n    (\"CBG Ser224Ala (S246A)\",\"p.Ser246Ala\",      \"neutral\",  100,  100),\n]\nprint(\"\\n=== Reported human allelic series (heterozygous carrier values) ===\")\nfor nm, pr, cl, lv, af in series:\n    print(f\"  {nm:<24} {pr:<20} {cl:<9} CBG {lv:>4}%  affinity {af:>4}%\")\n\n# ------------------------------------------------------------------\n# Figure\n# ------------------------------------------------------------------\nfig, axes = plt.subplots(1, 2, figsize=(13.5, 5.0))\n\nax = axes[0]\nbars = ax.bar([\"Southern Italian\\nvillage (Cizza 2011)\", \"gnomAD expectation\\n(Lyon + all pLoF)\"],\n              [p_village, p_expect], color=[\"#C44E52\", \"#4C72B0\"],\n              edgecolor=\"black\", linewidth=0.6)\nax.errorbar(0, p_village, yerr=[[p_village-ci.low],[ci.high-p_village]],\n            fmt=\"none\", ecolor=\"black\", capsize=5, lw=1.4)\nax.set_yscale(\"log\"); ax.set_ylabel(\"Heterozygous carrier frequency\")\nax.set_ylim(1e-4, 0.2)\nax.text(0, p_village*1.9, f\"{p_village:.1%}\", ha=\"center\", fontsize=11)\nax.text(1, p_expect*1.9, f\"{p_expect:.2%}\", ha=\"center\", fontsize=11)\nax.set_title(f\"A. Founder enrichment: {p_village/p_expect:.0f}-fold excess of carriers\\n\"\n             f\"exact binomial P = {res.pvalue:.1e}\", fontsize=10)\n\nax = axes[1]\ncmap = {\"quantity\":\"#4C72B0\", \"quality\":\"#DD8452\", \"neutral\":\"#999999\"}\nnames = [s[0] for s in series]\ny = np.arange(len(series))\nh = 0.38\nax.barh(y-h/2, [s[3] for s in series], h, label=\"plasma CBG concentration\",\n        color=[cmap[s[2]] for s in series], edgecolor=\"black\", linewidth=0.5)\nax.barh(y+h/2, [s[4] for s in series], h, label=\"cortisol-binding affinity\",\n        color=[cmap[s[2]] for s in series], edgecolor=\"black\", linewidth=0.5,\n        hatch=\"///\", alpha=0.75)\nax.axvline(100, color=\"black\", ls=\":\", lw=1)\nax.set_yticks(y); ax.set_yticklabels(names, fontsize=8.5)\nax.set_xlabel(\"Percent of reference value (heterozygous carriers)\")\nax.invert_yaxis(); ax.legend(fontsize=8, loc=\"lower right\")\nax.set_title(\"B. Two mutation classes: truncating alleles cut the amount,\\n\"\n             \"missense alleles cut the affinity\", fontsize=10)\n\nplt.tight_layout(); plt.show()\n",
  "plot_number": 4
}