sonar-c 0.4.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (33) hide show
  1. sonar_c-0.4.0/PKG-INFO +183 -0
  2. sonar_c-0.4.0/README.md +157 -0
  3. sonar_c-0.4.0/pyproject.toml +38 -0
  4. sonar_c-0.4.0/setup.cfg +4 -0
  5. sonar_c-0.4.0/src/sonar_c/__init__.py +18 -0
  6. sonar_c-0.4.0/src/sonar_c/backends.py +1045 -0
  7. sonar_c-0.4.0/src/sonar_c/cli.py +1454 -0
  8. sonar_c-0.4.0/src/sonar_c/figures.py +314 -0
  9. sonar_c-0.4.0/src/sonar_c/filters.py +932 -0
  10. sonar_c-0.4.0/src/sonar_c/hic_norm.py +261 -0
  11. sonar_c-0.4.0/src/sonar_c/metrics.py +184 -0
  12. sonar_c-0.4.0/src/sonar_c/noise_fullmap.py +1356 -0
  13. sonar_c-0.4.0/src/sonar_c/noise_gradient.py +282 -0
  14. sonar_c-0.4.0/src/sonar_c/noise_sampling.py +843 -0
  15. sonar_c-0.4.0/src/sonar_c/noise_to_weights.py +571 -0
  16. sonar_c-0.4.0/src/sonar_c/reference.py +758 -0
  17. sonar_c-0.4.0/src/sonar_c.egg-info/PKG-INFO +183 -0
  18. sonar_c-0.4.0/src/sonar_c.egg-info/SOURCES.txt +31 -0
  19. sonar_c-0.4.0/src/sonar_c.egg-info/dependency_links.txt +1 -0
  20. sonar_c-0.4.0/src/sonar_c.egg-info/entry_points.txt +2 -0
  21. sonar_c-0.4.0/src/sonar_c.egg-info/requires.txt +20 -0
  22. sonar_c-0.4.0/src/sonar_c.egg-info/top_level.txt +1 -0
  23. sonar_c-0.4.0/tests/test_backends.py +212 -0
  24. sonar_c-0.4.0/tests/test_bias_vector_shape.py +74 -0
  25. sonar_c-0.4.0/tests/test_cli_parsers.py +138 -0
  26. sonar_c-0.4.0/tests/test_filters.py +787 -0
  27. sonar_c-0.4.0/tests/test_hic_norm.py +109 -0
  28. sonar_c-0.4.0/tests/test_metrics.py +79 -0
  29. sonar_c-0.4.0/tests/test_noise_fullmap.py +311 -0
  30. sonar_c-0.4.0/tests/test_noise_gradient.py +341 -0
  31. sonar_c-0.4.0/tests/test_noise_to_weights.py +224 -0
  32. sonar_c-0.4.0/tests/test_oe_consistency.py +141 -0
  33. sonar_c-0.4.0/tests/test_reference.py +279 -0
