{
  "filename": "plot_4.png",
  "iteration": 4,
  "description": "Test whether pathogenic ABAT missense variants lie closer to the PLP cofactor than population-tolerated missense variants",
  "timestamp": "2026-11-28 20:36:54",
  "code": "\nimport requests, json\nimport numpy as np, pandas as pd\nfrom scipy import stats\nimport matplotlib.pyplot as plt\nS=requests.Session(); S.headers.update({\"User-Agent\":\"research/1.0\"})\npdb = S.get(\"https://files.rcsb.org/download/1OHV.pdb\", timeout=120).text\nhseq = S.get(\"https://rest.uniprot.org/uniprotkb/P80404.json\", timeout=120).json()[\"sequence\"][\"value\"]\n\naa3={'ALA':'A','ARG':'R','ASN':'N','ASP':'D','CYS':'C','GLN':'Q','GLU':'E','GLY':'G','HIS':'H',\n     'ILE':'I','LEU':'L','LYS':'K','MET':'M','PHE':'F','PRO':'P','SER':'S','THR':'T','TRP':'W',\n     'TYR':'Y','VAL':'V'}\natoms=[]\nfor l in pdb.splitlines():\n    if l.startswith((\"ATOM  \",\"HETATM\")):\n        atoms.append(dict(rec=l[:6].strip(), name=l[12:16].strip(), resn=l[17:20].strip(),\n                          chain=l[21], resi=int(l[22:26]), x=float(l[30:38]),\n                          y=float(l[38:46]), z=float(l[46:54])))\nA=pd.DataFrame(atoms)\n\nca = A[(A.chain==\"A\")&(A.name==\"CA\")&(A.resn.isin(aa3))][[\"resi\",\"resn\",\"x\",\"y\",\"z\"]].drop_duplicates(\"resi\").sort_values(\"resi\")\nca[\"aa\"]=ca.resn.map(aa3)\nbest=None\nfor off in range(0,60):\n    ok=[(ca.aa.iloc[i]==hseq[ca.resi.iloc[i]+off-1]) for i in range(len(ca)) if 0 < ca.resi.iloc[i]+off <= len(hseq)]\n    f=np.mean(ok) if ok else 0\n    if best is None or f>best[1]: best=(off,f)\nOFF,IDENT=best\nprint(f\"best precursor-numbering offset = +{OFF}, sequence identity = {IDENT:.3f} (pig 1OHV vs human P80404)\")\nca[\"pres\"]=ca.resi+OFF\nprint(\"catalytic Lys357 check: 1OHV residue\", 357-OFF, \"=\", ca.set_index('pres').loc[357,'resn'])\n\n# cofactor atoms: PLP ring and the [2Fe-2S] cluster, chain A\nplp = A[(A.resn==\"PLP\")&(A.chain==\"A\")][[\"x\",\"y\",\"z\"]].values\nfes = A[(A.resn==\"FES\")&(A.chain==\"A\")][[\"x\",\"y\",\"z\"]].values\nprint(\"PLP atoms (chain A):\",len(plp),\" FES atoms (chain A):\",len(fes))\n# also use chain B cofactors: the active site sits at the dimer interface\nplpB = A[(A.resn==\"PLP\")&(A.chain==\"B\")][[\"x\",\"y\",\"z\"]].values\ncof = np.vstack([plp,plpB])\n\nXYZ = ca[[\"x\",\"y\",\"z\"]].values\nd_plp = np.min(np.linalg.norm(XYZ[:,None,:]-cof[None,:,:],axis=2),axis=1)\nd_fes = np.min(np.linalg.norm(XYZ[:,None,:]-fes[None,:,:],axis=2),axis=1) if len(fes) else np.full(len(ca),np.nan)\nca[\"d_plp\"]=d_plp; ca[\"d_fes\"]=d_fes\ndist = ca.set_index(\"pres\")[[\"aa\",\"d_plp\",\"d_fes\"]]\n\n# ---- variant sets (human precursor numbering) -----------------------------\npatho = {152:\"P152S\",211:\"L211F\",478:\"L478P\",220:\"R220K\",296:\"Q296H\",377:\"R377W\",\n         92:\"R92Q\",213:\"F213C\",465:\"G465D\",465.1:\"G465R\"}\npatho_pos = sorted({int(p) for p in patho})\n# tolerated set: gnomAD missense alleles with AF >= 1e-5 (seen many times, no disease report)\nq=\"\"\"query { gene(gene_symbol:\"ABAT\", reference_genome:GRCh38){\n variants(dataset: gnomad_r4){ hgvsp consequence exome{ac an} genome{ac an} } } }\"\"\"\nS.headers.update({\"Content-Type\":\"application/json\"})\nvs=S.post(\"https://gnomad.broadinstitute.org/api\",data=json.dumps({\"query\":q}),timeout=300).json()[\"data\"][\"gene\"][\"variants\"]\nrows=[]\nfor v in vs:\n    if v[\"consequence\"]!=\"missense_variant\": continue\n    e=v.get(\"exome\") or {}; g=v.get(\"genome\") or {}\n    ac=(e.get(\"ac\") or 0)+(g.get(\"ac\") or 0); an=(e.get(\"an\") or 0)+(g.get(\"an\") or 0)\n    hp=v.get(\"hgvsp\") or \"\"\n    import re as _re\n    mm=_re.match(r\"p\\.[A-Za-z]{3}(\\d+)[A-Za-z]{3}$\",hp)\n    if mm: rows.append(dict(pos=int(mm.group(1)), af=ac/an if an else 0))\nM=pd.DataFrame(rows)\ntol = sorted(set(M.loc[M.af>=1e-5,\"pos\"]) - set(patho_pos))\nprint(f\"\\npathogenic missense positions: {patho_pos}\")\nprint(f\"tolerated (gnomAD AF>=1e-5) missense positions: n={len(tol)}\")\n\ndp = dist.reindex(patho_pos).dropna(subset=[\"d_plp\"])\ndt = dist.reindex(tol).dropna(subset=[\"d_plp\"])\nprint(f\"\\nmodelled: pathogenic n={len(dp)}, tolerated n={len(dt)}\")\nu,p = stats.mannwhitneyu(dp.d_plp, dt.d_plp, alternative=\"less\")\n# rank-biserial effect size\nrbc = 1 - 2*u/(len(dp)*len(dt)) if False else (2*u/(len(dp)*len(dt)) - 1)\nprint(f\"distance to PLP cofactor (CA, angstrom): pathogenic median {dp.d_plp.median():.1f} \"\n      f\"(IQR {dp.d_plp.quantile(.25):.1f}-{dp.d_plp.quantile(.75):.1f}), \"\n      f\"tolerated median {dt.d_plp.median():.1f} (IQR {dt.d_plp.quantile(.25):.1f}-{dt.d_plp.quantile(.75):.1f})\")\nprint(f\"Mann-Whitney U={u:.0f}, one-sided p={p:.4g}, rank-biserial r={rbc:+.3f}\")\nu2,p2 = stats.mannwhitneyu(dp.d_fes, dt.d_fes, alternative=\"less\")\nprint(f\"distance to [2Fe-2S]: pathogenic median {dp.d_fes.median():.1f}, tolerated median {dt.d_fes.median():.1f}, p={p2:.4g}\")\nprint(\"\\nper-variant distances:\")\nprint(dp.assign(label=[patho[i] if i in patho else f\"{i}\" for i in dp.index]).round(1).to_string())\n\nfig,ax=plt.subplots(1,2,figsize=(12,4.6))\na=ax[0]\nparts=a.violinplot([dt.d_plp.values,dp.d_plp.values],showmedians=True,widths=.8)\nfor pc,c in zip(parts['bodies'],[\"#a0aec0\",\"#c53030\"]): pc.set_facecolor(c); pc.set_alpha(.6)\na.scatter(np.random.default_rng(0).normal(2,.05,len(dp)),dp.d_plp,color=\"#742a2a\",zorder=3,s=28)\na.set_xticks([1,2]); a.set_xticklabels([f\"gnomAD missense\\nAF>=1e-5 (n={len(dt)})\",f\"pathogenic\\n(n={len(dp)})\"])\na.set_ylabel(\"CA distance to PLP cofactor (A)\")\na.set_title(f\"Pathogenic ABAT missense sit near the cofactor\\nMann-Whitney p = {p:.3g}, rank-biserial r = {rbc:+.2f}\")\na.grid(alpha=.3,axis=\"y\")\n\nb=ax[1]\nb.plot(dist.index, dist.d_plp, color=\"#cbd5e0\", lw=1)\nb.scatter(dt.index, dt.d_plp, color=\"#4a5568\", s=14, label=\"gnomAD AF>=1e-5\")\nb.scatter(dp.index, dp.d_plp, color=\"#c53030\", s=55, zorder=4, label=\"pathogenic\")\nfor i,r in dp.iterrows():\n    b.annotate(patho.get(i,str(i)), (i,r.d_plp), textcoords=\"offset points\", xytext=(0,7),\n               ha=\"center\", fontsize=7, color=\"#742a2a\")\nb.axhline(10,ls=\":\",color=\"k\",lw=1); b.text(60,10.6,\"10 A active-site shell\",fontsize=7)\nb.set_xlabel(\"ABAT residue (P80404 precursor numbering)\")\nb.set_ylabel(\"CA distance to PLP (A)\")\nb.set_title(\"Position along the chain\")\nb.legend(fontsize=8); b.grid(alpha=.3)\nplt.tight_layout(); plt.show()\n",
  "plot_number": 4
}