# samtools/bcftools architecture

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

- Interactive diagram: https://gitdiagram.com/samtools/bcftools
- Repository: https://github.com/samtools/bcftools

## Overview

##### Main Components

a. Core Processing Components:
- VCF/BCF Processing Engine
- File Format Conversion System
- Variant Calling Pipeline
- Statistical Analysis Module
- Plugin System

b. Input/Output Components:
- File Readers (VCF, BCF, SAM/BAM)
- File Writers
- Index Management (tabix)

c. External Dependencies:
- HTSlib Integration
- Operating System Interface

##### Component Relationships

**[Input Layer]**

**[Core Processing Layer]**

**[Output Layer]**

##### Detailed Component Breakdown

a. Input Layer:
- Supported input formats (VCF, BCF, SAM/BAM)
- File validation components
- Index handling (tabix integration)

b. Core Processing Layer:
- Central Command Router
- Plugin Management System
- Individual Tool Components:
- Variant Calling (vcfcall.c)
- Merging (vcfmerge.c)
- Normalization (vcfnorm.c)
- Statistics (vcfstats.c)
- Filtering (vcffilter.c)
- Annotation (vcfannotate.c)

c. Output Layer:
- Format Conversion
- Compression Handling
- Index Generation

##### Connection Types

- Double lines for primary data paths

##### Notes

- Keep the core functionality prominent
- Clear separation between mandatory and optional components
- Scalability points
- Version-specific features
- Error handling paths

- Hierarchical layouts
- Export to various formats
- Text annotation capabilities

## Diagram (Mermaid)

```mermaid
flowchart TB
    subgraph Input
        VCF[VCF Files]
        BCF[BCF Files]
        SAM[SAM/BAM Files]
        IDX[Index Files]
    end

    subgraph Core["Core Processing Layer"]
        CMD["Command Router"]:::core
        click CMD "https://github.com/samtools/bcftools/blob/develop/main.c"
        
        subgraph Processing["Processing Components"]
            VPE["VCF/BCF Processing Engine"]:::core
            click VPE "https://github.com/samtools/bcftools/blob/develop/bcftools.h"
            
            FFC["File Format Conversion"]:::core
            click FFC "https://github.com/samtools/bcftools/blob/develop/vcfconvert.c"
            
            VCP["Variant Calling Pipeline"]:::core
            click VCP "https://github.com/samtools/bcftools/blob/develop/vcfcall.c"
            
            SAM_PROC["BAM/SAM Processor"]:::core
            click SAM_PROC "https://github.com/samtools/bcftools/blob/develop/bam2bcf.c"
        end

        subgraph Tools["Tool Components"]
            MERGE["Variant Merging"]:::tool
            click MERGE "https://github.com/samtools/bcftools/blob/develop/vcfmerge.c"
            
            NORM["Normalization"]:::tool
            click NORM "https://github.com/samtools/bcftools/blob/develop/vcfnorm.c"
            
            STATS["Statistics"]:::tool
            click STATS "https://github.com/samtools/bcftools/blob/develop/vcfstats.c"
            
            FILTER["Filtering"]:::tool
            click FILTER "https://github.com/samtools/bcftools/blob/develop/vcffilter.c"
            
            ANNOT["Annotation"]:::tool
            click ANNOT "https://github.com/samtools/bcftools/blob/develop/vcfannotate.c"
        end

        subgraph Management["System Management"]
            PLUGIN["Plugin System"]:::mgmt
            click PLUGIN "https://github.com/samtools/bcftools/tree/develop/plugins/"
            
            MEM["Memory Management"]:::mgmt
            click MEM "https://github.com/samtools/bcftools/blob/develop/abuf.c"
            
            BUF["Buffer Management"]:::mgmt
            click BUF "https://github.com/samtools/bcftools/blob/develop/vcfbuf.c"
        end
    end

    subgraph IO["I/O Layer"]
        FR["File Readers"]:::io
        click FR "https://github.com/samtools/bcftools/blob/develop/vcfview.c"
        
        FW["File Writers"]:::io
        
        IDX_MGT["Index Management"]:::io
        click IDX_MGT "https://github.com/samtools/bcftools/blob/develop/vcfindex.c"
    end

    subgraph External["External Dependencies"]
        HTSLIB["HTSlib"]:::ext
        OS["Operating System Interface"]:::ext
    end

    %% Connections
    VCF & BCF & SAM --> FR
    IDX --> IDX_MGT
    FR --> VPE
    SAM --> SAM_PROC
    CMD --> Processing
    CMD --> Tools
    VPE --> Tools
    Tools --> FW
    Processing --> FW
    PLUGIN -.-> Tools
    MEM --> Processing
    BUF --> Processing
    FW --> IDX_MGT
    HTSLIB --> Processing
    OS --> Core

    %% Styles
    classDef core fill:#a8e6cf,stroke:#3b6978
    classDef tool fill:#dcedc1,stroke:#3b6978
    classDef mgmt fill:#ffd3b6,stroke:#3b6978
    classDef io fill:#ffaaa5,stroke:#3b6978
    classDef ext fill:#98c1d9,stroke:#3b6978

    %% Legend
    subgraph Legend
        L1["Core Components"]:::core
        L2["Tool Components"]:::tool
        L3["Management Systems"]:::mgmt
        L4["I/O Components"]:::io
        L5["External Dependencies"]:::ext
    end
```
