{
  "filename": "plot_7.png",
  "iteration": 5,
  "description": "Capstone: testing whether a 1982 isoelectric-focusing survey of 500 plasmas reproduces the modern gnomAD allele frequency for CBG Leuven, and extrapolating the Leuven affinity deficit to body temperature",
  "timestamp": "2026-11-28 09:25:03",
  "code": "\nimport numpy as np, matplotlib.pyplot as plt\nfrom scipy import stats\n\n# =====================================================================\n# TEST A. Two independent estimates of the CBG Leuven allele frequency,\n#         40 years and two technologies apart.\n#   1982: isoelectric focusing of 500 Caucasian plasmas, 3 heterozygotes\n#         (PMID 7061486)\n#   2024: gnomAD v4 exome+genome AF for p.Leu115His (L93H)\n# =====================================================================\nn_screened, n_carriers = 500, 3\nq_gnomad = 2.4595e-3                      # gnomAD allele frequency\np_exp    = 2*q_gnomad*(1-q_gnomad)        # HWE carrier frequency\n\nbt  = stats.binomtest(n_carriers, n_screened, p_exp)   # two-sided\nci  = bt.proportion_ci(confidence_level=0.95)\nq_1982    = n_carriers/(2*n_screened)                  # allele freq from survey\nq_1982_ci = (ci.low/2, ci.high/2)\n\nprint(\"TEST A  CBG Leuven allele frequency, 1982 protein survey vs gnomAD\")\nprint(f\"  1982 : {n_carriers}/{n_screened} carriers = {n_carriers/n_screened:.4f}\"\n      f\"  -> q = {q_1982:.2e}  (95% CI {q_1982_ci[0]:.2e} - {q_1982_ci[1]:.2e})\")\nprint(f\"  gnomAD q = {q_gnomad:.2e} -> expected carriers = {p_exp*n_screened:.2f}/500\")\nprint(f\"  binomial P = {bt.pvalue:.3f}  ->  the two estimates do not differ\")\nprint(f\"  ratio q_1982 / q_gnomad = {q_1982/q_gnomad:.2f}\")\nprint(f\"  gnomAD q lies inside the 1982 CI: {q_1982_ci[0] <= q_gnomad <= q_1982_ci[1]}\")\n\n# Leuven homozygotes in the same 1982 survey (Polish family, n=2)\nprint(\"  The same survey found 2 homozygotes in a Polish family, ascertained\")\nprint(\"  by protein screening, not by illness.\")\n\n# =====================================================================\n# TEST B. The Leuven affinity deficit grows with temperature.\n#   2.6-fold at 4 C and 3.6-fold at 28 C (PMID 7061486).\n#   Extrapolate to 37 C on a log-linear fit (2 points, so indicative only).\n# =====================================================================\nT    = np.array([4.0, 28.0])\nfold = np.array([2.6, 3.6])\nslope, icept = np.polyfit(T, np.log(fold), 1)\nT37   = 37.0\nf37   = np.exp(icept + slope*T37)\nprint(\"\\nTEST B  Leuven affinity deficit versus temperature\")\nprint(f\"  log-linear fit: d(ln fold)/dT = {slope:.5f} per degC\")\nprint(f\"  extrapolated fold-reduction at 37 C = {f37:.2f}\")\nprint( \"  Two calibration points only, so this is indicative, not a measurement.\")\nprint( \"  It agrees with the 3-fold carrier-plasma figure (PMID 19643166) and\")\nprint( \"  with increased Trp371 side-chain flexibility at 40 C (PMID 33085168).\")\n\n# =====================================================================\n# Figure\n# =====================================================================\nfig, ax = plt.subplots(1, 3, figsize=(16, 5))\n\n# Panel A: allele frequency convergence\nest    = [q_1982, q_gnomad]\nerrlo  = [q_1982 - q_1982_ci[0], 0]\nerrhi  = [q_1982_ci[1] - q_1982, 0]\nax[0].errorbar([0], [q_1982], yerr=[[errlo[0]],[errhi[0]]], fmt='o', ms=13,\n               color='#1f3b73', capsize=8, lw=2, label='1982 isoelectric focusing\\n(500 plasmas, PMID 7061486)')\nax[0].plot([1], [q_gnomad], 's', ms=13, color='#e67e22', label='gnomAD v4 exome+genome')\nax[0].axhline(q_gnomad, color='#e67e22', ls='--', lw=1.3, alpha=.8)\nax[0].set_xlim(-0.6, 1.6); ax[0].set_xticks([0,1])\nax[0].set_xticklabels(['protein survey\\n1982', 'sequencing\\n2024'])\nax[0].set_ylabel('CBG Leuven allele frequency')\nax[0].set_title(f'A. Two methods, 40 years apart,\\nagree on the allele (P = {bt.pvalue:.2f})', fontsize=11)\nax[0].legend(fontsize=8, loc='upper left'); ax[0].grid(alpha=.3)\n\n# Panel B: temperature dependence\nTg = np.linspace(0, 40, 200)\nax[1].plot(Tg, np.exp(icept + slope*Tg), '-', color='#c0392b', lw=2, label='log-linear fit')\nax[1].plot(T, fold, 'o', ms=12, color='#1f3b73', zorder=4, label='measured (PMID 7061486)')\nax[1].plot([T37], [f37], '*', ms=20, color='#e67e22', zorder=5,\n           label=f'extrapolated 37 \u00b0C: {f37:.1f}-fold')\nax[1].axvline(37, color='grey', ls=':', lw=1.2)\nax[1].text(37.3, 1.9, 'body\\ntemperature', fontsize=8, color='grey')\nax[1].set_xlabel('Temperature (\u00b0C)')\nax[1].set_ylabel('Fold reduction in cortisol affinity')\nax[1].set_title('B. The Leuven defect worsens as\\ntemperature rises', fontsize=11)\nax[1].legend(fontsize=8, loc='upper left'); ax[1].grid(alpha=.3)\n\n# Panel C: the full allelic series, corrected\nnames = ['CBG Leuven\\np.Leu115His', 'CBG Lyon\\np.Asp389Asn', 'CBG Athens\\np.Trp393Ser',\n         'Null alleles\\np.Trp11Ter etc.']\nresid = [1/f37*100, 0.0, 0.0, 0.0]            # residual binding activity of the variant protein\nprot  = [100, 100, 100, 0]                     # protein present by immunoassay\nx = np.arange(4); w = 0.37\nax[2].bar(x-w/2, prot,  w, color='#7f8c8d', label='protein detected by immunoassay (%)')\nax[2].bar(x+w/2, resid, w, color='#e67e22', label='cortisol-binding activity of variant (%)')\nfor xi,(p_,r_) in enumerate(zip(prot,resid)):\n    ax[2].text(xi-w/2, p_+2.5, f'{p_:.0f}', ha='center', fontsize=9)\n    ax[2].text(xi+w/2, r_+2.5, f'{r_:.0f}', ha='center', fontsize=9)\nax[2].set_xticks(x); ax[2].set_xticklabels(names, fontsize=8.5)\nax[2].set_ylabel('Percent')\nax[2].set_ylim(0, 122)\nax[2].set_title('C. Only CBG Leuven is a partial allele;\\nthe other missense alleles are dead', fontsize=11)\nax[2].legend(fontsize=8, loc='upper center'); ax[2].grid(alpha=.3, axis='y')\n\nplt.suptitle('CBG Leuven: an allele common enough to be found by protein screening in 1982 and confirmed by sequencing in 2024',\n             fontsize=12.5, y=1.02)\nplt.tight_layout()\nplt.show()\n",
  "plot_number": 7
}