# minjikimlab/miasort architecture

> Architecture diagram of the GitHub repository minjikimlab/miasort, 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/minjikimlab/miasort
- Repository: https://github.com/minjikimlab/miasort

## Overview

##### Project Type and Purpose
- MIA-Sort is a bioinformatics Python library designed for the efficient analysis and sorting of multiplex chromatin interaction data. It implements several algorithms (e.g., abc_sort, multiple_sort, unlimited_multiple_sort) to process genomic region information and generate plots, histograms, and CSV reports. It is used in the context of scientific analysis (as described in the related research paper) and leverages external tools like bedtools for genomic operation support.

##### Analyzing the File Structure
- Top-Level Files and Directories:
- “miasort/”: Contains the core Python library modules (e.g., helper, histogram, miasort, plot, records, sort, start). This is the heart of the system where the main processing and plotting functions live.
- “bin/”: Includes various shell scripts and C++ source files for testing, installation, debugging, and timing. These scripts help in executing different workflows, testing external tools (like bedtools) and benchmarking performance.
- “tests/”: Contains several Python scripts for testing the library’s sorting functions under different scenarios (with and without plots, with histogram options) and for various input data configurations.
- “data/”: Provides sample data files (e.g., .bedte, .domains, .region) used as input for the sorting pipelines.
- “imgs/”: Stores sample plot images generated by the library.
- Configuration files (like requirements.txt and setup.py) support library installation and dependency management.

##### Components and Their Relationships
- External Dependencies:
- “bedtools” is a key prerequisite; it is installed externally (e.g., via conda/mamba) and used by some of the shell scripts and possibly through calls within the Python modules.
- Core Library (miasort):
- This module encapsulates key functions like abc_sort, multiple_sort, and unlimited_multiple_sort that deal with processing genomic regions, sorting chromatin complexes, and generating visualizations (plots/histograms).
- It interacts with sub-modules like “plot” (for visualization) and “histogram” (for statistical summaries).
- Command Line Interface / Utility Scripts:
- The “bin/” folder contains several scripts for quickly running tests, debugging, timing, and even compiling helper tools (e.g., C++ files for converting specific data formats). These are meant to facilitate operations on the command line and often orchestrate the use of the miasort library and bedtools.
- Testing and Validation:
- The “tests/” directory has specialized scripts that invoke various miasort functions with predefined input files (from “data/”) to validate and profile different sorting and plotting functionality.
- Data Flow:
- Input data (from “data/”) feeds into core functions in miasort.
- The library processes these inputs, potentially calls bedtools (via the scripts or internal calls), and outputs results (CSV files, plots saved to “imgs/” or specified output directories).

##### Architectural Patterns & Design Principles
- Modular Design: There is a clear separation between the core functionality (in miasort), the shell scripts (for installation, debugging, performance testing), and the demonstration/validation via tests.
- Layered Architecture: The application can be conceptually divided into:
- Data Input / External Tools Layer: User input files and external bedtools.
- Core Processing Layer: The miasort Python package handling algorithms for sorting and visualization.
- Presentation/Output Layer: Creation of plots, CSV reports, and histograms.
- Extensibility: The modular setup (with separate functions for different sorting schemes) allows for future additions or customizations without major overhauls.

