# tplinderoth/popgenomicstools architecture

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

- Interactive diagram: https://gitdiagram.com/tplinderoth/popgenomicstools
- Repository: https://github.com/tplinderoth/popgenomicstools

## Overview

##### Project type and purpose
- This is not a web or mobile app but a CLI “toolkit” of population‐genetics programs. Each .cpp or script corresponds to a standalone command‐line utility (e.g., relateStats, dxyWindow, betaAFOutlier.R, selkit, etc.). The purpose is to perform various population‐genetic and selection‐analysis tasks on input files (pedigrees, relatedness matrices, allele‐frequency files, VCFs, etc.).

##### File structure
- Top‐level files:
- Makefile – build orchestration for all C++ tools
- LICENSE, .gitignore, README.md – project metadata
- Matrix.h, StatDist.cpp/h – a core numerical library for matrix operations and statistical distributions
- selkit.cpp/h – core of the selkit toolbox
- Multiple “Window” .cpp tools: dxyWindow.cpp, fstWindow.cpp, hetWindow.cpp, ihsWindow.cpp, xpehhWindow.cpp
- stand‐alone utilities: relateStats.cpp/h, betaAFOutlier.R, pafAlleles.cpp, ngsMisc.pl
- No “frontend” or web‐service directories. Everything is invoked from the CLI.

##### Extract architecture insights from the README
- All C++ programs are compiled via Makefile with g++ -O3.
- The R and Perl scripts are interpreted, not compiled.
- selkit depends on bgzip‐indexed VCFs; betaAFOutlier.R uses Rscript.
- Inputs and outputs are file‐based; there are no network calls or persistent services.

##### Elements
- Makefile → Compiler → Executables
- Core Lib → C++ Tools
- selkit Lib → selkit Executable
- Input Files → Tools → Output Files
- C++ executables in a third
- Scripts (R/Perl) in a fourth
- Data stores (input/output files) as parallelograms

