sonar-c
Lightweight Hi-C noise analysis toolkit for .hic (hicstraw) and cooler formats (.cool, .mcool, .scool).
Features
- Per-row noise estimates with optional subsampling simulations to gauge robustness.
- Configurable row filtering based on distance-normalized signal and window occupancy.
- Works with
.hic,.cool,.mcool, and.scoolinput matrices (SciPy-backed pipeline for cooler formats). - Whole-genome noise tracks at requested resolutions.
- Simple plotting helpers for comparing noise distributions (log-scaled histograms).
Installation
Default install — both backends (cooler + hicstraw):
pip install sonar-c
Single-backend profiles:
# cooler only (.cool / .mcool / .scool)
pip install "sonar-c[cooler]"
# hicstraw only (.hic)
pip install "sonar-c[straw]"
Windows users — known PyPI install error
hic-strawdoes not ship pre-built wheels for Windows on PyPI and may fail to compile from source. Ifpip install sonar-cerrors during the hicstraw build step, bypass the default install and use the cooler-only profile:pip install sonar-c --no-deps pip install numpy pandas statsmodels matplotlib scipy coolerTo process
.hicfiles on Windows, convert them first withhic2cooland use the cooler backend:pip install hic2cool hic2cool convert sample.hic sample.mcool --resolutions 10000 sonar-c sample-noise --hic sample.mcool --cooler_path /resolutions/10000 --res 10000 --out_dir outputs/
Command Line Usage
Sampled noise with subsampling summaries
sonar-c sample-noise \
--hic sample.cool \
--res 10000 \
--min_mean_score 0.9 \
--min_nonzero_frac 0.05 \
--subsample_ratios 1.0,0.75,0.5,0.25 \
--norm balance \
--out_dir outputs/10kb \
--seed 42 \
--profile outputs/10kb/profile.csv
Produces one <chrom>_<res>.bedgraph for the original map and a subsample_summary.tsv
table with mean/median/log noise, ACF, variability, and empty-bin ratios at each subsample.
Noise bedgraph (genome-wide)
sonar-c noise-bedgraph \
--hic sample.hic \
--res 5000,10000 \
--out_dir outputs/
# Add --cpu <N> to parallelize per (chrom, res) tasks
sonar-c noise-bedgraph \
--hic sample.hic \
--res 5000,10000 \
--out_dir outputs/ \
--cpu 4
# For .mcool/.scool inputs you can add: --cooler_path /resolutions/10000
Plotting
sonar-c plot \
--noise_bed outputs/chr1_10000_sampled.bedgraph \
--out_png noise_density.png
Build a blacklist from bedgraphs
sonar-c blacklist \
--input outputs/10kb/*.bedgraph \
--out blacklist.bed \
--top_quantile 0.95
This command removes any rows with NaN noise values and blacklists the top 5% most
noisy intervals by default. Provide --zscore_cutoff to supply an explicit z-score
threshold instead of using the percentile.
Python API
from sonar_c import noise_sampling
noise_sampling.compute_sampled_noise(
hic_path="sample.cool",
res=10_000,
sample_fraction=1.0,
min_mean_score=0.9,
min_nonzero_frac=0.05,
subsample_ratios=[1.0, 0.5, 0.25],
norm="balance",
out_dir="outputs",
seed=42,
)
Notes
- For
.mcool, the CLI selects the group matching--res(e.g./resolutions/10000). Provide--cooler_pathfor.scoolcell groups or custom URIs. --normacceptsnone,balance(cooler weights / KR for.hic), or a path to a bedgraph/vector defining custom bin weights.- All commands print a summary line with wall-clock time and memory usage; install the optional
profileextra for psutil-backed RSS reporting. --profilewrites per-chromosome runtime and memory metrics to a CSV for downstream plotting.--cpu <N>parallelizesnoise-bedgraphby(chromosome, resolution)tasks (default 1, capped at available cores).- Every CLI invocation now emits a
contacts_overview.tsvsummarizing per-chromosome totals at the coarsest resolution.
Backends
This project supports two I/O backends, both included in the default install:
| Install | Backend | Formats |
|---|---|---|
pip install sonar-c (default) |
cooler + hicstraw | .cool, .mcool, .scool, .hic |
pip install "sonar-c[cooler]" |
cooler only | .cool, .mcool, .scool |
pip install "sonar-c[straw]" |
hicstraw only | .hic |
Runtime guidance:
- If you pass a
.hicfile without hicstraw installed, the tool will suggestpip install "sonar-c[straw]". - If you pass a cooler-format file without
coolerinstalled, the tool will suggestpip install "sonar-c[cooler]". - The same
--cooler_pathargument selects resolution groups in.mcoolfiles and cell groups in.scoolfiles.
Changelog
v0.3.0
noise-bedgraphsubcommand — renamed fromfull-noisefor clarity. All existing flags are unchanged.- Region-filtered
--chrom_sizes— the chromosome sizes file now accepts optional region columns (cols 3+) instart:endorstart-endformat (0-based, half-open). When regions are present, only bins overlapping those regions are emitted. The noise window still extends up to--bindist_bpon each side of the region, with chromosome-end clamping applied as usual. A region smaller than one bin outputs the single overlapping bin. Regions that exceed the chromosome size produce a warning and are skipped; chromosomes with no valid regions are skipped entirely.# Example extended chrom_sizes file (TSV): # chrom size region1 region2 chr1 248956422 0:50000000 100000000:150000000 chr2 242193529 chrX 156040895 5000000-10000000 - Multi-mode blacklist output —
blacklistanddefault-runnow produce four output directories per run (density_only/,noise_only/,union/,intersection/) instead of a single file, enabling comparison of conservative and permissive thresholds. - Default transforms changed to
log1p— both--density_transformand--noise_transformnow default tolog1p(previouslynoneandsqrtrespectively).log1pis more robust to outlier bins (repeats, centromeres) that can skew elbow detection. - Both backends in default install —
pip install sonar-cnow includes bothcoolerandhic-straw. Single-backend profiles[cooler]and[straw]are available for constrained environments.
v0.2.4
- Initial public release.
Metadata
Release files for sonar-c 0.4.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| sonar_c-0.4.0.tar.gz | 128.8 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| sonar_c-0.4.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 235.5 kB
Release files / sonar_c-0.4.0.tar.gz
| Download URL | sonar_c-0.4.0.tar.gz |
|---|---|
| Size | 128.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
91ef04acec73e79dc557b112a4c4ca09183ad99b6e4105ad10a2b510c9fac3ce
|
|
BLAKE2b-256 checksum How to use checksums |
e1ebd9e249928fd160ef5444580dd5c899cc3201645773ff14c705de45c5a616
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|
Release files / sonar_c-0.4.0-py3-none-any.whl
| Download URL | sonar_c-0.4.0-py3-none-any.whl |
|---|---|
| Size | 106.7 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
de6903d00f94fb1dc65971313da04b280d78795a1fe0b1d40988150ba8d7f14c
|
|
BLAKE2b-256 checksum How to use checksums |
6b159be9c0b8d32726799638d3eb1b17666dc5dde7287a25a152ed630a86e3cc
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.12.13
|