coverage.md
225 lines · skills/gtars/references/coverage.md at 5f2bc03
Most marks come from matching words in the file, so treat them as pointers.
Coverage, uniwig, and bigWig
Source-reviewed against gtars-cli==0.10.0 / gtars-uniwig==0.9.0 on 2026-10-01; CLI/Rust templates were not executed in this audit. Published crate source takes precedence when older guide examples differ.
Distinguish two meanings of coverage
- Python
RegionSet.coverage(other)returns a single fraction of base pairs in the first set covered by the second. gtars uniwigcreates positional signal tracks (WIG, NPY, bedGraph, bigWig, and limited BAM-derived outputs).
Python 0.10.0 does not export gtars.uniwig. Old examples using gtars.uniwig.coverage_from_bed, coverage.normalize(), smooth(), call_peaks(), or to_bigwig() are not current APIs.
Input contract
For BED and narrowPeak:
- use 0-based half-open intervals;
- supply the exact assembly's local
chrom.sizes; - require every contig to exist and every end to be within bounds;
- sort by chromosome dictionary order, then numeric start/end;
- use one local file (BED, narrowPeak, or BAM);
- preserve strand separately—uniwig's BED path produces start/end/core counts, not a generic BED6 strand-aware split.
The official module guide states that uniwig expects a single chromosome-sorted input. Never concatenate samples, patients, or assemblies without a reviewed aggregation policy.
Run the deterministic preflight:
python3 -B scripts/coverage_preflight.py \
--input fragments.sorted.bed.gz \
--input-type bed \
--chrom-sizes GRCh38.p14.chrom.sizes \
--assembly GRCh38.p14 \
--output-prefix derived/sample01 \
--output-type bw \
--count-type core \
--threads 4It validates local paths, bounds, sorting, Gtars u32 coordinates, output prefix collisions (including derived output files), and a dense-value budget rounded separately for each contig. It writes and executes nothing.
Current batch CLI
BigWig generation uses the root uniwig command directly—there is no generate subcommand:
gtars uniwig \
--file fragments.sorted.bed.gz \
--filetype bed \
--chromref GRCh38.p14.chrom.sizes \
--smoothsize 5 \
--stepsize 1 \
--fileheader derived/sample01_ \
--outputtype bw \
--counttype core \
--threads 4 \
--zoom 1Equivalent short options are -f, -t, -c, -m, -s, -l, -y, -u, -p, and -z. Valid batch count types are:
start: accumulations at interval starts;end: accumulations at interval ends;core: interval-body accumulations;all: produce start, end, and core;shift: BAM-specific shifted workflow.
The implementation accepts wig, npy, bedgraph, bw, and bigwig strings along relevant paths, but use the documented compact bw for BigWig. BED and narrowPeak can produce WIG, NPY, bedGraph, or BigWig. BAM paths produce BigWig or BED in the documented workflow.
Other batch flags:
--scoreuses narrowPeak score;--bamscale FLOATscales BAM values (default1.0);--no-bamshiftdisables direction-aware BAM shifting;--wigstep fixed|variableselects WIG step style;--debugincreases output.
Validate scientific meaning before using start/end/shift signals. ATAC cut-site shifts and ChIP fragment-body counts are not interchangeable.
Raw lines 53 to 96Streaming mode
For large BED input, CLI 0.10.0 exposes a streaming processor. Memory still depends on the operation and interval distribution; pilot representative data:
gtars uniwig \
--file fragments.sorted.bed.gz \
--filetype bed \
--chromref GRCh38.p14.chrom.sizes \
--smoothsize 5 \
--stepsize 1 \
--fileheader derived/sample01_ \
--outputtype bedgraph \
--counttype core \
--streaming \
--dense 0Streaming constraints in tagged source:
- only BED input;
- only
wigorbedgraphoutput, not BigWig or NPY; - count type
start,end,core, orall(not BAMshift); --dense 0is sparse,--dense -1is fully dense, and positiveNfills gaps no wider thanN;--stdoutis available; multiple count types receive separator comments.
If stdin is used with --counttype all, the handler buffers stdin into memory so it can replay it. Do not claim constant memory for that combination.
BAM QC and BAM coverage
Library-complexity metrics are a subcommand:
gtars uniwig bamqc \
--input aligned.bam \
--output bamqc.tsv \
--threads 1Parallel BAM QC (--threads >1) requires a .bai index. Bound BAM size, index size, decompression work, threads, and output. Metrics NRF/PBC1/PBC2 are technical QC summaries, not evidence of biological quality or suitability.
For BAM-to-bigWig, the batch path requires the same --smoothsize, --stepsize, --fileheader, --chromref, and output controls. Keep alignment assembly, filtering, duplicate policy, paired-end handling, and shift/scaling in the provenance record.
BigWig preflight and postflight
Before generation:
- verify the exact chromosome dictionary and checksum;
- reject unknown/out-of-bounds contigs;
- ensure sorted input and numeric signal values;
- reserve disk for intermediate bedGraph plus final BigWig;
- set threads explicitly (upstream batch default is 6);
- use a new output prefix;
- avoid patient identifiers in filenames and track labels.
After generation:
- verify nonzero file size and BigWig readability with a trusted, pinned reader;
- compare its chromosome dictionary and lengths with the input checksum;
- query fixed synthetic positions with known expected coverage;
- check min/max/NaN behavior and start/end/core suffixes;
- record SHA-256, tool versions, parameters, and input hashes.
UCSC documents bedGraph coordinates as 0-based half-open and numerically ordered. Its BigWig tools require matching chromosome sizes. A successful binary write does not prove the assembly or signal semantics are correct.
Raw lines 148 to 171Rust APIs
Enable only uniwig:
[dependencies]
gtars = { version = "=0.10.0", default-features = false, features = ["uniwig"] }The wrapper re-exports gtars_uniwig as gtars::uniwig. The primary batch function is:
uniwig_main(
vec_count_type, smoothsize, filepath, chromsizerefpath, bwfileheader,
output_type, filetype, num_threads, score, stepsize, zoom, debug,
bam_shift, bam_scale, wigstep
) -> Result<(), Box<dyn Error>>It is deliberately string-heavy and has many arguments; prefer the pinned CLI unless embedding is necessary. The typed streaming API is:
uniwig::stream::uniwig_streaming(
input, output, chrom_sizes, smooth_size, step_size,
CountType::{Start|End|Core},
OutputFormat::{Wig|BedGraph},
max_gap
)read_chrom_sizes(BufRead) parses the dictionary. BigWig is a batch API, not a streaming OutputFormat.
Threading and resources
- Batch uniwig builds a Rayon pool of exactly
--threads; the CLI default is 6. - Streaming mode is not controlled by the batch
--threadspath. - Output work can scale with total assembly span divided by step size, not only with BED row count.
- Smoothing, dense gap filling, three count types, BigWig intermediates, and high thread counts can multiply memory/disk.
- Start with one thread and one small synthetic contig. Increase only after measuring peak RSS, temporary disk, throughput, and deterministic equivalence.