# tutkuyaras/pgsxplorer architecture

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

- Interactive diagram: https://gitdiagram.com/tutkuyaras/pgsxplorer
- Repository: https://github.com/tutkuyaras/pgsxplorer

## Overview

##### Project Type and Purpose
- PGSXplorer is a Nextflow-based bioinformatics workflow (data pipeline) for calculating polygenic scores (PGS).
- It orchestrates a series of quality-control, phasing, imputation, and PGS-calculation modules around genomic input data and GWAS summary statistics.
- It runs locally or on HPC (SLURM) and can be containerized with Docker.

##### File Structure Analysis
- Root:
- main.nf – Nextflow entry point (pipeline definition)
- nextflow.config – global configuration (profiles, executors, parameters)
- .command.sh – helper wrapper
- Modules directory: one NF process script per analysis step (e.g., CalculateQC, ConvertVCFtoPLINK, LDpred2grid.nf, etc.)
- bin directory: supporting R scripts and native executables (PLINK, PRSice, ldak6, etc.)
- QC_graphs, outputs, target, .nextflow/cache: data directories and cache store
- README.md: exhaustive description, external-tool dependencies, parameters, usage examples

## Diagram (Mermaid)

```mermaid
flowchart TB
    %% Input Layer
    subgraph "Input Layer"
        direction TB
        RawData["Raw Genotype Data<br/>(PLINK/VCF)"]:::input
        GWASStats["GWAS Summary Statistics"]:::input
        Phenotype["Optional Phenotype File"]:::input
    end

    %% Orchestrator
    subgraph "Nextflow Orchestrator" 
        direction TB
        Orchestrator["Nextflow Engine"]:::orchestrator
    end

    RawData --> Orchestrator
    GWASStats --> Orchestrator
    Phenotype --> Orchestrator

    click Orchestrator "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/main.nf"
    click Orchestrator "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/nextflow.config"

    %% QC Module
    subgraph "QC Module" 
        direction TB
        QC1["SNP & Individual Filtering"]:::qc
        QC2["Heterozygosity & Relatedness"]:::qc
        QCVis["QC Visualization"]:::qc
    end

    Orchestrator --> QC1
    QC1 --> QC2
    QC2 --> QCVis

    click QC1 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/GWAS_QC.nf"
    click QC1 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/FilterIndividuals.nf"
    click QC1 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/QCSNPmissingness.nf"
    click QC1 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/QCindmissingness.nf"
    click QC1 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/FilterMAF.nf"
    click QC1 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/InitialHWEFilter.nf"
    click QC1 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/SecondHWEFilter.nf"
    click QC1 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/RemoveLowMAF.nf"
    click QC1 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/RelCutoff.nf"
    click QC2 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/CalculateHet.nf"
    click QC2 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/ProcessHet.nf"
    click QC2 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/FindDuplicates.nf"
    click QC2 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/GenerateIBD.nf"
    click QC2 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/FindDuplicateSNPs.nf"
    click QC2 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/RemoveDuplicates.nf"
    click QC2 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/CleanHetFailInd.nf"
    click QCVis "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/PlotMAF.nf"
    click QCVis "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/PlotHWE.nf"
    click QCVis "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/PlotHet.nf"
    click QCVis "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/PlotIBD.nf"
    click QCVis "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/bin/plot_maf.R"
    click QCVis "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/bin/plot_hwe.R"
    click QCVis "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/bin/plot_het.R"
    click QCVis "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/bin/plot_ibd.R"

    %% Convert VCF ↔ PLINK
    subgraph "Convert VCF ↔ PLINK" 
        direction TB
        Convert["VCF/PLINK Conversion"]:::qc
    end
    QCVis --> Convert
    Convert --> Phasing

    click Convert "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/ConvertVCFtoPLINK.nf"
    click Convert "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/ConvertPLINKtoVCF.nf"
    click Convert "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/VCFtoPLINK.nf"
    click Convert "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/SortVCF.nf"
    click Convert "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/SplitVCF.nf"
    click Convert "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/MergedVCF.nf"

    %% Phasing & Imputation
    subgraph "Phasing & Imputation"
        direction TB
        Phasing["Phasing Module"]:::phasing
        Imputation["Imputation Module"]:::phasing
        PostQC["Post-Imputation QC"]:::phasing
    end

    click Phasing "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/PhaseVCF.nf"
    click Phasing "https://github.com/tutkuyaras/pgsxplorer/tree/PGSXplorer2/eagle/"
    click Imputation "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/ImputeVCF.nf"
    click Imputation "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/Impute.nf"
    click Imputation "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/.command.sh"
    click PostQC "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/QCSNPmissingness.nf"
    click PostQC "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/QCindmissingness.nf"

    Convert --> Phasing
    Phasing --> Imputation
    Imputation --> PostQC

    %% Ancestry & PCA
    subgraph "Ancestry & PCA"
        direction TB
        Ancestry["Ancestry Inference"]:::pgs
        PCA["PCA Module"]:::pgs
    end

    PostQC --> Ancestry
    PostQC --> PCA

    click Ancestry "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/fastmixture.nf"
    click PCA "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/CalculatePCA.nf"

    %% PGS Modules
    subgraph "PGS Tools" 
        direction TB
        Clump["Pruning & Thresholding"]:::pgs
        PRSice["PRSice-2"]:::pgs
        LDgrid["LDpred2-grid"]:::pgs
        LDauto["LDpred2-auto"]:::pgs
        Lasso["Lassosum2"]:::pgs
        Mega["MegaPRS"]:::pgs
        SBayesR["SBayesR-C"]:::pgs
        Stepwise1["Stepwise LDpred2 Step1"]:::pgs
        Stepwise2["Stepwise LDpred2 Step2"]:::pgs
    end

    PostQC --> Clump
    PostQC --> PRSice
    PostQC --> LDgrid
    PostQC --> LDauto
    PostQC --> Lasso
    PostQC --> Mega
    PostQC --> SBayesR
    LDgrid --> Stepwise1
    Stepwise1 --> Stepwise2

    click Clump "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/ClumpSNPs.nf"
    click Clump "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/PruneSNPs.nf"
    click PRSice "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/PRSice2.nf"
    click PRSice "https://github.com/tutkuyaras/pgsxplorer/tree/PGSXplorer2/bin/PRSice_mac"
    click LDgrid "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/LDpred2grid.nf"
    click LDgrid "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/bin/LDpred2grid.R"
    click LDauto "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/LDpred2auto.nf"
    click LDauto "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/bin/LDpred2auto.R"
    click Lasso "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/Lassosum2.nf"
    click Lasso "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/bin/Lassosum2.R"
    click Mega "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/MegaPRS.nf"
    click SBayesR "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/Sbayesrc.nf"
    click SBayesR "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/bin/ldak6.mac"
    click Stepwise1 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/Step1_Run_LDpred2.nf"
    click Stepwise2 "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/Step2_LDpred2_Tuning.nf"

    %% Multi-Ancestry PGS
    subgraph "Multi-Ancestry PGS"
        direction TB
        PRSCSx["PRS-CSx"]:::pgs
        MUSSEL["MUSSEL"]:::pgs
        Combine["Combine Models"]:::pgs
    end

    PostQC --> PRSCSx
    PostQC --> MUSSEL
    MUSSEL --> Combine

    click PRSCSx "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/PRSCSx.nf"
    click MUSSEL "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/Step3_Run_MUSS.nf"
    click Combine "https://github.com/tutkuyaras/pgsxplorer/blob/PGSXplorer2/modules/Step4_Combine_PRS_Models.nf"

    %% Visualization & Reporting
    subgraph "Visualization & Reporting"
        direction TB
        Reports["Generate Plots & QC_graphs"]:::viz
    end

    QCVis --> Reports
    Clump --> Reports
    PRSice --> Reports
    LDgrid --> Reports
    LDauto --> Reports
    Lasso --> Reports
    Mega --> Reports
    SBayesR --> Reports
    PRSCSx --> Reports
    Combine --> Reports

    click Reports "https://github.com/tutkuyaras/pgsxplorer/tree/PGSXplorer2/QC_graphs/"

    %% Data Stores
    Outputs["Outputs/ (Intermediate & Final)"]:::storage
    Cache[".nextflow/cache"]:::storage

    Reports --> Outputs
    Stepwise2 --> Outputs
    Combine --> Outputs
    Outputs --> Cache

    %% Legend and Styles
    classDef input fill:#f5f5f5,stroke:#333;
    classDef orchestrator fill:#757575,stroke:#000,color:#fff;
    classDef qc fill:#bbdefb,stroke:#0b3c5d;
    classDef phasing fill:#c8e6c9,stroke:#1b5e20;
    classDef pgs fill:#ffe0b2,stroke:#e65100;
    classDef viz fill:#e1bee7,stroke:#4a148c;
    classDef storage fill:#eeeeee,stroke:#424242,stroke-dasharray: 5 5;
```
