How samtools/htslib works
Main Components
a. Core Library Components:
• File Format Handlers
• SAM/BAM Handler
• CRAM Handler
• VCF/BCF Handler
• Tabix Indexer
• Compression Layer (BGZip)
• Index Management (CSI/BAI/TBI)
• Threading System
• I/O Abstraction Layer
b. External Dependencies:
• zlib (compression library)
• Operating System I/O
• Optional cloud storage interfaces (S3, GCS)
Component Relationships
┌─────────────────────── Client Applications ───────────────────────┐
• (samtools, bcftools, other bioinformatics tools) │
• Public API Layer ──────────────────────────┤
• ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────┐ ┌─────────────┐ │
• SAM/BAM │ │ CRAM │ │ VCF/BCF │ │ FAIDX │ │ Thread Pool │ │
• ┘ └─────────┘ └─────────┘ └─────────┘ └─────────────┘ │
• Internal Implementation ─────────────────────┤
• ┌─────────┐ ┌─────────┐ ┌──────────┐ ┌────────────┐ │
• BGZF │ │ Index │ │ HTScodec │ │ Text Utils │ │
• ┘ └─────────┘ └──────────┘ └────────────┘ │
• I/O Layer ───────────────────────────────┤
• ┌─────────┐ ┌─────────┐ ┌──────────┐ ┌────────────┐ │
• Local │ │ S3 │ │ GCS │ │ HTTP/HTTPS │ │
• ┘ └─────────┘ └──────────┘ └────────────┘ │
• ┘
Important Details
a. File Format Support:
• Supported formats (SAM, BAM, CRAM, VCF, BCF)
• Index format support (CSI, BAI, TBI)
b. Threading Model:
• Thread pool implementation
• Parallel processing capabilities
c. I/O Abstractions:
• Local file system
• Remote storage (S3, GCS)
• HTTP/HTTPS access
Key Architectural Patterns
• Plugin Architecture: Show how the storage backends are pluggable
• Threading Model: Illustrate the thread pool design
• Buffering System: Show BGZF compression integration
• Index Management: Show relationship between formats and indices
Implementation Notes
• Version information
• Notes about performance characteristics
• Format conversion paths