{
  "filename": "plot_2.png",
  "iteration": 2,
  "description": "Quantify ATP6AP2 population constraint against the ClinVar variant interpretation burden, and check whether reported disease alleles appear in gnomAD",
  "timestamp": "2026-11-26 22:27:45",
  "code": "\nimport requests, json, pandas as pd, numpy as np\nimport matplotlib.pyplot as plt\nH = {\"User-Agent\": \"Mozilla/5.0 research-agent\", \"Content-Type\": \"application/json\"}\n\n# --- allele frequency of the reported pathogenic ATP6AP2 alleles in gnomAD v4 ---\nq = \"\"\"query($s:String!){ gene(gene_symbol:$s, reference_genome: GRCh38){\n  variants(dataset: gnomad_r4){ variant_id hgvsc hgvsp consequence\n    exome{ ac an af } genome{ ac an af } }\n}}\"\"\"\nj = requests.post(\"https://gnomad.broadinstitute.org/api\", headers=H,\n                  json={\"query\": q, \"variables\": {\"s\": \"ATP6AP2\"}}, timeout=120).json()\nv = pd.DataFrame(j[\"data\"][\"gene\"][\"variants\"])\ndef tot_ac(row):\n    e = row[\"exome\"] or {}; gm = row[\"genome\"] or {}\n    return (e.get(\"ac\") or 0) + (gm.get(\"ac\") or 0), (e.get(\"an\") or 0) + (gm.get(\"an\") or 0)\nv[[\"ac\",\"an\"]] = v.apply(lambda r: pd.Series(tot_ac(r)), axis=1)\nprint(\"gnomAD v4 ATP6AP2 variants returned:\", len(v))\n\ntargets = [\"c.321C>T\", \"c.345C>T\", \"c.293T>C\", \"c.212G>A\", \"c.185G>A\", \"c.284C>A\", \"c.168+6T>A\", \"c.628G>T\"]\nhit = v[v.hgvsc.astype(str).str.contains(\"|\".join([t.replace(\">\", \">\") for t in targets]), na=False)]\nprint(\"\\nReported disease alleles present in gnomAD v4:\")\nprint(hit[[\"variant_id\",\"hgvsc\",\"hgvsp\",\"consequence\",\"ac\",\"an\"]].to_string(index=False) if len(hit) else \"  none of the reported pathogenic alleles found in gnomAD v4\")\n\n# observed LoF alleles\nlof = v[v.consequence.isin([\"stop_gained\",\"frameshift_variant\",\"splice_donor_variant\",\"splice_acceptor_variant\"])]\nprint(f\"\\npLoF variant entries in gnomAD v4 for ATP6AP2: {len(lof)}; total pLoF allele count = {lof.ac.sum()} / AN ~ {int(v.an.median())}\")\n\n# --- figure: constraint + ClinVar interpretation burden ---\nconst = {\"pLoF\": (1, 23.42), \"Missense\": (174, 271.33), \"Synonymous\": (90, 97.12)}\nclinvar = {\"Uncertain significance\": 132, \"Likely benign\": 85, \"Benign\": 23,\n           \"Benign/Likely benign\": 5, \"Conflicting\": 12, \"Pathogenic\": 5, \"Likely pathogenic\": 1,\n           \"No classification\": 86}\n\nfig, axes = plt.subplots(1, 2, figsize=(13.5, 5))\n\nax = axes[0]\nlabels = list(const.keys())\nobs = [const[k][0] for k in labels]; exp = [const[k][1] for k in labels]\nx = np.arange(len(labels)); w = 0.38\nax.bar(x - w/2, exp, w, label=\"expected\", color=\"#b0b7c3\")\nax.bar(x + w/2, obs, w, label=\"observed\", color=\"#4c78a8\")\nfor i, k in enumerate(labels):\n    ax.text(i, max(obs[i], exp[i]) + 7, f\"o/e = {obs[i]/exp[i]:.2f}\", ha=\"center\", fontsize=9, weight=\"bold\")\nax.set_xticks(x); ax.set_xticklabels(labels)\nax.set_ylabel(\"variant count in gnomAD v4\")\nax.set_title(\"ATP6AP2 is extremely intolerant to loss of function\\npLI = 0.9999, LOEUF = 0.203, missense z = 2.52, synonymous z = 0.43\")\nax.legend(frameon=False)\nfor sp in [\"top\",\"right\"]: ax.spines[sp].set_visible(False)\n\nax = axes[1]\norder = [\"Pathogenic\", \"Likely pathogenic\", \"Conflicting\", \"Uncertain significance\",\n         \"Likely benign\", \"Benign/Likely benign\", \"Benign\", \"No classification\"]\ncols = [\"#b2182b\", \"#d6604d\", \"#f4a582\", \"#f7f0a0\", \"#92c5de\", \"#6aa7cf\", \"#2166ac\", \"#cccccc\"]\nvals = [clinvar[k] for k in order]\nax.barh(range(len(order))[::-1], vals, color=cols)\nfor i, (k, val) in enumerate(zip(order, vals)):\n    ax.text(val + 2, len(order) - 1 - i, str(val), va=\"center\", fontsize=9)\nax.set_yticks(range(len(order))[::-1]); ax.set_yticklabels(order, fontsize=9)\nax.set_xlabel(\"ClinVar single-gene ATP6AP2 variants (n = 349)\")\nax.set_title(\"Only 6 of 349 small ATP6AP2 variants are P/LP;\\n132 remain of uncertain significance\")\nfor sp in [\"top\",\"right\"]: ax.spines[sp].set_visible(False)\n\nplt.tight_layout()\nplt.show()\n",
  "plot_number": 2
}