Skip to content
Root-TesterPublic

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Β 
Β 

Latest commit

Β 

History

9 Commits

Folders and files

Repository files navigation

HIV-1 Drug Resistance Prediction & ART Regimen Selector

Clinical Decision-Support System for Antiretroviral Therapy (ART) Selection

Python 3.9+ FastAPI PyTorch XGBoost React 18 Tests


πŸ“Œ Executive Summary

This software is an advanced AI-driven clinical decision-support system engineered to assist infectious disease specialists and healthcare practitioners in detecting HIV-1 antiretroviral drug resistance and optimizing combination Antiretroviral Therapy (ART) regimens.

The system features a hybrid multi-tier clinical intelligence architecture:

  1. Machine Learning Diagnostic Portfolio (ml/models_xgb/):
    • 25 Antiretroviral Drugs across all 5 therapeutic classes (NRTI, NNRTI, INSTI, PI, and Capsid inhibitor Lenacapavir).
    • 50 fine-tuned XGBoost models (25 classifiers + 25 log-fold-change regressors) trained on 14,820 clinical genotype-phenotype isolate pairs from the Stanford HIV Drug Resistance Database (HIVdb).
  2. Sequence-Aware Deep Learning Framework (ml/deep_learning/):
    • Multi-Scale 1D-CNN: Multi-receptive field convolutional kernels ($k=3, 5, 7$) capturing physical binding pockets, catalytic triads, and flap loops.
    • ESM-2 Protein Transformer with Pure PyTorch LoRA: 4-layer RoPE Transformer encoder ($d=256$, 16 attention heads) with built-in Low-Rank Adaptation for parameter-efficient transfer learning.
    • Dirichlet Evidential Deep Learning (Subjective Logic): Quantifies epistemic model uncertainty ($u \in [0, 1]$) with clinical reliability tiers (High Reliability, Moderate, High Epistemic Uncertainty / Out-of-Distribution).
    • Surveillance Epistatic Mutation-Pair (SEMP) Graph: Multi-head cross-attention layer detecting biological epistasis (synergy, antagonism, compensatory rescue).
    • 1D Grad-CAM Sequence Heatmaps: Continuous per-residue gradient activation mapping explaining resistance decisions.
  3. Clinical Decision Rules Engine (clinical/):
    • Scores and ranks candidate ART regimens (e.g. TDF + 3TC + DTG, BIC + FTC + TAF) applying WHO and DHHS 2026 guidelines, dual-NRTI backbone requirements, class diversity bonuses, and incompatible co-administration penalties.
  4. Zero-PII Patient Tracking & Longitudinal History:
    • Automated cryptographic identifier: $\text{PatientTestId} = \text{HIV-} \parallel \text{YYYY} \parallel \text{-} \parallel \text{HEX}_5$ (e.g. HIV-2026-A8F3D).
    • Physical paper chart reference card ensures zero Personally Identifiable Information (PII) is ever stored in the database.
    • Instant returning patient lookup automatically restoring previous resistance results and historical regimen rankings for longitudinal comparison.

πŸ› οΈ System Architecture

                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚                React 18 / Vite Frontend                β”‚
                 β”‚  - Step 1: Automated PatientTestId & Physical Card     β”‚
                 β”‚  - Step 2: 60+ Curated Mutation Catalog Multi-Select   β”‚
                 β”‚  - Step 3: Dual-Engine Regimen Ranking & Scores        β”‚
                 β”‚  - Step 4: Grad-CAM, Evidential Gauge & SEMP Grid      β”‚
                 β”‚  - Diagnostics: 25-Drug Stanford HIVdb Analytics       β”‚
                 β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜
                                             β”‚ REST API (FastAPI)
                                             β–Ό
                 β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
                 β”‚                 FastAPI Backend Server                 β”‚
                 β”‚  - SQLite Engine (`hiv_selector.db`)                   β”‚
                 β”‚  - Zero-PII Case Registry & Longitudinal Search        β”‚
                 β”‚  - ReportLab Dynamic PDF Clinical Report Generator     β”‚
                 β””β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”¬β”€β”€β”€β”€β”€β”€β”€β”˜
                        β”‚                    β”‚                    β”‚
                        β–Ό                    β–Ό                    β–Ό
       β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”  β”Œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”
       β”‚ 50 XGBoost ML Models    β”‚  β”‚ Sequence-Aware DL β”‚  β”‚ Clinical Rules       β”‚
       β”‚ - 25 Classifiers        β”‚  β”‚ - 1D-CNN (k=3,5,7)β”‚  β”‚ - 9 Scoring Weights  β”‚
       β”‚ - 25 Regressors         β”‚  β”‚ - ESM-2 + LoRA    β”‚  β”‚ - 27 Formularies     β”‚
       β”‚ - 14,820 Stanford Pairs β”‚  β”‚ - Dirichlet EDL   β”‚  β”‚ - Redundancy Penalty β”‚
       β”‚ - Tree-Gain Importance  β”‚  β”‚ - SEMP Epistasis  β”‚  β”‚ - Backbone Bonuses   β”‚
       β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜  β””β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”˜

