hic-sca 0.0.0__py3-none-any.whl

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.
@@ -0,0 +1,645 @@
1
+ Metadata-Version: 2.4
2
+ Name: hic-sca
3
+ Version: 0.0.0
4
+ Summary: HiC-SCA: Hi-C Spectral Compartment Assignment for predicting A-B chromosomal compartments
5
+ Author-email: Justin Chan <chan.waisoon@qst.go.jp>, Hidetoshi Kono <kono.hidetoshi@qst.go.jp>
6
+ License-Expression: MIT
7
+ Project-URL: Homepage, https://github.com/iQLS-MMS/hic-sca
8
+ Classifier: Development Status :: 4 - Beta
9
+ Classifier: Intended Audience :: Science/Research
10
+ Classifier: Topic :: Scientific/Engineering :: Bio-Informatics
11
+ Classifier: Programming Language :: Python :: 3
12
+ Classifier: Programming Language :: Python :: 3.10
13
+ Classifier: Programming Language :: Python :: 3.11
14
+ Classifier: Operating System :: OS Independent
15
+ Requires-Python: >=3.10
16
+ Description-Content-Type: text/markdown
17
+ License-File: LICENSE
18
+ Requires-Dist: numpy>=1.19.0
19
+ Requires-Dist: scipy>=1.15.0
20
+ Requires-Dist: hic-straw>=1.3.0
21
+ Requires-Dist: h5py>=3.0.0
22
+ Requires-Dist: matplotlib>=3.0.0
23
+ Requires-Dist: pandas>=1.3.0
24
+ Requires-Dist: openpyxl>=3.0.0
25
+ Requires-Dist: h5typer>=0.1.0
26
+ Provides-Extra: tests
27
+ Requires-Dist: pytest>=6.0; extra == "tests"
28
+ Requires-Dist: pytest-cov>=2.0; extra == "tests"
29
+ Dynamic: license-file
30
+
31
+ # HiC-SCA: Hi-C Spectral Compartment Analysis
32
+
33
+ A Python package for predicting A-B chromosomal compartments from Hi-C (chromosome conformation capture) data using spectral decomposition and observed/expected normalization.
34
+
35
+ ## Overview
36
+
37
+ HiC-SCA implements a complete pipeline for analyzing Hi-C contact matrices to identify chromatin compartmentalization patterns. It uses spectral decomposition with adaptive tolerance adjustment and an advanced eigenvector selection algorithm to predict A and B chromosomal compartments.
38
+
39
+ **Key capabilities:**
40
+ - Process .hic files at single or multiple resolutions
41
+ - Automatic genome-wide O/E normalization with smoothing
42
+ - Quality-based eigenvector selection
43
+ - Cross-resolution evaluation to identify suitable resolutions
44
+ - Multiple output formats (HDF5, Excel, BED, BedGraph, plots)
45
+
46
+ ## Table of Contents
47
+
48
+ - [Installation](#installation)
49
+ - [Requirements](#requirements)
50
+ - [Install from Source](#install-from-source)
51
+ - [Dependencies](#dependencies)
52
+ - [Quick Start](#quick-start)
53
+ - [Command-Line Interface](#command-line-interface)
54
+ - [Python API](#python-api)
55
+ - [Command-Line Interface](#command-line-interface-1)
56
+ - [Arguments](#arguments)
57
+ - [Usage Examples](#usage-examples)
58
+ - [Output Files](#output-files)
59
+ - [Troubleshooting CLI](#troubleshooting-cli)
60
+ - [Python API](#python-api-1)
61
+ - [Core Classes](#core-classes)
62
+ - [Results Dictionary Structure](#results-dictionary-structure)
63
+ - [Evaluation Tools](#evaluation-tools)
64
+ - [Testing](#testing)
65
+ - [Other Documentation](#other-documentation)
66
+ - [Citation](#citation)
67
+ - [License](#license)
68
+ - [Contributing](#contributing)
69
+ - [Acknowledgments](#acknowledgments)
70
+
71
+ ## Installation
72
+
73
+ ### Requirements
74
+
75
+ - Python >= 3.10
76
+ - pip >= 21.0
77
+
78
+ ### Install from Source
79
+
80
+ HiC-SCA requires the [h5typer](https://github.com/iQLS-MMS/h5typer) package as a dependency.
81
+
82
+ ```bash
83
+ # Clone repositories
84
+ git clone https://github.com/iQLS-MMS/h5typer.git
85
+ git clone https://github.com/iQLS-MMS/hic-sca.git
86
+
87
+ # Install h5typer first (required dependency)
88
+ cd h5typer
89
+ pip install .
90
+
91
+ # Install HiC-SCA
92
+ cd ../hicsca
93
+ pip install .
94
+
95
+ # Or install with test dependencies
96
+ pip install ".[tests]"
97
+ ```
98
+
99
+ ### Dependencies
100
+
101
+ The package automatically installs:
102
+ - hicstraw >= 1.3.0 (reading .hic files)
103
+ - numpy >= 1.19.0 (numerical computations)
104
+ - scipy >= 1.15.0 (sparse matrices, eigendecomposition)
105
+ - h5py >= 3.0.0 (HDF5 I/O)
106
+ - pandas >= 1.0.0 (Excel export)
107
+ - openpyxl >= 3.0.0 (Excel I/O)
108
+ - matplotlib >= 3.0.0 (plotting)
109
+ - h5typer >= 0.1.0 (HDF5 type mapping)
110
+
111
+ ## Quick Start
112
+
113
+ ### Command-Line Interface
114
+
115
+ The easiest way to use HiC-SCA is through the command-line interface:
116
+
117
+ ```bash
118
+ # Process single resolution
119
+ hic-sca -f hic-sca/tests/test_data/ENCFF216ZNY_Intra_Only.hic -r 100000 -p my_sample
120
+
121
+ # Process with BED and BedGraph output
122
+ hic-sca -f hic-sca/tests/test_data/ENCFF216ZNY_Intra_Only.hic -r 100000 -p my_sample --bed --bedgraph
123
+
124
+ # Process multiple resolutions
125
+ hic-sca -f hic-sca/tests/test_data/ENCFF216ZNY_Intra_Only.hic -r 100000 50000 25000 -p my_sample
126
+
127
+ # Process all available resolutions with verbose output
128
+ hic-sca -f hic-sca/tests/test_data/ENCFF216ZNY_Intra_Only.hic -p my_sample -v
129
+
130
+ # Specify output directory
131
+ hic-sca -f hic-sca/tests/test_data/ENCFF216ZNY_Intra_Only.hic -r 100000 -p my_sample -o results/
132
+
133
+ # Process specific chromosomes
134
+ hic-sca -f hic-sca/tests/test_data/ENCFF216ZNY_Intra_Only.hic -r 100000 -c chr1 chr2 chr3 -p my_sample
135
+ ```
136
+
137
+ **Output files:**
138
+ - `my_sample_results.h5` - HDF5 file with complete results
139
+ - `my_sample_100000bp.xlsx` - Excel file (mandatory)
140
+ - `my_sample_100000bp.bed` - BED file (if `--bed` specified)
141
+ - `my_sample_100000bp.bedgraph` - BedGraph file (if `--bedgraph` specified)
142
+ - `my_sample_chr1_100000bp.png` - Compartment plot for chr1
143
+ - `my_sample_cross_resolution_mcc.png` - Cross-resolution MCC heatmap (if multiple resolutions)
144
+
145
+ ### Python API
146
+
147
+ ```python
148
+ from hicsca import HiCSCA
149
+
150
+ # Initialize pipeline with Hi-C file
151
+ hicsca = HiCSCA(
152
+ hic_file_path="hic-sca/tests/test_data/ENCFF216ZNY_Intra_Only.hic",
153
+ resolutions=[100000], # or None for auto-detect all
154
+ chr_names=None # None = all autosomal chromosomes
155
+ )
156
+
157
+ # Process all chromosomes
158
+ hicsca.process_all_chromosomes(verbose=True)
159
+
160
+ # Access results
161
+ result = hicsca.results[100000]['chr1']
162
+ if result['Success']:
163
+ compartment = result['assigned_AB_compartment']
164
+ eig_idx = result['selected_eig_idx']
165
+ score = result['modified_inter_eigval_score']
166
+ print(f"chr1: Selected Eig{eig_idx}, Score: {score:.4f}")
167
+
168
+ # Export results using convenience methods
169
+ hicsca.to_bed(100000, "compartments_100kb.bed")
170
+ hicsca.to_bedgraph(100000, "compartments_100kb.bedgraph")
171
+ hicsca.to_excel(100000, "compartments_100kb.xlsx")
172
+ hicsca.to_hdf5("saved_analysis.h5")
173
+
174
+ # Plot compartments (saves to files)
175
+ hicsca.plot_compartments(100000, output_dir="plots", output_prefix="sample")
176
+
177
+ # Plot cross-resolution MCC correlation
178
+ hicsca.plot_cross_resolution_mcc(save_path="cross_res_mcc.png")
179
+ ```
180
+
181
+ ## Command-Line Interface
182
+
183
+ ### Arguments
184
+
185
+ **Required (one of):**
186
+ - `-f, --hic-file PATH` - Path to input .hic file
187
+ - `--load-hdf5 PATH` - Load existing HDF5 results file
188
+
189
+ **Optional:**
190
+ - `-r, --resolutions BP [BP ...]` - Space-separated resolutions in bp (default: auto-detect all)
191
+ - `-p, --output-prefix PREFIX` - Prefix for output files (required)
192
+ - `-o, --output-dir DIR` - Output directory (default: current directory)
193
+ - `-c, --chromosomes CHR [CHR ...]` - Space-separated chromosome names (default: chr1-chr22)
194
+ - `-t, --data-type TYPE` - Data type: "observed" or "oe" (default: "observed")
195
+ - `-v, --verbose` - Enable verbose output
196
+ - `--bed` - Generate BED files for each resolution
197
+ - `--bedgraph` - Generate BedGraph files for each resolution
198
+
199
+ ### Usage Examples
200
+
201
+ ```bash
202
+ # Basic usage
203
+ hic-sca -f data.hic -r 100000 -p my_sample
204
+
205
+ # With BED and BedGraph output
206
+ hic-sca -f data.hic -r 100000 -p my_sample --bed --bedgraph
207
+
208
+ # Multiple resolutions
209
+ hic-sca -f data.hic -r 500000 250000 100000 50000 -p my_sample
210
+
211
+ # All available resolutions
212
+ hic-sca -f data.hic -p my_sample -v
213
+
214
+ # Custom output directory
215
+ hic-sca -f data.hic -r 100000 -p my_sample -o results/
216
+
217
+ # Specific chromosomes
218
+ hic-sca -f data.hic -r 100000 -c chr1 chr2 chr3 -p my_sample
219
+
220
+ # Use pre-normalized O/E data (skip background normalization)
221
+ hic-sca -f data.hic -r 100000 -p my_sample -t oe
222
+
223
+ # Load existing HDF5 and export to BED/BedGraph
224
+ hic-sca --load-hdf5 results.h5 -p output --bed --bedgraph
225
+
226
+ # Load HDF5 with .hic file (enables processing additional data)
227
+ hic-sca --load-hdf5 results.h5 -f data.hic -p output
228
+
229
+ # Load HDF5 and export filtered data (specific resolutions/chromosomes)
230
+ hic-sca --load-hdf5 results.h5 -r 100000 -c chr1 chr2 -p output --bed
231
+ ```
232
+
233
+ ### Output Files
234
+
235
+ The CLI generates the following output files:
236
+
237
+ #### 1. HDF5 Results File (always generated)
238
+ **Filename:** `{prefix}_results.h5`
239
+
240
+ Complete analysis results for all resolutions and chromosomes:
241
+ - All compartment predictions
242
+ - Pre-computed background normalizations (for fast reloading)
243
+ - Eigendecomposition results
244
+ - Quality control metrics
245
+ - Self-contained: stores chromosome lengths, no .hic file path stored
246
+ - Can be loaded with or without .hic file for export or further processing
247
+
248
+ **Loading HDF5 files:**
249
+ ```python
250
+ from hicsca import HiCSCA
251
+
252
+ # Load for export only
253
+ hicsca = HiCSCA.from_hdf5("results.h5")
254
+ hicsca.to_bed(100000, "compartments.bed")
255
+
256
+ # Load with .hic file to enable processing additional data
257
+ hicsca = HiCSCA.from_hdf5("results.h5", hic_file_path="data.hic")
258
+ hicsca.process_chromosome("chr1") # Can process more chromosomes
259
+ ```
260
+
261
+ #### 2. Excel Files (always generated)
262
+ **Filename:** `{prefix}_{resolution}bp.xlsx`
263
+
264
+ One file per resolution with:
265
+ - **Per-chromosome worksheets** containing:
266
+ - `Start`: Bin start position (1-indexed, in bp)
267
+ - `End`: Bin end position (in bp)
268
+ - `Value`: Compartment eigenvector value
269
+ - `Compartment`: "A" (positive values), "B" (negative values), or "" (excluded bins)
270
+ - **Summary worksheet "Inter-AB Scores"** containing:
271
+ - `Chromosome`: Chromosome name
272
+ - `Inter-AB Score`: Quality metric (numeric value or "N/A" if processing failed)
273
+ - `Confidence`: "High Confidence" if 1.75 ≤ score ≤ 3.20, else "Low Confidence"
274
+
275
+ #### 3. BED Files (optional, with `--bed`)
276
+ **Filename:** `{prefix}_{resolution}bp.bed`
277
+
278
+ BED9 format with RGB colors:
279
+ - Consecutive bins of same compartment are merged
280
+ - A compartments: red (255,0,0)
281
+ - B compartments: blue (0,0,255)
282
+ - Zero values (excluded regions) are skipped
283
+ - Track header included for genome browser compatibility
284
+
285
+ **Format:**
286
+ ```
287
+ track name=AB_Compartments_100000bp description="..." itemRgb="On"
288
+ chr1 0 300000 A 0 . 0 300000 255,0,0
289
+ chr1 400000 800000 B 0 . 400000 800000 0,0,255
290
+ ```
291
+
292
+ #### 4. BedGraph Files (optional, with `--bedgraph`)
293
+ **Filename:** `{prefix}_{resolution}bp.bedgraph`
294
+
295
+ Continuous compartment scores for genome browser visualization:
296
+ - One value per bin (not merged)
297
+ - Zero values (excluded regions) are skipped
298
+ - Track header included
299
+
300
+ **Format:**
301
+ ```
302
+ track type=bedGraph name="AB_Compartments_100000bp"
303
+ chr1 0 100000 0.123456
304
+ chr1 100000 200000 -0.098765
305
+ ```
306
+
307
+ #### 5. Compartment Plots (always generated)
308
+ **Filename:** `{prefix}_{chr_name}_{resolution}bp.png`
309
+
310
+ Publication-quality plots (300 DPI) for each chromosome:
311
+ - Red line: A compartment (positive values)
312
+ - Blue line: B compartment (negative values)
313
+ - Automatic unit scaling (bp, Kbp, Mbp)
314
+ - 5 evenly-spaced x-axis ticks
315
+
316
+ #### 6. Cross-Resolution MCC Plot (if multiple resolutions)
317
+ **Filename:** `{prefix}_cross_resolution_mcc.png` and `{prefix}_cross_resolution_mcc_colorbar.png`
318
+
319
+ Heatmap showing Matthews Correlation Coefficient between resolutions:
320
+ - Assesses consistency across different resolutions
321
+ - Main heatmap and separate colorbar figure
322
+ - Gray cells indicate incompatible resolution pairs (not round multiples)
323
+ - Red-white-blue colormap for MCC values (0-1)
324
+
325
+ ### Troubleshooting CLI
326
+
327
+ **"Error: Must provide either --load-hdf5 or -f/--hic-file"**
328
+ - Provide at least one input source: `-f` for new .hic file, or `--load-hdf5` for existing results
329
+
330
+ **"Error: Hi-C file not found"**
331
+ - Verify path to .hic file
332
+ - Use absolute paths if relative paths cause issues
333
+
334
+ **"Error: HDF5 file not found"**
335
+ - Verify path to HDF5 results file
336
+ - Ensure correct file name with `.h5` extension
337
+
338
+ **"No resolutions available"**
339
+ - Check that .hic file contains data at specified resolutions
340
+ - Use auto-detection (omit `-r` flag) to see available resolutions
341
+
342
+ **Memory errors**
343
+ - Process fewer resolutions at once
344
+ - Use higher resolutions (e.g., 100kb instead of 10kb)
345
+ - Close other applications to free up RAM
346
+
347
+ ## Python API
348
+
349
+ ### Core Classes
350
+
351
+ #### HiCSCA - Main Pipeline Class
352
+
353
+ Complete pipeline for A-B compartment prediction from Hi-C data.
354
+
355
+ **Initialization:**
356
+ ```python
357
+ from hicsca import HiCSCA
358
+
359
+ hicsca = HiCSCA(
360
+ hic_file_path="data/sample.hic",
361
+ chr_names=None, # None = all autosomal chromosomes (chr1-chr22)
362
+ resolutions=None, # None = all available resolutions
363
+ data_type="observed", # "observed" or "oe"
364
+ norm_type="NONE",
365
+ smoothing_cutoff=400
366
+ )
367
+ ```
368
+
369
+ **Parameters:**
370
+ - `hic_file_path` (str): Path to .hic file
371
+ - `chr_names` (list or None): Chromosome names to process (default: all autosomal)
372
+ - `resolutions` (list or None): Resolutions in bp (default: auto-detect all)
373
+ - `data_type` (str): "observed" (raw contacts with O/E normalization) or "oe" (pre-normalized, skip O/E)
374
+ - `norm_type` (str): Normalization type for hicstraw (default: "NONE")
375
+ - `smoothing_cutoff` (int): Smoothing parameter for O/E normalization (default: 400, only used when data_type="observed")
376
+
377
+ **Key Methods:**
378
+ ```python
379
+ # Compute background normalization (automatic when processing, can be called explicitly)
380
+ hicsca.compute_background_normalization(resolutions=None)
381
+
382
+ # Process single chromosome at specified resolutions
383
+ hicsca.process_chromosome(chr_name, resolutions=None, verbose=True)
384
+
385
+ # Process all chromosomes at specified resolutions
386
+ hicsca.process_all_chromosomes(resolutions=None, verbose=True)
387
+
388
+ # Load saved HiCSCA instance
389
+ hicsca = HiCSCA.from_hdf5(hdf5_path, hic_file_path=None)
390
+ ```
391
+
392
+ **Export Methods:**
393
+ ```python
394
+ # Save complete instance to HDF5
395
+ hicsca.to_hdf5(output_path, update=False)
396
+
397
+ # Generate BED file
398
+ hicsca.to_bed(resolution, output_path, chr_names=None, dataset_id=None)
399
+
400
+ # Generate BedGraph file
401
+ hicsca.to_bedgraph(resolution, output_path, chr_names=None, dataset_id=None, track_name=None)
402
+
403
+ # Generate Excel file
404
+ hicsca.to_excel(resolution, output_path, chr_names=None, dataset_id=None)
405
+
406
+ # Plot compartments (saves to files and/or displays in Jupyter)
407
+ hicsca.plot_compartments(
408
+ resolution,
409
+ chr_names=None,
410
+ output_dir=None, # Specify to save files
411
+ output_prefix=None,
412
+ display=True, # Set False to disable Jupyter display
413
+ dpi=300,
414
+ figsize=(3.595, 2)
415
+ )
416
+
417
+ # Plot cross-resolution MCC correlation heatmap
418
+ hicsca.plot_cross_resolution_mcc(
419
+ chr_name='all', # 'all' or specific chromosome
420
+ resolutions=None, # None = all resolutions
421
+ chr_names=None, # For genome-wide ('all') calculation
422
+ figsize=(2.8, 2.8),
423
+ dpi=300,
424
+ background_alpha=1, # 0=transparent, 1=opaque
425
+ plot_colorbar=True, # Generate separate colorbar figure
426
+ save_path=None # Path to save main figure
427
+ )
428
+ ```
429
+
430
+ **Usage:**
431
+ ```python
432
+ # Example 1: Using observed data (default - with O/E normalization)
433
+ hicsca = HiCSCA(
434
+ "data/sample.hic",
435
+ resolutions=[100000, 50000],
436
+ data_type="observed",
437
+ norm_type="NONE"
438
+ )
439
+
440
+ # Process all chromosomes (results stored in hicsca.results)
441
+ hicsca.process_all_chromosomes(verbose=True)
442
+
443
+ # Access results
444
+ result = hicsca.results[100000]["chr1"]
445
+ if result['Success']:
446
+ compartment = result['assigned_AB_compartment']
447
+ eig_idx = result['selected_eig_idx']
448
+ score = result['modified_inter_eigval_score']
449
+
450
+ # Export results
451
+ hicsca.to_bed(100000, "compartments_100kb.bed")
452
+ hicsca.to_excel(100000, "compartments_100kb.xlsx")
453
+ hicsca.to_hdf5("saved_analysis.h5")
454
+
455
+ # Example 2: Using pre-normalized O/E data (skips background normalization)
456
+ hicsca_oe = HiCSCA(
457
+ "data/sample.hic",
458
+ resolutions=[100000],
459
+ data_type="oe", # Data already O/E normalized
460
+ norm_type="KR" # Can use normalized data if available
461
+ )
462
+ hicsca_oe.process_all_chromosomes(verbose=True)
463
+
464
+ # Example 3: Load previously saved HiCSCA instance
465
+ hicsca_loaded = HiCSCA.from_hdf5("saved_analysis.h5")
466
+ # All results and normalizations already loaded - no processing needed
467
+ result = hicsca_loaded.results[100000]['chr1']
468
+ ```
469
+
470
+ ### Results Dictionary Structure
471
+
472
+ Results are stored in: `hicsca.results[resolution][chr_name]`
473
+
474
+ Each result dictionary contains:
475
+
476
+ **Core Fields (always present):**
477
+ - `Success` (bool): Whether processing succeeded
478
+ - `Eig Converged` (bool): Whether eigendecomposition converged
479
+
480
+ **Compartment Prediction (when Success=True):**
481
+ - `assigned_AB_compartment` (ndarray): Normalized compartment eigenvector (positive=A, negative=B, zero=excluded)
482
+ - `selected_eig_idx` (int): Index of selected eigenvector (1-10)
483
+ - `modified_inter_eigval_score` (float): Eigenvalue-weighted eigenvector selection score
484
+ - `unmodified_inter_AB_score` (float): Raw inter-compartment contact score
485
+
486
+ **Eigendecomposition Results:**
487
+ - `eigvals` (ndarray): All eigenvalues (11 values: trivial + 10 non-trivial)
488
+ - `eigenvects` (ndarray): All eigenvectors (11 × N matrix, row-major format)
489
+
490
+ **Quality Control:**
491
+ - `cutoff` (float): Low-coverage filter cutoff value
492
+ - `include_bool` (ndarray): Boolean array indicating bins included in analysis
493
+ - `non_zero_not_included_bool` (ndarray): Boolean array for excluded non-zero bins
494
+ - `deg` (ndarray): Degree (column sums) of filtered O/E matrix
495
+ - `OE_normed_diag` (ndarray): Diagonal of O/E matrix for included bins
496
+
497
+ **See RESULTS_STRUCTURE.md for complete documentation.**
498
+
499
+ ### Evaluation Tools
500
+
501
+ #### CrossResolutionAnalyzer
502
+
503
+ Analyzes agreement between different resolutions within the same Hi-C dataset.
504
+
505
+ ```python
506
+ from hicsca.evals import CrossResolutionAnalyzer
507
+
508
+ # Initialize with HiCSCA results (auto-detects resolutions and chromosomes)
509
+ analyzer = CrossResolutionAnalyzer(hicsca.results)
510
+
511
+ # Or specify custom resolutions/chromosomes
512
+ analyzer = CrossResolutionAnalyzer(
513
+ hicsca.results,
514
+ resolutions=[500000, 250000, 100000, 50000],
515
+ chr_names=['chr1', 'chr2', ..., 'chr22']
516
+ )
517
+
518
+ # Analyze (results stored internally, cached)
519
+ analyzer.analyze()
520
+
521
+ # Plot genome-wide cross-resolution MCC with colorbar
522
+ fig, ax, cbar_fig, cbar_ax = analyzer.plot_cross_resolution_mcc()
523
+
524
+ # Plot specific chromosome with transparent background
525
+ fig, ax, cbar_fig, cbar_ax = analyzer.plot_cross_resolution_mcc(
526
+ chr_name='chr1',
527
+ save_path='chr1_mcc.png',
528
+ background_alpha=0
529
+ )
530
+ # Saves: chr1_mcc.png and chr1_mcc_colorbar.png
531
+
532
+ # Access MCC matrices directly
533
+ genome_wide_mcc = analyzer.mcc_matrices['all']
534
+ chr1_mcc = analyzer.mcc_matrices['chr1']
535
+ ```
536
+
537
+ #### CrossDatasetAnalyzer
538
+
539
+ Analyzes agreement between different Hi-C datasets at the same resolution(s).
540
+
541
+ ```python
542
+ from hicsca.evals import CrossDatasetAnalyzer
543
+
544
+ # Create dataset dictionary (dataset_id -> HiCSCA results)
545
+ dataset_dict = {
546
+ 'dataset1': hicsca_inst1.results,
547
+ 'dataset2': hicsca_inst2.results,
548
+ 'dataset3': hicsca_inst3.results
549
+ }
550
+
551
+ # Initialize (auto-detects resolutions, dataset_ids, and chromosomes)
552
+ analyzer = CrossDatasetAnalyzer(dataset_dict)
553
+
554
+ # Analyze all resolutions
555
+ analyzer.analyze()
556
+
557
+ # Plot genome-wide MCC correlation at 100kb with colorbar
558
+ fig1, ax1, cbar_fig1, cbar_ax1 = analyzer.plot_mcc_correlation(
559
+ 100000,
560
+ tick_labels=['A', 'B', 'C'],
561
+ save_path='mcc_100kb.png'
562
+ )
563
+ # Saves: mcc_100kb.png and mcc_100kb_colorbar.png
564
+
565
+ # Plot chr1 orientation agreement
566
+ fig2, ax2, cbar_fig2, cbar_ax2 = analyzer.plot_orientation_agreement(
567
+ 100000,
568
+ chr_name='chr1',
569
+ save_path='orient_chr1_100kb.png'
570
+ )
571
+
572
+ # Access matrices directly
573
+ mcc_genome_wide = analyzer.mcc_matrices[100000]['all']
574
+ ```
575
+
576
+ #### MCCCalculator
577
+
578
+ Compute Matthews Correlation Coefficient between compartment predictions.
579
+
580
+ ```python
581
+ from hicsca.evals import MCCCalculator
582
+
583
+ mcc, tp, fp, tn, fn, zeroed, reversed = MCCCalculator.compute_AB_MCC(
584
+ reference_compartments,
585
+ predicted_compartments,
586
+ auto_flip=True # Automatically handle orientation
587
+ )
588
+
589
+ print(f"MCC: {mcc:.4f}")
590
+ ```
591
+
592
+ ## Testing
593
+
594
+ The package includes a comprehensive test suite:
595
+
596
+ ```bash
597
+ # Run all tests (including regression tests)
598
+ pytest tests/
599
+
600
+ # Run with coverage
601
+ pytest tests/ --cov=hicsca --cov-report=html
602
+
603
+ # Specific test classes
604
+ pytest tests/test_hicsca.py::TestResultStructure
605
+ pytest tests/test_hicsca.py::TestRegressionComparison
606
+ ```
607
+
608
+ **Test Coverage:**
609
+ - Data availability checks
610
+ - Result structure validation
611
+ - Regression tests (compartment vectors, scores, eigenvalues)
612
+ - Cross-resolution analysis validation
613
+
614
+ **Note**: Regression tests require test data files in `tests/test_data/` (ENCFF216ZNY_Intra_Only.hic and reference.h5).
615
+
616
+ ### Test Data
617
+ The test .hic dataset contains only the intra-chromosomal contacts of [ENCFF216ZNY](https://www.encodeproject.org/files/ENCFF216ZNY/). The file is located at [tests/test_data/ENCFF216ZNY_Intra_Only.hic](./tests/test_data/ENCFF216ZNY_Intra_Only.hic)
618
+
619
+ ## Other Documentation
620
+
621
+ - **RESULTS_STRUCTURE.md**: Complete documentation of results dictionary structure
622
+
623
+ ## Citation
624
+
625
+ If you use this software in your research, please cite:
626
+
627
+ Chan, J. & Kono, H. HiC-SCA: A Spectral Clustering Method for Reliable A/B Compartment Assignment From Hi-C Data. Preprint at https://doi.org/10.1101/2025.09.22.677711 (2025).
628
+
629
+ ## License
630
+
631
+ MIT License
632
+
633
+ ## Contributing
634
+
635
+ Contributions are welcome! Please feel free to submit a Pull Request.
636
+
637
+ ## Acknowledgments
638
+
639
+ This package uses:
640
+ - [hicstraw](https://github.com/aidenlab/straw) for reading .hic files
641
+ - NumPy and SciPy for numerical computations and sparse matrix operations
642
+ - matplotlib for visualization
643
+ - h5py for HDF5 file I/O
644
+ - h5typer for automatic HDF5 type mapping
645
+ - LOBPCG algorithm (SciPy) for efficient eigenvalue decomposition
@@ -0,0 +1,11 @@
1
+ hic_sca-0.0.0.dist-info/licenses/LICENSE,sha256=58XdpW1w9bAYTrokz315fY90xhh-SMsFh55EUiZL0V0,1106
2
+ hicsca/__init__.py,sha256=Vy3g10k9TB_UGddxetJDnPLamcH_yKAxBQcsiplvuGk,658
3
+ hicsca/evals.py,sha256=WEigUOJfsDpRmd7vZSDL30A6M6iBLdMQOCcm3Rt2kQo,38430
4
+ hicsca/formats.py,sha256=gHwkfriG_6DPGdhhU2pCcL_9xRq39UmMOcn8VKATots,33456
5
+ hicsca/hicsca.py,sha256=CD-TVcE1zkZE7dtKi2CzLwGMHqa8JBBRCLptxqfD9rI,61712
6
+ hicsca/hicsca_cli.py,sha256=pbH9IE483P0OauclzHFj66wM0vqOMurofR3mrZsLtKU,13372
7
+ hic_sca-0.0.0.dist-info/METADATA,sha256=wa5VH7KeU2d19yEiemLU99n6ke-4fodDpGih1VInCUU,21129
8
+ hic_sca-0.0.0.dist-info/WHEEL,sha256=_zCd3N1l69ArxyTb8rzEoP9TpbYXkqRFSNOD5OuxnTs,91
9
+ hic_sca-0.0.0.dist-info/entry_points.txt,sha256=BpVzJuv3jw_Od-Ynv6FWL5ZtbKXLJUmzUtGYECmjDnY,51
10
+ hic_sca-0.0.0.dist-info/top_level.txt,sha256=zM9i5ME2rNPKqhthAXC0oyezf_r5yiMcEbO8m3wIuH8,7
11
+ hic_sca-0.0.0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (80.9.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ hic-sca = hicsca.hicsca_cli:main
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Molecular Modelling and Simulation Team, iQLS, QST
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
@@ -0,0 +1 @@
1
+ hicsca