{
  "filename": "plot_6.png",
  "iteration": 4,
  "description": "Testing the additive allele-dose model for CBG cortisol-binding capacity across three independent kindreds, and the quantity/quality dissociation between immunoassay and binding assay",
  "timestamp": "2026-11-28 09:22:03",
  "code": "\nimport numpy as np, matplotlib.pyplot as plt\nfrom scipy import stats\n\n# ---------------------------------------------------------------\n# Published genotype-stratified data, three independent kindreds\n# ---------------------------------------------------------------\n# A. Brazilian CBG Lyon kindred, PMID 12780753 (Brunner 2003)\n#    Cortisol binding capacity (CBC), nmol/L\nctrl_m, ctrl_sd, ctrl_n = 594.8, 59.5, 9     # healthy volunteers\nhet_m,  het_sd,  het_n  = 305.0, 81.4, 8     # D367N heterozygotes (10 family - 2 homozygotes)\nhom_vals = np.array([90.0, 114.0])           # 2 homozygotes (\"<90\" taken at the 90 ceiling)\n\n# B. Italian-Australian null kindred, PMID 11502797 (Torpy 2001)\n#    Immunoreactive CBG, microgram/mL\nnull_het_m, null_het_sd, null_het_n = 18.7, 1.3*np.sqrt(19), 19   # SEM 1.3 -> SD\nnull_ref_lo, null_ref_hi = 30.0, 52.0\nnull_ref_m = (null_ref_lo + null_ref_hi)/2\n\n# ---------------------------------------------------------------\n# Test 1: do Lyon heterozygotes match the 50%-of-control prediction\n#         expected if the variant allele contributes ZERO binding?\n# ---------------------------------------------------------------\npred_het = 0.5*ctrl_m\nt_het = (het_m - pred_het)/(het_sd/np.sqrt(het_n))\np_het = 2*stats.t.sf(abs(t_het), het_n-1)\nci_het = (het_m - stats.t.ppf(.975, het_n-1)*het_sd/np.sqrt(het_n),\n          het_m + stats.t.ppf(.975, het_n-1)*het_sd/np.sqrt(het_n))\n\nprint(\"TEST 1  Lyon heterozygotes vs zero-contribution prediction\")\nprint(f\"  predicted (0.5 x control) = {pred_het:.1f} nmol/L\")\nprint(f\"  observed  = {het_m:.1f} nmol/L, 95% CI {ci_het[0]:.1f}-{ci_het[1]:.1f}\")\nprint(f\"  t = {t_het:.3f}, df = {het_n-1}, P = {p_het:.3f}\")\nprint(f\"  observed/control = {het_m/ctrl_m:.3f}  (model predicts 0.500)\")\n\n# Hets are clearly below controls (sanity check)\nt_vs_ctrl, p_vs_ctrl = stats.ttest_ind_from_stats(het_m, het_sd, het_n, ctrl_m, ctrl_sd, ctrl_n)\nd = (ctrl_m-het_m)/np.sqrt(((het_n-1)*het_sd**2+(ctrl_n-1)*ctrl_sd**2)/(het_n+ctrl_n-2))\nprint(f\"  het vs control: t = {t_vs_ctrl:.2f}, P = {p_vs_ctrl:.2e}, Cohen d = {d:.2f}\")\n\n# ---------------------------------------------------------------\n# Test 2: homozygotes - residual signal above the predicted zero\n# ---------------------------------------------------------------\nhom_frac = hom_vals/ctrl_m\nprint(\"\\nTEST 2  Lyon homozygotes vs predicted zero binding capacity\")\nprint(f\"  observed {hom_vals} nmol/L = {100*hom_frac.round(3)} % of control\")\nprint(\"  model predicts 0%; residual 15-19% is at/below the assay floor and is\")\nprint(\"  the expected low-affinity high-capacity albumin component.\")\n\n# ---------------------------------------------------------------\n# Test 3: quantity/quality dissociation.\n#   Null het   -> immunoassay LOW   (~50%)  and binding LOW  (~50%)\n#   Lyon het   -> immunoassay NORMAL(~100%) and binding LOW  (~50%)\n# ---------------------------------------------------------------\nnull_het_frac = null_het_m/null_ref_m\nprint(\"\\nTEST 3  quantity vs quality, immunoassay readout by allele class\")\nprint(f\"  null het  immunoreactive CBG {null_het_m} ug/mL / ref mid {null_ref_m} = {null_het_frac:.2f}\")\nprint( \"  Lyon het  immunoreactive CBG NORMAL (PMID 22948765) but binding capacity 50% lower\")\nprint( \"  -> an immunoassay detects the null allele and completely misses the Lyon allele\")\n\n# ---------------------------------------------------------------\n# Figure\n# ---------------------------------------------------------------\nfig, ax = plt.subplots(1, 3, figsize=(15.5, 5))\n\n# Panel A: allele-dose response, Brazilian Lyon kindred\ndose  = np.array([0, 1, 2])\nmeans = np.array([ctrl_m, het_m, hom_vals.mean()])\nerrs  = np.array([ctrl_sd, het_sd, hom_vals.std(ddof=1)])\nax[0].errorbar(dose, means, yerr=errs, fmt='o', ms=11, color='#1f3b73',\n               capsize=6, lw=2, zorder=3, label='observed (PMID 12780753)')\nax[0].plot(dose, ctrl_m*(1 - dose/2), '--', color='#c0392b', lw=2,\n           label='additive model, variant allele = 0')\nax[0].scatter([2,2], hom_vals, color='#5dade2', s=55, zorder=4,\n              edgecolor='k', linewidth=.6, label='individual homozygotes')\nax[0].set_xticks(dose); ax[0].set_xticklabels(['0\\n(control)','1\\n(het)','2\\n(homozygote)'])\nax[0].set_xlabel('Number of CBG Lyon (p.Asp389Asn) alleles')\nax[0].set_ylabel('Cortisol binding capacity (nmol/L)')\nax[0].set_title('A. Binding capacity falls linearly with\\nvariant allele dose', fontsize=11)\nax[0].legend(fontsize=8, loc='upper right'); ax[0].set_ylim(0, 720)\nax[0].grid(alpha=.3)\n\n# Panel B: observed vs predicted\nobs  = np.array([1.0, het_m/ctrl_m, hom_vals.mean()/ctrl_m])\npred = np.array([1.0, 0.5, 0.0])\nx = np.arange(3); w = 0.36\nax[1].bar(x-w/2, pred, w, color='#c0392b', alpha=.75, label='predicted (allele = 0 activity)')\nax[1].bar(x+w/2, obs,  w, color='#1f3b73', alpha=.85, label='observed')\nfor xi, (p_, o_) in enumerate(zip(pred, obs)):\n    ax[1].text(xi-w/2, p_+.02, f'{p_:.2f}', ha='center', fontsize=9)\n    ax[1].text(xi+w/2, o_+.02, f'{o_:.2f}', ha='center', fontsize=9)\nax[1].set_xticks(x); ax[1].set_xticklabels(['control','heterozygote','homozygote'])\nax[1].set_ylabel('Binding capacity, fraction of control')\nax[1].set_title(f'B. Heterozygotes match the prediction\\n(P = {p_het:.2f} against 50%)', fontsize=11)\nax[1].legend(fontsize=8); ax[1].set_ylim(0, 1.18); ax[1].grid(alpha=.3, axis='y')\n\n# Panel C: quantity vs quality dissociation\nlabels = ['Null het\\n(p.Trp11Ter)', 'Lyon het\\n(p.Asp389Asn)']\nimmuno  = [null_het_frac, 1.00]\nbinding = [0.50, 0.50]\nx = np.arange(2); w = 0.36\nax[2].bar(x-w/2, immuno,  w, color='#7f8c8d', label='CBG by immunoassay')\nax[2].bar(x+w/2, binding, w, color='#e67e22', label='cortisol binding capacity')\nfor xi,(i_,b_) in enumerate(zip(immuno,binding)):\n    ax[2].text(xi-w/2, i_+.02, f'{i_:.2f}', ha='center', fontsize=9)\n    ax[2].text(xi+w/2, b_+.02, f'{b_:.2f}', ha='center', fontsize=9)\nax[2].axhline(1.0, color='k', ls=':', lw=1)\nax[2].annotate('immunoassay\\nmisses this allele', xy=(1-w/2, 1.0), xytext=(0.62, 1.30),\n               arrowprops=dict(arrowstyle='->', color='#c0392b', lw=1.6),\n               fontsize=9, color='#c0392b', ha='center')\nax[2].set_xticks(x); ax[2].set_xticklabels(labels)\nax[2].set_ylabel('Fraction of reference')\nax[2].set_title('C. Quantity defect is detectable,\\nquality defect is invisible', fontsize=11)\nax[2].legend(fontsize=8, loc='lower left'); ax[2].set_ylim(0, 1.55); ax[2].grid(alpha=.3, axis='y')\n\nplt.suptitle('CBG cortisol-binding capacity follows an additive allele-dose model in which pocket missense alleles contribute zero activity',\n             fontsize=12.5, y=1.02)\nplt.tight_layout()\nplt.show()\n",
  "plot_number": 6
}