##### Detail without overthinking
- Every executable and script as its own component
- Shared dependencies explicitly (e.g., which tools use Matrix.h)
- Runtime environment (g++ toolchain, R, Perl)
- File types each tool consumes and produces

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Build Stage
    subgraph "Build Stage"
        Makefile["Makefile"]:::build
        Compiler["g++ Compiler"]:::build
    end

    %% Core Library Layer
    subgraph "Core Library"
        Matrix["Matrix.h"]:::core
        StatDistCPP["StatDist.cpp"]:::core
        StatDistH["StatDist.h"]:::core
    end

    %% selkit Library
    subgraph "selkit Library"
        selkitCPP["selkit.cpp"]:::selkit
        selkitH["selkit.h"]:::selkit
    end

    %% C++ Executables
    subgraph "C++ Executables"
        relateStats["relateStats"]:::cppExe
        dxyWindow["dxyWindow"]:::cppExe
        fstWindow["fstWindow"]:::cppExe
        hetWindow["hetWindow"]:::cppExe
        ihsWindow["ihsWindow"]:::cppExe
        xpehhWindow["xpehhWindow"]:::cppExe
        pafAlleles["pafAlleles"]:::cppExe
    end

    %% Scripts
    subgraph "Scripts"
        RRuntime["Rscript Runtime"]:::script
        betaAFOutlier["betaAFOutlier.R"]:::script
        PerlRuntime["Perl Runtime"]:::script
        ngsMisc["ngsMisc.pl"]:::script
    end

    %% Data I/O
    InputFiles["Input Files\n(ped, rmat, MAF, VCF, region)"]:::data
    OutputFiles["Output Files\n(.pedstat1, .dist, .pdf, .topo)"]:::data

    %% Build relationships
    Makefile -->|"orchestrates build"| Compiler
    Compiler -->|"compiles"| relateStats
    Compiler -->|"compiles"| dxyWindow
    Compiler -->|"compiles"| fstWindow
    Compiler -->|"compiles"| hetWindow
    Compiler -->|"compiles"| ihsWindow
    Compiler -->|"compiles"| xpehhWindow
    Compiler -->|"compiles"| pafAlleles
    Compiler -->|"compiles"| selkitCPP

    %% Library dependencies
    Matrix --> relateStats
    StatDistCPP --> relateStats
    Matrix --> dxyWindow
    StatDistCPP --> dxyWindow
    Matrix --> fstWindow
    StatDistCPP --> fstWindow
    Matrix --> hetWindow
    StatDistCPP --> hetWindow
    Matrix --> ihsWindow
    StatDistCPP --> ihsWindow
    Matrix --> xpehhWindow
    StatDistCPP --> xpehhWindow
    Matrix --> pafAlleles
    StatDistCPP --> pafAlleles

    selkitCPP --> selkit["selkit Executable"]:::cppExe
    selkitH --> selkit

    %% selkit uses core
    Matrix --> selkit
    StatDistCPP --> selkit

    %% Data flow
    InputFiles -->|CLI invocation| relateStats
    InputFiles -->|CLI invocation| dxyWindow
    InputFiles -->|CLI invocation| fstWindow
    InputFiles -->|CLI invocation| hetWindow
    InputFiles -->|CLI invocation| ihsWindow
    InputFiles -->|CLI invocation| xpehhWindow
    InputFiles -->|CLI invocation| pafAlleles
    InputFiles -->|CLI invocation| selkit

    relateStats -->|writes| OutputFiles
    dxyWindow -->|writes| OutputFiles
    fstWindow -->|writes| OutputFiles
    hetWindow -->|writes| OutputFiles
    ihsWindow -->|writes| OutputFiles
    xpehhWindow -->|writes| OutputFiles
    pafAlleles -->|writes| OutputFiles
    selkit -->|writes| OutputFiles

    InputFiles -->|reads| betaAFOutlier
    RRuntime -->|executes| betaAFOutlier
    betaAFOutlier -->|writes| OutputFiles

    InputFiles -->|reads| ngsMisc
    PerlRuntime -->|executes| ngsMisc
    ngsMisc -->|writes| OutputFiles

    %% Click Events
    click Makefile "https://github.com/tplinderoth/popgenomicstools/tree/master/Makefile"
    click Matrix "https://github.com/tplinderoth/popgenomicstools/blob/master/Matrix.h"
    click StatDistCPP "https://github.com/tplinderoth/popgenomicstools/blob/master/StatDist.cpp"
    click StatDistH "https://github.com/tplinderoth/popgenomicstools/blob/master/StatDist.h"
    click selkitCPP "https://github.com/tplinderoth/popgenomicstools/blob/master/selkit.cpp"
    click selkitH "https://github.com/tplinderoth/popgenomicstools/blob/master/selkit.h"
    click relateStats "https://github.com/tplinderoth/popgenomicstools/blob/master/relateStats.cpp"
    click dxyWindow "https://github.com/tplinderoth/popgenomicstools/blob/master/dxyWindow.cpp"
    click fstWindow "https://github.com/tplinderoth/popgenomicstools/blob/master/fstWindow.cpp"
    click hetWindow "https://github.com/tplinderoth/popgenomicstools/blob/master/hetWindow.cpp"
    click ihsWindow "https://github.com/tplinderoth/popgenomicstools/blob/master/ihsWindow.cpp"
    click xpehhWindow "https://github.com/tplinderoth/popgenomicstools/blob/master/xpehhWindow.cpp"
    click pafAlleles "https://github.com/tplinderoth/popgenomicstools/blob/master/pafAlleles.cpp"
    click betaAFOutlier "https://github.com/tplinderoth/popgenomicstools/blob/master/betaAFOutlier.R"
    click ngsMisc "https://github.com/tplinderoth/popgenomicstools/blob/master/ngsMisc.pl"

    %% Styles
    classDef build fill:#f9f,stroke:#333,stroke-width:1px
    classDef core fill:#bbf,stroke:#333,stroke-width:1px
    classDef selkit fill:#bfb,stroke:#333,stroke-width:1px
    classDef cppExe fill:#fbf,stroke:#333,stroke-width:1px
    classDef script fill:#ffb,stroke:#333,stroke-width:1px
    classDef data fill:#fbb,stroke:#333,stroke-width:1px
```
