Skip to content

bigWig coverage tracks - #114

Open
ewels wants to merge 12 commits into
mainfrom
cursor/bigwig-coverage-tracks-09a4
Open

ewels wants to merge 12 commits into
mainfrom
cursor/bigwig-coverage-tracks-09a4

Conversation

@ewels

@ewels ewels commented Jun 16, 2026 •

Copy link
Copy Markdown
Member

Closes #112.

rustqc rna now writes genome-wide bigWig coverage tracks in its single pass over the BAM. The tracks match bedtools genomecov (v2.31.1) followed by UCSC bedClip and bedGraphToBigWig, and the defaults give exactly the three files that nf-core/rnaseq publishes in {aligner}/bigwig/. The aim is that nf-core/rnaseq can later drop its BEDTOOLS_GENOMECOV_* and BEDGRAPH_BEDCLIP_BEDGRAPHTOBIGWIG_* tasks and use RustQC's output instead (that pipeline change is not part of this PR).

Output

Files go in bigwig/ (or the output directory with --flat-output). With the default settings each file equals the output of bedtools genomecov ... | LC_ALL=C sort -k1,1 -k2,2n, then bedClip and bedGraphToBigWig with the BAM's chromosome sizes:

File Written for bedtools genomecov
{sample}.bigWig every library -ibam {bam} -split -bg
{sample}.forward.bigWig stranded libraries -split -du -strand + -bg (-strand - for a reverse-stranded library)
{sample}.reverse.bigWig stranded libraries -split -du -strand - -bg (-strand + for a reverse-stranded library)

forward/reverse name the transcript strand, so their -strand filters swap for reverse-stranded libraries, as in nf-core/rnaseq's conf/modules/bigwig.config. A track with no coverage is skipped with a warning (a bigWig cannot hold an empty track); a BAM that is not coordinate-sorted gets no tracks and a warning. Neither fails the run.

Options

Each option is a key under rna.bigwig in the YAML config, a CLI flag and a RUSTQC_* env var; CLI flags override the config. Options apply to all tracks of a run.

YAML key CLI flag Default bedtools
enabled --skip-bigwig true (whole step)
tracks --bigwig-tracks combined,forward,reverse combined, plus forward,reverse if stranded -strand +/-
split --bigwig-split[=BOOL] true -split
du --bigwig-du[=BOOL] true -du
scale --bigwig-scale <FLOAT> 1.0 -scale
bga --bigwig-bga[=BOOL] false -bga (else -bg)
read_end --bigwig-read-end 5p|3p unset -5 / -3
fragment_size --bigwig-fragment-size <N> unset -fs
  • Semantics follow bedtools' CoverageBam source
    • Only unmapped reads are dropped: duplicates, secondary, supplementary, QC-failed and any-MAPQ reads all count, and overlapping mates count twice.
    • D always splits a read into blocks (no -ignoreD); N splits only with split.
    • -du flips read 2 only when the read is paired and its mate is mapped, and only affects the -strand filter (so it is a no-op on the combined track).
    • -5, -3 and -fs use the read's own strand; -fs takes priority over -5/-3, which take priority over -split, as in bedtools (which refuses -split together with -5/-3, so read_end simply ignores split).
    • -scale multiplies in float and rounds to the six significant digits bedtools prints (ties to even, like glibc), so values equal what bedGraphToBigWig would store; with scale 1 depths are exact integers.
    • With bga the bigWig stores zero spans (and whole uncovered contigs) as 0 instead of leaving gaps.
  • Not implemented
    • -pc (paired fragment coverage): its interval runs from read 1's mate position to read 1's end, so it is only known when read 1 arrives, which can be an arbitrary insert size (hundreds of kb for spliced RNA-seq pairs) behind the sweep cursor. Supporting it means holding a whole chromosome's coverage or fragile mate matching, so it does not fit the streaming design.
    • -ignoreD, -max, -d/-dz/histogram output and -trackline were not requested and are left out.

Replacing bedtools in nf-core/rnaseq

