# bihealth/digestiflow-demux architecture

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

- Interactive diagram: https://gitdiagram.com/bihealth/digestiflow-demux
- Repository: https://github.com/bihealth/digestiflow-demux

## Overview

##### Main Components
- CLI Interface & Configuration: Represent the program’s entry point (via __main__.py) which reads user-specified command-line arguments and configuration files (e.g., ~/.digestiflowrc.toml).
- Configuration Loader: A component responsible for processing the TOML configuration file. This is essential since settings like API URL, token, demultiplexing options, and cluster execution parameters are defined here.
- Wrapper Components: Illustrate separate components for each of the wrapped tools:
○ bcl2fastq (and its alternative variant)
○ FastQC
○ MultiQC
○ Picard (with its variants for basecalls_to_fastq and extract_barcodes)
- Logging & Exception Handling: Include a dedicated error-handling component (exceptions.py) and logging subsystem that captures and records each step’s outcome.
- Testing and Versioning Components: Though secondary for the execution flow, note the presence of a tests directory and versioning tools (versioneer.py, _version.py) which support maintenance and quality assurance.

##### Relationships and Interactions
- A feedback loop from the logging/exception systems to the main execution flow to denote error reporting and status management.

##### Architectural Patterns and Design Principles
- Modular Design: Highlight that each component (API client, workflow engine, wrappers) is clearly separated by directories and Python modules.
- Pipeline Orchestration: Emphasize the role of Snakemake in controlling the flow of tasks, which maps to a typical workflow management pattern.
- Extensibility: Note that the wrappers for each tool (found in the "wrappers" directory) demonstrate a plug-in-like system; these could be expanded or modified independently.
- Configuration-Driven Behavior: Point out that the heavy reliance on a common configuration file (with REST API and demux parameters) ensures that changes in external settings do not require code changes.

##### Relevant Technologies, Frameworks, and Libraries
- Python as the primary programming language.
- Snakemake for pipeline management.
- External bioinformatics tools (bcl2fastq, FastQC, MultiQC, Picard) that are wrapped for execution.
- REST API interactions to interface with Digestiflow’s Web UI.
- Cluster execution support via DRMAA and jobscript parameters for HPC environments.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Core Components
    subgraph "Core Components"
        CLI("CLI Interface & Configuration"):::cli
        Config("Configuration Loader"):::config
        API("API Client Module"):::api
        Logging("Logging & Exception Handling"):::logging
        CLI -->|"reads_config"| Config
        CLI -->|"initiates_API"| API
    end

    %% Workflow Orchestration Subsystem
    subgraph "Workflow Orchestration"
        Snakemake("Snakemake Support"):::workflow
        WFMan("Workflow Manager"):::workflow
        Snakemake -->|"prepares_workflow"| WFMan
    end

    CLI -->|"starts_workflow"| Snakemake

    %% Tool Wrappers Subsystem
    subgraph "Tool Wrappers"
        BCL("Tool Wrapper: bcl2fastq"):::wrapper
        BCL2("Tool Wrapper: Alternative_bcl2fastq"):::wrapper
        FastQC("Tool Wrapper: FastQC"):::wrapper
        MultiQC("Tool Wrapper: MultiQC"):::wrapper
        Picard1("Tool Wrapper: Picard_(basecalls_to_fastq)"):::wrapper
        Picard2("Tool Wrapper: Picard_(extract_barcodes)"):::wrapper
    end

    WFMan -->|"triggers"| BCL
    WFMan -->|"triggers"| BCL2
    WFMan -->|"triggers"| FastQC
    WFMan -->|"triggers"| MultiQC
    WFMan -->|"triggers"| Picard1
    WFMan -->|"triggers"| Picard2

    BCL -->|"reports_result"| API
    BCL2 -->|"reports_result"| API
    FastQC -->|"reports_result"| API
    MultiQC -->|"reports_result"| API
    Picard1 -->|"reports_result"| API
    Picard2 -->|"reports_result"| API

    %% Logging Feedback Loop
    API -->|"errors_logged"| Logging
    WFMan -->|"errors_logged"| Logging
    Logging -->|"alerts"| CLI

    %% Support Components
    subgraph "Support Components"
        Tests("Testing Suite"):::support
        Ver1("Version Component: _version.py"):::support
        Ver2("Version Component: versioneer.py"):::support
    end

    %% Click Events
    click CLI "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/__main__.py"
    click API "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/api_client.py"
    click Snakemake "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/snakemake_support.py"
    click WFMan "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/workflow.py"
    click BCL "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/wrappers/bcl2fastq/wrapper.py"
    click BCL2 "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/wrappers/bcl2fastq2/wrapper.py"
    click FastQC "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/wrappers/fastqc/wrapper.py"
    click MultiQC "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/wrappers/multiqc/wrapper.py"
    click Picard1 "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/wrappers/picard/basecalls_to_fastq/wrapper.py"
    click Picard2 "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/wrappers/picard/extract_barcodes/wrapper.py"
    click Logging "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/exceptions.py"
    click Tests "https://github.com/bihealth/digestiflow-demux/tree/master/tests"
    click Ver1 "https://github.com/bihealth/digestiflow-demux/blob/master/digestiflow_demux/_version.py"
    click Ver2 "https://github.com/bihealth/digestiflow-demux/blob/master/versioneer.py"

    %% Styles
    classDef cli fill:#FFD700,stroke:#333,stroke-width:2px;
    classDef config fill:#ADFF2F,stroke:#333,stroke-width:2px;
    classDef api fill:#87CEEB,stroke:#333,stroke-width:2px;
    classDef workflow fill:#DA70D6,stroke:#333,stroke-width:2px;
    classDef wrapper fill:#FF6347,stroke:#333,stroke-width:2px;
    classDef logging fill:#FFA07A,stroke:#333,stroke-width:2px;
    classDef support fill:#98FB98,stroke:#333,stroke-width:2px;
```
