# yoseflab/cassiopeia architecture

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

- Interactive diagram: https://gitdiagram.com/yoseflab/cassiopeia
- Repository: https://github.com/yoseflab/cassiopeia

## Overview

##### And Isolate the Main Components
- Preprocessing Module – Located under “cassiopeia/preprocess”, it handles alignment, UMI/cell barcode correction, and other output preparation from raw sequencing files (FASTQs/BAMs).
- Data Structures – Found in “cassiopeia/data”, these are the fundamental classes (like CassiopeiaTree and Layers) managing the tree representations and metadata.
- Solver Component – Under “cassiopeia/solver”, this contains multiple tree reconstruction algorithms (Neighbor Joining, ILP, greedy methods, etc.). Highlight the data flow from the data structures (trees) into these solvers.
- Simulator – In “cassiopeia/simulator”, different simulation methods generate synthetic lineage tracing datasets. Emphasize its interaction with the core data structures and its role in benchmarking.
- Visualization/Plotting – Under “cassiopeia/plotting”, this module includes utilities for both 2D and 3D visualization. It takes reconstructed trees and additional annotation data to produce plots.
- Critique and Evaluation – The “cassiopeia/critique” module provides functionality to compare trees or evaluate their quality.
- Tools/Miscellaneous – Found under “cassiopeia/tools”, these components include branch length estimation, fitness estimation, and additional utilities to support analysis.
- Mixins – The “cassiopeia/mixins” directory deals with common utilities such as logging, error, and warning handling that are used across all modules.

##### Interdependencies and Data Flows
- Begin the flow with raw sequencing data entering the pipeline (not shown explicitly in code but mentioned in README and test datasets).
- Preprocessing reads these inputs, corrects errors, and outputs a processed dataset (or intermediate representations) that the Data Module then uses to create tree structures.
- These tree structures feed into the Solver component, which offers multiple algorithms to reconstruct the lineage tree.
- In parallel, the Simulator can generate synthetic datasets, which can be funneled into the Solver or used separately for benchmarking.
- Once a tree is reconstructed, the Plotting module visualizes the tree using various display techniques (local, 3D, etc.).
- The Critique module then assesses tree quality or compares different tree reconstructions.
- Tools and Mixins provide auxiliary functionality (error handling, logging, branch/fiteness estimation) across the pipeline.

##### Architectural Patterns and Design Principles
- Use of Mixins – Illustrate that common behaviors (e.g., error management, logging) are abstracted in mixins, which are used by many other modules.

##### Specific Technologies and Libraries
- Python is the main language; modules written in Python with some Cython (e.g. collapse_cython in preprocess and ilp_solver_utilities) for performance.
- Third-party dependencies include Gurobi for ILP solving and optionally CCPhylo for fast NJ and UPGMA implementations.
- Use of notebooks for examples and tutorials indicates an emphasis on reproducibility and ease of adoption.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    RawData["Raw Sequencing Data"]:::externalStyle
    Preproc["Preprocessing Module"]:::preprocessStyle
    Data["Data Structures"]:::dataStyle
    Solver["Solver Component"]:::solverStyle
    Simulator["Simulator"]:::simulatorStyle
    Plotting["Visualization/Plotting"]:::plottingStyle
    Critique["Critique and Evaluation"]:::critiqueStyle
    Tools["Tools/Miscellaneous"]:::toolsStyle
    Mixins["Mixins (Common Utilities)"]:::mixinsStyle
    Gurobi["Gurobi (ILP Solver)"]:::externalStyle
    CCPhylo["CCPhylo (Fast Methods)"]:::externalStyle

    %% Main Pipeline Flow
    RawData -->|"processes"| Preproc
    Preproc -->|"generates"| Data
    Data -->|"feeds"| Solver
    Data -->|"feeds"| Simulator
    Solver -->|"reconstructs"| Plotting
    Simulator -->|"benchmarks"| Plotting
    Plotting -->|"evaluated by"| Critique
    Critique -->|"feedback"| Preproc

    %% External Dependencies Connections
    Solver ---|"optional"| Gurobi
    Solver ---|"optional"| CCPhylo

    %% Utility Connections (dotted lines indicate auxiliary usage)
    Preproc ---|"uses"| Tools
    Data ---|"uses"| Tools
    Solver ---|"uses"| Tools
    Simulator ---|"uses"| Tools
    Plotting ---|"uses"| Tools
    Critique ---|"uses"| Tools

    Preproc ---|"uses"| Mixins
    Data ---|"uses"| Mixins
    Solver ---|"uses"| Mixins
    Simulator ---|"uses"| Mixins
    Plotting ---|"uses"| Mixins
    Critique ---|"uses"| Mixins

    %% Click Events
    click Preproc "https://github.com/yoseflab/cassiopeia/tree/master/cassiopeia/preprocess"
    click Data "https://github.com/yoseflab/cassiopeia/tree/master/cassiopeia/data"
    click Solver "https://github.com/yoseflab/cassiopeia/tree/master/cassiopeia/solver"
    click Simulator "https://github.com/yoseflab/cassiopeia/tree/master/cassiopeia/simulator"
    click Plotting "https://github.com/yoseflab/cassiopeia/tree/master/cassiopeia/plotting"
    click Critique "https://github.com/yoseflab/cassiopeia/tree/master/cassiopeia/critique"
    click Tools "https://github.com/yoseflab/cassiopeia/tree/master/cassiopeia/tools"
    click Mixins "https://github.com/yoseflab/cassiopeia/tree/master/cassiopeia/mixins"

    %% Styles
    classDef preprocessStyle fill:#cce5ff,stroke:#004085,stroke-width:2px;
    classDef dataStyle fill:#d4edda,stroke:#155724,stroke-width:2px;
    classDef solverStyle fill:#fff3cd,stroke:#856404,stroke-width:2px;
    classDef simulatorStyle fill:#f8d7da,stroke:#721c24,stroke-width:2px;
    classDef plottingStyle fill:#d1ecf1,stroke:#0c5460,stroke-width:2px;
    classDef critiqueStyle fill:#ffeeba,stroke:#856404,stroke-width:2px;
    classDef toolsStyle fill:#c3e6cb,stroke:#155724,stroke-width:2px;
    classDef mixinsStyle fill:#e2e3e5,stroke:#6c757d,stroke-width:2px;
    classDef externalStyle fill:#ffffff,stroke:#6f42c1,stroke-dasharray: 5, 5,stroke-width:2px;
```
