Skip to content
rvn5801Public

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

Β 

History

2 Commits

Folders and files

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

Repository files navigation

🧬 RareMatch

AI-Powered Rare Disease Drug Repurposing Engine

"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.


The Problem

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.


The Solution: Three Pipelines

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

Why AI only reads β€” never decides

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.


Quick Start

Prerequisites

  • Python 3.11+
  • Free Gemini API key from aistudio.google.com
  • Internet connection (PubMed and OpenFDA are called live)

Install

# 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

Run

# 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)
pytest
Service URL
Streamlit Frontend http://localhost:8501
FastAPI Swagger Docs http://localhost:8000/docs
Health Check http://localhost:8000/api/health

Architecture

RareMatch/
β”œβ”€β”€ 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

Drug Database

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.

Adding a New Drug (No Code Required)

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.


Safety System

Traffic Light Rules (Priority Order)

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.

GoF / LoF Direction Rules

  • 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

API Reference

POST /api/search

{
  "disease_name": "ALPS",
  "patient_age": 8,
  "avoid_liver_toxicity": false,
  "avoid_cardiac_risk": false,
  "avoid_immunosuppression": false,
  "custom_avoid": ["rash", "pneumonitis"]
}

Other Endpoints

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

Testing

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 only

All 29 tests run without a real Gemini API key and without network access. The Gemini API is fully mocked.

The Most Important Test

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.


Technology Stack

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.


Disclaimer

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.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages