# sanger-tol/variantcalling architecture

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

- Interactive diagram: https://gitdiagram.com/sanger-tol/variantcalling
- Repository: https://github.com/sanger-tol/variantcalling

## Overview

##### Project Type and Purpose
- This project is a bioinformatics pipeline for variant calling. It processes input PacBio aligned or unaligned reads (CRAM/BAM files) along with a reference FASTA file. The pipeline splits the FASTA into individual sequences, optionally aligns reads, filters for primary alignments, executes variant calling using DeepVariant, then merges the resulting VCF/GVCF files and computes statistics.
- The README emphasizes best-practices, containerization (Docker/Singularity/etc), and modularity (many nf-core modules integrated) using Nextflow DSL2.

##### Analyzing the File Structure
- Top-Level Files/Directories:
- The presence of directories like “conf”, “docs”, “lib”, “modules”, “subworkflows”, and “workflows” signals a modular Nextflow pipeline.
- "main.nf" at the root is the primary workflow script.
- “modules” contains a host of nf-core modules (e.g., bcftools, blast, cat, deepvariant) organized in subdirectories with environment files, configuration files, and tests. This indicates that the pipeline is built to link together many modular steps.
- “subworkflows” house additional, possibly optional, workflow snippets (like aligning and filtering) that are integrated into the primary workflow.
- “lib” includes Groovy scripts (e.g., WorkflowMain, WorkflowVariantcalling, Utils) — these scripts are likely custom code supporting the pipeline’s logic.
- Standard files such as nextflow.config, Docker/Conda profiles, and CI workflows in “.github” reflect production-readiness and community integration with nf-core.
- Architectural Pattern:
- The pipeline leverages the Nextflow DSL2 modular design, which organizes processes into distinct modules and subworkflows.
- Containerization is used to encapsulate each process individually for reproducibility.
- An MVC-like split is evident where Nextflow manages the workflow orchestration (controller), the process scripts and modules act as the business logic (model), and output reporting/documentation comprises the view.

a. Primary Components:
- User/Trigger: The entry point where a user submits parameters (input samplesheet, FASTA, etc.) through a Nextflow run command.
- Nextflow Workflow Engine: Core orchestrator represented by “main.nf” and the configuration/system files (nextflow.config, profiles in “conf”).
- Input Data Nodes: The samplesheet CSV and FASTA genome file.
- Preprocessing Steps:
- Fasta splitter (splits the FASTA file into individual sequence files).
- Read alignment (if needed) and merge steps (merging with same sample names), indicated in the README.
- Filtering Process: The step that applies the “-F 0x900” filter to remove secondary alignments.
- Variant Calling (DeepVariant processes): Modules that run variant calling using DeepVariant via containerized processes.
- Post-processing: Modules for merging VCF/GVCF outputs (and subsequent processing using VCFtools for heterozygosity and diversity analysis).
- Software Dependency & Container Management: Docker, Singularity, Conda, etc., which manage the environment for each process. Represent this as an underpinning “container layer.”
- External Integrations: nf-core/modules that are reused and community-curated; also Nextflow Tower for launching jobs.

b. Relationships and Data Flow:
- Dependency between configuration profiles (from “conf” and “nextflow.config”) and container invocation (Docker/Singularity profile selection).

##### Architectural Patterns and Design Principles
- Containerization: Illustrate the container layer (using Docker/Singularity symbols) associated with each processing module.
- Data Flow Orientation: Emphasize the sequential pipeline steps (fasta splitting → alignment/filtering → DeepVariant execution → VCF merge → VCFtools analysis).
- Testing & CI: Optionally include a component that represents the automated testing and CI workflows (from the “.github/workflows” folder).

##### Emphasizing Essential Architectural Elements
- Starting with user input and configuration profiles.
- Nextflow workflow orchestration that invokes modules and subworkflows.
- The containerized execution of processes (ensuring reproducibility).
- The integration of modular nf-core components along with custom scripts in “lib”.
- How each processing step connects to its subsequent component so that the full variant calling process (from reading inputs to generating final statistical reports) is visible.

