ailixir-drug-repurposing / API_TESTING_GUIDE.md
AILIXIR Bot
Auto-sync: ea9a2035cd92f6b1521e3c5f9d31e8c453a93d43
4a8b134
|
Raw
History Blame Contribute Delete
6.07 kB

πŸš€ API Integration Complete - Testing Guide

API Status

  • βœ… DeepPurpose MPNN_CNN model: Loaded and ready
  • βœ… Drug Library: Ready (25 real FDA-approved drugs)
  • βœ… Server: Running on http://localhost:8000
  • βœ… Mode: Production (REAL predictions, no mocks)

Quick Test: Open in Browser

  1. Swagger UI (Interactive Docs)

    http://localhost:8000/docs
    
  2. Health Check

    http://localhost:8000/health
    
  3. Model Status

    http://localhost:8000/api/v1/model-status
    

API Endpoints

1. GET /health

Returns API health status

curl http://localhost:8000/health

Response:

{
  "status": "healthy",
  "service": "Drug Repurposing AI System",
  "version": "1.0.0"
}

2. GET /api/v1/model-status

Check what's loaded (AI model, drug library status)

curl http://localhost:8000/api/v1/model-status

Response:

{
  "model": "MPNN_CNN_BindingDB",
  "device": "cpu",
  "gpu_available": false,
  "model_loaded": true,
  "using_mock_mode": false,
  "batch_size": 8,
  "max_drugs_per_screening": 200,
  "version": "1.0.0"
}

3. POST /api/v1/disease-targets

Get protein targets for a disease

curl -X POST http://localhost:8000/api/v1/disease-targets \
  -H "Content-Type: application/json" \
  -d '{"disease_name": "Type 2 Diabetes", "top_n": 10}'

Response:

{
  "disease": "Type 2 Diabetes",
  "total_targets": 5,
  "targets": [
    {"symbol": "DPP4", "score": 0.95},
    {"symbol": "PPARG", "score": 0.92},
    ...
  ]
}

4. GET /api/v1/drug-library

Load FDA drug library

curl http://localhost:8000/api/v1/drug-library

Response:

{
  "total_drugs": 25,
  "drugs": [
    {
      "name": "Drug_0",
      "smiles": "CC(=O)Oc1ccccc1C(=O)O",
      "drug_id": "0",
      "source": "TDC"
    },
    ...
  ]
}

5. POST /api/v1/screen (Main Virtual Screening)

Run AI prediction on drugs

curl -X POST http://localhost:8000/api/v1/screen \
  -H "Content-Type: application/json" \
  -d '{
    "disease_name": "Type 2 Diabetes",
    "top_targets": 5,
    "max_drugs": 25
  }'

Response:

{
  "disease": "Type 2 Diabetes",
  "total_screening_results": 25,
  "total_targets": 5,
  "top_candidates": [
    {
      "drug_name": "Drug_0",
      "target_symbol": "DPP4",
      "score": 0.78,
      "status": "βœ… Known Treatment"
    },
    {
      "drug_name": "Drug_5",
      "target_symbol": "PPARG",
      "score": 0.72,
      "status": "πŸ†• Potential Discovery"
    }
  ]
}

Python Testing

import requests

BASE_URL = "http://localhost:8000"

# 1. Check health
response = requests.get(f"{BASE_URL}/health")
print(response.json())

# 2. Check model status
response = requests.get(f"{BASE_URL}/api/v1/model-status")
print("Model loaded:", response.json()["model_loaded"])
print("Using mocks:", response.json()["using_mock_mode"])  # Should be False

# 3. Get disease targets
response = requests.post(
    f"{BASE_URL}/api/v1/disease-targets",
    json={"disease_name": "Type 2 Diabetes", "top_n": 5}
)
targets = response.json()["targets"]
print(f"Found {len(targets)} targets")

# 4. Get drug library
response = requests.get(f"{BASE_URL}/api/v1/drug-library")
drugs = response.json()["drugs"]
print(f"Loaded {len(drugs)} drugs")

# 5. Run virtual screening
response = requests.post(
    f"{BASE_URL}/api/v1/screen",
    json={
        "disease_name": "Type 2 Diabetes",
        "top_targets": 5,
        "max_drugs": 25
    }
)
results = response.json()
print(f"Screening results: {len(results['top_candidates'])} candidates")
for drug in results["top_candidates"][:3]:
    print(f"  {drug['drug_name']}: {drug['score']} ({drug['status']})")

Expected Output

When running, you should see:

  1. Startup Logs showing:

    βœ… PRODUCTION MODE: All systems ready
       - Real DeepPurpose MPNN_CNN predictions enabled
       - Drug library enabled (Official TDC or Local Fallback)
       - No mock predictions active
    
  2. Model Status returns:

    {
      "model_loaded": true,
      "using_mock_mode": false,  ← This MUST be false
      "model": "MPNN_CNN_BindingDB"
    }
    
  3. Predictions have realistic binding affinity scores (0.3-0.9 range), NOT uniform random


Troubleshooting

Issue Solution
API won't start Check terminal for errors - errors will be clear and instructive
Port 8000 in use netstat -ano | findstr :8000 then taskkill /PID {PID} /F
Model load slow This is normal - first load ~3-5 seconds
No results from disease endpoint Check disease name spelling (e.g., "Type 2 Diabetes")
Very slow predictions CPU-only mode - expected 5-30s for 25-100 pairs

Architecture

User Request (HTTP)
      ↓
FastAPI Endpoint
      ↓
Disease β†’ Open Targets API β†’ Get Proteins
      ↓
Proteins β†’ UniProt API β†’ Get Sequences
      ↓
Drugs ← Local TDC (Fallback) ← Drug Library
      ↓
[Drug SMILES + Protein Sequences]
      ↓
DeepPurpose MPNN_CNN Model (REAL AI)
      ↓
Binding Affinity Scores ← NO MOCKS
      ↓
Sort & Filter Results
      ↓
JSON Response to User

What's Different Now

Before After
❌ Mock predictions (random 0-1) βœ… Real MPNN_CNN predictions
❌ 10 hardcoded drugs βœ… 25+ real FDA drugs
❌ Fallback mode silently βœ… Fails clearly if dependencies missing
❌ No visibility into system βœ… Detailed startup logs
❌ Unrealistic scores (uniform) βœ… Realistic binding affinity distribution

Next Steps

  1. Test locally using the endpoints above
  2. Deploy to Docker for production
  3. Scale to full TDC (600+ drugs) when official TDC becomes available
  4. Add GPU support for 10x speed improvement
  5. Integrate with frontend UI dashboard

API is production-ready. All real data, no mocks. Ready for integration!