Run RustQC with defaults on the BAM that nf-core/rnaseq gives to bedtools genomecov, with the sample's strandedness:

rustqc rna sample.markdup.sorted.bam --gtf genes.gtf --stranded reverse -o results/

This writes results/bigwig/{sample}.bigWig, plus {sample}.forward.bigWig and {sample}.reverse.bigWig when --stranded is forward or reverse, the same files as nf-core/rnaseq's three genomecov/bedClip/bedGraphToBigWig chains. The other bigWig options must stay at their defaults.

Implementation

  • Streaming, memory-bounded accumulation (kept from the original branch)
    • The BAM is coordinate-sorted, so each track keeps only a sparse map of coverage deltas ahead of the read cursor and finalises everything behind it. Live state is bounded by the widest read (or -fs fragment, which keeps that much open behind the cursor), not by genome size.
    • Finished coverage is stored per chromosome as (end, depth) runs keyed by reference id (8 bytes per depth change, no per-interval chromosome String), and -bga zero spans are produced at write time.
  • Pure-Rust bigWig writer (src/rna/bigwig/writer.rs, 508 lines)
    • No bigtools, no tokio, no cargo feature: RustQC stays pure Rust after Make RustQC pure Rust: drop the C++ RNG shim and native font libraries #211 (cargo tree has no cc, cmake or libdeflate). zlib comes from flate2, which was already a dependency.
    • It follows UCSC bedGraphToBigWig: header, chromosome B+ tree (name-sorted, only chromosomes with data, multi-level past 256), zlib-compressed bedGraph sections of up to 1024 items, R-tree index with blockSize 256, and zoom levels plus the total summary.
    • Zoom levels are a port of bbiWriteZoomLevels: candidate sizes start at the average interval size and grow 4x, the first level is the finest whose estimated size is at most half the data, and each further level merges the previous one until the record count stops falling. Summaries are f32, as in UCSC, so they round the same way.
  • Branch history
    • main is merged in (no rebase); the accumulator now uses the noodles shim (crate::rna::bam).
    • The merge exposed a bug: main's deliberately unsorted CRAM fixture (same_reference_multi_slice.cram) produced overlapping intervals. Out-of-order input is now detected and the tracks are dropped with a warning.

