# nourmarzouka/multiclasspairs architecture

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

- Interactive diagram: https://gitdiagram.com/nourmarzouka/multiclasspairs
- Repository: https://github.com/nourmarzouka/multiclasspairs

## Overview

##### Project Overview
- Type & Purpose:
- An R package (“multiclassPairs”) providing a toolbox for single-sample, pair‐based multiclass classification.
- Implements two schemes:
– One-vs-rest using Top-Score Pairs (TSP via switchBox)
– Random Forest (RF via ranger, optional Boruta pruning)
- Organizes code under /R, documentation under /man + vignettes, assets under /images.

##### Main Components & Layers
A. Package Structure
- R/                — Source functions (ReadData, filter*, train*, predict*, sort*, plot*).
- man/              — Rd files for each public function.
- vignettes/        — Tutorial workflows (Rmd + generated figures).
- DESCRIPTION, NAMESPACE — Package metadata and exports.
B. Core Functional Modules
1. Data Ingestion & Wrangling
- ReadData: wraps data.frame, matrix, or ExpressionSet → multiclassPairs object.
2. Feature Filtering / Sorting
a. TSP branch: filter_genes_TSP → produces per‐class filtered gene lists.
b. RF branch: sort_genes_RF → ranks genes “altogether” & “one_vs_rest.”
3. Rule Generation & Sorting
a. TSP branch: train_one_vs_rest_TSP builds and scores binary rule sets.
b. RF branch: sort_rules_RF → combines top genes into rules, ranks by importance.
4. Model Training
a. TSP: internally calls switchBox::SWAP.Train.KTSP to pick optimal k‐rules.
b. RF: train_RF uses ranger (with optional Boruta feature pruning) to fit multiclass RF.
5. Prediction & Scoring
- predict_one_vs_rest_TSP / predict_RF apply trained models to new data, output class scores & labels.
6. Visualization
- plot_binary_TSP / plot_binary_RF produce heatmaps of rule truth values and class scores.
C. External Dependencies
- Biobase (ExpressionSet support)
- switchBox (KTSP algorithm & scoring)
- ranger (fast Random Forest)
- Boruta (optional rule pruning)
- caret / gplots / ggplot2 (visualization & evaluation)

##### Relationships & Data Flow
[User Data] → ReadData → [multiclassPairs object]
↙                          ↘
TSP branch                  RF branch
↓                             ↓
filter_genes_TSP           sort_genes_RF
↓                             ↓
train_one_vs_rest_TSP     sort_rules_RF
↓                             ↓
predict_one_vs_rest_TSP   train_RF
↓                             ↓
plot_binary_TSP           predict_RF
↓
plot_binary_RF

