AIE: queryable alignment evidence on real PBMC inputs

DuckHTS reads standard BAM; DuckDB prepares alignment, junction and evidence-family tables. Region and junction macros query that serving cache without reparsing CIGAR. Each row keeps the BGZF offset of its source record, so read names, CIGARs and raw tags stay in the BAM and remain reachable.

This product reproduces useful AIE capabilities with an explicit counting contract, rather than inheriting every Gravlax policy. Annotation replay remains the demo’s separately scoped compatibility surface; it is not yet an independently validated product surface.

Count meanings

The default trusts supplied CB and retains raw UR for annotation-ready evidence. An explicit UB cache selects supplied corrected tags. Missing tags are audited, not silently substituted. See the counting contract.

Different count meanings prevent an equal-output speedup claim. The graphs compare costs of the declared products and preserve their returned counts.

Actual PBMC input

Source: public 10x Cell Ranger 3.0.0 pbmc_1k_v3, a 4.79 GB BAM with GRCh38 contig names. The complete source was acquired over HTTPS with its observed ETag fixed, size checked, samtools quickcheck verified and SHA-256 recorded.

One source pass produces nested 1M / 2M / 4M genuine primary records—no read or barcode replication. These inputs retain mapped, nonsupplementary NH=1 records with all CB/UB/CR/UR tags present. They are restricted real-cohort prefixes, not the entire cohort and not general multimapper performance. Source and derived BAMs use an owned tmpfs cache; prepared states use the local filesystem. The protocol declares these choices and budgets before acquisition and measurement.

Preparation

Real PBMC preparation with one thread: the same BAM enters two different retained representations.
Real PBMC preparation with four threads.
One-thread maximum whole-process RSS for preparation.
Four-thread maximum whole-process RSS for preparation.

Preparation includes CLI startup, BAM parsing, policy processing and persisting state. The SQL cache retains one row per source record, a pointer to it and two explicit count surfaces; Gravlax retains its dedicated molecular archive. Prepared bytes are reported below, not treated as representation parity.

What the rewrite changed

Records Threads Previous SQL s Current SQL s Gravlax s Previous MiB Current MiB Gravlax MiB
1e+06 1 6.21 2.49 2.26 69.3 36.5 1.8
2e+06 1 12.39 4.98 4.47 137.8 72.0 3.7
4e+06 1 24.80 10.03 8.53 269.5 140.3 6.9
1e+06 4 3.92 1.41 1.37 77.5 36.8 1.8
2e+06 4 6.86 2.21 2.73 150.8 72.8 3.7
4e+06 4 13.86 4.30 5.23 301.5 144.0 6.9

Both SQL columns ran on the same extension, CLI and host, so this difference comes from the SQL. The same 4M, four-thread profile of the previous SQL spent 8.2 of 13.7 seconds in one statement that built the tag map and wrote observations; the CIGAR regex took about 0.3 seconds. A scan of the same 4M records takes 0.52 seconds with named tags and 2.04 seconds through the tag map. The rewrite:

Every table, view and retained column matches the previous SQL on the real 4M input, apart from ids, and all 72 SQL query results in the two runs have the same cell and count totals. The cost is that raw tags are no longer queryable in bulk from the cache: aie_source_record(bam, alignment_id) returns one record by scanning the BAM, which took 5.7 seconds on the 4M input in a single run.

Without a .bai, four-thread 4M preparation takes 4.49 seconds.

Full-chromosome query

One-thread full chr1 query latency. SQL labels, SQL families and Gravlax classes have different count meanings.
Four-thread full chr1 query latency; these are cost contrasts, not equal-output speedups.
One-thread whole-CLI peak RSS for the full chr1 query.
Four-thread whole-CLI peak RSS for the full chr1 query.

The fixed-window query is 1:1-3000000; the full query is 1:1-248956422. Three fresh processes per point include startup, state opening, evaluation and writing every cell count. There are no five-second padding loops. Short query latencies are CLI diagnostics, not a STYLE timing verdict. Whiskers are the three-run range, not confidence intervals.

Validation and biological differences

