{
  "filename": "plot_5.png",
  "iteration": 3,
  "description": "Test whether the Atm knockout mouse recapitulates the human ataxia-telangiectasia phenotype spectrum",
  "timestamp": "2026-11-26 21:18:41",
  "code": "\nimport requests, pandas as pd, json, collections, re\nimport matplotlib.pyplot as plt\nimport numpy as np\n\nbase=\"https://www.alliancegenome.org/api\"\nres=requests.get(f\"{base}/gene/MGI:107202/phenotypes\", params={\"limit\":300}, timeout=50).json()[\"results\"]\nmp=[]\nfor x in res:\n    mp.append({\"statement\":x[\"phenotypeStatement\"],\n               \"pmids\":[c[\"referencedCurie\"] for c in (x.get(\"pubmedPublications\") or [])]})\nmdf=pd.DataFrame(mp).drop_duplicates(\"statement\")\nprint(\"unique mouse Atm phenotype statements:\", len(mdf), \"from\", len({p for l in mdf.pmids for p in l}), \"publications\")\n\n# --- human A-T HPO categories (ontology.jax.org, OMIM:208900) ---\nhj=requests.get(\"https://ontology.jax.org/api/network/annotation/OMIM:208900\", timeout=50).json()\nhcats={k:[t[\"name\"] for t in v] for k,v in hj[\"categories\"].items() if v}\nprint(\"\\nhuman A-T HPO systems:\", len(hcats), \"terms:\", sum(len(v) for v in hcats.values()))\n\n# --- map both onto shared organ-system buckets by keyword ---\nBUCKETS = {\n \"Nervous system\":      r\"ataxia|cerebell|purkinje|neuro|nerve|brain|motor|tremor|seizure|dystonia|gait|coordinat|myelin|behavi|dysarthr|nystagm\",\n \"Immune system\":       r\"immun|lymphocyt|thymus|thymocyt|T cell|B cell|igg|iga|antibod|spleen|leukocyt|infect|hematopoiet|haematopoiet\",\n \"Neoplasm\":            r\"tumor|tumour|lymphoma|neoplas|carcinom|cancer|leukemia|leukaemia\",\n \"Eye / telangiectasia\":r\"telangiect|ocul|eye|conjunctiv|retina|cornea|lens|cataract\",\n \"Growth / body size\":  r\"growth|body size|body weight|body length|runt|emaciat|lean|adipose|weight\",\n \"Reproductive system\": r\"infertil|gonad|ovar|testis|testic|sperm|meiot|meiosis|oocyte|germ cell|reproduc\",\n \"Endocrine / metabolic\":r\"insulin|glucose|diabet|metaboli|thyroid|endocrin|lipid|cholesterol|hormone\",\n \"Cardiovascular\":      r\"heart|cardiac|vascul|aort|blood pressure|atheroscler\",\n \"Mortality / lifespan\":r\"lethal|mortalit|lifespan|premature death|survival|aging|ageing\",\n \"Cellular / DNA damage\":r\"chromosom|dna damage|radiosensit|apoptosis|cell cycle|telomer|genomic instab|micronucle|oxidative|senescen\",\n \"Skin / integument\":   r\"skin|hair|coat|pigment|graying|greying\",\n \"Skeletal / muscular\": r\"bone|skelet|muscle|muscul|myopath|kyphos\",\n}\ndef bucket(txt):\n    t=txt.lower(); hits=[b for b,p in BUCKETS.items() if re.search(p,t)]\n    return hits or [\"Other\"]\n\nmcount=collections.Counter()\nfor s in mdf.statement: \n    for b in bucket(s): mcount[b]+=1\nhcount=collections.Counter()\nhterm_bucket={}\nfor cat,terms in hcats.items():\n    for t in terms:\n        for b in bucket(cat+\" \"+t): hcount[b]+=1\n\norder=[b for b in BUCKETS]+[\"Other\"]\ncmp=pd.DataFrame({\"mouse_Atm\":[mcount.get(b,0) for b in order],\n                  \"human_AT_HPO\":[hcount.get(b,0) for b in order]}, index=order)\ncmp[\"mouse_frac\"]=cmp.mouse_Atm/cmp.mouse_Atm.sum()\ncmp[\"human_frac\"]=cmp.human_AT_HPO/cmp.human_AT_HPO.sum()\nprint(\"\\n\", cmp.to_string())\n\nfrom scipy import stats\nkeep=cmp[(cmp.mouse_Atm+cmp.human_AT_HPO)>=3]\nchi2,pv,dof,exp=stats.chi2_contingency(keep[[\"mouse_Atm\",\"human_AT_HPO\"]].T.values)\nn=keep[[\"mouse_Atm\",\"human_AT_HPO\"]].values.sum()\nV=np.sqrt(chi2/(n*(min(2,keep.shape[0])-1)))\nrho,prho=stats.spearmanr(cmp.mouse_frac, cmp.human_frac)\nprint(f\"\\nchi2={chi2:.1f} df={dof} p={pv:.3e}  Cramer V={V:.3f}  n={n}\")\nprint(f\"Spearman mouse vs human system fractions: rho={rho:.3f} p={prho:.3f}\")\n\n# telangiectasia / Purkinje specifics\nprint(\"\\nmouse statements matching telangiect:\", [s for s in mdf.statement if \"telangiect\" in s.lower()])\nprint(\"mouse statements matching purkinje/cerebell/ataxia:\", [s for s in mdf.statement if re.search(\"purkinje|cerebell|ataxia\",s.lower())])\nprint(\"\\nmouse neoplasm statements:\", [s for s in mdf.statement if re.search(\"lymphoma|tumor|neoplas\",s.lower())][:12])\n\n# ---- figure ----\nfig,axes=plt.subplots(1,2,figsize=(15,6))\nax=axes[0]\ny=np.arange(len(order)); w=0.4\nax.barh(y+w/2, cmp.mouse_frac*100, w, color=\"#4878a8\", label=f\"Mouse Atm (n={cmp.mouse_Atm.sum()} MP)\")\nax.barh(y-w/2, cmp.human_frac*100, w, color=\"#c44e52\", label=f\"Human A-T (n={cmp.human_AT_HPO.sum()} HPO)\")\nax.set_yticks(y); ax.set_yticklabels(order, fontsize=9); ax.invert_yaxis()\nax.set_xlabel(\"Share of annotated phenotypes (%)\")\nax.set_title(f\"Mouse Atm model vs human A-T phenotype spectrum\\nchi2={chi2:.0f}, p={pv:.1e}, Cramer V={V:.2f}\", fontsize=11)\nax.legend(fontsize=9); ax.grid(axis=\"x\", alpha=0.3)\n\nax2=axes[1]\nod=pd.DataFrame({\"species\":[\"S. cerevisiae\",\"C. elegans\",\"D. melanogaster\",\"D. rerio\",\"X. tropicalis\",\"X. laevis\",\"M. musculus\",\"R. norvegicus\"],\n                 \"symbol\":[\"TEL1\",\"atm-1\",\"tefu\",\"atm\",\"atm\",\"atm.L\",\"Atm\",\"Atm\"],\n                 \"matched\":[3,2,6,1,8,1,10,10],\"total\":[9,9,9,10,9,1,10,10]})\nod[\"pct\"]=100*od.matched/od.total\nax2.barh(od.species, od.pct, color=[\"#999\"]*6+[\"#4878a8\"]*2)\nfor i,(m,t) in enumerate(zip(od.matched,od.total)):\n    ax2.text(100*m/t+1.5, i, f\"{m}/{t}\", va=\"center\", fontsize=9)\nax2.set_xlabel(\"Orthology prediction methods in agreement (%)\")\nax2.set_title(\"ATM orthologue support across model species\\n(Alliance of Genome Resources, all best-reciprocal)\", fontsize=11)\nax2.set_xlim(0,118); ax2.grid(axis=\"x\", alpha=0.3)\nfor i,s in enumerate(od.symbol): ax2.text(2, i, s, va=\"center\", fontsize=9, style=\"italic\", color=\"white\", fontweight=\"bold\")\nplt.tight_layout()\nplt.show()\n",
  "plot_number": 5
}