# dpeerlab/seacells architecture

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

- Interactive diagram: https://gitdiagram.com/dpeerlab/seacells
- Repository: https://github.com/dpeerlab/seacells

## Overview

##### Main Components
- Core Python Library – Represent the heart of SEACells. This includes the principal modules within the SEACells package such as:
- core.py and build_graph.py: Handling the main aggregation and graph-building logic.
- cpu.py and gpu.py (including cpu_dense.py): These modules illustrate the implementation of alternative computation methods (parallel execution on CPU and GPU).
- accessibility.py, preprocess.py, tfactivity.py, genescores.py, evaluate.py: Dedicated modules for various data analyses (e.g., computing gene scores, TF activity, evaluation procedures).
- domainadapt.py: Implements cross-modality integration, especially between scRNA and scATAC data.
- Additional utility modules: utils.py and version.py (for common utility functions and versioning).

- Data and Input Components – Show how sample data and ancillary inputs are used:
- The Data folder (with sample_data.h5ad) indicates where test and demo datasets are stored.
- Notebooks folder: Contains multiple Jupyter notebooks (e.g., ArchR-related workflows, ATAC analysis, COVID integration) that demonstrate usage, preprocessing, computation, and integration procedures.
- SEACells/Rscripts: A subdirectory housing R scripts (e.g., chromVAR.R, tanay.R) which indicate integrations with R-based tools.

- Installation and Environment – Although not a "runtime" component, illustrate these aspects to explain deployment:
- Files like setup.py, requirements.txt, and environment.yaml represent the build and installation configuration.
- Pre-commit hooks and configuration files (e.g., .editorconfig, .gitignore, .pre-commit-config.yaml) show development tooling but can be grouped as auxiliary setup modules.

##### Relationships and Data Flow
- Input Data Flow: Show the data input (from the "data" directory and externally provided files) moving into preprocessing routines (preprocess.py and the ArchR notebooks).
- Processing and Core Computation: Demonstrate the flow from preprocessing to core aggregation (via core.py, build_graph.py), and then branching out:
- Two computation pathways: one through CPU-based methods (cpu.py, cpu_dense.py) and one utilizing GPU acceleration (gpu.py).
- Downstream analysis modules (accessibility.py, genescores.py, tfactivity.py) receive processed data to perform specific bioinformatics analyses.
- Domain adaptation (domainadapt.py) links or integrates outputs from different data modalities.
- Visualization and Reporting: Notebooks and plotting scripts (plot.py) serve as the front end for data visualization and result interpretation.
- R Integration: Represent the R scripts as a parallel processing or complementary analysis pathway integrating with the main Python workflow, suggesting bi-directional data exchange or alternative execution environments.

##### Architectural Patterns and Design Principles
- Modularity: Each module (computation, analysis, processing) is self-contained, with clear separation of concerns.
- Extensibility: The presence of both CPU and GPU modules indicates that the system can be extended to harness different hardware architectures.
- Interoperability: Support for both Python and R (via Rscripts) emphasizes the tool’s ability to integrate with a broader bioinformatics ecosystem.
- Dependency Management: Use of pip, conda, and configuration files (setup.py, environment.yaml) should be noted to reflect how external libraries are managed.

## Diagram (Mermaid)

