|
| 1 | +# CLAUDE.md |
| 2 | + |
| 3 | +This file provides guidance to Claude Code (claude.ai/code) when working with code in this repository. |
| 4 | + |
| 5 | +## Project Overview |
| 6 | + |
| 7 | +bqtools is a Rust CLI for working with BINSEQ files — a binary format family for high-performance DNA sequence processing. It encodes, decodes, greps, concatenates, samples, and pipes BINSEQ files (`.bq`, `.vbq`, `.cbq`). CBQ is the recommended format for most applications. |
| 8 | + |
| 9 | +## Build & Test Commands |
| 10 | + |
| 11 | +```bash |
| 12 | +cargo build # Debug build |
| 13 | +cargo build --release # Optimized build (uses LTO, slow) |
| 14 | +cargo install --path . # Install binary locally |
| 15 | + |
| 16 | +cargo test --verbose # Run all tests |
| 17 | +cargo test --verbose -F fuzzy # Run tests including fuzzy feature |
| 18 | +cargo test <test_name> # Run a single test by name |
| 19 | + |
| 20 | +cargo fmt --check # Check formatting |
| 21 | +cargo clippy --verbose # Lint (pedantic clippy enabled) |
| 22 | +``` |
| 23 | + |
| 24 | +Logging is controlled via `BQTOOLS_LOG` environment variable (uses `env_logger`). |
| 25 | + |
| 26 | +## Feature Flags |
| 27 | + |
| 28 | +- `htslib` (default): SAM/BAM/CRAM support via rust-htslib |
| 29 | +- `gcs` (default): Google Cloud Storage file reading |
| 30 | +- `fuzzy` (optional): Fuzzy matching via `sassy` — requires `RUSTFLAGS="-C target-cpu=native"` |
| 31 | + |
| 32 | +Build without defaults: `cargo build --no-default-features -F fuzzy,gcs` |
| 33 | + |
| 34 | +## Architecture |
| 35 | + |
| 36 | +### Module Layout |
| 37 | + |
| 38 | +- **`src/cli/`** — Clap derive-based argument definitions. `cli.rs` has the top-level `Commands` enum. `input.rs` and `output.rs` handle complex input/output argument parsing (file formats, compression, paired-end, spans). |
| 39 | +- **`src/commands/`** — Command implementations, each in its own subdirectory. `utils.rs` has shared compression helpers. |
| 40 | +- **`src/types.rs`** — Type aliases (`BoxedReader`, `BoxedWriter`). |
| 41 | +- **`src/main.rs`** — CLI dispatch and SIGPIPE handling. |
| 42 | + |
| 43 | +### Key Patterns |
| 44 | + |
| 45 | +**Parallel processing**: Commands use the `paraseq` crate's `ParallelProcessor` trait for embarrassingly parallel batch processing. Each command has a `processor.rs` implementing this trait with thread-local buffers and `Arc<Mutex<T>>` for shared global state. |
| 46 | + |
| 47 | +**Grep backends**: The grep command uses a `PatternMatcher` enum dispatching to three backends — `regex`, `aho-corasick` (fixed-string, multi-pattern), and `sassy` (fuzzy, feature-gated). The same pattern applies to `PatternCounter` for the `-P` pattern-count mode. |
| 48 | + |
| 49 | +**Encode modes**: Encoding dispatches across atomic (single/paired files), recursive (directory walk via `walkdir`), manifest (file list), and batch (multi-file thread distribution) modes. |
| 50 | + |
| 51 | +**Writer abstraction**: `SplitWriter` supports interleaved (single file) and split (separate R1/R2) output modes with polymorphic writers (file, stdout, compressed, chunked). |
| 52 | + |
| 53 | +### Core Dependencies |
| 54 | + |
| 55 | +| Crate | Role | |
| 56 | +|-------|------| |
| 57 | +| `binseq` | BINSEQ format read/write | |
| 58 | +| `bitnuc` | 2-bit/4-bit nucleotide encoding | |
| 59 | +| `paraseq` | Parallel FASTX/BINSEQ processing | |
| 60 | +| `clap` | CLI argument parsing (derive) | |
| 61 | +| `anyhow` | Error handling throughout | |
| 62 | + |
| 63 | +### Testing |
| 64 | + |
| 65 | +Integration tests live in `tests/`. `tests/common.rs` provides a builder (`write_fastx()`) for generating random FASTQ/FASTA test data with configurable compression (none, gzip, zstd). Tests use cartesian products over format/compression/mode combinations. Dev dependencies: `bon` (builder macro), `nucgen` (random sequences), `tempfile`, `itertools`. |
| 66 | + |
| 67 | +## Contribution Guide |
| 68 | + |
| 69 | +When making changes, keep the following documentation in sync: |
| 70 | + |
| 71 | +1. **CLAUDE.md** — Update this file when adding new commands, changing architecture, or modifying build/test workflows. |
| 72 | +2. **README.md** — Update usage examples and feature descriptions when adding or changing user-facing functionality (new commands, flags, behavior changes). |
| 73 | +3. **Clap doc comments** — All CLI arguments, flags, and subcommands use clap derive macros with `/// doc comments` and `#[clap(long_about)]` attributes. When adding or modifying flags, write clear help text directly on the struct fields in `src/cli/`. These doc comments are the `--help` output users see. |
| 74 | +4. **New feature flags** — If adding a Cargo feature flag, document it in both `CLAUDE.md` (Feature Flags section) and `README.md` (Feature Flags / Installation section). |
0 commit comments