# gt-lit-lab/funroi architecture

> Architecture diagram of the GitHub repository gt-lit-lab/funroi, 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/gt-lit-lab/funroi
- Repository: https://github.com/gt-lit-lab/funroi

## Overview

##### Main Components
- Core Package – The funROI module (located in the “funROI” directory) is structured into several submodules:
- Analysis Module (funROI/analysis): Contains functions for effect estimation, generating fROIs (froi_gen), computing spatial correlation (spcorr), creating parcels (parcels_gen), and calculating spatial overlaps. These components form the algorithmic backbone processing the data.
- First-Level Processing Module (funROI/first_level): Provides functions for preliminary analysis steps via wrappers for nilearn and SPM, as well as utilities to manage first-level data processing.
- Datasets Module (funROI/datasets): Handles dataset-specific operations (e.g., reading HCP data) which are critical for adapting to different fMRI datasets.
- Other Supporting Modules: Scripts like contrast.py, froi.py, parcels.py, settings.py, and utility scripts (funROI/utils.py) complete the package by providing configuration and high-level API calls.

- Documentation – The “doc” directory includes Sphinx configuration, API documentation, examples (like demo.ipynb), and guides that further explain the design and usage of the toolbox. Although it is not part of the runtime architecture, documenting the system is essential for maintainability.

##### Relationships and Interactions
- Data Flow:
- Input fMRI data is first preprocessed using tools provided in the first_level module. Preprocessing results feed into higher-level analysis.
- The datasets module provides interfaces to load and format the fMRI data.
- Processed data is then handed off to the analysis module where parcel generation, fROI definition, effect estimation, spatial correlation, and overlap calculations occur.
- Utility and Configuration:
- The settings and utils modules are used across other components for common configurations and helper functions, ensuring consistency across the toolbox.
- External Dependencies:

##### Important Architectural Patterns and Design Principles
- Modular Design: The clear separation of functionality into data handling (datasets), preprocessing (first_level), and analysis (analysis) shows a modular approach. This makes it easy to update parts of the pipeline without affecting the rest.
- Reusability: The use of utility modules and settings ensures that common functions and configuration details are not duplicated.
- Pipeline Flow: The design follows a pipeline-like structure from data ingestion to final analysis, which is key for fMRI analysis workflows.
- Extensibility: The separation into distinct modules (e.g., multiple choices for first-level processing) hints at a pluggable architecture, allowing integration of additional processing methods if needed.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Input Layer
    fMRI["Input fMRI Data"]:::input

    %% Datasets Module Subgraph
    subgraph "Datasets Module"
        DS_HCP["hcp.py"]:::component
        click DS_HCP "https://github.com/gt-lit-lab/funroi/blob/main/funROI/datasets/hcp.py"
    end

    %% First-Level Processing Module Subgraph
    subgraph "First-Level Processing Module"
        FL_Nilearn["nilearn.py"]:::component
        click FL_Nilearn "https://github.com/gt-lit-lab/funroi/blob/main/funROI/first_level/nilearn.py"
        FL_SPM["spm.py"]:::component
        click FL_SPM "https://github.com/gt-lit-lab/funroi/blob/main/funROI/first_level/spm.py"
        FL_Utils["utils.py"]:::component
        click FL_Utils "https://github.com/gt-lit-lab/funroi/blob/main/funROI/first_level/utils.py"
    end

    %% Analysis Module Subgraph
    subgraph "Analysis Module (fROI Definition, Effect Estimation, Spatial Metrics)"
        A_Effect["effect.py"]:::component
        click A_Effect "https://github.com/gt-lit-lab/funroi/blob/main/funROI/analysis/effect.py"
        A_froiGen["froi_gen.py"]:::component
        click A_froiGen "https://github.com/gt-lit-lab/funroi/blob/main/funROI/analysis/froi_gen.py"
        A_Overlap["overlap.py"]:::component
        click A_Overlap "https://github.com/gt-lit-lab/funroi/blob/main/funROI/analysis/overlap.py"
        A_ParcelsGen["parcels_gen.py"]:::component
        click A_ParcelsGen "https://github.com/gt-lit-lab/funroi/blob/main/funROI/analysis/parcels_gen.py"
        A_Spcorr["spcorr.py"]:::component
        click A_Spcorr "https://github.com/gt-lit-lab/funroi/blob/main/funROI/analysis/spcorr.py"
        A_Utils["utils.py"]:::component
        click A_Utils "https://github.com/gt-lit-lab/funroi/blob/main/funROI/analysis/utils.py"
    end

    %% Utility/Settings Subgraph
    subgraph "Utility/Settings"
        US_Settings["settings.py"]:::component
        click US_Settings "https://github.com/gt-lit-lab/funroi/blob/main/funROI/settings.py"
        US_Utils["utils.py"]:::component
        click US_Utils "https://github.com/gt-lit-lab/funroi/blob/main/funROI/utils.py"
        US_Contrast["contrast.py"]:::component
        click US_Contrast "https://github.com/gt-lit-lab/funroi/blob/main/funROI/contrast.py"
        US_fROI["froi.py"]:::component
        click US_fROI "https://github.com/gt-lit-lab/funroi/blob/main/funROI/froi.py"
        US_Parcels["parcels.py"]:::component
        click US_Parcels "https://github.com/gt-lit-lab/funroi/blob/main/funROI/parcels.py"
    end

    %% Documentation & Examples Subgraph
    subgraph "Documentation & Examples"
        DOC_Makefile["Makefile"]:::component
        click DOC_Makefile "https://github.com/gt-lit-lab/funroi/tree/main/doc/Makefile"
        DOC_Req["requirements.txt"]:::component
        click DOC_Req "https://github.com/gt-lit-lab/funroi/blob/main/doc/requirements.txt"
        DOC_API["doc/source/api"]:::component
        click DOC_API "https://github.com/gt-lit-lab/funroi/tree/main/doc/source/api"
        DOC_Examples["doc/source/examples"]:::component
        click DOC_Examples "https://github.com/gt-lit-lab/funroi/tree/main/doc/source/examples"
    end

    %% External Libraries
    ExternalNilearn["nilearn Library"]:::external
    ExternalSPM["SPM Library"]:::external

    %% Pipeline Flow Connections
    fMRI -->|"raw_data"| DS_HCP
    DS_HCP -->|"formatted_data"| FL_Nilearn
    FL_Nilearn -->|"preprocessed_data"| A_Effect

    %% External Dependencies to First-Level Processing
    ExternalNilearn -->|"dependency"| FL_Nilearn
    ExternalSPM -->|"dependency"| FL_SPM

    %% Utility/Settings Integration (dashed connections)
    US_Settings ---|"config"| DS_HCP
    US_Settings ---|"config"| FL_Nilearn
    US_Settings ---|"config"| A_Effect
    US_Settings ---|"config"| FL_SPM

    %% Documentation supports key modules
    DOC_Makefile ---|"guides"| DS_HCP
    DOC_Makefile ---|"guides"| A_Effect

    %% Class Styles
    classDef input fill:#ffe0b2,stroke:#e65100,stroke-width:2px;
    classDef component fill:#bbdefb,stroke:#0d47a1,stroke-width:2px;
    classDef external fill:#c8e6c9,stroke:#2e7d32,stroke-width:2px;
```
