A rare disease similarity pipeline for phenotype-driven diagnosis support. Given a patient's HPO terms or clinical text, RareSim ranks diseases by phenotypic similarity using multiple methods — semantic IC-based, set-based, TF-IDF, transformer, and LLM.
Patient HPO terms / clinical text
│
▼
HPO Extraction <-dictionary, NER, FastHPOCR, GPT, PhenoBrain
│
▼
Similarity Pipeline <-semantic (Resnik/Lin/JC), set-based, TF-IDF, transformer, LLM
│
▼
Ranked Disease Results <-scored against ~10,000 rare diseases
Disease knowledge is built from four ontologies: HP, ORDO, MONDO, and HOOM, merged and canonicalized to ORPHA identifiers.
RareSim/
packages/
raresim-core/ <-installable Python package (core logic)
raresim-api/ <-FastAPI backend (wraps raresim-core)
raresim-frontend/ <-Vue 3 web interface
scripts/
setup/ <-one-time setup: ontologies, artifacts, third-party tools
evaluation/ <-evaluate pipeline performance
validation_tools/ <-run and compare existing tools (LIRICAL etc.)
experiments/ <-ad-hoc experiments
analysis/ <-analyse outputs, automated reporting
tests/
unit/
integration/
validation_tool/
evaluation/
data/ <-gitignored large files (see data/README.md)
ontologies/ <-hp.owl, ordo.owl, mondo.owl, hoom.owl
datasets/ <-HMS.json, MME.json, LIRICAL.json, phenopackets/
outputs/ <-gitignored, generated at runtime
artifacts/ <-precomputed profiles, IC, ancestors, labels
transformer/
semantic/
evaluation/
validation/
gui/
third_party/ <-externally cloned tools (gitignored)
fast_hpo_cr/
wiki/ <-VitePress documentation site (see "Project Wiki" below)
.vitepress/
config.mts
docs/
notebooks/
pyproject.toml <-root: dev tooling + uv workspace
setup.sh <-bootstrap script: third-party tools, ontologies, artifacts
.env <-local paths (not committed)
README.md
- Python 3.11+
- Node.js 18+ (frontend only)
uv(recommended) orpip
git clone https://github.com/your-org/RareSim.git
cd RareSim# create and activate virtual environment
python -m venv .venv
source .venv/bin/activate
# install all packages (uv workspace)
uv sync
# or with pip
pip install -e packages/raresim-core
pip install -e packages/raresim-backendCreate a .env file at the repo root:
RARESIM_ROOT=/path/to/RareSim
OPENAI_API_KEY=sk-... # optional — only needed for GPT extraction./setup.shThis bootstraps RareSim from a fresh clone to a runnable state, and all three steps are required; RareSim will not run without them:
- Clones third-party tools (FastHPOCR) into
third_party/, skipping anything already cloned. - Downloads the ontology sources into
data/ontologies/. - Builds the shared artifacts into
outputs/artifacts/.
Running the steps individually
Useful for debugging a single step, or if you only need to rebuild artifacts after an ontology update.
Set up third-party tools
python -m raresim.build.setup_third_partyClones FastHPOCR into third_party/. Skips anything already cloned.
Download ontologies
python -m raresim.build.load_ontologies_to_localDownloads the following files into data/ontologies/ (see data/README.md for exact versions and sources):
| File | Source |
|---|---|
hp.owl |
hpo.jax.org |
ordo.owl |
BioPortal |
mondo.owl |
GitHub |
hoom.owl |
BioPortal |
phenotype.hpoa |
hpo.jax.org |
en_product4_HPO.xml |
Orphadata |
disease_to_phenotypic_feature_association.all.tsv.gz |
Monarch |
Build shared artifacts
python -m raresim.build.build_shared_artifactsGenerates precomputed files in outputs/artifacts/:
canonical_disease_profiles.jsonhpo_labels.jsonhpo_ancestors.jsoninformation_content.jsonalias_to_canonical.json
Only needed if you are using phenopacket datasets for evaluation.
python scripts/evaluation/data_prep/standardize_phenopackets.pyConverts raw phenopackets from data/datasets/phenopackets/raw/ into a standardized [[HP terms], [disease codes]] format, saved per release folder under data/datasets/phenopackets/standardized_to_json/.
Terminal interface:
# from HPO terms
python packages/raresim_cli/app.py --hpo HP:0001251,HP:0000545
# from a specific similarity method
python packages/raresim_core/similarity_methods/semantic/pipeline.pyWeb interface:
# terminal 1 — backend
uvicorn raresim_api.main:app --reload --port 8000
# With GPU:
CUDA_VISIBLE_DEVICES=4,5 uvicorn raresim_api.main:app --reload --port 8000
# terminal 2 — frontend
cd packages/raresim-frontend
npm install
npm run devOpen http://localhost:3000.
| Method | Type | Description |
|---|---|---|
semantic_resnik_bma |
Semantic | Resnik IC-based Best Match Average |
semantic_lin_bma |
Semantic | Lin normalized IC similarity |
semantic_jiang_conrath_bma |
Semantic | Jiang-Conrath distance-based |
set_cosine |
Set-based | Cosine similarity over HPO term vectors |
set_jaccard |
Set-based | Jaccard index |
set_dice |
Set-based | Sørensen-Dice coefficient |
set_overlap |
Set-based | Szymkiewicz-Simpson overlap |
tfidf |
TF-IDF | Term frequency-inverse disease frequency |
transformer |
Embedding | Sentence transformer cosine similarity |
llm |
LLM | GPT-based disease ranking |
| Method | Description |
|---|---|
dictionary |
Exact HPO label matching (fast baseline) |
biomedical_ner |
d4data/biomedical-ner-all transformer NER |
fast_hpo_cr |
FastHPOCR morphological token cluster matching |
chatgpt |
GPT-4o-mini prompted extraction |
phenobrain_api |
PhenoBrain public BERT-based API |
The phenotype extraction pipeline supports multiple methods. Some require additional setup:
No setup required. Uses regex matching against HPO labels.
Requires transformers and torch — already in requirements.txt. The model (d4data/biomedical-ner-all) will be downloaded automatically from HuggingFace on first use.
Morphological HPO concept recognition (recommended):
The index will be built automatically on first use (~12 min) and cached to outputs/fast_hpo_cr_index/.
Requires an OpenAI API key. Add to your .env file:
OPENAI_API_KEY=sk-...
No API key required. Uses the public PhenoBrain endpoint. Requires pip install requests (already in requirements.txt).
pytest tests/ruff check .
ruff format .- Create
packages/raresim-core/src/raresim/similarity_methods/<name>/ - Add
methods.pyandpipeline.pyfollowing existing patterns - Register the method name in
scripts/run_pipeline.py
raresim-core <-pure logic, no HTTP
│ Python import
raresim-api <-FastAPI, wraps raresim-core
│ HTTP /api/*
raresim-frontend <-Vue 3, calls raresim-api
raresim-core has zero knowledge of the API or frontend. Scripts and tests import directly from raresim-core.
Project documentation (method write-ups, setup guides, validation-tool notes, etc.) lives in a VitePress site under the wiki/ folder of this repository, rather than in GitLab's built-in wiki. The existing GitLab wiki pages have already been migrated into wiki/; continue updating them there, or add new pages following the steps below.
Install Node.js (if not already installed):
nvm install 24From the repository root, install the project dependencies:
npm installThis installs VitePress and only needs to be run once (or again after wiki/.vitepress/config.mts or its dependencies change).
-
Create a new Markdown file inside
wiki/, namedCategory_PageName.md(e.g.SimilarityMethods_SetBased.md). -
Write the page content in that file.
-
Open
wiki/.vitepress/config.mtsand add the new page under the correct sidebar category, using a link that matches the filename without the.mdextension:{ text: 'Set-based', link: '/SimilarityMethods_SetBased' },
To edit an existing page, just edit its Markdown file directly; no config changes are needed unless you are moving it to a different sidebar category.
npm run wiki:devOpen the local URL printed in the terminal to preview the site with your changes.
See data/README.md for full provenance, versions, and download instructions.