{
  "filename": "plot_9.png",
  "iteration": 5,
  "description": "Consolidation figure for the final report: ClinVar variant-class composition by clinical significance, the two structural/positional null tests with Wilson intervals, cumulative ovarian cancer risk by gene, and the RAD51D causal chain",
  "timestamp": "2026-11-19 03:56:46",
  "code": "\nimport numpy as np, matplotlib.pyplot as plt\nfrom scipy import stats\n\nfig = plt.figure(figsize=(15, 11))\ngs = fig.add_gridspec(2, 2, hspace=0.33, wspace=0.26)\n\n# ---------------- Panel A: ClinVar composition ----------------\naxA = fig.add_subplot(gs[0, 0])\ncats = ['Pathogenic /\\nlikely pathogenic', 'VUS', 'Benign /\\nlikely benign']\ntotals = np.array([297, 947, 723])\nmissense = np.array([1, 765, 13])\nother = totals - missense\nx = np.arange(3)\naxA.bar(x, other, 0.6, label='truncating, splice, CNV, other', color='#2c5f8a')\naxA.bar(x, missense, 0.6, bottom=other, label='missense substitution', color='#d9822b')\nfor i, (t, m) in enumerate(zip(totals, missense)):\n    axA.text(i, t + 25, f'n = {t}\\nmissense {m}', ha='center', fontsize=9)\naxA.set_xticks(x); axA.set_xticklabels(cats, fontsize=9)\naxA.set_ylabel('ClinVar records (retrieved 2026-11-19)')\naxA.set_ylim(0, 1150)\naxA.set_title('A. Only one of 297 pathogenic RAD51D records is a missense change', fontsize=10.5, loc='left')\naxA.legend(fontsize=8.5, loc='upper right')\n\n# ---------------- Panel B: positional and structural null tests ----------------\naxB = fig.add_subplot(gs[0, 1])\ntests = [\n    ('VUS residues in the\\nRecA-like ATPase core\\n(84-328)', 233, 314, 0.747, 0.608),\n    ('VUS residues at an\\ninter-subunit interface\\nin BCDX2 (PDB 8OUZ)', 101, 296, 0.334, 0.424),\n]\nys = np.arange(len(tests))[::-1]\nfor y, (lab, k, n, exp, p) in zip(ys, tests):\n    lo, hi = stats.binomtest(k, n).proportion_ci(confidence_level=0.95, method='wilson')\n    obs = k / n\n    axB.errorbar(obs, y, xerr=[[obs - lo], [hi - obs]], fmt='o', color='#2c5f8a',\n                 capsize=5, markersize=9)\n    axB.plot([exp, exp], [y - 0.25, y + 0.25], color='#c0392b', lw=2.5)\n    axB.text(hi + 0.012, y, f'observed {obs:.3f}, expected {exp:.3f}\\none-sided binomial p = {p:.3f}',\n             va='center', fontsize=8.5)\naxB.set_yticks(ys); axB.set_yticklabels([t[0] for t in tests], fontsize=8.5)\naxB.set_xlim(0.25, 0.98); axB.set_ylim(-0.6, 1.6)\naxB.set_xlabel('proportion of missense VUS residues (95% Wilson interval)')\naxB.set_title('B. Missense VUS carry no positional or interface signal\\n(red line = expectation from residue counts)',\n              fontsize=10.5, loc='left')\naxB.axvline(0, color='none')\n\n# ---------------- Panel C: cumulative ovarian cancer risk to age 80 ----------------\naxC = fig.add_subplot(gs[1, 0])\ngenes = ['population\\nbaseline', 'BRIP1', 'RAD51C', 'RAD51D', 'BRCA2', 'BRCA1']\nrisk = [1.3, 5.8, 11.0, 13.0, 17.0, 44.0]\ncols = ['#8c8c8c', '#7fa8c9', '#5b8db5', '#d9822b', '#2c5f8a', '#1b3a52']\naxC.barh(genes, risk, color=cols)\nfor g, r in zip(genes, risk):\n    axC.text(r + 0.7, g, f'{r}%', va='center', fontsize=9)\naxC.set_xlabel('cumulative tubo-ovarian cancer risk to age 80 (%)')\naxC.set_xlim(0, 52)\naxC.set_title('C. RAD51D is a moderate-penetrance tubo-ovarian cancer gene\\n(Yang 2020 PMID 32068527; Kuchenbaecker 2017 PMID 28632866)',\n              fontsize=10.5, loc='left')\n\n# ---------------- Panel D: causal chain ----------------\naxD = fig.add_subplot(gs[1, 1]); axD.axis('off')\nsteps = [\n 'Germline truncating RAD51D allele\\n(NM_002878.4), haploinsufficient carrier',\n 'Somatic loss of the wild-type allele in a\\nfallopian tube secretory epithelial cell',\n 'No functional RAD51D: BCDX2 cannot\\ncomplete its two composite ATP sites',\n 'RAD51 filament nucleation fails,\\nhomologous recombination is lost',\n 'Branch: TP53 intact -> G2/M arrest,\\nsenescence, the clone is eliminated',\n 'Branch: TP53 already inactivated ->\\narrest bypassed, clone survives',\n 'Error-prone repair, genome-wide LOH,\\nserous tubal intraepithelial carcinoma',\n 'High-grade serous tubo-ovarian carcinoma;\\nHRD confers platinum and PARPi sensitivity',\n]\nycur = 0.97\nface = ['#dce7f0']*4 + ['#f2dede', '#e4f0df'] + ['#dce7f0']*2\nfor s, f in zip(steps, face):\n    axD.text(0.5, ycur, s, ha='center', va='top', fontsize=8.4,\n             bbox=dict(boxstyle='round,pad=0.42', facecolor=f, edgecolor='#4a4a4a', lw=0.8),\n             transform=axD.transAxes)\n    ycur -= 0.122\nfor yy in [0.885, 0.763, 0.641]:\n    axD.annotate('', xy=(0.5, yy - 0.025), xytext=(0.5, yy),\n                 xycoords='axes fraction', arrowprops=dict(arrowstyle='-|>', color='#4a4a4a'))\nfor yy in [0.397, 0.275]:\n    axD.annotate('', xy=(0.5, yy - 0.025), xytext=(0.5, yy),\n                 xycoords='axes fraction', arrowprops=dict(arrowstyle='-|>', color='#4a4a4a'))\naxD.annotate('', xy=(0.5, 0.519 - 0.025), xytext=(0.5, 0.519),\n             xycoords='axes fraction', arrowprops=dict(arrowstyle='-|>', color='#4a4a4a'))\naxD.set_title('D. Causal chain from germline allele to carcinoma', fontsize=10.5, loc='left')\n\nplt.show()\n\n# print the Wilson intervals for the report text\nfor lab, k, n, exp, p in tests:\n    lo, hi = stats.binomtest(k, n).proportion_ci(confidence_level=0.95, method='wilson')\n    print(lab.replace('\\n', ' '), f'| {k}/{n} = {k/n:.4f} | 95% CI {lo:.4f}-{hi:.4f} | expected {exp}')\n",
  "plot_number": 9
}