← Về thư mục
📄 / / profiles / r-and-d / raw_evidence / scientific-agent-skills / skills / gtars / references / coverage.md

Coverage, uniwig, and bigWig

Verified against gtars-cli==0.9.0 / gtars-uniwig==0.9.0 on 2026-07-23. The public BEDbase page is partly under construction; tagged CLI and crate source take precedence where examples differ.

Distinguish two meanings of coverage

Python 0.9.2 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:

  1. use 0-based half-open intervals;
  2. supply the exact assembly's local chrom.sizes;
  3. require every contig to exist and every end to be within bounds;
  4. sort by chromosome dictionary order, then numeric start/end;
  5. use one local file (BED, narrowPeak, or BAM);
  6. 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 4

It validates local paths, bounds, sorting, Gtars u32 coordinates, output collision, and a conservative dense-value budget. 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 1

Equivalent short options are -f, -t, -c, -m, -s, -l, -y, -u, -p, and -z. Valid batch count types are:

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:

Validate scientific meaning before using start/end/shift signals. ATAC cut-site shifts and ChIP fragment-body counts are not interchangeable.

Streaming mode

For very large BED input, 0.9.0 exposes a streaming processor whose state is bounded by smoothing/gap behavior:

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 0

Streaming constraints in tagged source:

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 1

Parallel 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:

After generation:

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.

Rust APIs

Enable only uniwig:

[dependencies]
gtars = { version = "=0.9.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

Official sources (accessed 2026-07-23)