🧬 Complete 25-Drug Antiretroviral Portfolio

The platform models and evaluates resistance across 25 antiretroviral agents in 5 therapeutic classes:

Class Count Supported Drugs (Generic & Abbreviation)
NRTI (Nucleoside Reverse Transcriptase Inhibitors) 6 3TC (Lamivudine), ABC (Abacavir), AZT (Zidovudine), D4T (Stavudine), DDI (Didanosine), TDF (Tenofovir Disoproxil)
NNRTI (Non-Nucleoside Reverse Transcriptase Inhibitors) 5 EFV (Efavirenz), ETR (Etravirine), NVP (Nevirapine), RPV (Rilpivirine), DOR (Doravirine)
INSTI (Integrase Strand Transfer Inhibitors) 5 DTG (Dolutegravir), BIC (Bictegravir), CAB (Cabotegravir), EVG (Elvitegravir), RAL (Raltegravir)
PI (Protease Inhibitors) 8 ATV (Atazanavir), DRV (Darunavir), FPV (Fosamprenavir), IDV (Indinavir), LPV (Lopinavir), NFV (Nelfinavir), SQV (Saquinavir), TPV (Tipranavir)
Capsid Inhibitor 1 LEN (Lenacapavir) β€” Multistage capsid target inhibitor
TOTAL 25 50 Fine-Tuned XGBoost Models + Sequence Deep Learning Ensemble

πŸ”¬ Mathematical Formulations

1. Dirichlet Evidential Deep Learning (Subjective Logic)

Unlike standard softmax classification which produces overconfident logits on out-of-distribution mutations, our evidential head computes Dirichlet distribution parameters: $$e_k = \text{softplus}(z_k) = \ln(1 + e^{z_k}) \ge 0, \quad \alpha_k = e_k + 1$$ $$S = \sum_{k=1}^K \alpha_k, \quad p_k = \frac{\alpha_k}{S}, \quad u = \frac{K}{S} \in (0, 1]$$

  • High Reliability: $u < 0.20$
  • Moderate Uncertainty: $0.20 \le u < 0.45$
  • High Epistemic Uncertainty (OOD): $u \ge 0.45$

2. Parameter-Efficient LoRA (Pure PyTorch)

Injected into the multi-head attention projection layers ($W_q, W_v$) of the ESM transformer: $$W = W_0 + \frac{\alpha}{r} (B \cdot A)$$ where $W_0$ is frozen, $A \sim \mathcal{N}(0, \sigma^2)$, $B = 0$, rank $r = 8$, scaling $\alpha = 16$.

3. Surveillance Epistatic Mutation-Pair (SEMP) Graph

Captures non-linear biological couplings:

  • M184V + TDF/AZT: Hypersensitization to Tenofovir/Zidovudine.
  • M41L + T215Y: TAM-1 synergistic excision cross-resistance.
  • G140S + Q148H: Compensatory catalytic rescue restoring integrase fitness under INSTI pressure.
  • K65R + M184V: Antagonistic interaction.

πŸ“ Repository Directory Structure