```mermaid
graph TD
  %% Data/Input Layer
  subgraph "Data/Input"
    A1("Sample Data"):::data
    A2("Tutorial Notebooks"):::data
  end
  click A1 "https://github.com/dpeerlab/seacells/blob/main/SEACells/data/sample_data.h5ad"
  click A2 "https://github.com/dpeerlab/seacells/tree/main/notebooks/"

  %% Preprocessing Layer
  subgraph "Preprocessing"
    B1("Preprocessing (preprocess.py, ArchR Notebooks)"):::preprocess
  end

  %% Core Aggregation & Computation Layer
  subgraph "Core Aggregation & Computation"
    subgraph "Core Computation"
      C1("core.py"):::core
      C2("build_graph.py"):::core
    end
    subgraph "Hardware-Specific Computation"
      C3("cpu.py"):::hardware
      C4("cpu_dense.py"):::hardware
      C5("gpu.py"):::hardware
    end
    subgraph "Utilities"
      U1("utils.py"):::core
      U2("version.py"):::core
    end
  end
  click C1 "https://github.com/dpeerlab/seacells/blob/main/SEACells/core.py"
  click C2 "https://github.com/dpeerlab/seacells/blob/main/SEACells/build_graph.py"
  click C3 "https://github.com/dpeerlab/seacells/blob/main/SEACells/cpu.py"
  click C4 "https://github.com/dpeerlab/seacells/blob/main/SEACells/cpu_dense.py"
  click C5 "https://github.com/dpeerlab/seacells/blob/main/SEACells/gpu.py"
  click U1 "https://github.com/dpeerlab/seacells/blob/main/SEACells/utils.py"
  click U2 "https://github.com/dpeerlab/seacells/blob/main/SEACells/version.py"

  %% Downstream Analysis Layer
  subgraph "Downstream Analysis"
    D1("accessibility.py"):::analysis
    D2("genescores.py"):::analysis
    D3("tfactivity.py"):::analysis
    D4("evaluate.py"):::analysis
    D5("domainadapt.py"):::analysis
  end
  click D1 "https://github.com/dpeerlab/seacells/blob/main/SEACells/accessibility.py"
  click D2 "https://github.com/dpeerlab/seacells/blob/main/SEACells/genescores.py"
  click D3 "https://github.com/dpeerlab/seacells/blob/main/SEACells/tfactivity.py"
  click D4 "https://github.com/dpeerlab/seacells/blob/main/SEACells/evaluate.py"
  click D5 "https://github.com/dpeerlab/seacells/blob/main/SEACells/domainadapt.py"

  %% Visualization/Reporting Layer
  subgraph "Visualization/Reporting"
    E1("plot.py"):::viz
    E2("Tutorial Figures (Notebooks)"):::viz
  end
  click E1 "https://github.com/dpeerlab/seacells/blob/main/SEACells/plot.py"
  click E2 "https://github.com/dpeerlab/seacells/tree/main/figures/"

  %% R Integration Layer
  subgraph "R Integration"
    R1("chromVAR.R"):::r
    R2("tanay.R"):::r
  end
  click R1 "https://github.com/dpeerlab/seacells/blob/main/SEACells/Rscripts/chromVAR.R"
  click R2 "https://github.com/dpeerlab/seacells/blob/main/SEACells/Rscripts/tanay.R"

  %% Installation & Environment Layer
  subgraph "Installation & Environment"
    I1("Build & Config (setup.py, requirements.txt, environment.yaml)"):::install
    I2("Dev Tools (.editorconfig, .gitignore, .pre-commit-config.yaml)"):::install
  end
  click I1 "https://github.com/dpeerlab/seacells/blob/main/setup.py"
  click I2 "https://github.com/dpeerlab/seacells/blob/main/.editorconfig"

  %% Data Flow Connections
  A1 --> B1
  A2 --> B1
  B1 --> C1
  B1 --> C2
  B1 --> C3
  B1 --> C4
  B1 --> C5
  C1 --> D1
  C2 --> D1
  C3 --> D1
  C4 --> D1
  C5 --> D1
  U1 --> D1
  U2 --> D1
  D1 --> D2
  D2 --> D3
  D3 --> D4
  D4 --> D5
  D5 --> E1
  D5 --> E2

  %% R Integration interacts with Downstream Analysis (bidirectional)
  D5 <--> R1
  D5 <--> R2

  %% Installation supports the overall system (initialization)
  I1 --- A1
  I1 --- A2
  I2 --- A1
  I2 --- A2

  %% Styling Classes
  classDef data fill:#ffedcc,stroke:#b58900,stroke-width:2px;
  classDef preprocess fill:#cceeff,stroke:#2aa198,stroke-width:2px;
  classDef core fill:#e0ffe0,stroke:#859900,stroke-width:2px;
  classDef hardware fill:#ffe0e0,stroke:#dc322f,stroke-width:2px;
  classDef analysis fill:#e0e0ff,stroke:#268bd2,stroke-width:2px;
  classDef viz fill:#ffd6ff,stroke:#d33682,stroke-width:2px;
  classDef r fill:#f0e68c,stroke:#b58900,stroke-width:2px;
  classDef install fill:#f2f2f2,stroke:#93a1a1,stroke-width:2px;
```
