Before using code patterns, verify installed versions match. If versions differ:
Python: pip show <package> then help(module.function) to check signatures
CLI: <tool> --version then <tool> --help to confirm flags
If code throws ImportError, AttributeError, or TypeError, introspect the installed
package and adapt the example to match the actual API rather than retrying.
TAD Detection
"Call TADs from my Hi-C data" → Identify topologically associating domain boundaries using insulation score minima or other boundary-detection algorithms.
Python: cooltools.insulation(clr, window_bp) then threshold boundary strength
CLI: hicFindTADs (HiCExplorer)
Call topologically associating domains from Hi-C contact matrices.
Required Imports
import cooler
import cooltools
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
import bioframe
# Compute insulation at multiple scales
windows = [100000, 200000, 500000, 1000000]
insulation_multi = cooltools.insulation(clr, window_bp=windows, ignore_diags=2)
# Boundaries at each scale represent different hierarchy levels
for w in windows:
col = f'is_boundary_{w}'
n_bounds = insulation_multi[col].sum()
print(f'Window {w/1000:.0f}kb: {n_bounds} boundaries')
Export TADs
# Save as BED
tads[['chrom', 'start', 'end']].to_csv(
'tads.bed', sep='\t', index=False, header=False
)
# Save boundaries as BED
boundaries[boundaries['is_boundary']][['chrom', 'start', 'end', 'boundary_strength']].to_csv(
'boundaries.bed', sep='\t', index=False, header=False
)
# Save insulation as bedGraph
insulation[['chrom', 'start', 'end', 'log2_insulation_score_200000']].to_csv(
'insulation.bedgraph', sep='\t', index=False, header=False
)
Related Skills
hic-data-io - Load Hi-C matrices
hic-visualization - Visualize TADs on contact matrices
compartment-analysis - Compartments operate at larger scale than TADs