# bennordick/hiloop architecture

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

- Interactive diagram: https://gitdiagram.com/bennordick/hiloop
- Repository: https://github.com/bennordick/hiloop

## Overview

##### Project type and purpose
- HiLoop is an open-source toolbox consisting of standalone Python scripts.

##### File structure
- Top-level CLI scripts (entry points):
– countmotifs.py, sampledpvalue.py, examplemotifs.py, subnetwork.py, multistability.py, summarizemultistability.py, rendergraph.py
- Core helper modules (libraries):
– liuwangcycles.py (cycle detection), identityholder.py (data structures), load*.py (I/O utilities), minimumtopologies.py, permutenetwork.py, etc.
- Data files:
– .gxml network definitions (e.g. trrust.gxml), example networks, and SCC‐extracted versions.
- Configuration:
– requirements.txt, requirements_modeling.txt for dependency management.

##### README for additional insights
- Scripts are executed in two distinct environments:
– PyPy (fast pure-Python code for motif counting, sampling, rendering)
– CPython (required for modeling/simulation via Tellurium)
- Data flow is file‐based: GraphML → processing → CSV/JSON/PNG/GraphML outputs.

##### Main components
a. CLI Layer (User Interface)
– Each script is a separate CLI command.
b. Core Analysis Engine
– Cycle detection (liuwangcycles), motif enumeration (minimumtopologies), randomization (permutenetwork), statistical sampling (sampledpvalue).
c. Modeling Engine
– Tellurium‐based simulation invoked by multistability.py and summarizemultistability.py.
d. Data I/O
– GraphML loader/saver (loadadjmatrix, loadcitedtsv, NetworkX), CSV/JSON exporters, GraphML writers.
e. Rendering Engine
f. External Dependencies
– NetworkX, Graphviz, SciPy, Tellurium, PyPy/CPython runtime.
g. Data Artifacts
– Input networks (.gxml), extracted subnetworks, output images, CSV/JSON reports.

##### Relationships and interactions
- Core Analysis Engine ↔ Data I/O (reads .gxml via NetworkX, writes results)
- Core Analysis Engine → Modeling Engine (only in multistability workflows)
- Modeling Engine ↔ Tellurium and CPython environment
- Rendering Engine ↔ Graphviz external service
- Data flow: .gxml files → analysis → motif counts/ensembles → CSV/JSON → visualizations

##### Architectural patterns and design principles
- Modular CLI commands share a common core library (promotes code reuse).
- Separation of concerns: pure-analysis vs. simulation (different Python runtimes).
- File-based pipeline: easy chaining of scripts with intermediate artifacts.
- Extensibility points: adding new motif‐finding strategies or new simulation analyses.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% CLI Layer
    subgraph "CLI Layer"
        style CLI fill:#D0E8FF,stroke:#0366D6
        CM["countmotifs.py"]:::cli
        SP["sampledpvalue.py"]:::cli
        EM["examplemotifs.py"]:::cli
        SN["subnetwork.py"]:::cli
        MS["multistability.py"]:::cli
        SR["summarizemultistability.py"]:::cli
        RG["rendergraph.py"]:::cli
        CS["countandsample.py"]:::cli
    end

    %% Core Analysis Engine
    subgraph "Core Analysis Engine"
        style Core fill:#DFF5E1,stroke:#28A745
        LC["liuwangcycles.py"]:::core
        MT["minimumtopologies.py"]:::core
        PN["permutenetwork.py"]:::core
        IH["identityholder.py"]:::core
    end

    %% Data I/O
    subgraph "Data I/O"
        style IO fill:#FFF5CC,stroke:#FFD33D
        LA["loadadjmatrix.py"]:::dataio
        LC2["loadcitedtsv.py"]:::dataio
    end

    %% Rendering Engine
    RGEng["Rendering Engine\n(rendergraph + Graphviz)"]:::render

    %% Modeling Engine
    ME["Modeling Engine\n(multistability.py, Tellurium)"]:::model

    %% External Dependencies
    subgraph "External Services"
        style Ext fill:#F0F0F0,stroke:#6A737D
        NX["NetworkX"]:::external
        GV["Graphviz"]:::external
        TL["Tellurium"]:::external
        PY["PyPy/CPython"]:::external
    end

    %% Data Artifacts
    subgraph "Data Artifacts"
        style Data fill:#FFF0F0,stroke:#E36209
        GXML[".gxml Files"]:::data
        CSV["CSV/JSON Outputs"]:::data
        IMG["PNG/SVG Outputs"]:::data
    end

    %% Connections
    CM -->|calls| LC
    SP -->|calls| PN
    EM -->|calls| MT
    SN -->|calls| LC
    MS -->|calls| ME
    SR -->|calls| ME
    RG -->|calls| RGEng
    CM -->|reads/writes| LA
    SP -->|reads/writes| LA
    EM -->|reads/writes| LA
    SN -->|reads/writes| LC2
    MS -->|reads inputs| GXML
    MS -->|writes outputs| CSV
    RGEng -->|reads| GXML
    RGEng -->|writes| IMG
    ME -->|uses| TL
    ME -->|runs on| PY
    RGEng -->|runs on| PY
    LC -->|utilizes| NX
    RGEng -->|utilizes| GV

    %% Data flow
    GXML -->|input to| CM
    GXML -->|input to| SP
    IMG -->|produced by| RGEng
    CSV -->|produced by| SP

    %% Click Events
    click CM "https://github.com/bennordick/hiloop/blob/master/countmotifs.py"
    click SP "https://github.com/bennordick/hiloop/blob/master/sampledpvalue.py"
    click EM "https://github.com/bennordick/hiloop/blob/master/examplemotifs.py"
    click SN "https://github.com/bennordick/hiloop/blob/master/subnetwork.py"
    click MS "https://github.com/bennordick/hiloop/blob/master/multistability.py"
    click SR "https://github.com/bennordick/hiloop/blob/master/summarizemultistability.py"
    click RG "https://github.com/bennordick/hiloop/blob/master/rendergraph.py"
    click CS "https://github.com/bennordick/hiloop/blob/master/countandsample.py"
    click LC "https://github.com/bennordick/hiloop/blob/master/liuwangcycles.py"
    click MT "https://github.com/bennordick/hiloop/blob/master/minimumtopologies.py"
    click PN "https://github.com/bennordick/hiloop/blob/master/permutenetwork.py"
    click IH "https://github.com/bennordick/hiloop/blob/master/identityholder.py"
    click LA "https://github.com/bennordick/hiloop/blob/master/loadadjmatrix.py"
    click LC2 "https://github.com/bennordick/hiloop/blob/master/loadcitedtsv.py"

    %% Styles
    classDef cli fill:#D0E8FF,stroke:#0366D6,shape:rect
    classDef core fill:#DFF5E1,stroke:#28A745,shape:rect
    classDef dataio fill:#FFF5CC,stroke:#FFD33D,shape:rect
    classDef render fill:#FFE8CC,stroke:#E36209,shape:rect
    classDef model fill:#FFE8CC,stroke:#E36209,shape:rect
    classDef external fill:#F0F0F0,stroke:#6A737D,shape:cloud
    classDef data fill:#FFF0F0,stroke:#E36209,shape:cylinder
```
