# zaoqu-liu/mofs architecture

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

- Interactive diagram: https://gitdiagram.com/zaoqu-liu/mofs
- Repository: https://github.com/zaoqu-liu/mofs

## Overview

##### Project type and purpose
- This repository is a dual‐module R project composed of:
a) MOFSR: an R package providing functions and data structures for multimodal data fusion, clustering, classification, and enrichment.
b) MOFS‑ShinyApp: a Shiny web application exposing MOFSR functionality through a browser interface.

##### File structure
- Top‐level directories:
- MOFS‑ShinyApp/ – Shiny front‑end and server code, assets, embedded sample data and documentation.
- MOFSR/ – Standard R package layout (DESCRIPTION, NAMESPACE, R/, data/, man/).
- Figures and global resources (Figure*.R, PyRadiomics parameters.yaml) and overall README.
- MOFS‑ShinyApp substructure follows an MVC-like pattern:
- ui/ – UI modules (home.R, contact.R, help.R, about.R, footer.R).
- server/ – Server logic modules (home.R, help.R, contact.R).
- code/ & db/ – pre‑computed model artifacts and sample inputs.
- lib/ – shared R scripts (package loader).
- www/ – static assets (css, js, images).
- MOFSR package:
- R/ – dozens of R scripts implementing core algorithms (RunMOFS, RunIF, classifiers, feature selection, clustering, evaluation).
- data/ – gene_sets.rda.
- man/ – documentation for every function.
- DESCRIPTION & NAMESPACE define dependencies and exports.

##### README insights
- Describes multimodal fusion strategies (intermediate + late fusion).
- Highlights key functional areas: feature selection, integration (RunIF, RunMOFS), clustering algorithms, evaluation metrics, classification, enrichment.
- Mentions technologies: Shiny, IntNMF, mogsa, future.apply, tidyverse, Bioconductor packages.