## Diagram (Mermaid)

```mermaid
flowchart TD
    %% Nodes
    UI("User Input (Samplesheet & FASTA)"):::user
    NF("Nextflow Workflow Engine (main.nf & nextflow.config)"):::engine

    subgraph "Preprocessing"
        IC("Input Check (subworkflows/local/input_check.nf)"):::preprocess
        FS("FASTA Splitting (subworkflows/local/input_filter_split.nf)"):::preprocess
    end

    Align("Read Alignment (subworkflows/local/align_pacbio.nf)"):::align
    Filter("Filtering Process (-F 0x900) (modules/local/pacbio_filter.nf / bin/pacbio_filter.sh)"):::filter
    DV("Variant Calling with DeepVariant (modules/nf-core/deepvariant/rundeepvariant)"):::variant
    Merge("VCF/GVCF Merging (modules/nf-core/bcftools/concat / modules/nf-core/samtools/merge)"):::post
    VCFT("VCFtools Analysis (modules/nf-core/vcftools)"):::post
    Final("Final Output & Statistics"):::post

    Container("Containerization (Docker/Singularity/Conda)"):::external
    Lib("Workflow Orchestration (lib/WorkflowMain.groovy & lib/WorkflowVariantcalling.groovy)"):::orchestration
    ExtInt("External Integrations (nf-core modules, Nextflow Tower)"):::external
    CI("Automated Testing & CI (.github/workflows)"):::ci

    %% Main Data Flow
    UI --> NF
    NF --> IC
    IC --> FS
    FS --> Align
    Align --> Filter
    Filter --> DV
    DV --> Merge
    Merge --> VCFT
    VCFT --> Final

    %% Additional Relationships
    NF --> Container
    Container --> Filter
    Container --> DV
    Container --> Merge
    Container --> VCFT
    NF --> Lib
    NF --> ExtInt
    NF --> CI

    %% Click Events
    click UI "https://github.com/sanger-tol/variantcalling/blob/main/assets/samplesheet.csv"
    click NF "https://github.com/sanger-tol/variantcalling/blob/main/main.nf"
    click IC "https://github.com/sanger-tol/variantcalling/blob/main/subworkflows/local/input_check.nf"
    click FS "https://github.com/sanger-tol/variantcalling/blob/main/subworkflows/local/input_filter_split.nf"
    click Align "https://github.com/sanger-tol/variantcalling/blob/main/subworkflows/local/align_pacbio.nf"
    click Filter "https://github.com/sanger-tol/variantcalling/blob/main/modules/local/pacbio_filter.nf"
    click DV "https://github.com/sanger-tol/variantcalling/tree/main/modules/nf-core/deepvariant/rundeepvariant/"
    click Merge "https://github.com/sanger-tol/variantcalling/tree/main/modules/nf-core/bcftools/concat/"
    click VCFT "https://github.com/sanger-tol/variantcalling/tree/main/modules/nf-core/vcftools/"
    click Lib "https://github.com/sanger-tol/variantcalling/blob/main/lib/WorkflowMain.groovy"
    click CI "https://github.com/sanger-tol/variantcalling/tree/main/.github/workflows/"

    %% Styles
    classDef user fill:#ffcccc,stroke:#ff0000,stroke-width:2px
    classDef engine fill:#ccffcc,stroke:#008000,stroke-width:2px
    classDef preprocess fill:#cce5ff,stroke:#0056b3,stroke-width:2px
    classDef align fill:#d1c4e9,stroke:#512da8,stroke-width:2px
    classDef filter fill:#ffebcc,stroke:#ff9900,stroke-width:2px
    classDef variant fill:#e1bee7,stroke:#9c27b0,stroke-width:2px
    classDef post fill:#d0f0c0,stroke:#388e3c,stroke-width:2px
    classDef orchestration fill:#f0d9ff,stroke:#8a2be2,stroke-width:2px
    classDef external fill:#fef9c3,stroke:#d4ac0d,stroke-width:2px
    classDef ci fill:#f0f0f0,stroke:#999,stroke-width:2px
```
