{
  "filename": "plot_3.png",
  "iteration": 2,
  "description": "Compare the HPO phenotype profiles of the three ATP6AP2 allelic entities and quantify their overlap",
  "timestamp": "2026-11-26 22:29:03",
  "code": "\nimport pandas as pd, numpy as np\nimport matplotlib.pyplot as plt\n\n# HPO annotation sets retrieved from ontology.jax.org (iteration 2) for the three allelic entities\nhpo = {\n\"MRXSH (OMIM 300423 / MONDO:0010319)\": [\n (\"HP:0001249\",\"Intellectual disability\",\"Nervous\"),(\"HP:0001263\",\"Global developmental delay\",\"Nervous\"),\n (\"HP:0001270\",\"Motor delay\",\"Nervous\"),(\"HP:0000750\",\"Delayed speech and language development\",\"Nervous\"),\n (\"HP:0001250\",\"Seizure\",\"Nervous\"),(\"HP:0002069\",\"Bilateral tonic-clonic seizure\",\"Nervous\"),\n (\"HP:0001288\",\"Gait disturbance\",\"Nervous\"),(\"HP:0002527\",\"Falls\",\"Nervous\"),\n (\"HP:0031629\",\"Impaired tandem gait\",\"Nervous\"),(\"HP:0001272\",\"Cerebellar atrophy\",\"Brain MRI\"),\n (\"HP:0002059\",\"Cerebral atrophy\",\"Brain MRI\"),(\"HP:0033725\",\"Thin corpus callosum\",\"Brain MRI\"),\n (\"HP:0002079\",\"Hypoplasia of the corpus callosum\",\"Brain MRI\"),(\"HP:0002188\",\"Delayed CNS myelination\",\"Brain MRI\"),\n (\"HP:0001300\",\"Parkinsonism\",\"Nervous\"),(\"HP:0002067\",\"Bradykinesia\",\"Nervous\"),\n (\"HP:0002345\",\"Action tremor\",\"Nervous\"),(\"HP:0002063\",\"Rigidity\",\"Muscle\"),\n (\"HP:0001257\",\"Spasticity\",\"Muscle\"),(\"HP:0003487\",\"Babinski sign\",\"Nervous\"),\n (\"HP:0001265\",\"Hyporeflexia\",\"Nervous\"),(\"HP:0002186\",\"Apraxia\",\"Nervous\"),\n (\"HP:0010527\",\"Astereognosis\",\"Nervous\"),(\"HP:0011812\",\"Agraphesthesia\",\"Nervous\"),\n (\"HP:0001350\",\"Slurred speech\",\"Nervous\"),(\"HP:0002307\",\"Drooling\",\"Head/neck\"),\n (\"HP:0000338\",\"Hypomimic face\",\"Head/neck\"),(\"HP:0000341\",\"Narrow forehead\",\"Head/neck\"),\n (\"HP:0003593\",\"Infantile onset\",\"Course\"),(\"HP:0003623\",\"Neonatal onset\",\"Course\"),\n (\"HP:0001419\",\"X-linked recessive inheritance\",\"Inheritance\")],\n\"XPDS (OMIM 300911 / MONDO:0010482)\": [\n (\"HP:0001300\",\"Parkinsonism\",\"Nervous\"),(\"HP:0002067\",\"Bradykinesia\",\"Nervous\"),\n (\"HP:0002322\",\"Resting tremor\",\"Nervous\"),(\"HP:0002396\",\"Cogwheel rigidity\",\"Muscle\"),\n (\"HP:0001257\",\"Spasticity\",\"Muscle\"),(\"HP:0001347\",\"Hyperreflexia\",\"Nervous\"),\n (\"HP:0003487\",\"Babinski sign\",\"Nervous\"),(\"HP:0000338\",\"Hypomimic face\",\"Head/neck\"),\n (\"HP:0003621\",\"Juvenile onset\",\"Course\"),(\"HP:0025709\",\"Intermediate young adult onset\",\"Course\"),\n (\"HP:0003596\",\"Middle age onset\",\"Course\"),(\"HP:0003677\",\"Slowly progressive\",\"Course\"),\n (\"HP:0001419\",\"X-linked recessive inheritance\",\"Inheritance\")],\n\"ATP6AP2-CDG / CDG-IIr (OMIM 301045 / MONDO:0026765)\": [\n (\"HP:0012301\",\"Type II transferrin isoform profile\",\"Lab\"),(\"HP:0001397\",\"Hepatic steatosis\",\"Lab/Liver\"),\n (\"HP:0002910\",\"Elevated hepatic transaminases\",\"Lab\"),(\"HP:0002240\",\"Hepatomegaly\",\"Liver\"),\n (\"HP:0001413\",\"Micronodular cirrhosis\",\"Liver\"),(\"HP:0001410\",\"Decreased liver function\",\"Liver\"),\n (\"HP:0000952\",\"Jaundice\",\"Liver\"),(\"HP:0001541\",\"Ascites\",\"Liver\"),\n (\"HP:0002719\",\"Recurrent infections\",\"Immune\"),(\"HP:0032218\",\"Decreased CD4+ T cell proportion\",\"Immune\"),\n (\"HP:0004313\",\"Decreased circulating immunoglobulin\",\"Immune\"),(\"HP:0000973\",\"Cutis laxa\",\"Skin\"),\n (\"HP:0000047\",\"Hypospadias\",\"Genitourinary\"),(\"HP:0000347\",\"Micrognathia\",\"Head/neck\"),\n (\"HP:0000369\",\"Low-set ears\",\"Head/neck\"),(\"HP:0003593\",\"Infantile onset\",\"Course\"),\n (\"HP:0001419\",\"X-linked recessive inheritance\",\"Inheritance\")],\n}\n\nrows = [{\"entity\": e, \"hpo_id\": i, \"term\": t, \"system\": s} for e, L in hpo.items() for i, t, s in L]\ndf = pd.DataFrame(rows)\n\n# shared vs private terms\ncounts = df.groupby(\"hpo_id\").entity.nunique()\ndf[\"shared_in\"] = df.hpo_id.map(counts)\nprint(\"Annotation counts per entity:\\n\", df.groupby(\"entity\").size())\nprint(\"\\nTerms shared by 2 or more entities:\")\nprint(df[df.shared_in > 1][[\"hpo_id\",\"term\",\"entity\"]].sort_values(\"hpo_id\").to_string(index=False))\n\n# --- figure: system-level phenotype profile of the three allelic entities ---\nsysorder = [\"Nervous\",\"Brain MRI\",\"Muscle\",\"Head/neck\",\"Course\",\"Inheritance\",\n            \"Liver\",\"Lab\",\"Lab/Liver\",\"Immune\",\"Skin\",\"Genitourinary\"]\nmat = (df.groupby([\"entity\",\"system\"]).size().unstack(fill_value=0)\n         .reindex(columns=sysorder, fill_value=0))\nmat = mat.reindex(list(hpo.keys()))\n\nfig, ax = plt.subplots(figsize=(12.5, 4.2))\nbottom = np.zeros(len(mat))\ncmap = plt.get_cmap(\"tab20\")\nfor k, s in enumerate(sysorder):\n    vals = mat[s].values\n    ax.barh(range(len(mat)), vals, left=bottom, label=s, color=cmap(k % 20), edgecolor=\"white\")\n    for i, val in enumerate(vals):\n        if val:\n            ax.text(bottom[i] + val/2, i, str(val), ha=\"center\", va=\"center\", fontsize=8)\n    bottom += vals\nax.set_yticks(range(len(mat)))\nax.set_yticklabels([m.replace(\" (\", \"\\n(\") for m in mat.index], fontsize=9)\nax.set_xlabel(\"number of HPO terms annotated (source: ontology.jax.org, HPOA)\")\nax.set_title(\"HPO profiles of the three ATP6AP2 allelic entities: the two splicing diseases are\\n\"\n             \"purely neurological, the missense disease is hepatic, immune and dermatological\")\nax.legend(ncol=6, fontsize=7.5, frameon=False, loc=\"lower center\", bbox_to_anchor=(0.5, -0.42))\nfor sp in [\"top\",\"right\",\"left\"]: ax.spines[sp].set_visible(False)\nplt.tight_layout()\nplt.show()\n\nprint(f\"\\nTotal distinct HPO terms across the ATP6AP2-related disorder grouping: {df.hpo_id.nunique()}\")\nprint(f\"Overlap between MRXSH and XPDS: {len(set(df[df.entity.str.startswith('MRXSH')].hpo_id) & set(df[df.entity.str.startswith('XPDS')].hpo_id))} shared terms\")\nprint(f\"Overlap between neurological entities and ATP6AP2-CDG (excluding inheritance/course): \"\n      f\"{len((set(df[df.entity.str.startswith('MRXSH')].hpo_id) | set(df[df.entity.str.startswith('XPDS')].hpo_id)) & set(df[df.entity.str.contains('CDG')].hpo_id) - {'HP:0001419','HP:0003593'})}\")\n",
  "plot_number": 3
}