# lukfor/pgs-calc architecture

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

- Interactive diagram: https://gitdiagram.com/lukfor/pgs-calc
- Repository: https://github.com/lukfor/pgs-calc

## Overview

##### Project Type and Purpose
This is a command-line tool for applying polygenic scores (PGS) on imputed genotypes, primarily interacting with genetic data and the PGS Catalog.

##### Main Components

A. Core Components:
- Input Processing System
- Score Processing Engine
- File Management System
- Report Generation System
- Command Interface Layer

B. External Integrations:
- PGS Catalog API
- dbSNP Database
- File System (VCF, Score files)

##### Command Layer (Top Level)
- Subcomponents for each major command:
- Apply Score
- Download Score
- Resolve Score
- Create Report
- LiftOver Score

##### Processing Core (Middle Layer)
- Subcomponents:
- Variant Processing
- Score Calculation
- Quality Control
- Build Management

##### I/O Layer (Bottom Layer)
- Input Handlers:
- VCF File Reader
- Score File Reader
- Sample File Reader
- Output Handlers:
- Score Writer
- Report Generator
- Variant Writer

##### External Services (Side Connections)
- PGS Catalog Integration
- dbSNP Database
- Chain File System

Use the following visual elements:
- Rectangular containers for major components
- Rounded rectangles for subcomponents
- Blue: Command Layer
- Green: Processing Core
- Yellow: I/O Layer
- Gray: External Services

Important Relationships to Show:

##### Data Flow
- Input files → File Readers → Processing Core → Output Writers
- Command Interface → Processing Core
- External Services → Processing Core

##### Component Dependencies
- How the command layer orchestrates the processing core
- How the I/O layer supports both input and output operations
- Demonstrate external service integration points

Key Architectural Patterns to Highlight:

##### Command Pattern
- How each command class in the commands package interfaces with the core system

##### Factory Pattern
- RiskScoreFormatFactory for handling different file formats

##### Task-based Processing
- Task system for major operations (ApplyScore, CreateReport, etc.)

Level of Detail:
- Keep main components visible at a glance
- Use nested containers to show subcomponents
- Class names from the codebase
- Major data flows and dependencies

##### The flexibility in handling different file formats and builds

- Component types
- Any abbreviations used

This will create a comprehensive yet clear visualization of the PGS Calculator's architecture while maintaining the appropriate level of detail for a principal software engineer to understand the system's structure and interactions.

## Diagram (Mermaid)

```mermaid
graph TB
    %% Styles
    classDef command fill:#d0e1f9,stroke:#333
    classDef core fill:#b3e6b3,stroke:#333
    classDef io fill:#fff3b3,stroke:#333
    classDef external fill:#e6e6e6,stroke:#333
    classDef factory fill:#ffd9b3,stroke:#333

    %% Command Layer
    subgraph CommandLayer
        CLI["Command Interface"]
        ApplyScore["Apply Score Command"]
        DownloadScore["Download Score Command"]
        ResolveScore["Resolve Score Command"]
        CreateReport["Create Report Command"]
        LiftOver["LiftOver Score Command"]
    end

    %% Processing Core
    subgraph ProcessingCore
        ScoreEngine["Score Processing Engine"]
        VariantProc["Variant Processing"]
        ScoreCalc["Score Calculation"]
        QualityControl["Quality Control"]
        BuildMgmt["Build Management"]
    end

    %% I/O Layer
    subgraph IOLayer
        InputHandlers["Input Handlers"]
        VCFReader["VCF Reader"]
        ScoreReader["Score Reader"]
        SampleReader["Sample Reader"]
        
        OutputHandlers["Output Handlers"]
        ScoreWriter["Score Writer"]
        ReportGen["Report Generator"]
        VariantWriter["Variant Writer"]
        
        FormatFactory["Risk Score Format Factory"]
        ScoreCollection["Score Collection Manager"]
    end

    %% External Services
    subgraph ExternalServices
        PGSCatalog["PGS Catalog API"]
        dbSNP["dbSNP Database"]
        ChainFiles["Chain File System"]
    end

    %% Relationships
    CLI --> ApplyScore & DownloadScore & ResolveScore & CreateReport & LiftOver
    ApplyScore & DownloadScore & ResolveScore & CreateReport & LiftOver --> ScoreEngine
    
    ScoreEngine --> VariantProc
    ScoreEngine --> ScoreCalc
    ScoreEngine --> QualityControl
    ScoreEngine --> BuildMgmt
    
    InputHandlers --> VCFReader & ScoreReader & SampleReader
    OutputHandlers --> ScoreWriter & ReportGen & VariantWriter
    
    VCFReader & ScoreReader & SampleReader --> ScoreEngine
    ScoreEngine --> ScoreWriter & ReportGen & VariantWriter
    
    PGSCatalog -.-> ScoreEngine
    dbSNP -.-> ScoreEngine
    ChainFiles -.-> BuildMgmt
    
    FormatFactory --> ScoreReader
    ScoreCollection --> ScoreReader

    %% Click Events
    click CLI "https://github.com/lukfor/pgs-calc/tree/master/src/main/java/genepi/riskscore/commands/"
    click ScoreEngine "https://github.com/lukfor/pgs-calc/tree/master/src/main/java/genepi/riskscore/tasks/"
    click InputHandlers "https://github.com/lukfor/pgs-calc/tree/master/src/main/java/genepi/riskscore/io/"
    click PGSCatalog "https://github.com/lukfor/pgs-calc/blob/master/src/main/java/genepi/riskscore/io/PGSCatalog.java"
    click dbSNP "https://github.com/lukfor/pgs-calc/blob/master/src/main/java/genepi/riskscore/io/dbsnp/DbSnpReader.java"
    click ReportGen "https://github.com/lukfor/pgs-calc/blob/master/src/main/java/genepi/riskscore/tasks/CreateHtmlReportTask.java"
    click FormatFactory "https://github.com/lukfor/pgs-calc/blob/master/src/main/java/genepi/riskscore/io/formats/RiskScoreFormatFactory.java"
    click VCFReader "https://github.com/lukfor/pgs-calc/tree/master/src/main/java/genepi/riskscore/io/vcf/"
    click ChainFiles "https://github.com/lukfor/pgs-calc/tree/master/files/chains/"
    click ScoreCollection "https://github.com/lukfor/pgs-calc/tree/master/src/main/java/genepi/riskscore/io/scores/"

    %% Style Applications
    class CLI,ApplyScore,DownloadScore,ResolveScore,CreateReport,LiftOver command
    class ScoreEngine,VariantProc,ScoreCalc,QualityControl,BuildMgmt core
    class InputHandlers,OutputHandlers,VCFReader,ScoreReader,SampleReader,ScoreWriter,ReportGen,VariantWriter io
    class PGSCatalog,dbSNP,ChainFiles external
    class FormatFactory,ScoreCollection factory
```
