{
  "filename": "plot_3.png",
  "iteration": 1,
  "description": "East-Asian-specific HWE analysis of UROC1 p.Trp285Ter homozygotes",
  "timestamp": "2026-11-20 14:26:00",
  "code": "\nimport requests, pandas as pd, numpy as np, matplotlib.pyplot as plt\nfrom scipy import stats\n\nQ=\"\"\"query V($v:String!){ variant(variantId:$v, dataset: gnomad_r4){\n exome{ac an homozygote_count populations{id ac an homozygote_count}} } }\"\"\"\nv=requests.post(\"https://gnomad.broadinstitute.org/api\",json={\"query\":Q,\"variables\":{\"v\":\"3-126504043-C-T\"}},\n   timeout=120,headers={\"Content-Type\":\"application/json\",\"User-Agent\":\"Mozilla/5.0\"}).json()[\"data\"][\"variant\"]\npops={p[\"id\"]:p for p in v[\"exome\"][\"populations\"]}\nprint(\"subpopulation ids available:\", [k for k in pops if k.startswith(\"eas\")])\n\neas=pops[\"eas\"]; af=eas[\"ac\"]/eas[\"an\"]; N=eas[\"an\"]/2\nexp=af**2*N; obs=eas[\"homozygote_count\"]\np_exc=stats.poisson.sf(obs-1,exp)\nprint(\"East Asian: AC=%d AN=%d (N=%d), AF=%.4f\"%(eas[\"ac\"],eas[\"an\"],N,af))\nprint(\"  expected hom under HWE = %.2f ; observed = %d ; Poisson one-sided p(excess) = %.2e\"%(exp,obs,p_exc))\nprint(\"  carrier freq in EAS = 1 in %.0f ; predicted biallelic genotype freq = 1 in %,.0f\".replace(\",\",\"\")%(1/(2*af),0) )\nprint(\"  predicted EAS homozygote frequency = 1 in %.0f\"%(1/af**2))\n\nfor k in [k for k in pops if k.startswith(\"eas_\")]:\n    p=pops[k]; print(\"   \",k,\"AC=%d AN=%d AF=%.4f hom=%d\"%(p[\"ac\"],p[\"an\"],p[\"ac\"]/p[\"an\"] if p[\"an\"] else 0,p[\"homozygote_count\"]))\n\n# Compare to reported-case count\nreported_cases = 8   # conservative upper bound of individuals in literature since 1971\nworld_births_since_1971 = 55*130e6\nexpected_world = (af**2)  # EAS-specific; use global pLoF q instead below\nprint(\"\\nPredicted biallelic p.Trp285Ter individuals alive in East Asia (pop 1.6e9): %.0f\"%(af**2*1.6e9))\n\nfig,ax=plt.subplots(figsize=(7.5,4.8))\ncats=[\"expected under HWE\\nin gnomAD East Asians\",\"observed homozygotes\\nin gnomAD East Asians\"]\nax.bar(cats,[exp,obs],color=[\"#5b6b7c\",\"#b4553a\"],width=0.5)\nfor i,val in enumerate([exp,obs]): ax.text(i,val+0.12,f\"{val:.2f}\" if i==0 else str(val),ha=\"center\")\nax.set_ylabel(\"p.Trp285Ter homozygous individuals\")\nax.set_title(\"UROC1 nonsense homozygotes are present in a population reference cohort\\nEast Asian AF = %.3f%%, N = %d\"%(af*100,N))\nplt.tight_layout(); plt.show()\n",
  "plot_number": 3
}