{
  "filename": "plot_1.png",
  "iteration": 1,
  "description": "Phenotype frequency spectrum of DOCK11 deficiency from HPO annotations",
  "timestamp": "2026-11-19 03:21:48",
  "code": "\nimport requests, json, pandas as pd, numpy as np\nimport matplotlib.pyplot as plt\n\nd=requests.get(\"https://ontology.jax.org/api/network/annotation/OMIM%3A301109\",timeout=60).json()\nrows=[]\nfor cat,items in d[\"categories\"].items():\n    for it in items:\n        f=it[\"metadata\"].get(\"frequency\",\"\")\n        if \"/\" not in f: continue\n        k,n=f.split(\"/\"); k=int(k); n=int(n)\n        rows.append({\"category\":cat,\"term\":it[\"name\"],\"hpo\":it[\"id\"],\"k\":k,\"n\":n,\"pct\":100*k/n})\ndf=pd.DataFrame(rows)\ndf=df[~df.category.isin([\"Clinical course\"])]\n\n# Wilson 95% CI\ndef wilson(k,n,z=1.96):\n    p=k/n; den=1+z**2/n\n    c=(p+z**2/(2*n))/den\n    h=z*np.sqrt(p*(1-p)/n+z**2/(4*n**2))/den\n    return 100*(c-h),100*(c+h)\ndf[[\"lo\",\"hi\"]]=df.apply(lambda r: pd.Series(wilson(r.k,r.n)),axis=1)\n\ndf=df.sort_values([\"pct\",\"n\"],ascending=[True,True])\ncolors={\"Blood and blood-forming tissues\":\"#c0392b\",\"Immunology\":\"#2874a6\",\"Digestive System\":\"#1e8449\",\n        \"Cardiovascular\":\"#8e44ad\",\"Cellular phenotype\":\"#d68910\",\"Growth\":\"#7f8c8d\",\n        \"Connective tissue\":\"#16a085\",\"Head and neck\":\"#b03a2e\",\"Skeletal system\":\"#5d6d7e\",\n        \"Genitourinary system\":\"#884ea0\",\"Ear\":\"#935116\",\"Musculature\":\"#117a65\",\"Respiratory System\":\"#1f618d\"}\n\nfig,ax=plt.subplots(figsize=(11,13))\ny=np.arange(len(df))\nax.barh(y,df.pct,color=[colors.get(c,\"#555\") for c in df.category],edgecolor=\"none\")\nax.errorbar(df.pct,y,xerr=[df.pct-df.lo,df.hi-df.pct],fmt=\"none\",ecolor=\"#333\",elinewidth=0.8,capsize=2)\nax.set_yticks(y)\nax.set_yticklabels([f\"{t}  ({h})\" for t,h in zip(df.term,df.hpo)],fontsize=8)\nax.set_xlabel(\"Frequency among reported DOCK11-deficient patients (%), 95% Wilson CI\")\nax.set_title(\"ADMIDX (DOCK11 deficiency, OMIM:301109): HPO phenotype frequencies\\nfrom the two index cohorts, PMID 36952639 (n=8) and PMID 37342957 (n=4)\",fontsize=11)\nfor yi,(p,k,n) in enumerate(zip(df.pct,df.k,df.n)):\n    ax.text(min(p+ (df.hi-df.pct).iloc[yi] +2,104),yi,f\"{k}/{n}\",va=\"center\",fontsize=7,color=\"#222\")\nhandles=[plt.Rectangle((0,0),1,1,color=colors[c]) for c in df.category.unique()]\nax.legend(handles,df.category.unique(),fontsize=7,loc=\"lower right\",frameon=False)\nax.set_xlim(0,118); ax.spines[[\"top\",\"right\"]].set_visible(False)\nplt.tight_layout(); plt.show()\n",
  "plot_number": 1
}