The product passes an independent scalar CIGAR cursor and pairwise interval-graph oracle under both tag policies. Tests cover later introns, D versus N, strand and contig separation, transitive overlaps, GEM-group identity, missing tags and primary filtering and variable-length leading-A UMI labels. Real raw-label counts on the 4M-record input’s full-chr1 and 3 Mb queries also match independent samtools/awk. Five semantic mutants—skip cursor, reference span, 50 kb merging, strand loss and secondary inclusion—disagree with that oracle; restored SQL passes. Source-record pointers are checked against every fixture record.

The real 109,271-record pilot has 653 cell-count differences when using supplied CB/UB. Selecting CB/raw UR reduces disagreement with Gravlax to one cell (28 versus 29). That cell has three raw barcode variants in the input. This narrows the remaining investigation; it does not justify relabelling the entire discrepancy as intentional or demanding blind upstream emulation.

The raw real-comparison rows include output cell counts and count sums for every query. Returned counts must remain visible alongside performance.

Exact data and limitations

Engine Operation Records Threads Status CLI ms: median [min, max] Max RSS MiB Prepared MiB Output cells Count sum
gravlax prepare 1e+06 1 PASS 2264.0 [2227.0, 2334.0] 182.9 1.8
sql prepare 1e+06 1 PASS 2491.0 [2490.0, 2520.0] 405.5 36.5
gravlax region-full 1e+06 1 PASS 94.0 [92.0, 100.0] 69.2 NA 23170 322755
sql region-full-families 1e+06 1 PASS 33.0 [31.0, 37.0] 36.0 NA 23171 373870
sql region-full-labels 1e+06 1 PASS 97.0 [91.0, 100.0] 65.4 NA 23171 322759
gravlax region-window 1e+06 1 PASS 21.0 [20.0, 22.0] 19.2 NA 4614 42974
sql region-window-families 1e+06 1 PASS 24.0 [22.0, 25.0] 31.2 NA 4615 47616
sql region-window-labels 1e+06 1 PASS 28.0 [28.0, 32.0] 36.4 NA 4615 42975
gravlax prepare 2e+06 1 PASS 4469.0 [4459.0, 4491.0] 271.4 3.7
sql prepare 2e+06 1 PASS 4976.0 [4953.0, 5130.0] 693.3 72.0
gravlax region-full 2e+06 1 PASS 181.0 [176.0, 198.0] 124.9 NA 41958 641307
sql region-full-families 2e+06 1 PASS 52.0 [48.0, 58.0] 42.8 NA 41959 744884
sql region-full-labels 2e+06 1 PASS 167.0 [167.0, 173.0] 102.8 NA 41959 641317
gravlax region-window 2e+06 1 PASS 22.0 [18.0, 22.0] 19.4 NA 4614 42974
sql region-window-families 2e+06 1 PASS 26.0 [17.0, 26.0] 31.6 NA 4615 47616
sql region-window-labels 2e+06 1 PASS 29.0 [28.0, 36.0] 36.3 NA 4615 42975
gravlax prepare 4e+06 1 PASS 8526.0 [8520.0, 8617.0] 455.1 6.9
sql prepare 4e+06 1 PASS 10028.0 [10019.0, 10043.0] 1287.6 140.3
gravlax region-full 4e+06 1 PASS 354.0 [342.0, 357.0] 247.0 NA 70260 1301501
sql region-full-families 4e+06 1 PASS 80.0 [76.0, 82.0] 53.0 NA 70262 1522290
sql region-full-labels 4e+06 1 PASS 326.0 [324.0, 329.0] 176.5 NA 70262 1301527
gravlax region-window 4e+06 1 PASS 22.0 [22.0, 23.0] 19.5 NA 4614 42974
sql region-window-families 4e+06 1 PASS 23.0 [20.0, 23.0] 31.7 NA 4615 47616
sql region-window-labels 4e+06 1 PASS 29.0 [24.0, 31.0] 36.7 NA 4615 42975
gravlax prepare 1e+06 4 PASS 1369.0 [1354.0, 1413.0] 426.8 1.8
sql prepare 1e+06 4 PASS 1411.0 [1401.0, 1477.0] 428.6 36.8
gravlax region-full 1e+06 4 PASS 72.0 [69.0, 73.0] 79.5 NA 23170 322755
sql region-full-families 1e+06 4 PASS 34.0 [34.0, 34.0] 40.9 NA 23171 373870
sql region-full-labels 1e+06 4 PASS 67.0 [63.0, 73.0] 89.2 NA 23171 322759
gravlax region-window 1e+06 4 PASS 16.0 [14.0, 23.0] 19.2 NA 4614 42974
sql region-window-families 1e+06 4 PASS 23.0 [19.0, 25.0] 33.1 NA 4615 47616
sql region-window-labels 1e+06 4 PASS 33.0 [27.0, 34.0] 41.9 NA 4615 42975
gravlax prepare 2e+06 4 PASS 2730.0 [2717.0, 2755.0] 516.8 3.7
sql prepare 2e+06 4 PASS 2211.0 [2209.0, 2222.0] 831.1 72.8
gravlax region-full 2e+06 4 PASS 128.0 [124.0, 129.0] 137.0 NA 41958 641307
sql region-full-families 2e+06 4 PASS 47.0 [43.0, 53.0] 48.8 NA 41959 744884
sql region-full-labels 2e+06 4 PASS 94.0 [93.0, 95.0] 124.4 NA 41959 641317
gravlax region-window 2e+06 4 PASS 19.0 [18.0, 20.0] 18.9 NA 4614 42974
sql region-window-families 2e+06 4 PASS 23.0 [22.0, 25.0] 33.6 NA 4615 47616
sql region-window-labels 2e+06 4 PASS 30.0 [28.0, 32.0] 41.9 NA 4615 42975
gravlax prepare 4e+06 4 PASS 5226.0 [5203.0, 5389.0] 700.0 6.9
sql prepare 4e+06 4 PASS 4298.0 [4232.0, 4518.0] 1568.7 144.0
gravlax region-full 4e+06 4 PASS 248.0 [246.0, 248.0] 259.4 NA 70260 1301501
sql region-full-families 4e+06 4 PASS 67.0 [61.0, 72.0] 61.7 NA 70262 1522290
sql region-full-labels 4e+06 4 PASS 176.0 [171.0, 179.0] 216.9 NA 70262 1301527
gravlax region-window 4e+06 4 PASS 22.0 [22.0, 22.0] 19.8 NA 4614 42974
sql region-window-families 4e+06 4 PASS 23.0 [22.0, 28.0] 33.4 NA 4615 47616
sql region-window-labels 4e+06 4 PASS 34.0 [30.0, 34.0] 42.0 NA 4615 42975