##### Main components
a. User Interface (Browser)
– Entry point: Shiny UI modules (ui/).
b. Shiny Server
– Orchestrates user requests, loads code from lib/, dispatches to server modules.
– Reads sample data or user‐uploaded data from db/data or external sources.
c. R Package (MOFSR)
– Core engine: functions under R/ for feature selection, fusion, clustering, evaluation, classification, enrichment.
– Data objects: gene_sets.rda, model artifacts (fit.rda).
d. Data Storage
– Static sample data (db/data/InputExample.csv, fit.rda).
– Documentation (doc/help/*.md).
e. External Services & Libraries
– CRAN/Bioconductor dependencies, future parallel backend, JavaScript libraries (jQuery, custom.js) for UI.

##### Relationships and data flow
- Browser → HTTP/WebSocket → Shiny Server
- Shiny Server calls lib/load_packages.R to load MOFSR and dependencies.
- Server modules invoke MOFSR functions:
- Input ingestion → Preprocessing → FeatureSelection → DataNormalization → Intermediate Fusion (RunIF) → Clustering (IntNMF, CPCA, …) → Late Fusion (RunMOFS) → Evaluation (CalPAC, CalCHI, Silhouette) → Classification (RunEnsemble) → Enrichment (RunGSVA, ssMwwGST).
- Intermediate results and consensus matrices can be cached in code/ or returned live.
- Results are passed back to UI modules for plotting and download.

##### Architectural patterns and principles
- MVC pattern in Shiny (ui vs server modules).
- Modular R package design: single‐responsibility scripts for each algorithm.
- Layered approach: Data ingestion → Core engine → Visualization.
- Parallelism via future.apply for heavy computations.
- Dependency injection: lib/load_packages.R centralizes library loading.

##### Relevant technologies and frameworks
- R, Shiny, Bioconductor, CRAN.
- Parallel computing (future.apply, doParallel).
- NMF and PCA (IntNMF, mogsa).
- JavaScript/CSS for UI enhancements.
- Data storage: RDS/RDA, CSV.

##### Detail
- Every folder’s role in a minimal consolidated form.

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% User Interface Layer
    UI["Shiny UI Modules\n(ui/)"]:::ui
    click UI "https://github.com/zaoqu-liu/mofs/tree/master/MOFS-ShinyApp/ui/"

    %% Shiny Server Layer
    subgraph "Shiny Server" 
        direction TB
        App["app.R\n(Entry Point)"]:::backend
        subgraph "Server Logic"
            direction TB
            SHome["home.R"]:::backend
            SContact["contact.R"]:::backend
            SHelp["help.R"]:::backend
        end
        Load["load_packages.R\n(lib/)"]:::backend
        Assets["Static Assets\n(www/)"]:::backend
    end
    click App "https://github.com/zaoqu-liu/mofs/blob/master/MOFS-ShinyApp/app.R"
    click SHome "https://github.com/zaoqu-liu/mofs/blob/master/MOFS-ShinyApp/server/home.R"
    click SContact "https://github.com/zaoqu-liu/mofs/blob/master/MOFS-ShinyApp/server/contact.R"
    click SHelp "https://github.com/zaoqu-liu/mofs/blob/master/MOFS-ShinyApp/server/help.R"
    click Load "https://github.com/zaoqu-liu/mofs/blob/master/MOFS-ShinyApp/lib/load_packages.R"
    click Assets "https://github.com/zaoqu-liu/mofs/tree/master/MOFS-ShinyApp/www/"

    %% MOFSR Core Engine
    subgraph "MOFSR Core Engine" 
        direction TB
        MFEngine["Algorithms\n(MOFSR/R/)"]:::backend
    end
    click MFEngine "https://github.com/zaoqu-liu/mofs/tree/master/MOFSR/R/"

    %% Data Storage Layer
    subgraph "Data Storage"
        direction TB
        SampleIn["Sample Inputs\n(InputExample.csv)"]:::data
        Models["Precomputed Models\n(fit.rda)"]:::data
        GeneSets["Gene Sets\n(gene_sets.rda)"]:::data
    end
    click SampleIn "https://github.com/zaoqu-liu/mofs/blob/master/MOFS-ShinyApp/code/InputExample.csv"
    click Models "https://github.com/zaoqu-liu/mofs/blob/master/MOFS-ShinyApp/code/fit.rda"
    click GeneSets "https://github.com/zaoqu-liu/mofs/blob/master/MOFSR/data/gene_sets.rda"

    %% Documentation
    Doc["Documentation\n(doc/)"]:::data
    click Doc "https://github.com/zaoqu-liu/mofs/blob/master/MOFS-ShinyApp/doc/README.md"

    %% External Libraries
    External["External Libraries\n(CRAN, Bioconductor, JS)"]:::ext

    %% Data Flow
    UI -->|"User Actions"| App
    App -->|"Load Packages"| Load
    App -->|"Route Request"| SHome
    App -->|"Route Request"| SContact
    App -->|"Route Request"| SHelp
    Load -->|"Initialize Engine"| MFEngine
    SHome -->|"Read Input"| SampleIn
    SContact -->|"Read Input"| SampleIn
    SHelp -->|"Read Input"| SampleIn
    SHome -->|"Invoke Algorithms"| MFEngine
    SContact -->|"Invoke Algorithms"| MFEngine
    SHelp -->|"Invoke Algorithms"| MFEngine
    MFEngine -->|"Read Data"| GeneSets
    MFEngine -->|"Cache/Load Models"| Models
    MFEngine -->|"Return Results"| App
    App -->|"Render UI"| UI
    External --> App
    External --> MFEngine

    %% Styling
    classDef ui fill:#D6EAF8,stroke:#3498DB,color:#154360;
    classDef backend fill:#FADBD8,stroke:#E74C3C,color:#641E16;
    classDef data fill:#D5F5E3,stroke:#27AE60,color:#145A32;
    classDef ext fill:#FCF3CF,stroke:#F1C40F,color:#7D6608;
```
