How lessup/fq-compressor works
Purpose and Entry Points
fq-compressor is a C++23 CLI for lossless, bounded-memory FASTQ compression, decompression, and integrity verification. It supports plain and gzip FASTQ, stdin/stdout pipelines, and paired inputs while preserving pair adjacency. The executable entry point is src/main.cpp; the production binary is built through CMakeLists.txt and src/CMakeLists.txt.
CLI Dispatch and Operation Engine
src/main.cpp parses global and subcommand options, then routes compress, decompress, and verify into one v2 archive engine. The shared engine is the central control boundary: compression turns FASTQ records into sequential archive frames; decompression emits canonical interleaved FASTQ; verification fully reads and validates archives without producing output.
• include/fqc/commands/v2_archive_engine.h
• src/commands/v2_archive_engine.cpp
• src/main.cpp
FASTQ Input and Stream Abstraction
Input handling separates transport/compression from logical FASTQ parsing. A stream factory opens files or standard streams; compressed-stream support handles .gz; the parser validates and yields FASTQ records. This boundary lets the engine work consistently with files, gzip input, and pipes.
• include/fqc/io/stream_factory.h
• include/fqc/io/compressed_stream.h
• src/io/fastq_parser.cpp
Sequential V2 Archive Format
The archive layer owns the wire format: checked global header, independent frames, and a checked footer. Frames hold logical ID/comment, sequence, and quality streams; the reader rejects unsupported versions/codecs, oversized or inconsistent frames, checksum failures, truncation, and trailing data. There is intentionally no v1 compatibility or random access.
• include/fqc/format/v2_archive.h
• src/format/v2_archive.cpp
• ARCHITECTURE.md
Codec and Memory Model
Compression uses Zstd level 1 for framed metadata, packed sequences, and quality streams. Sequences use 2-bit uppercase A/C/G/T representation plus exact exceptions for lowercase and other IUPAC symbols. XXH64 protects headers, frames, and footer totals. The archive engine admits frame work against the configured hard memory budget, keeping operation memory bounded rather than performing global analysis.
• src/commands/v2_archive_engine.cpp
• src/format/v2_archive.cpp
• include/fqc/common/types.h
Pairing, Profiles, and Data Integrity
For paired input, the engine consumes R1/R2 together, preserves adjacency, and ensures frames contain complete pairs; output is one interleaved stream. Dataset profile detection/override (illumina, ont, pacbio-hifi, pacbio-clr) is persisted in the archive, though all currently use the validated fallback codec. Errors and status reporting are centralized rather than exposed as raw lower-layer failures.
• include/fqc/common/error.h
• src/common/error.cpp
• src/common/logger.cpp
Build, Dependencies, and Performance Governance
CMake builds the native CLI, with Conan supplying dependencies/toolchains and C++23 compiler requirements. The material external libraries implied by the format are Zstd, gzip/zlib support, and XXH64. Python benchmark tooling runs dataset/workload manifests, adapters, evidence collection, and codec admission reporting; it is a governance path separate from the production CLI.
• conanfile.py
• benchmark_v2/unified_runner.py
• benchmark_v2/CODEC_GATES.md
Main entry points: v2_archive_engine.cpp V2 archive engine · stream_factory.h Stream factory · v2_archive.cpp Archive reader/writer · conanfile.py Conan toolchain
Components 18
Native CLI
- CLI entry point · Parses global and subcommand options.
src/main.cpp - Errors and status · Centralizes user-facing failures and reporting.
include/fqc/common/error.h
Input pipeline
- Stream factory · Opens files and standard streams.
include/fqc/io/stream_factory.h - Compressed streams · Supports gzip FASTQ input.
include/fqc/io/compressed_stream.h - FASTQ parser · Validates and yields logical FASTQ records.
src/io/fastq_parser.cpp
Archive engine
- Archive engine API
include/fqc/commands/v2_archive_engine.h - V2 archive engine · Coordinates bounded-memory compress, decompress, and verify operations.
src/commands/v2_archive_engine.cpp - Pair handling · Consumes R1/R2 together and preserves interleaved adjacency.
src/commands/v2_archive_engine.cpp - Memory admission · Admits frame work under the configured hard memory budget.
src/commands/v2_archive_engine.cpp - V2 archive format · Checked header, independent frames, and checked footer.
include/fqc/format/v2_archive.h - Archive reader/writer · Rejects invalid versions, frames, checksums, truncation, and trailing data.
src/format/v2_archive.cpp - Frame codec · Zstd metadata and streams, 2-bit bases with exact sequence exceptions, and XXH64 checks.
src/format/v2_archive.cpp - Dataset profile · Persists detected or overridden sequencing profile.
src/commands/v2_archive_engine.cpp
Build & governance
- CMake build · Builds the C++23 production executable.
CMakeLists.txt - Conan toolchain
conanfile.py - Benchmark runner · Runs workload manifests, adapters, and evidence collection.
benchmark_v2/unified_runner.py - Codec gates · Defines codec admission reporting criteria.
benchmark_v2/CODEC_GATES.md - Zstd, zlib, XXH64
Connections 19
- Conan toolchain → CMake build: supplies toolchain
- CMake build → CLI entry point: builds
- Conan toolchain → Zstd, zlib, XXH64: provides
- CLI entry point → Archive engine API: dispatches commands
- Archive engine API → V2 archive engine: implements
- V2 archive engine → Stream factory: opens input
- Stream factory → Compressed streams: wraps gzip input
- Stream factory → FASTQ parser: feeds streams
- FASTQ parser → Pair handling: yields records
- Pair handling → V2 archive engine: complete pairs
- V2 archive engine → Memory admission: admits frame work
- V2 archive engine → Dataset profile: detects or overrides
- V2 archive engine → Archive reader/writer: reads and writes frames
- Archive reader/writer → V2 archive format: enforces
- Archive reader/writer → Frame codec: encodes and validates streams
- Zstd, zlib, XXH64 → Frame codec: implements primitives
- V2 archive engine → Errors and status: reports failures
- Codec gates → Benchmark runner: governs reporting
- Benchmark runner → Frame codec: evaluates admission