Validation

  • Real bedtools fixtures for every track and option
    • tests/create_bigwig_test_data.sh runs bedtools 2.31.1 genomecov (via a bedtools + samtools container) on tests/data/test.bam and on a new hand-written edge-case BAM (tests/data/bigwig_edge.sam: reads 1/2 on each strand with mapped and unmapped mates, single-end reads, N and D CIGARs, a read past the contig end, secondary/duplicate/QC-fail/supplementary records, an unmapped read, a second contig).
    • Cases: combined (-split -bg), -du -strand + and -strand -, -bga, -scale 0.37, -5, -3, -fs 25, and on the edge BAM also no -split and -strand - without -du. These replace the expectations that were only derived from the bedtools source; all of the old hand-derived values agreed with real bedtools.
    • The integration test decodes each written bigWig with a small reader in the test module (B+ tree, R-tree, zlib sections) and compares it with the fixture, for forward, reverse and unstranded libraries, on 1 and 4 threads. A bedtools track with no coverage must produce no file. Another test writes 257 chromosomes and ~386K intervals through the library to check multi-level B+ and R-trees.
  • UCSC tools (biocontainers ucsc-bigwigtobedgraph:469, ucsc-bigwiginfo:469, ucsc-bigwigsummary:482, and nf-core's ucsc-bedgraphtobigwig:482)
    • Before removing bigtools, its bigWigs were kept as a reference: test.bam (default, forward, reverse, bga, scale, 5p, 3p, fs, split=false) and the 52.8K-read benchmark BAM (3 tracks), 17 files. bigWigToBedGraph decodes all 17 new files to exactly the bigtools output.
    • A synthetic 300-contig, 300K-read BAM (900 sections, two-level R-tree, two-level chromosome tree) also decodes identically, apart from chromosome order: bigWigToBedGraph lists chromosomes in B+ tree order, which is now name-sorted as UCSC requires (bigtools wrote them in id order).
    • The benchmark tracks decode to exactly the real bedtools + bedClip snapshots in RustQC-benchmarks refactor: remove BED input support, make --gtf required #28 (snapshots/rna/small/bigwig/, 54,615 / 24,961 / 29,656 lines), compared locally only.
    • bigWigInfo and bigWigSummary were compared with bedGraphToBigWig files built from the same bedGraphs: identical zoom levels (e.g. 352 to 92,274,688 bp, 10 levels on the benchmark track), identical total summary, and identical bigWigSummary mean/max/min/coverage/std over whole chromosomes and sub-regions on the benchmark, -bga and 300-contig files. bigtools' zoom summaries did not match UCSC's (region means were several-fold too low).
    • The files are not byte-identical to bedGraphToBigWig output: zlib-rs compresses differently, and UCSC pads its last R-tree leaf with 24-byte rather than 32-byte empty slots.
  • Checks
    • cargo fmt --check, cargo clippy -- -D warnings and cargo test --release pass; cargo +1.89 check --all-targets passes (MSRV unchanged). clippy --all-targets adds no new warnings.

Performance

Release build, Apple silicon, RustQC-benchmarks small/test.bam (3.8 MB, 52.8K reads, chr6), -s reverse so all three tracks are written, median of 7 runs:

Threads Tracks off Tracks on With bigtools before
1 1.96 s, 220 MB 2.02 s, 222 MB 2.44 s, 221 MB
4 1.97 s, 250 MB 2.01 s, 250 MB 2.11 s, 261 MB

The three tracks now add about 0.05 s. The writer is single-threaded and runs after the BAM pass.

🤖 Generated with Claude Code

@ewels

ewels commented Jun 16, 2026 •

Copy link
Copy Markdown
Member Author

Code review: bigWig coverage tracks (# 114)

Reviewed the full diff. This is a clean, well-documented addition that slots the coverage accumulation into the existing single-pass BAM loop and matches bedtools genomecov semantics carefully. Docs, changelog, citations, and config are all updated consistently. Integration tests cross-check decoded bedGraph against the real bedtools + UCSC toolchain, which is the right bar.

Below are the things worth addressing before merge, ordered by impact.

🔴 Memory: dense per-base arrays held for the whole genome

ChromCoverage allocates a dense Vec<DiffPoint> of length = chromosome size, and DiffPoint is 8 bytes (2 × u32). So each track costs ~8 bytes per genome base.

  • The parallel path allocates per-batch accumulators and then merges them all into one accumulator (ChromResult::merge), so the merged result holds every chromosome's dense array simultaneously.
  • For a human genome (~3.1 Gb) that is ~25 GB for the combined track alone, and ~75 GB for stranded libraries (combined + forward + reverse).

By contrast bedtools genomecov on a coordinate-sorted BAM only keeps the current chromosome's array and flushes when the chromosome changes, so its peak is roughly one chromosome (~1-2 GB). This is a 10-25x memory regression against the tool RustQC is matching, and the headline use case is ~186M reads on a real genome. It risks OOM on anything smaller than the benchmark instance, and the PR description doesn't mention the memory cost.

Options worth considering:

  • Since input is coordinate-sorted, stream per-chromosome: emit bedGraph as each chromosome completes and free its array (closest to bedtools' profile).
  • Or use a sparse breakpoint map (e.g. BTreeMap<pos, delta>) per chromosome. RNA-seq coverage is sparse, so this would be far smaller than dense arrays.

At minimum, please document the expected memory footprint.

🟠 Hot-loop allocation per read

In process_track (src/rna/bigwig/accumulator.rs):

if settings.split {
    let mut blocks_buf = Vec::new();
    genomecov_blocks(record, &mut blocks_buf);
    ...
}

A fresh Vec is allocated on every call, and process_track runs once per track per read (up to 3 tracks for stranded). That is hundreds of millions of heap allocations on a large BAM. genomecov_blocks even starts with blocks.clear(), which signals it was designed to take a reusable scratch buffer, but the caller defeats that by allocating fresh each time. Hoist a single scratch Vec (per worker / per process_read call) and pass it down.

🟠 Hot-loop linear search by chromosome name

TrackAccum::chrom_mut does a linear scan with string comparison:

self.chroms.iter_mut().find(|(name, _)| name == chrom)

This runs per read per track. The caller already has the tid in hand (record.tid()), so indexing the track by tid (a Vec indexed by tid, or a tid→slot map built once) would remove the per-read string compare entirely and align with how the other accumulators key off tid.

🟡 Minor

  • Redundant BAM re-open (main.rs): chrom sizes are obtained by opening a brand-new Reader::from_path(bam_path) purely to read the header, after count_reads already had the header available. Consider threading the sizes out of the count pass instead of re-opening.
  • tokio runtime per track (output.rs): write_bedgraph_bigwig builds a fresh multi-thread runtime for each track (up to 3 per sample). Build it once in write_bigwig_tracks and reuse.
  • Dead non-split branch: every caller sets split: true, so the else branch in process_track (and TrackSettings.split itself) is currently unreachable. Either drop it or add a test that exercises it.
  • clip_bedgraph is largely a no-op: chrom_to_bedgraph already bounds end to cov.size, so clipping to chrom sizes can never trim anything. Fine as defensive code, but worth a comment saying so, since the docs present it as load-bearing bedClip parity.
  • GenomeCovAccum / GenomeCovResult duplication: identical field layout with a From impl. The type split is reasonable for an accumulate-then-finalize boundary, but a one-line note on why they're separate would help.

✅ Things I checked and are fine

  • record.flags() & BAM_FREAD2 != 0 parses correctly: in Rust & binds tighter than != (unlike C), so this is (flags & BAM_FREAD2) != 0.
  • chrom_to_bedgraph difference-array walk matches bedtools ReportChromCoverageBedGraph (traced the unit test by hand: [2,4] inclusive ×2 → (2,5,2), correct half-open output).
  • u32 depth counters won't overflow at realistic coverage.
  • Empty per-strand track skipping is handled and documented.

❓ Worth confirming

The -du strand flip adds !record.is_mate_unmapped() as a guard:

if settings.deduplicate_strand
    && record.is_paired()
    && !record.is_mate_unmapped()
    && record.flags() & BAM_FREAD2 != 0

bedtools' -du flips strand for the second mate based on the second-mate flag; the mate-unmapped guard is an extra condition. The integration tests pass against bedtools on test.bam, so this matches on the test data, but it's worth confirming the test BAM actually contains a second mate whose mate is unmapped, otherwise that edge isn't covered.

Test coverage

Good: two integration tests cross-check combined and stranded-forward against the real bedtools + UCSC chain, plus unit tests for chrom_to_bedgraph and clip_bedgraph. Gaps to consider: a stranded-reverse case (to exercise the swapped strand labels), and an explicit empty-per-strand-track skip assertion.

Overall: solid, faithful implementation with strong validation. The memory profile is the one item I'd want resolved (or at least explicitly documented) before this runs on real genomes; the two hot-loop items are straightforward wins given RustQC's performance focus.

@ewels

ewels commented Jun 16, 2026

Copy link
Copy Markdown
Member Author

Review follow-up

Pushed three commits addressing the review (b0e5a07, 86bbd2d, and the perf fixes before them). Status against each finding:

🔴 Memory — fixed

The dense whole-genome difference array is gone. The accumulator now does a streaming sweep: since each chromosome's reads arrive coordinate-sorted, it keeps only a sparse map of pending coverage deltas plus a cursor, emits finished bedGraph intervals as the cursor advances, and drops the deltas below it. Peak memory is bounded by the widest single-read span (introns included) — a few KB per track — instead of chromosome length × depth × thread count. The ~25 GB (combined) / ~75 GB (stranded) footprint on a human genome is eliminated and no longer scales with genome size or core count.

Output is unchanged, validated bit-for-bit against native bedtools genomecov v2.30 + UCSC bedClip/bedGraphToBigWig/bigWigToBedGraph: 738/738 intervals identical for both the combined (-split) and stranded (-split -du -strand +) tracks. Added a randomised brute-force equivalence test (200 trials) plus targeted cases for overlap, nesting, end-clamping, and net-zero interval merging.

🟠 Per-read allocation — fixed

Split-read blocks now use a single reusable scratch buffer instead of a fresh Vec per record per track.

🟠 Per-read linear chromosome scan — fixed

Eliminated entirely. The streaming design accumulates one active chromosome at a time, so there is no per-read name lookup at all.

🟡 Redundant BAM re-open — fixed

Chromosome sizes are carried through GenomeCovResult (BAM header order) from the count pass; the output step no longer re-opens the BAM.

🟡 Dead non-split branch — fixed

Removed; all nf-core/rnaseq tracks are -split.

🟡 clip_bedgraph redundancy — documented

Kept as a defensive bedClip-parity step with a comment noting the streaming accumulator already clamps interval ends.

❓ -du mate-unmapped guard — validated on test data

The stranded -du -strand + track matches bedtools exactly (738/738) on the test BAM, so the strand-flip logic is correct for that data. The specific mate-unmapped edge isn't independently asserted; worth a dedicated case if a BAM that exercises it is available.

Not changed: tokio runtime per track

Left as-is. bigtools::BigWigWrite::write takes the Runtime by value (consumes it), so reusing one runtime across the up-to-3 tracks isn't possible without a deeper API change. The cost is a few ms at the output stage, not in any hot loop.

Remaining / optional

  • Integration tests for the stranded-reverse track and an explicit empty-per-strand-track skip assertion (the reverse strand filter and skip logic are exercised indirectly but not asserted directly).
  • The upstream cross-check tests still require bedtools + UCSC tools to be present locally/CI; they skip cleanly otherwise.

All 241 tests pass; clippy and fmt are clean.

@ewels

ewels commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

Test coverage update

Closed out the remaining test gaps from the review follow-up:

  • -du mate-unmapped guard — added a synthetic-BAM cross-check (test_bigwig_strand_edge_cases_match_bedtools) that pins this down against bedtools as the ground truth. A read-2 with an unmapped mate stays on the forward track, exactly as bedtools does. The same fixture covers read-1/read-2 flipping, single-end, spliced (N) and deletion (D) CIGARs, end-clamping, secondary/duplicate/QC-fail/supplementary inclusion, unmapped exclusion, and a second chromosome — compared across combined/forward/reverse tracks at 1 and 4 threads (sequential + parallel paths). Verified end-to-end against bedtools v2.30 + UCSC tools; skips cleanly when those aren't present.
  • Stranded-reverse track — now covered by the reverse comparison in that test.
  • Empty per-strand track skipping — added a tool-independent test (test_bigwig_per_strand_track_presence): unstranded → combined track only; --stranded forward on a forward-only BAM → forward written, empty reverse skipped (no stub file).

Commits a479729, 3ce2694. Full suite green, clippy/fmt clean.

@ewels ewels changed the title feat: add nf-core-compatible bigWig coverage tracks bigWig coverage tracks Jun 17, 2026
cursoragent and others added 8 commits June 17, 2026 10:49
Implement bedtools genomecov-equivalent coverage accumulation in the
existing BAM streaming pass and write bigWig files via bigtools.

Produces nf-core/rnaseq-compatible outputs:
- {sample}.bigWig (combined, -split -bg)
- {sample}.forward/reverse.bigWig for stranded libraries (-split -du -strand)

Validated against bedtools genomecov + UCSC bedClip/bedGraphToBigWig in
integration tests.

Co-authored-by: Phil Ewels <phil.ewels@seqera.io>
Add a dedicated bigWig docs page and update README, AGENTS.md,
CONTRIBUTING.md, getting-started guides, credits, CLI/config references,
benchmark details, and library doc comments to describe nf-core/rnaseq-
compatible genome coverage track output.

Co-authored-by: Phil Ewels <phil.ewels@seqera.io>
Co-authored-by: Phil Ewels <phil.ewels@seqera.io>
Address review feedback on the bigWig coverage tracks:

- Reuse a single scratch buffer for split-read alignment blocks instead
  of allocating a Vec per record per track in the hot loop.
- Index each track's chromosomes by name (HashMap) for O(1) lookup per
  read, replacing the previous linear name scan.
- Carry BAM header-ordered chromosome sizes through GenomeCovResult so
  the output step no longer re-opens the BAM purely to read the header.
- Drop the unreachable non-split code path (all nf-core/rnaseq tracks
  use -split) and document clip_bedgraph as defensive.
- Tidy a clippy manual-find warning in the bigWig integration helper.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
… size

The difference-array accumulator allocated one counter per genome base and
kept every chromosome resident, costing ~25 GB (combined) to ~75 GB
(stranded) on a human genome. Replace it with a streaming sweep that
exploits the coordinate-sorted BAM: keep only a sparse map of pending
coverage deltas plus a cursor, emit finished bedGraph intervals as the
cursor advances, and drop deltas below it. Peak memory is now bounded by
the widest single-read span (introns included), independent of chromosome
length, sequencing depth, and thread count.

Output is unchanged: validated bit-for-bit against bedtools genomecov
v2.30 + UCSC bedClip/bedGraphToBigWig/bigWigToBedGraph (738/738 intervals
identical for both combined `-split` and stranded `-split -du -strand +`),
plus a randomised brute-force equivalence test covering overlaps, nesting,
clamping, and net-zero interval merging.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The streaming accumulator already clamps interval ends to each chromosome's
length and never emits a chromosome absent from chrom_sizes, so clip_bedgraph
was a pure pass-through. Remove it and write the bedGraph intervals directly.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Builds a synthetic BAM exercising the full matrix of cases that affect
genomecov coverage and strand assignment, and compares the combined,
forward, and reverse tracks against bedtools genomecov + UCSC tools at
both 1 and 4 threads (sequential and parallel paths):

- read-1 vs read-2 strand flipping under -du
- read-2 with an *unmapped* mate (not flipped — bedtools only flips when
  the mate is mapped; this pins down the previously-unverified guard)
- read-1 mate-unmapped and single-end reads (no flip)
- spliced (N) and deletion (D) CIGAR splitting
- a read overhanging the chromosome end (clamping)
- secondary, duplicate, QC-fail, supplementary (counted); unmapped (ignored)
- a second chromosome (parallel per-chromosome merge)

Verified end-to-end against bedtools v2.30 + UCSC bedClip/bedGraphToBigWig/
bigWigToBedGraph; skips cleanly when those tools are absent.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Tool-independent test using a forward-only BAM: an unstranded run produces
only the combined track, and a --stranded forward run populates the forward
track while skipping the empty reverse track (no stub file written).

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
@ewels
ewels force-pushed the cursor/bigwig-coverage-tracks-09a4 branch from 9a7485b to 44a6a89 Compare June 17, 2026 08:53
@ewels

ewels commented Jun 17, 2026 •

Copy link
Copy Markdown
Member Author

Rebased this branch onto the corrected main.

This branch had main merged into it while the accidental noodles migration (#115) was still on main, so it was carrying that commit. Merging as-is would have silently re-introduced the noodles migration into main. I've rebased the branch onto the current `main` (rust-htslib), dropping the stale #115 and the duplicated #116 commits and keeping only the bigWig coverage work (8 commits). The two perf commits conflicted in src/main.rs and src/rna/bigwig/accumulator.rs (they were authored over the noodles tree); resolved to the htslib-compatible versions. cargo check and cargo check --tests both pass locally.

Force-pushed, so please re-pull if you have a local copy. The noodles work itself lives in #118.

@ewels

ewels commented Jun 17, 2026

Copy link
Copy Markdown
Member Author

Corresponding PRs for testing / benchmarks:

No manual effort done here, so still a way to go with validation work.

@ewels
ewels marked this pull request as draft June 17, 2026 13:10
@ewels ewels added this to the v0.3 milestone Dec 3, 2026
Brings the bigWig branch up to date with the noodles migration (#118) and
everything else on main. The bigWig accumulator and its integration-test
helper now use the rust-htslib-shaped shim at crate::rna::bam instead of
rust_htslib.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
ewels and others added 2 commits December 3, 2026 14:50
Make the coverage tracks follow bedtools genomecov v2.31.1 (CoverageBam)
and expose its options, while the defaults still give exactly
nf-core/rnaseq's three files:

- tracks: combined / forward / reverse (default: combined, plus the two
  stranded tracks for stranded libraries; forward/reverse swap their
  -strand for reverse-stranded libraries, as rnaseq does)
- split (-split, default on), du (-du, default on), scale (-scale,
  applied in float and rounded to the six significant digits bedtools
  prints), bga (-bga), read_end (-5 / -3), fragment_size (-fs)

All are settable under rna.bigwig in YAML and as --bigwig-* flags /
RUSTQC_BIGWIG_* env vars; --skip-bigwig turns the tracks off.

Finished coverage is now kept as per-chromosome (end, depth) runs keyed
by tid, 8 bytes a run instead of a String per interval, and zero spans
for -bga are synthesised at write time. -fs keeps a fragment_size
window open behind the cursor so reverse reads can extend backwards.
Input that is not coordinate-sorted (which the streaming sweep cannot
handle) now drops the tracks with a warning instead of failing the run
with an overlapping-interval error from bigtools; this fixes the
same_reference_multi_slice CRAM test from main.

bigtools and tokio are optional behind a default-on `bigwig` feature;
without it the run warns that no bigWig tracks are written and
everything else works. Empty tracks are skipped with a warning.

Tests: the combined track is read back from the bigWig container and
compared with a real `bedtools genomecov -split -bg` fixture for
tests/data/test.bam (from #166; regenerate with
tests/create_bigwig_test_data.sh) on 1 and 4 threads, plus -bga and
-scale derived from it. A synthetic BAM pins the default tracks for
forward and reverse libraries and every option against bedtools'
source semantics. The live-bedtools tests, which always skipped without
bedtools installed, are replaced.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ature

- bigwig.mdx: exact bedtools genomecov + sort + bedClip + bedGraphToBigWig
  command for each output file, an options table with bedtools flags,
  read filters, a "Replacing bedtools in nf-core/rnaseq" section,
  unsupported options (-pc and why), the bigwig cargo feature, and how
  the tracks are validated
- configuration and CLI reference: rna.bigwig keys, --bigwig-* flags and
  RUSTQC_BIGWIG_* env vars
- The default build compiles libdeflate (via bigtools) with the C
  compiler Rust already links with; installation, CONTRIBUTING,
  AGENTS.md and the lib docs now say so, and that
  --no-default-features compiles no C code
- Cite the bigWig format paper (Kent et al. 2010) and fix the bigtools
  reference; README, CHANGELOG and AGENTS.md updated

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ewels
ewels marked this pull request as ready for review December 3, 2026 13:59
Replace bigtools (which builds libdeflate in C) and tokio with a small
bigWig writer that follows UCSC bedGraphToBigWig: chromosome B+ tree,
zlib (flate2) bedGraph sections, R-tree indexes with blockSize 256 and
1024 items per slot, and zoom levels chosen and summarised as in
bbiWriteZoomLevels, plus the total summary. bigWigInfo and bigWigSummary
report the same zoom levels and values as for bedGraphToBigWig files.

The `bigwig` cargo feature and its gates are gone; RustQC is pure Rust
again.

Tests now decode the bigWig in the test module and compare every track
and option with real bedtools 2.31.1 genomecov output, for test.bam and
a new edge-case BAM (bigwig_edge.sam), regenerated by
tests/create_bigwig_test_data.sh.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Feature request: Generate coverage tracks

2 participants