Raw rows, source snapshots and input/runtime hashes for this run and the earlier run with its acquisition receipts are preserved. Each process has a 180-second wall ceiling and 4 GiB RSS ceiling; DuckDB uses 2 GiB buffer and 2 GiB spill limits. Prepared state is capped at 4 GiB. Failures remain in the table; no retry replaces them.

This is real-input evidence, not full product completion. Whole-cohort annotation performance, a general multimapper workload and full STYLE qualification remain unverified. The purpose-built original still wins one-thread preparation, peak memory and archive size, by about 20 times on size. Its fixed-window query is level with SQL families and faster than SQL labels at one thread.

Reproduce

cd demos/aie
./check_evidence.sh
./derive_real.sh /path/to/pbmc_1k_v3.bam /new/ladder
Rscript --vanilla measure_real.R /new/ladder work/new-real-comparison
# One reusable product cache, with explicit tag policy:
./prepare_evidence.sh /path/to/input.bam work/input.duckdb sample UR 4
duckdb work/input.duckdb -c "SELECT * FROM aie_region_families('1',1,3000000);"

DUCKDB and DUCKHTS_EXTENSION select recorded runtime artifacts. Use new output directories; preserve previous receipts. Render this report from committed evidence, not by rerunning engines. From the repository root, Rscript scripts/plot-benchmarks.R regenerates the static SVGs.