- Clear Labels: Each component (e.g., “Data Input”, “miasort Library – Sorting & Plotting”, “CLI & Utility Scripts”, “Tests”, and “External Dependencies: Bedtools”) should be clearly labeled.
- Core processes (modules within miasort),
- External tools (e.g., bedtools),
- Utility/CLI scripts,
- Testing components.
- Notes on Technology: Briefly mention any specific technology used at each component (for example, Python for miasort operations, shell scripting for automation and calling bedtools, and Matplotlib for plotting).

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Data Input Layer
    subgraph "Data Input"
        Data["Data Directory (input files)"]:::data
    end

    %% Core Processing Layer: MIA-Sort Library Modules
    subgraph "Core Processing Layer (MIA-Sort Library)"
        MIA["MIA-Sort Library"]:::core
        M1["miasort.py"]:::core
        H1["helper.py"]:::core
        S1["sort.py"]:::core
        P1["plot.py"]:::core
        H2["histogram.py"]:::core
        R1["records.py"]:::core
        ST1["start.py"]:::core
    end

    %% CLI and Utility Scripts Layer
    subgraph "CLI & Utility Scripts"
        CLI["CLI & Utility Scripts"]:::cli
        RSH["run.sh"]:::cli
        ISH["install.sh"]:::cli
        DBG["debug.py"]:::cli
        CPP["pairs2complexes.cpp"]:::cli
    end

    %% Testing Suite Layer
    subgraph "Testing Suite"
        TEST["Testing Suite"]:::test
        T1["test_abc_sort.py"]:::test
        T2["gl_multiple_sorting_with_plots_GM12878_SPRITE_hg38.py"]:::test
    end

    %% Output / Visualization Layer
    subgraph "Output/Visualization"
        OUTPUT["Output (Plots/CSV)"]:::output
        IMGS["imgs/ Directory (Plot Images)"]:::output
    end

    %% External Dependencies Layer
    subgraph "External Dependencies"
        BED["Bedtools (External)"]:::external
        BINTERSECT["bedtools-intersect.sh"]:::external
        BTEST["bedtools-testing-full.sh"]:::external
    end

    %% Connections between Layers
    Data -->|"feeds"| MIA
    MIA -->|"produces"| OUTPUT
    MIA -->|"invoked by"| TEST
    CLI -->|"orchestrates"| MIA
    CLI -->|"calls"| BED
    IMGS -->|"part of"| OUTPUT

    %% Internal connections inside Core Processing Layer
    MIA --> M1
    MIA --> H1
    MIA --> S1
    MIA --> P1
    MIA --> H2
    MIA --> R1
    MIA --> ST1

    %% CLI Sub-components
    CLI --> RSH
    CLI --> ISH
    CLI --> DBG
    CLI --> CPP

    %% External Dependencies Sub-components
    BED --> BINTERSECT
    BED --> BTEST

    %% Testing Suite Sub-components
    TEST --> T1
    TEST --> T2

    %% Click Events for Component Mapping
    click Data "https://github.com/minjikimlab/miasort/tree/main/data/"
    click M1 "https://github.com/minjikimlab/miasort/blob/main/miasort/miasort.py"
    click H1 "https://github.com/minjikimlab/miasort/blob/main/miasort/helper.py"
    click S1 "https://github.com/minjikimlab/miasort/blob/main/miasort/sort.py"
    click P1 "https://github.com/minjikimlab/miasort/blob/main/miasort/plot.py"
    click H2 "https://github.com/minjikimlab/miasort/blob/main/miasort/histogram.py"
    click R1 "https://github.com/minjikimlab/miasort/blob/main/miasort/records.py"
    click ST1 "https://github.com/minjikimlab/miasort/blob/main/miasort/start.py"
    click RSH "https://github.com/minjikimlab/miasort/blob/main/bin/run.sh"
    click ISH "https://github.com/minjikimlab/miasort/blob/main/bin/install.sh"
    click DBG "https://github.com/minjikimlab/miasort/blob/main/bin/debug.py"
    click CPP "https://github.com/minjikimlab/miasort/blob/main/bin/pairs2complexes.cpp"
    click T1 "https://github.com/minjikimlab/miasort/blob/main/tests/test_abc_sort.py"
    click T2 "https://github.com/minjikimlab/miasort/blob/main/tests/gl_multiple_sorting_with_plots_GM12878_SPRITE_hg38.py"
    click BINTERSECT "https://github.com/minjikimlab/miasort/blob/main/bin/bedtools-intersect.sh"
    click BTEST "https://github.com/minjikimlab/miasort/blob/main/bin/bedtools-testing-full.sh"
    click IMGS "https://github.com/minjikimlab/miasort/tree/main/imgs/"

    %% Styling for Visual Distinction
    classDef data fill:#ffcccc,stroke:#cc0000,stroke-width:2px;
    classDef core fill:#ccffcc,stroke:#006600,stroke-width:2px;
    classDef cli fill:#cce5ff,stroke:#003366,stroke-width:2px;
    classDef test fill:#ffe6cc,stroke:#cc6600,stroke-width:2px;
    classDef output fill:#e6ffe6,stroke:#006600,stroke-width:2px;
    classDef external fill:#f9e79f,stroke:#b7950b,stroke-width:2px;
```
