# kbogas/ddi_blkg architecture

> Architecture diagram of the GitHub repository kbogas/ddi_blkg, generated by GitDiagram from its file tree, README and a sample of source files (last updated 2025-05-06). It is an AI-made overview: check details against the source.

- Interactive diagram: https://gitdiagram.com/kbogas/ddi_blkg
- Repository: https://github.com/kbogas/ddi_blkg

## Overview

##### Project Type and Purpose
- Type: Research‐oriented Python package for link‐prediction on a biomedical literature knowledge graph (KG).
- Purpose: Predict drug-drug interactions by extracting semantic paths in a disease-specific KG and comparing against standard embedding methods (TransE, HolE, DistMult, RESCAL).

##### Directories and Files
- data/
- Embeddings/ – precomputed feature vectors and KG embedding files for all methods
- Predictions/ – model output (predicted DDIs)
- run_tests.py – sample script to run experiments (replicate published results)
- requirements.txt – Python dependencies (TorchKGE, scikit-learn, etc.)
- README.md – project overview, data download instructions, and usage

##### Components
a. External Data Sources (outside this repo)
- Biomedical Literature & Structured DBs (Disease Ontology, Gene Ontology, MeSH)
- Harvesters & Extraction Tools (from Biomedical‐Knowledge‐Integration repo)
b. Knowledge Graph Construction (external module)
- Triple Store: subject–relation–object KG for Alzheimer’s, Lung Cancer, (and future COVID-19)
c. Embedding Generation (TorchKGE pipeline)
- Competing Methods: TransE, HolE, DistMult, RESCAL
- Output: vector embeddings for drug‐pair nodes
d. Feature Extraction Module (DDI-BLKG method)
- Semantic‐path extraction between drug nodes
- Output: feature vectors for drug pairs
e. Model Training & Evaluation (run_experiment_AIME2020.py or run_tests.py)
- Input: embeddings + feature vectors + ground‐truth labels
- Algorithm: binary classifier (link prediction)
- Output: predicted DDIs → saved to data/Predictions
f. Results & Visualization
- Metrics comparison across methods
- Tables/images (from images/ folder)

##### Relationships and Data Flows
- KG → Embedding Generation pipelines
- Embeddings → Model Training
- Feature Extraction → Model Training
- Model Training → Predictions
- Predictions → data/Predictions output
- Users invoke run_experiment_AIME2020.py (or run_tests.py) to orchestrate pipelines

##### Architectural Patterns & Design Principles
- Modular separation:
- Data ingestion / KG build (external)
- Embedding modules for each algorithm
- Feature‐extraction core
- Training & evaluation script
- Reusability: shareable embeddings; standardized input/output folders
- Extensibility: add new embedding methods by dropping files into data/Embeddings and updating script

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% External Data Sources
    subgraph "External Data Sources"
        direction TB
        EX1["Biomedical Literature & Structured DBs"]:::external
        EX2["Harvesters & Extraction Tools"]:::external
    end

    %% Knowledge Graph Construction
    KG["KG Construction (Triple Store)"]:::processing

    %% Embedding Generation
    subgraph "Embedding Generation"
        direction TB
        T1["TorchKGE: TransE"]:::processing
        T2["TorchKGE: HolE"]:::processing
        T3["TorchKGE: DistMult"]:::processing
        T4["TorchKGE: RESCAL"]:::processing
    end

    %% Feature Extraction
    FE["DDI-BLKG Semantic-Path Feature Extraction"]:::processing

    %% Model Training & Prediction
    subgraph "Model Training & Prediction"
        direction TB
        SCRIPT["run_tests.py"]:::script
        TRAIN["Model Training & Evaluation"]:::processing
        PRED["Predicted DDIs (.csv)"]:::datastore
    end

    %% Data Stores & Artifacts
    DS["data/"]:::datastore
    EMB["data/Embeddings"]:::datastore
    click EMB "https://github.com/kbogas/ddi_blkg/tree/master/data/Embeddings/"
    PDS["data/Predictions"]:::datastore
    click PDS "https://github.com/kbogas/ddi_blkg/tree/master/data/Predictions/"
    IMG["images/"]:::datastore
    click IMG "https://github.com/kbogas/ddi_blkg/tree/master/images/"

    %% Documentation & Dependencies
    README["README.md"]:::script
    click README "https://github.com/kbogas/ddi_blkg/blob/master/README.md"
    REQ["requirements.txt"]:::script
    click REQ "https://github.com/kbogas/ddi_blkg/blob/master/requirements.txt"

    %% Relationships
    EX1 --> KG
    EX2 --> KG
    KG --> T1
    KG --> T2
    KG --> T3
    KG --> T4
    T1 --> EMB
    T2 --> EMB
    T3 --> EMB
    T4 --> EMB
    EMB --> TRAIN
    FE --> TRAIN
    SCRIPT --> TRAIN
    TRAIN --> PRED
    PRED --> PDS
    TRAIN --> IMG

    %% Orchestration
    SCRIPT --> KG
    SCRIPT --> T1
    SCRIPT --> T2
    SCRIPT --> T3
    SCRIPT --> T4
    SCRIPT --> FE

    %% Data Store Overview
    DS --> EMB
    DS --> PDS
    DS --> IMG

    %% Click Events
    click SCRIPT "https://github.com/kbogas/ddi_blkg/blob/master/run_tests.py"
    click DS "https://github.com/kbogas/ddi_blkg/tree/master/data/"

    %% Styles
    classDef external fill:#ECEFF1,stroke-dasharray: 5 5,stroke:#90A4AE
    classDef processing fill:#C8E6C9,stroke:#388E3C
    classDef datastore fill:#BBDEFB,stroke:#1976D2,shape:cylinder
    classDef script fill:#FFE0B2,stroke:#F57C00,shape:roundrect
```
