{
  "filename": "plot_6.png",
  "iteration": 4,
  "description": "Full ClinVar MSH3 germline variant spectrum: classification distribution and consequence classes among pathogenic/likely pathogenic alleles",
  "timestamp": "2026-11-26 20:03:36",
  "code": "\nimport requests, time, re\nimport pandas as pd, numpy as np\nimport matplotlib.pyplot as plt\n\nE=\"https://eutils.ncbi.nlm.nih.gov/entrez/eutils/\"\nids=[]; total=None\nfor retstart in range(0, 8000, 500):\n    r=requests.get(E+\"esearch.fcgi\", params={\"db\":\"clinvar\",\"term\":'MSH3[gene]',\n        \"retmax\":500,\"retstart\":retstart,\"retmode\":\"json\"}, timeout=90).json()[\"esearchresult\"]\n    total=int(r[\"count\"]); b=r[\"idlist\"]\n    if not b: break\n    ids+=b\n    if len(ids)>=total: break\n    time.sleep(0.34)\nprint(\"ClinVar MSH3 records retrieved:\", len(ids), \"of\", total)\n\nrows=[]\nfor i in range(0, len(ids), 300):\n    s=requests.get(E+\"esummary.fcgi\", params={\"db\":\"clinvar\",\"id\":\",\".join(ids[i:i+300]),\n        \"retmode\":\"json\"}, timeout=150).json()[\"result\"]\n    for uid in ids[i:i+300]:\n        d=s.get(uid)\n        if not isinstance(d,dict): continue\n        g=d.get(\"germline_classification\",{}) or {}\n        vs=(d.get(\"variation_set\") or [{}])[0]\n        rows.append({\"clf\":g.get(\"description\",\"NA\"), \"type\":vs.get(\"variant_type\",\"NA\"),\n                     \"name\":vs.get(\"variation_name\",\"\")})\n    time.sleep(0.34)\ncv=pd.DataFrame(rows)\n\ndef consequence(nm, vtype):\n    p = nm.split(\"(p.\")[-1] if \"(p.\" in nm else \"\"\n    if re.search(r\"c\\.[\\d_+-]+[+-]\\d\", nm) and \"del\" not in p and \"fs\" not in p and \"Ter\" not in p:\n        return \"splice site\"\n    if \"fs\" in p: return \"frameshift\"\n    if \"Ter\" in p and \"delins\" not in p: return \"nonsense / stop-gain\"\n    if \"delins\" in p or \"insTer\" in p: return \"frameshift\"\n    if re.match(r\"^[A-Z][a-z]{2}\\d+[A-Z][a-z]{2}\\)?$\", p): return \"missense\"\n    if vtype in (\"copy number loss\",\"copy number gain\"): return \"copy number\"\n    if re.search(r\"[+-]\\d+[ACGT]>\", nm) or re.search(r\"\\d[+-]\\d\", nm): return \"splice site\"\n    return \"other / non-coding\"\n\ncv[\"csq\"]=[consequence(n,t) for n,t in zip(cv.name, cv.type)]\nplp = cv[cv.clf.isin([\"Pathogenic\",\"Likely pathogenic\",\"Pathogenic/Likely pathogenic\"])]\nprint(\"\\nTotal P/LP:\", len(plp))\nprint(plp.csq.value_counts())\nprint(\"\\nP/LP missense entries:\")\nprint(plp[plp.csq==\"missense\"].name.tolist()[:20])\nprint(\"\\nAll classifications:\")\nclf_counts = cv.clf.replace(\"\", \"not provided\").value_counts()\nprint(clf_counts)\nvus = clf_counts.get(\"Uncertain significance\",0)\nprint(f\"\\nVUS share: {vus}/{len(cv)} = {100*vus/len(cv):.1f}%\")\n\n# ---------- figure ----------\nfig, axes = plt.subplots(1,2, figsize=(14,5.6))\nax=axes[0]\norder=[\"Pathogenic\",\"Likely pathogenic\",\"Pathogenic/Likely pathogenic\",\"Conflicting classifications of pathogenicity\",\n       \"Uncertain significance\",\"Likely benign\",\"Benign\",\"Benign/Likely benign\"]\nvals=[clf_counts.get(o,0) for o in order]\ncols=[\"#C44E52\",\"#C44E52\",\"#C44E52\",\"#DD8452\",\"#8C8C8C\",\"#55A868\",\"#55A868\",\"#55A868\"]\nlab=[o.replace(\"Conflicting classifications of pathogenicity\",\"Conflicting\") for o in order]\nax.barh(range(len(order))[::-1], vals, color=cols)\nax.set_yticks(range(len(order))[::-1]); ax.set_yticklabels(lab, fontsize=9)\nfor i,v in zip(range(len(order))[::-1], vals):\n    ax.text(v+40, i, str(v), va=\"center\", fontsize=9)\nax.set_xlabel(\"ClinVar germline records\"); ax.set_xlim(0, max(vals)*1.18)\nax.set_title(f\"A. MSH3 germline variants in ClinVar (n={len(cv)}):\\n{100*vus/len(cv):.0f}% are variants of uncertain significance\", fontsize=10.5)\n\nax=axes[1]\ncq=plp.csq.value_counts()\nax.bar(cq.index, cq.values, color=\"#4C72B0\")\nfor i,v in enumerate(cq.values): ax.text(i, v+2, str(v), ha=\"center\", fontsize=9)\nax.set_ylabel(\"pathogenic / likely pathogenic records\")\nax.set_title(f\"B. The {len(plp)} P/LP MSH3 alleles are almost all\\ntruncating: no reported pathogenic missense\", fontsize=10.5)\nax.tick_params(axis=\"x\", labelrotation=20, labelsize=9)\nax.set_ylim(0, cq.values.max()*1.15)\nplt.tight_layout(); plt.show()\n",
  "plot_number": 6
}