{
  "filename": "plot_3.png",
  "iteration": 2,
  "description": "Full HPO annotation set with frequencies for Singleton-Merten syndrome 2",
  "timestamp": "2026-11-28 21:58:33",
  "code": "\nimport requests, pandas as pd, numpy as np, matplotlib.pyplot as plt\njs = requests.get(\"https://ontology.jax.org/api/network/annotation/OMIM:616298\", timeout=60).json()\nrows=[]\nfor cat, items in js[\"categories\"].items():\n    for it in items:\n        m=it[\"metadata\"]\n        rows.append({\"category\":cat,\"hpo_id\":it[\"id\"],\"term\":it[\"name\"],\n                     \"frequency\":m.get(\"frequency\"),\"sources\":\",\".join(m.get(\"sources\") or [])})\ndf=pd.DataFrame(rows)\ndef parse(f):\n    if not f or \"/\" not in str(f): return (np.nan,np.nan)\n    a,b=f.split(\"/\"); return (int(a),int(b))\ndf[[\"n\",\"N\"]]=df[\"frequency\"].apply(lambda f: pd.Series(parse(f)))\ndf[\"pct\"]=(df.n/df.N*100).round(1)\npd.set_option(\"display.width\",220); pd.set_option(\"display.max_rows\",100)\nprint(df.sort_values([\"category\",\"pct\"],ascending=[True,False]).to_string(index=False))\nprint(\"\\nTotal HPO terms annotated to OMIM:616298:\", len(df))\n\n# plot the terms with a quantified frequency, excluding inheritance and onset\nplot = df[df.N.notna() & (~df.category.isin([\"Inheritance\",\"Clinical course\"]))].sort_values(\"pct\")\nfig,ax=plt.subplots(figsize=(9,0.45*len(plot)+1.6))\ncolors=[\"#C0392B\" if p>0 else \"#AEB6BF\" for p in plot.pct]\nax.barh(plot.term+\" (\"+plot.hpo_id+\")\", plot.pct, color=colors)\nfor y,(p,n,N) in enumerate(zip(plot.pct,plot.n,plot.N)):\n    ax.text(p+1.5,y,f\"{int(n)}/{int(N)}\",va=\"center\",fontsize=8)\nax.set_xlim(0,118); ax.set_xlabel(\"percent of annotated individuals\")\nax.set_title(\"HPO phenotype frequencies for Singleton-Merten syndrome 2 (OMIM:616298)\\nsource annotation PMID 25620203\", fontsize=10)\nax.tick_params(labelsize=8); ax.spines[[\"top\",\"right\"]].set_visible(False)\nplt.tight_layout(); plt.show()\n",
  "plot_number": 3
}