8000 GitHub - WGLab/RareMind Β· GitHub
[go: up one dir, main page]

Skip to content
WGLabPublic

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

16 Commits

Folders and files

NameName
Last commit message
Last commit date
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

🧬 RareMind

From multimodal patient evidence to ranked rare-disease hypotheses and actionable next steps

RareMind is a locally deployable, multi-agent clinical reasoning pipeline grounded in RareGraph, the structured rare-disease knowledge graph developed for this project. It converts clinical notes, phenotype terms, images, and genomic evidence into:

  • a ranked rare-disease differential;
  • clinician-readable explanations for the leading diagnoses;
  • prioritized next tests and evaluations; and
  • the specialties or referral services responsible for those actions.

Pipeline: RareMind
Knowledge graph: RareGraph
Default model: Qwen/Qwen3-8B
Default workflow: Stages 1–10, from extraction through clinical recommendations


✨ What RareMind does

  • πŸ“ Extracts phenotypes, negated findings, demographics, family history, prior testing, and genes from clinical notes
  • πŸ–ΌοΈ Incorporates phenotype evidence from medical images when available
  • 🧬 Accepts structured HPO terms and completed genomic-ranking results
  • πŸ”— Grounds retrieval and reasoning in RareGraph, HPO, MONDO, OMIM, and Orphanet
  • πŸ€– Audits evidence, compares candidates, and reconciles subtype- and disease-group rankings
  • πŸ“Š Preserves the Original Rank, Final Rank, and major reasoning transitions
  • 🩺 Produces a readable Top-10 disease-group differential
  • πŸ§ͺ Recommends normalized next tests and initial evaluations
  • πŸ‘©β€βš•οΈ Identifies responsible specialties and explicit referrals when supported by RareGraph

RareMind is designed for auditable clinical research: ground-truth diagnoses and future observed tests are used only for retrospective evaluation and never during patient inference.


🧭 Pipeline overview

Stage Purpose Main result
1 Multimodal extraction Clinical findings, family history, testing, genes, and image evidence
2 Ontology normalization Normalized HPO evidence, temporal context, inheritance, and incongruity
3 Retrieval and composite scoring Original subtype and disease-group rankings
3.5 Case-signal assessment Genetic/rare-disease, acquired/control, or insufficient-information signal
4 Optional frontier consultation Targeted second opinion for selected ambiguous cases
5 Evidence audit Supporting, contradictory, and unresolved expected evidence
6 Pairwise adjudication Direct comparisons among plausible candidates
7 Rank aggregation Aggregated subtype and disease-group rankings
8 Reconciliation and fusion Canonical Final Rank
9 Clinical synthesis Patient summary and readable Top-10 differential
10 Next-step synthesis Top investigations, responsible specialties, and supported referrals

Detailed stage logic, resume behavior, sharding, and the complete artifact list are documented in the Pipeline reference.


πŸ“¦ Installation

RareMind is tested on Linux with Python 3.11 and an NVIDIA GPU.

git clone https://github.com/WGLab/RareMind.git
cd RareMind

conda create -n raremind python=3.11 -y
conda activate raremind
python -m pip install --upgrade pip uv

uv pip install -r requirements.txt \
  "vllm==0.32.0" \
  --extra-index-url https://wheels.vllm.ai/0.32.0/cu129 \
  --torch-backend=cu129

flashinfer download-kernels

After installation, verify:

python - <<'PY'
import torch
import vllm
print("torch:", torch.__version__, "CUDA build:", torch.version.cuda)
print("vLLM:", vllm.__version__)
PY

If installation fails with ImportError: libcudart.so.13: cannot open shared object file, see GitHub Issue #1.

If inference fails with RuntimeError: Could not find nvcc and default cuda_home='/usr/local/cuda' doesn't exist, see GitHub Issue #2.

Only the local PHI-deidentification workflow needs one additional model download:

python -m spacy download en_core_web_lg

Authenticate with Hugging Face if a configured model is gated:

hf auth login

Check the environment and configured resources before a long run:

python scripts/check_setup.py --config configs/default.yaml

πŸ“š Required data and model resources

The large data/ resources are intentionally not committed to Git.

Download locally

python scripts/00_download_hpo.py

This downloads data/hpo/hp.obo.

Request from the authors

Request access to the gated RareGraph dataset. After approval, run from the repository root:

hf auth login
RESOURCE_REPO="quannguyenminh103/RareGraph"

hf download "$RESOURCE_REPO" \
  data/knowledge_graph/RareGraph.json \
  data/knowledge_graph/raregraph_next_steps_normalized.json \
  data/mondo/hierarchy.json \
  data/mondo/omim_conversion.json \
  data/mondo/orphanet_conversion.json \
  --repo-type dataset \
  --local-dir .

Build the BioLORD normalization caches:

python scripts/01_build_indexes.py --config configs/default.yaml

Qwen and BioLORD weights download from Hugging Face on first use unless already available in a shared cache.

Patient and benchmark data

No patient records are distributed with the repository. CHOP and UDN data require authorization from the data-owning institution. Public benchmark cohorts must be obtained from their original sources and converted to the input structure below. Ground-truth label files are needed only for evaluationβ€”not inference.


