{
  "filename": "plot_3.png",
  "iteration": 3,
  "description": "Map ClinVar pathogenic GATAD2B variants onto p66-beta domain architecture; test CR1/CR2 enrichment; estimate GAND birth prevalence",
  "timestamp": "2026-11-19 04:32:29",
  "code": "\nimport requests, re, time, json\nimport pandas as pd, numpy as np\nimport matplotlib.pyplot as plt\nfrom matplotlib.patches import Rectangle\nfrom scipy.stats import beta as betadist\n\nE=\"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/\"\nr=requests.get(E+\"esearch.fcgi\",params=dict(db=\"clinvar\",term=\"GATAD2B[gene]\",retmax=1000,retmode=\"json\"),timeout=60)\nids=r.json()[\"esearchresult\"][\"idlist\"]\nrecs=[]\nfor i in range(0,len(ids),200):\n    j=requests.get(E+\"esummary.fcgi\",params=dict(db=\"clinvar\",id=\",\".join(ids[i:i+200]),retmode=\"json\"),timeout=120).json()[\"result\"]\n    for uid in j.get(\"uids\",[]):\n        d=j[uid]; g=d.get(\"germline_classification\",{})\n        recs.append(dict(title=d.get(\"title\",\"\"),clinsig=g.get(\"description\",\"\")))\n    time.sleep(0.4)\ndf=pd.DataFrame(recs)\n\nAA3=r\"(?:Ala|Arg|Asn|Asp|Cys|Gln|Glu|Gly|His|Ile|Leu|Lys|Met|Phe|Pro|Ser|Thr|Trp|Tyr|Val|Ter)\"\ndef protpos(t, kind):\n    if kind==\"missense\":\n        m=re.search(rf\"p\\.({AA3})(\\d+)({AA3})\\)\",t)\n        if m and m.group(3)!=\"Ter\": return int(m.group(2))\n    if kind==\"trunc\":\n        m=re.search(rf\"p\\.({AA3})(\\d+)(?:Ter|[A-Z][a-z]{{2}}fs)\",t)\n        if m: return int(m.group(2))\n    return None\n\nplp=df[df.clinsig.str.contains(\"Pathogenic\",na=False)]\nvus=df[df.clinsig==\"Uncertain significance\"]\nben=df[df.clinsig.str.contains(\"enign\",na=False)]\n\nplp_mis=[p for p in plp.title.map(lambda t:protpos(t,\"missense\")) if p]\nplp_tr =[p for p in plp.title.map(lambda t:protpos(t,\"trunc\")) if p]\nvus_mis=[p for p in vus.title.map(lambda t:protpos(t,\"missense\")) if p]\nben_mis=[p for p in ben.title.map(lambda t:protpos(t,\"missense\")) if p]\nprint(\"P/LP missense positions:\",sorted(plp_mis))\nprint(\"P/LP truncating positions (n=%d): %s\"%(len(plp_tr),sorted(plp_tr)))\nprint(\"VUS missense n=%d ; Benign/LB missense n=%d\"%(len(vus_mis),len(ben_mis)))\n\n# domains\nCR1=(165,195); CR2=(340,480); ZNF=(414,467); L=593\ndef infrac(pos,dom): return sum(dom[0]<=p<=dom[1] for p in pos)\ndom_len=(CR1[1]-CR1[0]+1)+(CR2[1]-CR2[0]+1)\nexp_frac=dom_len/L\nfrom scipy.stats import binomtest\nfor nm,pos in [(\"P/LP missense\",plp_mis),(\"VUS missense\",vus_mis),(\"Benign/LB missense\",ben_mis)]:\n    k=infrac(pos,CR1)+infrac(pos,CR2); n=len(pos)\n    if n:\n        bt=binomtest(k,n,exp_frac,alternative=\"greater\")\n        print(f\"{nm}: {k}/{n} ({100*k/n:.0f}%) fall in CR1+CR2 (expected {100*exp_frac:.0f}% by length); binomial p={bt.pvalue:.4g}\")\n\n# ---------- Prevalence estimate from published NDD cohorts ----------\nprint(\"\\n=== GAND frequency among severe/moderate ID-NDD probands (published cohorts) ===\")\ncoh=pd.DataFrame([\n    (\"Hamdan 2014 (PMID 25356899), moderate/severe ID trios, Canada\",41,1),\n    (\"Pande 2024 (PMID 38114583), syndromic ID with de novo variants, India\",54,1),\n],columns=[\"cohort\",\"n\",\"gatad2b\"])\ncoh[\"pct\"]=100*coh.gatad2b/coh.n\ntot_n=coh.n.sum(); tot_k=coh.gatad2b.sum()\nlo,hi=betadist.ppf(0.025,tot_k,tot_n-tot_k+1), betadist.ppf(0.975,tot_k+1,tot_n-tot_k)\nprint(coh.to_string(index=False))\nprint(f\"Pooled: {tot_k}/{tot_n} = {100*tot_k/tot_n:.2f}% (95% CI {100*lo:.2f}-{100*hi:.2f}%)\")\nprint(\"NOTE: these denominators are *solved* ID cohorts, so this is an upper-bound-prone estimate.\")\n\n# Derived population prevalence: severe ID prevalence ~0.3-0.4% of births (literature consensus)\nfor sid in [0.003,0.004]:\n    for f,lab in [(tot_k/tot_n,\"point\"),(lo,\"lower\"),(hi,\"upper\")]:\n        pass\npt=tot_k/tot_n\nprint(\"\\nDerived birth prevalence of GAND, assuming moderate/severe ID birth prevalence 0.3-0.4%:\")\nfor sid,lbl in [(0.003,\"0.3%\"),(0.004,\"0.4%\")]:\n    print(f\"  severe/moderate ID = {lbl}:  point {1e5*sid*pt:.2f} per 100,000  (95% CI {1e5*sid*lo:.2f} - {1e5*sid*hi:.2f})\")\n\n# ---------- Figure: lollipop of variants on domain map ----------\nfig,ax=plt.subplots(figsize=(13,5))\nax.add_patch(Rectangle((1,-0.22),L,0.44,facecolor=\"#DDE1E6\",edgecolor=\"k\",lw=0.6))\nfor (s,e),c,lab in [(CR1,\"#4C72B0\",\"CR1 165-195\\nMBD2/MBD3 binding\"),\n                    (CR2,\"#DD8452\",\"CR2 340-480\\nhistone-tail binding, CHD3/CHD4 recruitment\"),\n                    (ZNF,\"#55A868\",\"GATA-type Zn finger\\n414-467\")]:\n    y=-0.22 if lab.startswith(\"GATA\")==False else -0.14\n    h=0.44 if not lab.startswith(\"GATA\") else 0.28\n    ax.add_patch(Rectangle((s,y),e-s,h,facecolor=c,edgecolor=\"k\",lw=0.6,alpha=0.95))\n    ax.text((s+e)/2, 0.40 if lab.startswith(\"CR1\") else (0.40 if lab.startswith(\"CR2\") else -0.55),\n            lab,ha=\"center\",va=\"bottom\" if not lab.startswith(\"GATA\") else \"top\",fontsize=8.5)\n\nfor p in plp_tr:\n    ax.plot([p,p],[0.22,0.95],c=\"#999999\",lw=0.7,zorder=1)\n    ax.plot(p,0.95,\"o\",ms=4,c=\"#8C8C8C\",zorder=2)\nfor p in plp_mis:\n    ax.plot([p,p],[0.22,1.5],c=\"#C44E52\",lw=1.3,zorder=3)\n    ax.plot(p,1.5,\"o\",ms=8,c=\"#C44E52\",zorder=4)\n    ax.annotate(str(p),(p,1.55),ha=\"center\",fontsize=8,color=\"#C44E52\")\nax.plot([],[],\"o\",c=\"#8C8C8C\",label=\"P/LP truncating (n=%d)\"%len(plp_tr))\nax.plot([],[],\"o\",c=\"#C44E52\",label=\"P/LP missense (n=%d)\"%len(plp_mis))\nax.set_xlim(-10,L+25); ax.set_ylim(-1.0,2.1); ax.set_yticks([])\nax.set_xlabel(\"p66-beta (GATAD2B, UniProt Q8WXI9) amino acid position, 593 aa\")\nax.set_title(\"Pathogenic GATAD2B missense variants fall in the conserved CR1/CR2 interaction domains,\\nwhile truncating variants are distributed across the protein\")\nax.legend(loc=\"upper left\",frameon=False)\nfor s in [\"top\",\"right\",\"left\"]: ax.spines[s].set_visible(False)\nplt.tight_layout(); plt.show()\n",
  "plot_number": 3
}