# tallulandrews/m3drop architecture

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

- Interactive diagram: https://gitdiagram.com/tallulandrews/m3drop
- Repository: https://github.com/tallulandrews/m3drop

## Overview

##### Project type and purpose
- This is an R/Bioconductor package that implements statistical models (modified Michaelis-Menten and depth-adjusted negative binomial) to analyse dropouts in scRNA-seq data and perform feature selection, normalization, simulation, and plotting.
- It is _not_ a full‐stack web app or microservice; it’s a domain‐specific library offering a suite of R functions, bundled with documentation and vignettes.

##### File structure
- Top‐level:
- R/ ‑ all .R source files, each grouping related functions (model fitting, normalization, plotting, simulations, etc.)
- man/ ‑ Rd files for automated help pages (one per exported function)
- inst/NEWS ‑ release notes
- vignettes/ ‑ long‐form usage demos
- DESCRIPTION, NAMESPACE, README – package metadata
- There are no frontend/backend divisions: the “architecture” is purely modular within R.
- No deployment scripts; packaging is handled via R’s build system.

##### README for additional insights
- Confirms two core modelling paradigms (MM and DANB), plus Brennecke HVG comparison and new Pearson residual functions.
- Highlights downstream use cases: clustering, pseudotime, etc.

##### Main components & their relationships
a. Data Input & Preprocessing
- Reads gene×cell count matrices (e.g., from SingleCellExperiment objects)
- Wrapper functions convert to internal formats
b. Model Fitting
- Michaelis-Menten (R/Brennecke_implementation.R)
- Depth-Adjusted NB (R/DANB_*.R)
c. Feature Selection
- Dropout‐based FS (R/Other_FS_functions.R, DANB_HVG, NB_UMI, Brennecke)
d. Normalization
- Pearson residuals (NBumiPearsonResiduals)
- Traditional DE normals (R/Normalization.R)
e. Simulation
- Synthetic data generators (R/Simulations_Functions.R, R/M3D_Imputation.R)
f. Plotting & Reporting
g. Documentation & Packaging
- Rd files tie back to each R function
- Vignettes demonstrate end‐to‐end workflows

Data flows from Input → Model Fitting & Simulation → Feature Selection & Normalization → Plotting/Export.

##### Architectural patterns & design principles
- Modular, single‐responsibility R files grouping related functions.
- Clear separation between computational logic (models, FS) and visualization.
- Use of R’s S3/S4 object conventions and namespace exports.

