"AI reads the literature. Python decides the matches. Safety gates everything."
RareMatch takes a rare disease name, reads the latest PubMed literature using AI, identifies the disrupted biological pathway, and returns a ranked list of repurposable drugs β each with a live FDA safety profile and a GREEN / YELLOW / RED traffic light tailored to the specific patient.
95% of rare diseases have no approved treatment. Drug repurposing β using existing approved drugs for new indications β is the highest-leverage intervention, but the knowledge required to identify candidates is scattered across thousands of PubMed abstracts, FDA labels, and pathway databases. No tool synthesizes this in real time.
Disease Name
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PIPELINE 1 β EXTRACT β
β PubMed API (live) β 5 abstracts β Gemini extracts JSON β
β Output: pathway + mechanism + confidence score β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PIPELINE 2 β MATCH (100% deterministic, zero AI) β
β pathway_drug_index lookup β GoF/LoF direction filter β
β Output: ranked drug candidates from curated database β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β PIPELINE 3 β SAFETY GATE β
β OpenFDA API (live) β 9 priority rules β traffic light β
β Output: GREEN / YELLOW / RED per drug for this patient β
βββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββββ
β
βΌ
Ranked Results in Streamlit UI
If Gemini is asked "what drug treats ALPS?", it will produce a plausible-sounding answer that may be entirely hallucinated. For a safety-critical application, a confident hallucination is more dangerous than "I don't know."
RareMatch's solution: The AI reads unstructured biomedical text β a task it excels at. Drug candidates come entirely from a hand-verified JSON database. The AI never names, suggests, or ranks a drug.
- Python 3.11+
- Free Gemini API key from aistudio.google.com
- Internet connection (PubMed and OpenFDA are called live)
# Create and activate virtual environment
python -m venv rare_env
rare_env\Scripts\activate # Windows
source rare_env/bin/activate # Mac/Linux
# Install dependencies
pip install -r requirements.txt
# Add your Gemini API key
cp .env.example .env
# Edit .env β GEMINI_API_KEY=your_key_here# Terminal 1 β Backend
uvicorn backend.main:app --port 8000 --reload --reload-dir backend
# Terminal 2 β Frontend
streamlit run frontend/app.py
# Terminal 3 β Tests (optional)
pytestRareMatch/
βββ backend/
β βββ core/
β β βββ inference_engine.py # Gemini API + Pydantic validation (303 lines)
β β βββ matching_engine.py # Deterministic drug lookup + GoF/LoF rules (282 lines)
β β βββ safety_filter.py # 9 safety rules + OpenFDA enrichment (368 lines)
β βββ services/
β β βββ pubmed_client.py # NCBI E-utilities + disk cache (249 lines)
β β βββ openfda_client.py # FDA drug label API (96 lines)
β βββ api/
β β βββ routes.py # 5 FastAPI endpoints (309 lines)
β βββ prompts/
β β βββ mechanism_prompt.py # Gemini system prompt + controlled vocabulary
β βββ data/
β β βββ repurposing_database.json # 26 drugs, 14 pathways, synonym map
β β βββ abstracts/ # PubMed cache (auto-populated)
β βββ main.py # FastAPI app entrypoint
βββ frontend/
β βββ app.py # Streamlit UI β 3 screens (923 lines)
βββ tests/
β βββ test_inference.py # 11 tests β AI extraction layer
β βββ test_matching.py # 9 tests β matching engine
β βββ test_safety.py # 9 tests β safety filter
βββ conftest.py # Shared pytest fixtures
βββ pytest.ini # Test config
βββ requirements.txt
26 drugs across 14 biological pathways. Zero AI involved in drug selection.
| Pathway | Drugs | Example Diseases |
|---|---|---|
| mTOR | Sirolimus, Everolimus, Metformin | ALPS, TSC, PHTS |
| PI3K/AKT | Alpelisib, Idelalisib, Everolimus | PIK3CA syndromes, CLOVES |
| RAS/MAPK | Selumetinib, Trametinib, Lovastatin, Growth Hormone | SYNGAP1, NF1, Noonan |
| FAS/Apoptosis | Mycophenolate Mofetil, Rituximab, Hydroxychloroquine | ALPS, lymphoproliferative |
| GABA | Cannabidiol, Clobazam, Fenfluramine, Vigabatrin | Dravet, Lennox-Gastaut |
| Sodium Channel | Sodium Valproate, Carbamazepine*, Lamotrigine | Dravet, SCN epilepsies |
| Complement | Eculizumab, Ravulizumab | aHUS, PNH |
| NMDA/Glutamate | Memantine | SYNGAP1, Rett Syndrome |
| Lysosomal storage | Laronidase | MPS I, LSDs |
| Ubiquitin-proteasome | Minocycline | Angelman |
*Carbamazepine is a safety trap β confidence=0 in Dravet Syndrome (SCN1A LoF). Included to demonstrate the safety filter correctly assigns RED.
Open backend/data/repurposing_database.json and follow the _how_to_add_data template. Add a drug object to drugs[] and its ID to pathway_drug_index. No Python changes needed.
| Priority | Rule | Condition | Result |
|---|---|---|---|
| 1 | Safety Trap | confidence_score == 0 | π΄ RED |
| 2 | Direction Blocked | direction_flag == BLOCKED | π΄ RED |
| 3 | Pediatric RED | ped_flag==RED + age < 18 | π΄ RED |
| 4 | Liver Constraint | liver==SEVERE + avoid_liver | π΄ RED |
| 5 | Cardiac Constraint | cardiac_risk + avoid_cardiac | π΄ RED |
| 6 | Custom Avoid | drug matches custom list | π΄ RED |
| 7 | Pediatric Monitor | ped_flag==YELLOW + age < 18 | π‘ YELLOW |
| 8 | Black Box Warning | FDA boxed_warning exists | π‘ YELLOW |
| 9 | All Clear | none of the above | π’ GREEN |
RED drugs are never hidden β suppressing them would be more dangerous.
- Gain of Function (pathway too active) β blocks Activators, Agonists, Enhancers
- Loss of Function (pathway deficient) β blocks Inhibitors, Blockers, Antagonists
- Dominant Negative β treated as Loss of Function
{
"disease_name": "ALPS",
"patient_age": 8,
"avoid_liver_toxicity": false,
"avoid_cardiac_risk": false,
"avoid_immunosuppression": false,
"custom_avoid": ["rash", "pneumonitis"]
}| Method | Endpoint | Purpose |
|---|---|---|
| GET | /api/health | Engine status + database stats |
| GET | /api/diseases | Known diseases for autocomplete |
| GET | /api/pathways | All supported pathways |
| GET | /api/drug/{id} | Single drug deep-dive |
pytest # All 29 tests (~5 seconds)
pytest -m unit -v # Unit tests only, verbose
pytest tests/test_matching.py # Matching engine only
pytest tests/test_safety.py # Safety filter onlyAll 29 tests run without a real Gemini API key and without network access. The Gemini API is fully mocked.
test_carbamazepine_blocked_in_dravet β Carbamazepine blocks sodium channels. Dravet Syndrome (SCN1A LoF) has deficient sodium channels. This test verifies the system assigns confidence=0 and RED. If it ever fails, a critical safety regression has been introduced.
| Component | Technology | Why |
|---|---|---|
| AI / LLM | Google Gemini 2.5-flash | Free tier, large context, JSON mode |
| Backend | FastAPI 0.111 | Auto-Swagger, Pydantic v2, async |
| Validation | Pydantic v2 | Enforces controlled vocabulary on LLM output |
| Frontend | Streamlit 1.35 | Single Python file, no build step |
| Literature | NCBI PubMed (free) | 30M+ abstracts, no API key |
| Safety Data | OpenFDA (free) | Official FDA labels, no API key |
| Testing | pytest + unittest.mock | All mocked, 5 second run |
No external infrastructure. No database server. No Docker. No cloud account required.
RareMatch is a research tool built for a hackathon. It is not a clinical decision support tool and does not provide medical advice. All outputs require physician review.