How sulkysubject37/qwd works
1. Repository shape
QwD is organized around a single Zig analysis engine, with multiple frontends layered on top: a command-line app, Python and R bindings, and a macOS SwiftUI dashboard. The engine is the source of truth; the other components are thin adapters around it.
2. Core engine boundary
The core/ tree contains the reusable runtime: parsing, decompression, scheduling, pipeline orchestration, SIMD helpers, memory management, metrics, and structured output. This is the architectural center of the repo and is what all consumers ultimately depend on.
3. Input formats and ingestion
Input support is centered on FASTQ and BAM, with BGZF/GZIP handling for compressed streams. The io/ and core/io/ modules provide readers and decompression primitives, while core/parser/, core/bam, and io/fastq handle format-specific decoding. The data flow starts with file/stream readers and moves into normalized read records for downstream analysis.
4. Decompression and streaming pipeline
A major design point is streaming decompression overlapped with analysis. core/io/ includes native BGZF/GZIP and fallback deflate implementations, plus libdeflate-backed paths where available. This is a performance boundary: compressed bytes are turned into records as a streaming pipeline rather than via full-file materialization.
5. Vectorized data representation
The engine emphasizes SIMD and columnar processing. core/columnar/, core/vector/, core/simd/, and core/encoding/ implement the internal representations and transforms used to make read-level analytics fast. The architecture is designed so many QC operations can run on compact bitplanes or columnar buffers instead of per-base scalar loops.
6. Pipeline, scheduler, and stages
core/pipeline/, core/scheduler/, core/stage/, and core/parallel/ define the execution model, while stages/ contains the actual analytics modules. Each stage corresponds to a specific QC or statistics task such as adapter detection, GC distribution, k-mer spectrum, duplication, quality decay, N statistics, trimming, and taxonomic screening. The pipeline assembles these stages into ordered work units, and the scheduler distributes them across threads.
7. Analytics and reporting
Results are accumulated through core/metrics/, core/api/metrics_stream.zig, and core/output/structured_output.zig. This suggests a streaming metrics model rather than a batch-only report writer. The output boundary is important because the same structured results are consumed by the CLI, bindings, and dashboard.
8. CLI frontend
apps/cli/main.zig is the minimal native entrypoint for users who want command-line execution. It likely wires arguments into the core pipeline configuration and prints or emits the structured report. The CLI is the simplest consumer and serves as the operational baseline for the engine.
9. Language bindings
The bindings/ tree exposes the same core engine to Python and R, with a Zig C API layer under bindings/c/. The Python package (bindings/python/) and R package (bindings/r/) are wrappers over that C-facing interface, so the binding boundary is intentionally narrow: native engine on one side, language-specific ergonomics on the other.
10. macOS dashboard architecture
apps/dashboard/ is a separate SwiftUI application that embeds the native engine via a C shim and XCFramework (QwD.xcframework). The SwiftUI views (DashboardView, ReportView, SettingsView, QualityHeatmapView, KmerSpectrumView, TaxonomyProfileView) present analysis results and expose interactive controls. The README indicates this dashboard is not just a viewer; it can inject analysis parameters such as trimming and filtering into the engine.
11. Build and packaging boundaries
The repo uses Zig’s build system at the top level (build.zig), plus a Swift Package/Xcode project for the dashboard. The dashboard also has scripts to build the XCFramework and wrap the native library for Apple platforms. This means the project has two main packaging surfaces: native Zig artifacts and Apple app artifacts.
12. Validation, performance, and reproducibility
tests/ is broad and mirrors the architecture: fastq, bam, pipeline, stages, bindings, fuzz, stress, reproducibility, and interface tests. benchmarks/ measures columnar, SIMD, decomposition, and parallel scaling behavior. Together these form the nonfunctional boundary of the system: correctness, cross-language compatibility, and performance are all treated as first-class concerns.
13. Auxiliary tooling
tools/ and scripts/ provide generation and debugging helpers such as synthetic FASTQ generation, stress data generation, gzip debugging, and BGZF tooling. These are not runtime dependencies, but they support test data creation and performance exploration around the core engine.
14. Overall data flow
The main flow is: input file or stream → format reader/decompressor → parsed reads → columnar/SIMD-friendly internal structures → scheduled QC/analysis stages → structured metrics/reporting → consumed by CLI, Python/R bindings, or the SwiftUI dashboard. The important architectural boundary is that all presentation and language-specific layers sit on top of the same Zig engine.
Main entry points: pipeline.zig Pipeline · structured_output.zig Structured output · parser.zig Parser · gzip_reader.zig IO core
Components 22
Core engine
Reusable Zig runtime and analysis pipeline
- Pipeline · Builds ordered analysis work units and execution flow
core/pipeline/pipeline.zig - Scheduler · Distributes pipeline work across threads
core/scheduler/scheduler.zig - Parallel runtime · Parallel execution helpers and buffers
core/parallel/parallel_scheduler.zig - Parser · Normalized read and record parsing boundary
core/parser/parser.zig - Columnar · Compact read-level buffers and bitplane structures
core/columnar/column_builder.zig - SIMD · Vectorized decode, scan, and transpose operations
core/simd/simd_ops.zig - Metrics · Runtime metrics and streaming metric accumulation
core/metrics/metrics.zig - Structured output · Structured report emission consumed by all frontends
core/output/structured_output.zig
Frontends
CLI, language bindings, and dashboard consumers
- CLI · Command-line app that wires arguments into the engine
apps/cli/main.zig - Dashboard · macOS UI that embeds the native engine and renders reports
apps/dashboard/Sources/QwDDashboard/QwDDashboardApp.swift - C shim · Swift-facing C wrapper and packaged XCFramework boundary
apps/dashboard/Sources/CQwD/qwd.c - C API · Stable C-facing API exported from Zig
bindings/c/qwd_api.zig - Python · Python package built on the C API
bindings/python/qwd.py - R · R package built on the C API
bindings/r/R/qwd.R
Analysis stages
Domain analytics assembled into pipeline stages
- QC stages · Primary quality-control and statistics stages
stages/qc/qc_stage.zig - Alignment stages · Alignment-derived analytics such as coverage and insert size
stages/alignment/alignment_stats_stage.zig - K-mer stage · K-mer spectrum and related sequence composition analytics
stages/kmer/kmer_stage.zig - GC stage · GC distribution analysis
stages/gc/gc_stage.zig - Trim stage · Trimming and filtering analysis/control stage
stages/trim/trim_stage.zig
Input handling
File readers and compressed stream ingestion
- IO core · BGZF/GZIP readers and deflate implementations
core/io/gzip_reader.zig - FASTQ reader · FASTQ ingestion and record decoding
io/fastq/fastq_reader.zig - BAM reader · BAM ingestion and alignment-aware decoding
io/bam/bam_reader.zig
Connections 28
- CLI → Pipeline: configures · CLI translates arguments into pipeline execution
- Dashboard → C shim: calls · SwiftUI app uses the C shim for native execution
- C shim → C API: wraps · Dashboard bridge sits on the same native API boundary
- Python → C API: uses · Python package delegates to the C API
- R → C API: uses · R package delegates to the C API
- Pipeline → Scheduler: dispatches · Pipeline hands work to the scheduler
- Scheduler → Parallel runtime: runs on · Scheduler uses shared parallel runtime primitives
- Pipeline → Parser: feeds · Pipeline receives parsed records
- IO core → FASTQ reader: reads · Core IO supports FASTQ streams
- IO core → BAM reader: reads · Core IO supports BAM streams
- IO core → Parser: normalizes · Compressed input is turned into parseable records
- FASTQ reader → Parser: emits · FASTQ reader produces normalized records
- BAM reader → Parser: emits · BAM reader produces normalized records
- Parser → Columnar: packs · Parsed reads are packed into compact internal buffers
- Columnar → SIMD: accelerates · Columnar layout is optimized for SIMD kernels
- SIMD → QC stages: feeds · Vectorized primitives support core QC work
- Pipeline → QC stages: assembles · Pipeline composes QC stages into ordered work
- Pipeline → Alignment stages: assembles · Pipeline composes alignment analytics when BAM is present
- Pipeline → K-mer stage: assembles · Pipeline may include k-mer analysis
- Pipeline → GC stage: assembles · Pipeline may include GC analysis
- Pipeline → Trim stage: assembles · Pipeline may include trimming and filtering stages
- QC stages → Metrics: records · Stages stream results into metrics collection
- Alignment stages → Metrics: records · Alignment analysis contributes metrics
- Metrics → Structured output: serializes · Structured output is built from streamed metrics
- Structured output → CLI: renders · CLI prints or emits structured reports
- Structured output → Python: consumed by · Bindings expose structured results to Python
- Structured output → R: consumed by · Bindings expose structured results to R
- Structured output → Dashboard: renders · Dashboard displays structured analysis results