πŸ“₯ Input format

The filename stem is the case identifier shared across modalities:

inputs/
└── demo/
    β”œβ”€β”€ free_hpo/
    β”‚   └── case001.txt            # cerebrocostomandibular syndrome
    β”œβ”€β”€ text/
    β”‚   └── case002.txt            # fragile X syndrome
    β”œβ”€β”€ image/
    β”‚   └── <case_id>.png          # optional clinical image (.png or .jpg)
    └── vcf/
        └── <case_id>.vcf          # optional genomic variants

Clinical text is the usual starting point. Never send protected health information to an external provider unless explicitly approved under the applicable governance process; the default text and vision providers are local.


πŸš€ Run RareMind

One patient

python scripts/run_pipeline.py \
  --config configs/default.yaml \
  --input_dir inputs \
  --dataset demo \
  --output_dir outputs \
  --case_id case001 \
  --workflow all

Entire dataset

python scripts/run_pipeline.py \
  --config configs/default.yaml \
  --input_dir inputs \
  --dataset demo \
  --output_dir outputs \
  --workflow all \
  --resume

--resume excludes cases already complete for the requested workflow and reconstructs missing prerequisites only where necessary.

SLURM

Submit from the repository root after activating the environment:

mkdir -p logs

sbatch \
  --job-name=raremind-demo \
  --partition=gpuq \
  --gres=gpu:a100:1 \
  --cpus-per-gpu=1 \
  --mem=64G \
  --time=5-00:00:00 \
  --output=logs/raremind-demo-%j.out \
  --error=logs/raremind-demo-%j.err \
  --export=ALL \
  --wrap="bash scripts/run_agents.sh \
    --config configs/default.yaml \
    --input_dir inputs \
    --dataset demo \
    --output_dir outputs \
    --text_model Qwen/Qwen3-8B \
    --workflow all \
    --resume"

Without a SLURM array, one job processes the complete dataset. For five deterministic shards, add --array=1-5 to sbatch and --n_shards 5 to run_agents.sh.

First run with a new model: submit only one shard initially. Wait until its log completes model/JIT initialization and begins processing Cases before submitting the remaining shards concurrently.

Workflow endpoints

Command option Runs through
--workflow extract Stage 2: extracted and normalized patient evidence
--workflow rank-original Stage 3: Original Rank
--workflow case-signal Stage 3.5 only, reusing/recovering Stages 1–3
--workflow rank-final Stage 8: Final Rank
--workflow all Stage 10: diagnoses, clinical report, tests, and specialties

To complete missing Stage 9/10 reports from saved upstream results:

python scripts/run_pipeline.py \
  --config configs/default.yaml \
  --input_dir inputs --dataset demo --output_dir outputs \
  --workflow all --start-stage 9 --resume

Use --workflow all --force-stages 9 when existing Stage 9/10 files must be overwritten.


πŸ“€ Key outputs

Each case is saved under outputs/<dataset>/<case_id>/.

stage1_extraction.json              structured clinical extraction
stage2_patient_evidence.json        normalized patient evidence
stage3_group_ranking.tsv            Original disease-group ranking
stage8_final_group_ranking.tsv      Final disease-group ranking
stage9_reasoning_report.json        structured clinical synthesis
stage9_reasoning_report.txt         readable clinical report
stage9_reasoning_report.pdf         review-ready report
stage10_next_steps.tsv              investigations, specialties, and referrals
rank_trajectory.tsv                 auditable ranking transitions

Stage 9 explains the leading disease groups without changing their ranks. Stage 10 converts those hypotheses into normalized investigations and responsible specialties; it labels an action as a literal referral only when the underlying RareGraph evidence explicitly recommends referral or consultation.


πŸ“Š Evaluation

The CPU-only disease-ranking evaluator calculates group-level Original or Final Rank performance using the fixed directional_label_compatible policy.

Quick final-rank evaluation:

bash evaluation/run_disease_ranking_evaluation.sh \
  --results-dir outputs/demo \
  --ground-truth evaluation/ground_truth_template.tsv \
  --hierarchy data/mondo/hierarchy.json \
  --kg data/knowledge_graph/RareGraph.json \
  --ranking final \
  --output-dir evaluation_results/demo_final

Use --ranking original to evaluate the Stage 3 ranking. Evaluation labels are used only by the evaluator and remain isolated from inference.


🧱 Repository map

src/raremind/                  main RareMind implementation
configs/                       runtime configuration and prompts
scripts/                       pipeline, setup, and SLURM entry points
evaluation/                    disease-ranking evaluation
clinical_impact_analyses/      retrospective clinical-impact analyses
docs/                          detailed project and pipeline references

All pipeline imports use the raremind namespace. RareGraph refers to the knowledge graph, not a Python package.


πŸ›‘οΈ Intended use

RareMind is a research decision-support system. Its rankings and suggested actions are not medical advice or a substitute for clinical judgment. All outputs require review in the context of the complete patient record, prior testing, local practice, and test availability.


πŸ“š Publication and citation

The full RareMind and RareGraph manuscripts are in preparation. Until they become available, please cite our related publication.

About

No description, website, or topics provided.

Resources

Stars

3 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages

0