Install any skill in seconds. Free to start, no credit card required.
Get Started Free →Load, convert, and manipulate Hi-C contact matrices using cooler format. Read .cool/.mcool files, convert from .hic format, access matrix data, and export to different formats. Use when loading or converting Hi-C contact matrices.
.claude/skills/bio-hi-c-analysis-hic-data-io/SKILL.md| Test case | Without → With | Effect | Δ tokens | Δ turns |
|---|---|---|---|---|
| case-01 | ✗→✓ | ▲ Improved | — | — |
| case-05 | ✗→✓ | ▲ Improved | — | — |
| case-17 | ✗→✓ | ▲ Improved | — | — |
| case-11 | ✗→✓ | ▲ Improved | — | — |
| case-07 | ✓→✓ | = Same ✓ | — | — |
Reference examples tested with: cooler 0.9+, numpy 1.26+, pandas 2.2+, scanpy 1.10+, scipy 1.12+
Before using code patterns, verify installed versions match. If versions differ:
pip show <package> then help(module.function) to check signatures<tool> --version then <tool> --help to confirm flagsIf code throws ImportError, AttributeError, or TypeError, introspect the installed package and adapt the example to match the actual API rather than retrying.
"Load my Hi-C contact matrix" → Read .cool/.mcool/.hic files into Python, access contact pixels, convert between formats, and export subsets.
cooler.Cooler('file.mcool::resolutions/10000')cooler load, hic2cool convertLoad and manipulate Hi-C contact matrices in cooler format.
pythonimport cooler import numpy as np import pandas as pd
python# Load a .cool file clr = cooler.Cooler('matrix.cool') # Basic info print(f'Chromosomes: {clr.chromnames}') print(f'Bin size: {clr.binsize}') print(f'Number of bins: {clr.info["nbins"]}') print(f'Sum of counts: {clr.info["sum"]}')
python# List available resolutions resolutions = cooler.fileops.list_coolers('matrix.mcool') print(f'Available resolutions: {resolutions}') # Load specific resolution clr = cooler.Cooler('matrix.mcool::resolutions/10000') print(f'Loaded at {clr.binsize}bp resolution')
python# Get bin table (genomic coordinates) bins = clr.bins()[:] print(bins.head()) # Columns: chrom, start, end, weight (if balanced) # Get bins for a chromosome chr1_bins = clr.bins().fetch('chr1') print(f'chr1 has {len(chr1_bins)} bins')
python# Get all contacts as DataFrame pixels = clr.pixels()[:] print(pixels.head()) # Columns: bin1_id, bin2_id, count # Get contacts for a region region_pixels = clr.pixels().fetch('chr1:0-10000000')
python# Get matrix for a chromosome matrix = clr.matrix(balance=True).fetch('chr1') print(f'Matrix shape: {matrix.shape}') # Get matrix for a region region_matrix = clr.matrix(balance=True).fetch('chr1:50000000-60000000') # Get raw (unbalanced) matrix raw_matrix = clr.matrix(balance=False).fetch('chr1') # Sparse matrix for memory efficiency from scipy import sparse sparse_matrix = clr.matrix(balance=True, sparse=True).fetch('chr1')
python# Get contacts between two regions region1 = 'chr1:50000000-60000000' region2 = 'chr1:70000000-80000000' submatrix = clr.matrix(balance=True).fetch(region1, region2) print(f'Submatrix shape: {submatrix.shape}') # Inter-chromosomal contacts inter_matrix = clr.matrix(balance=True).fetch('chr1', 'chr2')
bash# Using hic2cool CLI hic2cool convert input.hic output.mcool -r 0 # All resolutions # Specific resolution hic2cool convert input.hic output.cool -r 10000
python# Python alternative using hic2cool import hic2cool hic2cool.hic2cool_convert('input.hic', 'output.mcool', resolution=0)
python# From pairs file to cooler # First create bins import bioframe chromsizes = bioframe.fetch_chromsizes('hg38') bins = cooler.binnify(chromsizes, binsize=10000) # Then aggregate pairs cooler.create_cooler( 'output.cool', bins, pixels=None, # Will be loaded from pairs dtypes={'count': int}, ) # Or use cooler cload # cooler cload pairs -c1 2 -p1 3 -c2 4 -p2 5 chromsizes.txt:10000 pairs.txt output.cool
Goal: Convert an in-memory numpy contact matrix into a cooler file for use with cooltools and other Hi-C analysis tools.
Approach: Define genomic bins from chromosome sizes, convert the upper-triangle matrix entries into a pixel DataFrame of (bin1_id, bin2_id, count) tuples, and write to a new cooler file.
pythonimport cooler import numpy as np import bioframe # Create bins chromsizes = bioframe.fetch_chromsizes('hg38') bins = cooler.binnify(chromsizes, binsize=10000) # Create pixel dataframe from matrix n_bins = len(bins) # matrix = np.random.poisson(1, (n_bins, n_bins)) # Your matrix here # matrix = np.triu(matrix) # Upper triangle # Convert to pixels pixels = [] for i in range(n_bins): for j in range(i, n_bins): if matrix[i, j] > 0: pixels.append({'bin1_id': i, 'bin2_id': j, 'count': matrix[i, j]}) pixels_df = pd.DataFrame(pixels) # Create cooler cooler.create_cooler('new.cool', bins, pixels_df)
python# Merge multiple cooler files cooler.merge_coolers('merged.cool', ['sample1.cool', 'sample2.cool'])
python# Create lower resolution from high resolution cooler.coarsen_cooler('hires.cool', 'lowres.cool', factor=10) # 10x coarser # Or using zoomify for multiple resolutions cooler.zoomify_cooler('input.cool', 'output.mcool', resolutions=[10000, 50000, 100000, 500000])
python# Export matrix to numpy matrix = clr.matrix(balance=True).fetch('chr1') np.save('chr1_matrix.npy', matrix) # Export to text np.savetxt('chr1_matrix.txt', matrix, delimiter='\t') # Export pixels to CSV pixels = clr.pixels()[:] pixels.to_csv('pixels.csv', index=False)
bash# Using cooler dump cooler dump -t pixels --join matrix.cool > pairs.txt # Dump bins cooler dump -t bins matrix.cool > bins.txt
python# Get all metadata print(clr.info) # Specific metadata print(f'Genome assembly: {clr.info.get("genome-assembly", "Unknown")}') print(f'Creation date: {clr.info.get("creation-date", "Unknown")}') # Check if balanced if 'weight' in clr.bins().columns: print('Matrix has balancing weights')
python# For mcool coolers = cooler.fileops.list_coolers('multi.mcool') print(f'Available: {coolers}') # Check if valid cooler is_valid = cooler.fileops.is_cooler('file.cool') print(f'Valid cooler: {is_valid}')
| Case | Status | Duration (ms) | Turns | Tokens | Tool calls | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Without | With | Δ | Without | With | Δ | Without | With | Δ | Without | With | Δ | ||
case-01 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-03 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-04 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-02 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-05 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-06 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-07 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-08 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-09 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-14 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-16 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-18 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-22 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-17 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-12 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-21 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-11 | fail→pass | — | — | — | — | — | — | — | — | — | — | — | — |
case-20 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-15 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-19 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-10 | fail→fail | — | — | — | — | — | — | — | — | — | — | — | — |
case-13 | pass→pass | — | — | — | — | — | — | — | — | — | — | — | — |
DecimalAI ran this skill against gemini-3.6-flash twice over the same eval suite — once with the skill loaded and once without — and compared the two runs case by case. 22 cases were attempted, and 21 counted toward the lift figure. The other 1 produced results that are not comparable between the two arms, so they are excluded from the headline rather than averaged into it. The headline lift of +18 percentage points is the difference between those two pass rates over the 21 comparable cases.
The per-case answers from this run were removed by the retention sweep, so the case table below shows the verdicts without the text either arm produced. The counts above were recorded at the time and are unaffected. Answers are now kept for 180 days.
Other measured skills in the registry, with their headline benchmark lift.