sonar_c-0.4.0/PKG-INFO ADDED
@@ -0,0 +1,183 @@
1
+ Metadata-Version: 2.4
2
+ Name: sonar-c
3
+ Version: 0.4.0
4
+ Summary: Hi-C noise analysis toolkit for .hic/.cool matrices
5
+ Author: Tim Reznicek
6
+ License: BSD-3-Clause
7
+ Project-URL: Homepage, https://github.com/jrowley-lab-org/sonar-c
8
+ Requires-Python: >=3.9
9
+ Description-Content-Type: text/markdown
10
+ Requires-Dist: numpy>=1.21
11
+ Requires-Dist: pandas>=1.3
12
+ Requires-Dist: statsmodels>=0.13
13
+ Requires-Dist: matplotlib>=3.5
14
+ Requires-Dist: scipy>=1.8
15
+ Requires-Dist: cooler>=0.9.3
16
+ Requires-Dist: hic-straw>=1.3.1
17
+ Provides-Extra: cooler
18
+ Requires-Dist: cooler>=0.9.3; extra == "cooler"
19
+ Provides-Extra: straw
20
+ Requires-Dist: hic-straw>=1.3.1; extra == "straw"
21
+ Provides-Extra: profile
22
+ Requires-Dist: psutil>=5.9; extra == "profile"
23
+ Provides-Extra: dev
24
+ Requires-Dist: pytest>=7.0; extra == "dev"
25
+ Requires-Dist: pytest-cov; extra == "dev"
26
+
27
+ # sonar-c
28
+
29
+ Lightweight Hi-C noise analysis toolkit for `.hic` ([hicstraw](https://github.com/aidenlab/straw)) and cooler formats (`.cool`, `.mcool`, `.scool`).
30
+
31
+ ## Features
32
+ - Per-row noise estimates with optional subsampling simulations to gauge robustness.
33
+ - Configurable row filtering based on distance-normalized signal and window occupancy.
34
+ - Works with `.hic`, `.cool`, `.mcool`, and `.scool` input matrices (SciPy-backed pipeline for cooler formats).
35
+ - Whole-genome noise tracks at requested resolutions.
36
+ - Simple plotting helpers for comparing noise distributions (log-scaled histograms).
37
+
38
+ ## Installation
39
+
40
+ **Default install — both backends (cooler + hicstraw):**
41
+
42
+ ```bash
43
+ pip install sonar-c
44
+ ```
45
+
46
+ **Single-backend profiles:**
47
+
48
+ ```bash
49
+ # cooler only (.cool / .mcool / .scool)
50
+ pip install "sonar-c[cooler]"
51
+
52
+ # hicstraw only (.hic)
53
+ pip install "sonar-c[straw]"
54
+ ```
55
+
56
+ > **Windows users — known PyPI install error**
57
+ >
58
+ > `hic-straw` does not ship pre-built wheels for Windows on PyPI and may fail to
59
+ > compile from source. If `pip install sonar-c` errors during the hicstraw
60
+ > build step, bypass the default install and use the cooler-only profile:
61
+ >
62
+ > ```bash
63
+ > pip install sonar-c --no-deps
64
+ > pip install numpy pandas statsmodels matplotlib scipy cooler
65
+ > ```
66
+ >
67
+ > To process `.hic` files on Windows, convert them first with
68
+ > [`hic2cool`](https://github.com/4dn-dcic/hic2cool) and use the cooler backend:
69
+ >
70
+ > ```bash
71
+ > pip install hic2cool
72
+ > hic2cool convert sample.hic sample.mcool --resolutions 10000
73
+ > sonar-c sample-noise --hic sample.mcool --cooler_path /resolutions/10000 --res 10000 --out_dir outputs/
74
+ > ```
75
+ ## Command Line Usage
76
+ ### Sampled noise with subsampling summaries
77
+ ```bash
78
+ sonar-c sample-noise \
79
+ --hic sample.cool \
80
+ --res 10000 \
81
+ --min_mean_score 0.9 \
82
+ --min_nonzero_frac 0.05 \
83
+ --subsample_ratios 1.0,0.75,0.5,0.25 \
84
+ --norm balance \
85
+ --out_dir outputs/10kb \
86
+ --seed 42 \
87
+ --profile outputs/10kb/profile.csv
88
+ ```
89
+ Produces one `<chrom>_<res>.bedgraph` for the original map and a `subsample_summary.tsv`
90
+ table with mean/median/log noise, ACF, variability, and empty-bin ratios at each subsample.
91
+
92
+ ### Noise bedgraph (genome-wide)
93
+ ```bash
94
+ sonar-c noise-bedgraph \
95
+ --hic sample.hic \
96
+ --res 5000,10000 \
97
+ --out_dir outputs/
98
+ # Add --cpu <N> to parallelize per (chrom, res) tasks
99
+ sonar-c noise-bedgraph \
100
+ --hic sample.hic \
101
+ --res 5000,10000 \
102
+ --out_dir outputs/ \
103
+ --cpu 4
104
+ # For .mcool/.scool inputs you can add: --cooler_path /resolutions/10000
105
+ ```
106
+
107
+ ### Plotting
108
+ ```bash
109
+ sonar-c plot \
110
+ --noise_bed outputs/chr1_10000_sampled.bedgraph \
111
+ --out_png noise_density.png
112
+ ```
113
+
114
+ ### Build a blacklist from bedgraphs
115
+ ```bash
116
+ sonar-c blacklist \
117
+ --input outputs/10kb/*.bedgraph \
118
+ --out blacklist.bed \
119
+ --top_quantile 0.95
120
+ ```
121
+ This command removes any rows with `NaN` noise values and blacklists the top 5% most
122
+ noisy intervals by default. Provide `--zscore_cutoff` to supply an explicit z-score
123
+ threshold instead of using the percentile.
124
+
125
+ ## Python API
126
+ ```python
127
+ from sonar_c import noise_sampling
128
+
129
+ noise_sampling.compute_sampled_noise(
130
+ hic_path="sample.cool",
131
+ res=10_000,
132
+ sample_fraction=1.0,
133
+ min_mean_score=0.9,
134
+ min_nonzero_frac=0.05,
135
+ subsample_ratios=[1.0, 0.5, 0.25],
136
+ norm="balance",
137
+ out_dir="outputs",
138
+ seed=42,
139
+ )
140
+ ```
141
+
142
+ ### Notes
143
+ - For `.mcool`, the CLI selects the group matching `--res` (e.g. `/resolutions/10000`). Provide `--cooler_path` for `.scool` cell groups or custom URIs.
144
+ - `--norm` accepts `none`, `balance` (cooler weights / KR for `.hic`), or a path to a bedgraph/vector defining custom bin weights.
145
+ - All commands print a summary line with wall-clock time and memory usage; install the optional `profile` extra for psutil-backed RSS reporting.
146
+ - `--profile` writes per-chromosome runtime and memory metrics to a CSV for downstream plotting.
147
+ - `--cpu <N>` parallelizes `noise-bedgraph` by `(chromosome, resolution)` tasks (default 1, capped at available cores).
148
+ - Every CLI invocation now emits a `contacts_overview.tsv` summarizing per-chromosome totals at the coarsest resolution.
149
+
150
+ ## Backends
151
+
152
+ This project supports two I/O backends, both included in the default install:
153
+
154
+ | Install | Backend | Formats |
155
+ |---|---|---|
156
+ | `pip install sonar-c` (default) | cooler + hicstraw | `.cool`, `.mcool`, `.scool`, `.hic` |
157
+ | `pip install "sonar-c[cooler]"` | cooler only | `.cool`, `.mcool`, `.scool` |
158
+ | `pip install "sonar-c[straw]"` | hicstraw only | `.hic` |
159
+
160
+ Runtime guidance:
161
+ - If you pass a `.hic` file without hicstraw installed, the tool will suggest `pip install "sonar-c[straw]"`.
162
+ - If you pass a cooler-format file without `cooler` installed, the tool will suggest `pip install "sonar-c[cooler]"`.
163
+ - The same `--cooler_path` argument selects resolution groups in `.mcool` files and cell groups in `.scool` files.
164
+
165
+ ## Changelog
166
+
167
+ ### v0.3.0
168
+ - **`noise-bedgraph` subcommand** — renamed from `full-noise` for clarity. All existing flags are unchanged.
169
+ - **Region-filtered `--chrom_sizes`** — the chromosome sizes file now accepts optional region columns (cols 3+) in `start:end` or `start-end` format (0-based, half-open). When regions are present, only bins overlapping those regions are emitted. The noise window still extends up to `--bindist_bp` on 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.
170
+ ```
171
+ # Example extended chrom_sizes file (TSV):
172
+ # chrom size region1 region2
173
+ chr1 248956422 0:50000000 100000000:150000000
174
+ chr2 242193529
175
+ chrX 156040895 5000000-10000000
176
+ ```
177
+ - **Multi-mode blacklist output** — `blacklist` and `default-run` now produce four output directories per run (`density_only/`, `noise_only/`, `union/`, `intersection/`) instead of a single file, enabling comparison of conservative and permissive thresholds.
178
+ - **Default transforms changed to `log1p`** — both `--density_transform` and `--noise_transform` now default to `log1p` (previously `none` and `sqrt` respectively). `log1p` is more robust to outlier bins (repeats, centromeres) that can skew elbow detection.
179
+ - **Both backends in default install** — `pip install sonar-c` now includes both `cooler` and `hic-straw`. Single-backend profiles `[cooler]` and `[straw]` are available for constrained environments.
180
+
181
+ ### v0.2.4
182
+ - Initial public release.
183
+
@@ -0,0 +1,157 @@
1
+ # sonar-c
2
+
3
+ Lightweight Hi-C noise analysis toolkit for `.hic` ([hicstraw](https://github.com/aidenlab/straw)) and cooler formats (`.cool`, `.mcool`, `.scool`).
4
+
5
+ ## Features
6
+ - Per-row noise estimates with optional subsampling simulations to gauge robustness.
7
+ - Configurable row filtering based on distance-normalized signal and window occupancy.
8
+ - Works with `.hic`, `.cool`, `.mcool`, and `.scool` input matrices (SciPy-backed pipeline for cooler formats).
9
+ - Whole-genome noise tracks at requested resolutions.
10
+ - Simple plotting helpers for comparing noise distributions (log-scaled histograms).
11
+
12
+ ## Installation
13
+
14
+ **Default install — both backends (cooler + hicstraw):**
15
+
16
+ ```bash
17
+ pip install sonar-c
18
+ ```
19
+
20
+ **Single-backend profiles:**
21
+
22
+ ```bash
23
+ # cooler only (.cool / .mcool / .scool)
24
+ pip install "sonar-c[cooler]"
25
+
26
+ # hicstraw only (.hic)
27
+ pip install "sonar-c[straw]"
28
+ ```
29
+
30
+ > **Windows users — known PyPI install error**
31
+ >
32
+ > `hic-straw` does not ship pre-built wheels for Windows on PyPI and may fail to
33
+ > compile from source. If `pip install sonar-c` errors during the hicstraw
34
+ > build step, bypass the default install and use the cooler-only profile:
35
+ >
36
+ > ```bash
37
+ > pip install sonar-c --no-deps
38
+ > pip install numpy pandas statsmodels matplotlib scipy cooler
39
+ > ```
40
+ >
41
+ > To process `.hic` files on Windows, convert them first with
42
+ > [`hic2cool`](https://github.com/4dn-dcic/hic2cool) and use the cooler backend:
43
+ >
44
+ > ```bash
45
+ > pip install hic2cool
46
+ > hic2cool convert sample.hic sample.mcool --resolutions 10000
47
+ > sonar-c sample-noise --hic sample.mcool --cooler_path /resolutions/10000 --res 10000 --out_dir outputs/
48
+ > ```
49
+ ## Command Line Usage
50
+ ### Sampled noise with subsampling summaries
51
+ ```bash
52
+ sonar-c sample-noise \
53
+ --hic sample.cool \
54
+ --res 10000 \
55
+ --min_mean_score 0.9 \
56
+ --min_nonzero_frac 0.05 \
57
+ --subsample_ratios 1.0,0.75,0.5,0.25 \
58
+ --norm balance \
59
+ --out_dir outputs/10kb \
60
+ --seed 42 \
61
+ --profile outputs/10kb/profile.csv
62
+ ```
63
+ Produces one `<chrom>_<res>.bedgraph` for the original map and a `subsample_summary.tsv`
64
+ table with mean/median/log noise, ACF, variability, and empty-bin ratios at each subsample.
65
+
66
+ ### Noise bedgraph (genome-wide)
67
+ ```bash
68
+ sonar-c noise-bedgraph \
69
+ --hic sample.hic \
70
+ --res 5000,10000 \
71
+ --out_dir outputs/
72
+ # Add --cpu <N> to parallelize per (chrom, res) tasks
73
+ sonar-c noise-bedgraph \
74
+ --hic sample.hic \
75
+ --res 5000,10000 \
76
+ --out_dir outputs/ \
77
+ --cpu 4
78
+ # For .mcool/.scool inputs you can add: --cooler_path /resolutions/10000
79
+ ```
80
+
81
+ ### Plotting
82
+ ```bash
83
+ sonar-c plot \
84
+ --noise_bed outputs/chr1_10000_sampled.bedgraph \
85
+ --out_png noise_density.png
86
+ ```
87
+
88
+ ### Build a blacklist from bedgraphs
89
+ ```bash
90
+ sonar-c blacklist \
91
+ --input outputs/10kb/*.bedgraph \
92
+ --out blacklist.bed \
93
+ --top_quantile 0.95
94
+ ```
95
+ This command removes any rows with `NaN` noise values and blacklists the top 5% most
96
+ noisy intervals by default. Provide `--zscore_cutoff` to supply an explicit z-score
97
+ threshold instead of using the percentile.
98
+
99
+ ## Python API
100
+ ```python
101
+ from sonar_c import noise_sampling
102
+
103
+ noise_sampling.compute_sampled_noise(
104
+ hic_path="sample.cool",
105
+ res=10_000,
106
+ sample_fraction=1.0,
107
+ min_mean_score=0.9,
108
+ min_nonzero_frac=0.05,
109
+ subsample_ratios=[1.0, 0.5, 0.25],
110
+ norm="balance",
111
+ out_dir="outputs",
112
+ seed=42,
113
+ )
114
+ ```
115
+
116
+ ### Notes
117
+ - For `.mcool`, the CLI selects the group matching `--res` (e.g. `/resolutions/10000`). Provide `--cooler_path` for `.scool` cell groups or custom URIs.
118
+ - `--norm` accepts `none`, `balance` (cooler weights / KR for `.hic`), or a path to a bedgraph/vector defining custom bin weights.
119
+ - All commands print a summary line with wall-clock time and memory usage; install the optional `profile` extra for psutil-backed RSS reporting.
120
+ - `--profile` writes per-chromosome runtime and memory metrics to a CSV for downstream plotting.
121
+ - `--cpu <N>` parallelizes `noise-bedgraph` by `(chromosome, resolution)` tasks (default 1, capped at available cores).
122
+ - Every CLI invocation now emits a `contacts_overview.tsv` summarizing per-chromosome totals at the coarsest resolution.
123
+
124
+ ## Backends
125
+
126
+ This project supports two I/O backends, both included in the default install:
127
+
128
+ | Install | Backend | Formats |
129
+ |---|---|---|
130
+ | `pip install sonar-c` (default) | cooler + hicstraw | `.cool`, `.mcool`, `.scool`, `.hic` |
131
+ | `pip install "sonar-c[cooler]"` | cooler only | `.cool`, `.mcool`, `.scool` |
132
+ | `pip install "sonar-c[straw]"` | hicstraw only | `.hic` |
133
+
134
+ Runtime guidance:
135
+ - If you pass a `.hic` file without hicstraw installed, the tool will suggest `pip install "sonar-c[straw]"`.
136
+ - If you pass a cooler-format file without `cooler` installed, the tool will suggest `pip install "sonar-c[cooler]"`.
137
+ - The same `--cooler_path` argument selects resolution groups in `.mcool` files and cell groups in `.scool` files.
138
+
139
+ ## Changelog
140
+
141
+ ### v0.3.0
142
+ - **`noise-bedgraph` subcommand** — renamed from `full-noise` for clarity. All existing flags are unchanged.
143
+ - **Region-filtered `--chrom_sizes`** — the chromosome sizes file now accepts optional region columns (cols 3+) in `start:end` or `start-end` format (0-based, half-open). When regions are present, only bins overlapping those regions are emitted. The noise window still extends up to `--bindist_bp` on 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.
144
+ ```
145
+ # Example extended chrom_sizes file (TSV):
146
+ # chrom size region1 region2
147
+ chr1 248956422 0:50000000 100000000:150000000
148
+ chr2 242193529
149
+ chrX 156040895 5000000-10000000
150
+ ```
151
+ - **Multi-mode blacklist output** — `blacklist` and `default-run` now produce four output directories per run (`density_only/`, `noise_only/`, `union/`, `intersection/`) instead of a single file, enabling comparison of conservative and permissive thresholds.
152
+ - **Default transforms changed to `log1p`** — both `--density_transform` and `--noise_transform` now default to `log1p` (previously `none` and `sqrt` respectively). `log1p` is more robust to outlier bins (repeats, centromeres) that can skew elbow detection.
153
+ - **Both backends in default install** — `pip install sonar-c` now includes both `cooler` and `hic-straw`. Single-backend profiles `[cooler]` and `[straw]` are available for constrained environments.
154
+
155
+ ### v0.2.4
156
+ - Initial public release.
157
+
@@ -0,0 +1,38 @@
1
+ [build-system]
2
+ requires = ["setuptools>=61", "wheel"]
3
+ build-backend = "setuptools.build_meta"
4
+
5
+ [project]
6
+ name = "sonar-c"
7
+ version = "0.4.0"
8
+ description = "Hi-C noise analysis toolkit for .hic/.cool matrices"
9
+ readme = "README.md"
10
+ requires-python = ">=3.9"
11
+ license = {text = "BSD-3-Clause"}
12
+ authors = [
13
+ {name = "Tim Reznicek"}
14
+ ]
15
+ dependencies = [
16
+ "numpy>=1.21",
17
+ "pandas>=1.3",
18
+ "statsmodels>=0.13",
19
+ "matplotlib>=3.5",
20
+ "scipy>=1.8",
21
+ "cooler>=0.9.3",
22
+ "hic-straw>=1.3.1"
23
+ ]
24
+
25
+ [project.optional-dependencies]
26
+ cooler = ["cooler>=0.9.3"]
27
+ straw = ["hic-straw>=1.3.1"]
28
+ profile = ["psutil>=5.9"]
29
+ dev = ["pytest>=7.0", "pytest-cov"]
30
+
31
+ [project.urls]
32
+ Homepage = "https://github.com/jrowley-lab-org/sonar-c"
33
+
34
+ [project.scripts]
35
+ sonar-c = "sonar_c.cli:main"
36
+
37
+ [tool.setuptools.packages.find]
38
+ where = ["src"]
@@ -0,0 +1,4 @@
1
+ [egg_info]
2
+ tag_build =
3
+ tag_date = 0
4
+
@@ -0,0 +1,18 @@
1
+ """
2
+ sonar_c
3
+ -----------
4
+
5
+ Hi-C noise analysis library for .hic and .cool contact maps.
6
+ """
7
+
8
+ from . import backends, cli, figures, noise_fullmap, noise_sampling, filters, reference
9
+
10
+ __all__ = [
11
+ "backends",
12
+ "cli",
13
+ "figures",
14
+ "noise_fullmap",
15
+ "noise_sampling",
16
+ "filters",
17
+ "reference",
18
+ ]