# bmglab/histoparser architecture

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

- Interactive diagram: https://gitdiagram.com/bmglab/histoparser
- Repository: https://github.com/bmglab/histoparser

## Overview

##### Project Type & Purpose
- This is not a typical full-stack web application but rather a scientific/analytical pipeline tool designed to process histopathology images.
- The purpose is to process whole slide images, extract quantitative morphological and textural features, and perform clustering analysis (along with MRI integration), using several machine learning and image analysis libraries.

##### Analyzing the File Structure
- Top-level folders such as Sampling, Feature_Extraction, Feature_selection, Clustering, MR, and HistoandMR indicate a modular pipeline architecture.
- There are specific directories for outputs (Outputspdf, output, output_density) as well as directories for slides and cluster result analysis. This shows that the pipeline produces intermediate and final data artifacts.
- The presence of support files like requirements.txt and README.md ensures that dependencies and installation steps are well-documented.

##### Key Architectural Components
A. Tissue Sampling Module:
- Module: Sampling/sampling.py
- Function: Extracts tissue patches from whole slide images and outputs the patches (saved in slides/).
B. Feature Extraction & Aggregation:
- Modules: Feature_Extraction/feature_extraction_density.py and Feature_Extraction/mean_features.py
- Function: Processes the extracted patches to compute per-image and aggregated features.
- Outputs: CSV files in output_density (and possibly in output) containing mean and density features.
C. Feature Selection:
- Module: Feature_selection/feature_selection.py
- Function: Selects discriminative features based on aggregated feature data. The output is used later for clustering.
D. Clustering & Visualization:
- Module: Clustering/clustering_selected_features.py
- Function: Uses the selected features to run clustering algorithms (e.g., hierarchical clustering) and generate visualizations (dendrograms, PCA, UMAP, heatmaps) which are stored in Outputspdf.
E. MRI Radiomic Processing:
- Module: MR/mr_feature_list.py along with related files in the MR directory (and the CaPTk output files)
- Function: Processes MRI radiomic features and computes additional imaging measures.
F. Histopathology-MRI Integration:
- Module: HistoandMR/all_features.py
- Function: Combines histopathology features with MRI features for integrated, multimodal analysis.
G. Post-Analysis & Result Interpretation:
- Modules under Cluster_result_analysis may include further statistical or clinical integration assessments.

- Connecting Artifacts: Show how CSV files, image outputs (slides), and visualizations (PDF outputs in Outputspdf) move between the components.
- Architectural Patterns: Emphasize the linear and modular pipeline nature. You might choose a flowchart style that starts with raw data and flows through successive processing stages.
- Technologies and Dependencies: Add annotations mentioning the Python libraries (e.g., numpy, pandas, sklearn, umap-learn, histomicstk, etc.) that underpin each module. You could also highlight specific tools like OpenSlide for sampling and CaPTk for MRI feature extraction.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Top-level Inputs
    A["WSI Input"]:::input

    %% Tissue Sampling Module
    B["Sampling Module"]:::module
    A -->|"WholeSlide\nImage Data"| B
    B -->|"Tissue Patches"| C["Slides Data (slides/)"]:::datastore

    %% Feature Extraction & Aggregation Subgraph
    subgraph "Feature Extraction & Aggregation"
        D["Density Extraction"]:::module
        E["Mean Extraction"]:::module
    end
    C -->|"Patch Data"| D
    C -->|"Patch Data"| E
    D --> F["Aggregated Features (CSV: output/, output_density/)"]:::datastore
    E --> F

    %% Feature Selection Module
    G["Feature Selection"]:::module
    F -->|"Aggregated Features CSV"| G

    %% Clustering & Visualization Module
    H["Clustering & Visualization"]:::module
    G -->|"Selected Features CSV"| H
    H -->|"Visualization PDFs"| I["Visualizations (PDFs: Outputspdf/)"]:::datastore

    %% MRI Radiomics Processing Module
    J["MRI Radiomics Module"]:::module
    %% (Assume MRI data is provided to the module)
    J -->|"MRI Feature Data"| K["MRI Data Store (MR/)"]:::datastore

    %% Histopathology-MRI Integration Module
    L["Histopathology-MRI Integration"]:::module
    %% Aggregated histopathology features join with MRI features
    F ---|"Histopathology Features"| L
    J ---|"MRI Radiomic Features"| L
    L -->|"Integrated Feature CSV"| M["Integrated Results (HistoandMR/)"]:::datastore

    %% Post-Analysis & Result Interpretation Module
    N["Post-Analysis & Result Interpretation"]:::module
    I -->|"Cluster Visualization PDFs"| N
    M -->|"Integrated Analysis CSV"| N

    %% Styles
    classDef module fill:#ADD8E6,stroke:#000,stroke-width:2px;
    classDef datastore fill:#90EE90,stroke:#000,stroke-width:2px;
    classDef input fill:#FFD700,stroke:#000,stroke-width:2px;

    %% Click Events
    click B "https://github.com/bmglab/histoparser/blob/main/Sampling/sampling.py"
    click D "https://github.com/bmglab/histoparser/blob/main/Feature_Extraction/feature_extraction_density.py"
    click E "https://github.com/bmglab/histoparser/blob/main/Feature_Extraction/mean_features.py"
    click G "https://github.com/bmglab/histoparser/blob/main/Feature_selection/feature_selection.py"
    click H "https://github.com/bmglab/histoparser/blob/main/Clustering/clustering_selected_features.py"
    click J "https://github.com/bmglab/histoparser/blob/main/MR/mr_feature_list.py"
    click L "https://github.com/bmglab/histoparser/blob/main/HistoandMR/all_features.py"
    click N "https://github.com/bmglab/histoparser/tree/main/Cluster_result_analysis/"
```