##### Final advice
- Keep it self‐contained: assume the viewer knows R but not the package internals.
- Every R/ subfolder as a separate logical block.
- Do not overcomplicate with deployment or CI details (none present)—focus purely on modular code structure, data flow, and user API.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% User entry point
    User_API["User API\n(M3Drop() wrapper functions)"]

    %% Data Input
    subgraph "Data Input & Preprocessing"
        direction TB
        DataInput["Data Input & Preprocessing\n(R/basics.R)"]:::preprocessing
    end

    %% Model Fitting
    subgraph "Model Fitting" 
        direction TB
        MichaelisMenten["Michaelis-Menten\n(R/Brennecke_implementation.R)"]:::modelFitting
        DepthAdjNB["Depth-Adjusted NB\n(R/DANB_Coexpression.R,\nR/DANB_HVG.R)"]:::modelFitting
    end

    %% Simulation
    subgraph "Simulation"
        direction TB
        SimulationFunctions["Simulation\n(R/Simulations_Functions.R,\nR/M3D_Imputation.R)"]:::simulation
    end

    %% Feature Selection
    subgraph "Feature Selection"
        direction TB
        FS_Others["Other_FS\n(R/Other_FS_functions.R)"]:::featureSelection
        FS_NB_UMI["NB_UMI\n(R/NB_UMI.R)"]:::featureSelection
        FS_Brennecke["Brennecke_HVG\n(R/Brennecke_implementation.R)"]:::featureSelection
    end

    %% Normalization
    subgraph "Normalization"
        direction TB
        Norm_Traditional["Traditional_DE\n(R/Traditional_DE.R)"]:::normalization
        Norm_Pearson["NBumi_PearsonResiduals\n(R/NB_UMI.R)"]:::normalization
    end

    %% Plotting & Reporting
    subgraph "Plotting & Reporting"
        direction TB
        Plot_Functions["Plotting_fxns\n(R/Plotting_fxns.R)"]:::plotting
        Plot_Venn["VennDiagrams\n(R/Threeway_ProportionalArea_VennDiagrams.R)"]:::plotting
    end

    %% Documentation & Packaging
    Documentation["Documentation & Packaging\n(man/, vignettes/M3Drop_Vignette.Rnw,\nDESCRIPTION, NAMESPACE,\ninst/NEWS, README)"]:::documentation

    %% Data Flow
    User_API --> DataInput
    DataInput --> MichaelisMenten
    DataInput --> DepthAdjNB
    DataInput --> SimulationFunctions
    MichaelisMenten --> FS_Others
    DepthAdjNB --> FS_NB_UMI
    MichaelisMenten --> FS_Brennecke
    SimulationFunctions -.-> FS_Others
    SimulationFunctions -.-> FS_NB_UMI
    FS_Others --> Plot_Functions
    FS_NB_UMI --> Plot_Functions
    FS_Brennecke --> Plot_Functions
    DepthAdjNB --> Norm_Traditional
    MichaelisMenten --> Norm_Pearson
    SimulationFunctions -.-> Norm_Traditional
    SimulationFunctions -.-> Norm_Pearson
    Norm_Traditional --> Plot_Venn
    Norm_Pearson --> Plot_Venn
    Plot_Functions --> Plot_Venn

    %% Documentation Links
    User_API -.-> Documentation
    Documentation -.-> Plot_Venn

    %% Click Events
    click DataInput "https://github.com/tallulandrews/m3drop/blob/master/R/basics.R"
    click MichaelisMenten "https://github.com/tallulandrews/m3drop/blob/master/R/Brennecke_implementation.R"
    click DepthAdjNB "https://github.com/tallulandrews/m3drop/blob/master/R/DANB_Coexpression.R"
    click DepthAdjNB "https://github.com/tallulandrews/m3drop/blob/master/R/DANB_HVG.R"
    click FS_Others "https://github.com/tallulandrews/m3drop/blob/master/R/Other_FS_functions.R"
    click FS_NB_UMI "https://github.com/tallulandrews/m3drop/blob/master/R/NB_UMI.R"
    click FS_Brennecke "https://github.com/tallulandrews/m3drop/blob/master/R/Brennecke_implementation.R"
    click Norm_Traditional "https://github.com/tallulandrews/m3drop/blob/master/R/Traditional_DE.R"
    click Norm_Pearson "https://github.com/tallulandrews/m3drop/blob/master/R/NB_UMI.R"
    click SimulationFunctions "https://github.com/tallulandrews/m3drop/blob/master/R/Simulations_Functions.R"
    click SimulationFunctions "https://github.com/tallulandrews/m3drop/blob/master/R/M3D_Imputation.R"
    click Plot_Functions "https://github.com/tallulandrews/m3drop/blob/master/R/Plotting_fxns.R"
    click Plot_Venn "https://github.com/tallulandrews/m3drop/blob/master/R/Threeway_ProportionalArea_VennDiagrams.R"
    click Documentation "https://github.com/tallulandrews/m3drop/tree/master/man/"
    click Documentation "https://github.com/tallulandrews/m3drop/blob/master/vignettes/M3Drop_Vignette.Rnw"
    click Documentation "https://github.com/tallulandrews/m3drop/tree/master/DESCRIPTION"
    click Documentation "https://github.com/tallulandrews/m3drop/tree/master/NAMESPACE"
    click Documentation "https://github.com/tallulandrews/m3drop/tree/master/inst/NEWS"
    click Documentation "https://github.com/tallulandrews/m3drop/tree/master/README"

    %% Styles
    classDef modelFitting fill:#ADD8E6,stroke:#000
    classDef preprocessing fill:#90EE90,stroke:#000
    classDef featureSelection fill:#FFA500,stroke:#000
    classDef normalization fill:#90EE90,stroke:#000
    classDef plotting fill:#D8BFD8,stroke:#000
    classDef documentation fill:#D3D3D3,stroke:#000
    classDef simulation fill:#D3D3D3,stroke:#000
```