##### Architectural Patterns & Design Principles
- Modular design: each logical step is a standalone R function exported in NAMESPACE.
- Dual‐scheme parallelism: two interchangeable branches (TSP vs RF) share interface patterns (filter/train/predict/plot).
- Functional pipeline: pure functions pass well-specified objects, enabling reproducibility via seeds.
- Extensibility points: users can swap underlying algorithms (e.g., supply custom filter or ranger args, toggle Boruta).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Ingestion Layer
    subgraph "Data Ingestion" 
        direction TB
        UD["User Data<br/>(data.frame/matrix/ExpressionSet)"]:::data
        RD["ReadData()<br/>→ multiclassPairs object"]:::func
    end

    UD -->|"input_data"| RD

    %% Decision Point
    JS["Choose Scheme:<br/>TSP or RF"]:::decision

    RD --> JS

    %% TSP Branch
    subgraph "TSP Branch" 
        direction TB
        FT["filter_genes_TSP()<br/>filter per-class genes"]:::func
        TT["train_one_vs_rest_TSP()<br/>build k TSP rules"]:::func
        PT["predict_one_vs_rest_TSP()<br/>score & label"]:::func
        VP["plot_binary_TSP()<br/>heatmap of rule truths"]:::output
        SB["switchBox::SWAP.Train.KTSP"]:::external
    end

    JS -->|TSP| FT
    FT --> TT
    TT --> SB
    SB --> TT
    TT --> PT
    PT --> VP

    %% RF Branch
    subgraph "RF Branch"
        direction TB
        SRF["sort_genes_RF()<br/>rank genes"]:::func
        GRF["sort_rules_RF()<br/>combine & rank rules"]:::func
        TRF["train_RF()<br/>ranger RF (+ Boruta)"]:::func
        PRF["predict_RF()<br/>score & label"]:::func
        VRF["plot_binary_RF()<br/>heatmap of RF truths"]:::output
        RG["ranger + Boruta"]:::external
    end

    JS -->|RF| SRF
    SRF --> GRF
    GRF --> TRF
    TRF --> RG
    RG --> TRF
    TRF --> PRF
    PRF --> VRF

    %% Documentation & Metadata
    subgraph "Documentation & Metadata"
        direction TB
        DS["DESCRIPTION"]:::docs
        NS["NAMESPACE"]:::docs
        MG["man/*.Rd"]:::docs
        VIG["vignettes/"]:::docs
        IMG["images/"]:::docs
    end

    %% Flows to docs (dotted)
    RD -.-> DS
    RD -.-> NS
    RD -.-> MG
    RD -.-> VIG
    RD -.-> IMG

    %% Legends
    classDef data fill:#D0E8FF,stroke:#333,stroke-width:1px;
    classDef func fill:#D2F8D2,stroke:#333,stroke-width:1px;
    classDef external fill:#FFE4B5,stroke:#333,stroke-width:1px;
    classDef output fill:#E6D2FF,stroke:#333,stroke-width:1px;
    classDef decision fill:#FFD2D2,stroke:#333,stroke-width:1px;
    classDef docs fill:#F0F0F0,stroke:#333,stroke-width:1px,stroke-dasharray: 5 5;

    %% Click Events - Functions
    click RD "https://github.com/nourmarzouka/multiclasspairs/blob/master/R/functions.R"
    click FT "https://github.com/nourmarzouka/multiclasspairs/blob/master/R/functions.R"
    click SRF "https://github.com/nourmarzouka/multiclasspairs/blob/master/R/functions.R"
    click TT "https://github.com/nourmarzouka/multiclasspairs/blob/master/R/functions.R"
    click GRF "https://github.com/nourmarzouka/multiclasspairs/blob/master/R/functions.R"
    click TRF "https://github.com/nourmarzouka/multiclasspairs/blob/master/R/functions.R"
    click PT "https://github.com/nourmarzouka/multiclasspairs/blob/master/R/functions.R"
    click PRF "https://github.com/nourmarzouka/multiclasspairs/blob/master/R/functions.R"
    click VP "https://github.com/nourmarzouka/multiclasspairs/blob/master/R/functions.R"
    click VRF "https://github.com/nourmarzouka/multiclasspairs/blob/master/R/functions.R"

    %% Click Events - Man pages
    click DS "https://github.com/nourmarzouka/multiclasspairs/tree/master/DESCRIPTION"
    click NS "https://github.com/nourmarzouka/multiclasspairs/tree/master/NAMESPACE"
    click MG "https://github.com/nourmarzouka/multiclasspairs/blob/master/man/ReadData.Rd"
    click MG "https://github.com/nourmarzouka/multiclasspairs/blob/master/man/filter_genes_TSP.Rd"
    click MG "https://github.com/nourmarzouka/multiclasspairs/blob/master/man/sort_genes_RF.Rd"
    click MG "https://github.com/nourmarzouka/multiclasspairs/blob/master/man/train_one_vs_rest_TSP.Rd"
    click MG "https://github.com/nourmarzouka/multiclasspairs/blob/master/man/sort_rules_RF.Rd"
    click MG "https://github.com/nourmarzouka/multiclasspairs/blob/master/man/train_RF.Rd"
    click MG "https://github.com/nourmarzouka/multiclasspairs/blob/master/man/predict_one_vs_rest_TSP.Rd"
    click MG "https://github.com/nourmarzouka/multiclasspairs/blob/master/man/predict_RF.Rd"
    click MG "https://github.com/nourmarzouka/multiclasspairs/blob/master/man/plot_binary_TSP.Rd"
    click MG "https://github.com/nourmarzouka/multiclasspairs/blob/master/man/plot_binary_RF.Rd"
    click VIG "https://github.com/nourmarzouka/multiclasspairs/blob/master/vignettes/Tutorial.Rmd"
    click VIG "https://github.com/nourmarzouka/multiclasspairs/tree/master/vignettes/figure/"
    click VIG "https://github.com/nourmarzouka/multiclasspairs/tree/master/vignettes/images/"
    click IMG "https://github.com/nourmarzouka/multiclasspairs/tree/master/images/"
```
