# jwyang16/decoder architecture

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

- Interactive diagram: https://gitdiagram.com/jwyang16/decoder
- Repository: https://github.com/jwyang16/decoder

## Overview

##### Main Components
- R Package Core – The primary functionality is implemented in the R directory. Key files include:
- DECODER_function.R (core deconvolution logic)
- DECODER_pipeline.R (the end-to-end data processing pipeline including reading BAM files, peak calling, counting, and deconvolution)
- Additional utility scripts in R/demo.r, R/genomes.r, etc.
- External Data – Provided in the “data” and “inst/extdata” directories:
- “data” holds RData files (demo examples, reference datasets).
- “inst/extdata” contains example BAM files separated into “bulk” and “single_cell” as sample inputs.
- Documentation & Manual – The “man” directory stores Rd files that document each exported function (e.g., DECODER, DECODER.pipeline).
- Installation & Metadata – Files like DESCRIPTION, NAMESPACE, and README provide metadata and usage instructions.

##### Relationships and Interactions
- User Interface:
- Users load the package in R (via library(DECODER)) and call the DECODER or DECODER.pipeline function.
- Data Flow:
- Input data flows from BAM files (bulk and single-cell), which are read via the pipeline functions.
- Pre-processing steps such as peak calling and counting are performed internally.
- The core deconvolution method then processes these data to estimate cell-type proportions.
- External Interaction:
- The package may interface with standard R libraries; it also comes with example data for demonstration.
- GitHub is used as the distribution channel.

##### Architectural Patterns and Technologies
- Modular Design:
- Separation of concerns is achieved by splitting the core logic (DECODER_function.R) and the pipeline workflow (DECODER_pipeline.R).
- Domain-Specific Workflow:
- R Package Structure:
- Standard R package components (R scripts, data, docs) which ensure reproducibility and ease of installation.

##### Final Details
- Start from the user loading R, then the package fetches example or user-specified BAM files from the “inst/extdata” folder, processes them using the defined functions in the “R” scripts, and returns the results.
- Also highlighting the alternative usage modes (using built-in reference vs. user-defined reference) as branching points in the data flow.

## Diagram (Mermaid)

```mermaid
flowchart TD
    subgraph "User Interaction"
        U["User: Load DECODER Package"]:::user
    end

    subgraph "Input Data"
        B["Input: Bulk BAM Files"]:::input
        S["Input: Single Cell BAM Files"]:::input
        E["External Reference Data"]:::input
    end

    subgraph "Processing Pipeline"
        P["DECODER.pipeline Function"]:::processing
        DPre["Data Preprocessing (Peak Calling & Counting)"]:::processing
        DCore["Anchor-Based Deconvolution (DECODER_function)"]:::processing
        P --> DPre --> DCore
    end

    subgraph "Output"
        O["Output: Cell-Type Proportions"]:::output
    end

    subgraph "Support Components"
        Doc["Documentation & Manual"]:::support
        subgraph "Installation & Metadata"
            DESS["DESCRIPTION"]:::support
            NS["NAMESPACE"]:::support
            RMD["README.md"]:::support
        end
        RCore["R Package Core"]:::processing
    end

    %% Data Flow Connections
    U -->|"calls"| P
    B --> P
    S --> P
    E --> DCore
    DCore --> O
    P --> RCore
    Doc --- U

    %% Click Events
    click RCore "https://github.com/jwyang16/decoder/blob/master/R/DECODER_function.R"
    click RCore "https://github.com/jwyang16/decoder/blob/master/R/DECODER_pipeline.R"
    click RCore "https://github.com/jwyang16/decoder/blob/master/R/demo.r"
    click RCore "https://github.com/jwyang16/decoder/blob/master/R/genomes.r"
    click RCore "https://github.com/jwyang16/decoder/blob/master/R/get_count.R"
    click RCore "https://github.com/jwyang16/decoder/blob/master/R/ref_peak.r"
    click RCore "https://github.com/jwyang16/decoder/blob/master/R/reference.r"
    click E "https://github.com/jwyang16/decoder/tree/master/data/"
    click B "https://github.com/jwyang16/decoder/tree/master/inst/extdata/bulk"
    click S "https://github.com/jwyang16/decoder/tree/master/inst/extdata/single_cell"
    click Doc "https://github.com/jwyang16/decoder/tree/master/man/"
    click DESS "https://github.com/jwyang16/decoder/tree/master/DESCRIPTION"
    click NS "https://github.com/jwyang16/decoder/tree/master/NAMESPACE"
    click RMD "https://github.com/jwyang16/decoder/blob/master/README.md"

    %% Styles
    classDef user fill:#cfe2f3,stroke:#6c8ebf,stroke-width:2px;
    classDef input fill:#d9ead3,stroke:#38761d,stroke-width:2px;
    classDef processing fill:#fff2cc,stroke:#bf9000,stroke-width:2px;
    classDef output fill:#f4cccc,stroke:#b45f06,stroke-width:2px;
    classDef support fill:#d0e0e3,stroke:#1155cc,stroke-width:2px;
```