sih/
β”œβ”€β”€ backend/
β”‚   β”œβ”€β”€ database.py              # SQLite engine & sessionmaker
β”‚   β”œβ”€β”€ main.py                  # FastAPI REST endpoints & UI static file serving
β”‚   β”œβ”€β”€ models.py                # SQLAlchemy ORM schemas
β”‚   β”œβ”€β”€ schemas.py               # Pydantic validation schemas
β”‚   β”œβ”€β”€ hiv_selector.db          # SQLite clinical database
β”‚   └── static_reports/          # Cached ReportLab PDF reports
β”œβ”€β”€ clinical/
β”‚   β”œβ”€β”€ knowledge_base.json      # 9 scoring weights, 27 formularies, contraindications
β”‚   └── regimen_rules.py         # Clinical scoring and ranking algorithm
β”œβ”€β”€ ml/
β”‚   β”œβ”€β”€ data/                    # Processed Stanford HIVdb datasets (PI, NRTI, NNRTI, INSTI)
β”‚   β”œβ”€β”€ models/
β”‚   β”‚   └── metrics.json         # 25-drug Stanford HIVdb metrics & tree-gain importances
β”‚   β”œβ”€β”€ models_xgb/              # 50 trained XGBoost models (25 clf + 25 reg)
β”‚   β”‚   └── features_xgb.json    # Feature index to clinical mutation mapping
β”‚   β”œβ”€β”€ deep_models/             # Saved PyTorch .pt model weights
β”‚   └── deep_learning/
β”‚       β”œβ”€β”€ __init__.py          # Dual standalone/package import resolution
β”‚       β”œβ”€β”€ sequence_tokenizer.py# Consensus reconstruction (PR, RT, IN, CA)
β”‚       β”œβ”€β”€ models_cnn.py        # Multi-scale 1D-CNN (k=3, 5, 7)
β”‚       β”œβ”€β”€ models_esm.py        # RoPE Transformer with pure PyTorch LoRA
β”‚       β”œβ”€β”€ models_evidential.py # Dirichlet Evidential Head, Subjective Logic, Loss
β”‚       β”œβ”€β”€ models_epistatic.py  # SEMP epistatic coupling cross-attention graph
β”‚       β”œβ”€β”€ explainability.py    # 1D Grad-CAM residue activation mapping
β”‚       β”œβ”€β”€ predict_deep.py      # Unified multi-drug inference orchestrator
β”‚       └── train_deep.py        # Deep learning training pipeline
β”œβ”€β”€ frontend/
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ data/
β”‚   β”‚   β”‚   └── mutationCatalog.js       # 60+ categorized resistance mutations
β”‚   β”‚   β”œβ”€β”€ components/
β”‚   β”‚   β”‚   β”œβ”€β”€ MutationSelectDropdown.jsx# Searchable dropdown with class tabs
β”‚   β”‚   β”‚   └── SequenceGradCAMViewer.jsx # Heatmaps, Epistemic Gauge, SEMP grid
β”‚   β”‚   β”œβ”€β”€ App.jsx                      # Main clinical application dashboard
β”‚   β”‚   └── index.css                    # TailwindCSS styles
β”‚   └── dist/                            # Production Vite bundle (cache query ?v=7)
β”œβ”€β”€ tests/
β”‚   β”œβ”€β”€ test_api.py              # 8 API integration tests
β”‚   └── test_deep_learning.py    # 25 unit tests for evidential, epistatic & CNN
β”œβ”€β”€ DOCUMENTATION_UPDATES.md     # Chronological log and complete updates reference
β”œβ”€β”€ PROJECT_DOCUMENTATION.md     # Architecture and handoff guide
└── run_app.py                   # Automated server launcher

πŸš€ Quick Start Guide

1. Requirements

  • Python 3.9+
  • Packages: torch, xgboost, fastapi, uvicorn, sqlalchemy, pydantic, reportlab, scikit-learn, pandas, numpy

2. Launch the Platform

cd sih
python3 run_app.py --port 8000

Open http://localhost:8000 in your browser.

  • Default Authorized Clinician: doctor@hivclinic.org / clinicalpass123.

3. Run Automated Tests

cd sih
python3 -m unittest discover tests

Result: 33/33 tests pass (100% OK) in ~2.5 seconds.

4. Verify Standalone Deep Learning Package

cd sih/ml/deep_learning
python3 __init__.py

Outputs confirmation of all 22 exported modules.


πŸ”’ Patient Privacy & Compliance

The platform implements a Strict Zero-PII Policy:

  • Patient names, government identification numbers, telephone numbers, and email addresses are strictly excluded from data ingestion and database schemas.
  • Unique cryptographic tokens (HIV-2026-XXXXX) are referenced on physical paperwork.
  • The physical paper chart remains the sole linking mechanism, providing full privacy protection under HIPAA and GDPR.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages