Coolsecture compares Hi-C contact maps across species. Given two genome assemblies, a synteny map, and one Hi-C matrix per species, it lifts contacts between coordinate systems and measures cross-species agreement.
Coolsecture builds on C-InterSecture with a CLI-based workflow, native .cool/.mcool/.hic support, multi-resolution analysis, and lower-memory contact liftover. The liftcontacts and lift2matrix steps can spill intermediate tables to disk with --spill-threshold-mb and --tmp-dir; other commands still load their main inputs into memory.
- Assembly alignment with
minimap2ormummer4. - Conversion of
.linkor UCSC.chainfiles to Coolsecture.markformat. - Contact ranking from
.cool,.mcool, and.hicmatrices. - Bidirectional contact liftover and reciprocal consistency summaries.
- Reconstruction of observed/target
.coolor.hicmatrices. - PBAD and related metrics, diagnostic plots, and split-triangle cross-species heatmaps.
- HiCRep-inspired SCC-like similarity scoring.
- Command-by-command execution,
run-all, and example Snakemake workflows.
Requires Python 3.8+.
git clone https://github.com/pk-zhu/Coolsecture.git
cd Coolsecture
python -m pip install -e .Optional extras:
python -m pip install -e ".[hic]" # .hic input
python -m pip install -e ".[viz]" # Plotly HTML
python -m pip install -e ".[stats]" # Spearman metric + KDE plottingExternal tools:
minimap2— default aligner forasm2linkandrun-all.mummer4(nucmer,delta-filter,show-coords) — required only with-a mummer4/--asm-aligner mummer4.samtools— optional;run-allcan create a minimal.faiifsamtools faidxis unavailable.juicer_tools— required only forlift2matrix --format hicor--format both.snakemake— required only for the example workflows.
coolsecture -h
coolsecture <command> -h| Command | Purpose |
|---|---|
asm2link |
Align two assemblies and write .paf plus six-column .link. |
link2mark |
Convert .link or UCSC .chain files to .mark. |
prepare |
Convert .cool, .mcool, or .hic to ranked contact tables. |
roughlift |
Roughly lift a BED track for quick synteny QA. |
liftcontacts |
Run A→B and B→A contact liftover and reciprocal summaries. (liftcontracts is a deprecated alias.) |
contact-stat |
Plot percentile, distance, and ratio diagnostics. |
metric |
Compute PBAD and related metrics as bedGraph plus figures. |
lift2matrix |
Convert lifted contacts to observed/target .cool or .hic matrices. |
plot-cross |
Draw split-triangle cross-species heatmaps. |
multiscale |
Summarize PBAD stability across resolutions. |
similarity |
Compute a HiCRep-inspired SCC-like similarity score. |
run-all |
Run the main end-to-end workflow. |
In the current CLI, FASTA index arguments are named
--fadix,--fadix-a, and--fadix-b.
You need:
- FASTA and
.faifiles for both species. - One Hi-C matrix per species in
.cool,.mcool, or.hicformat. - A synteny file: six-column
.linkor UCSC.chain.
.link format (0-based, half-open):
chromA startA endA chromB startB endB
For .cool / .mcool, the bins table must contain at least one normalization vector among KR, VC_SQRT, VC, or weight.
run-all performs assembly alignment, mark generation, contact preparation, bidirectional liftover, diagnostics, metric calculation, matrix reconstruction, similarity scoring, and automatic plot-cross region selection.
coolsecture run-all \
--genome-a Asu.fa \
--genome-b Ath.fa \
--matrix-a Asu.mcool \
--matrix-b Ath.mcool \
--resolution 40000 \
--name-a Asu \
--name-b Ath \
--out-prefix run_allArguments can be forwarded to individual steps:
coolsecture run-all \
--genome-a Asu.fa \
--genome-b Ath.fa \
--matrix-a Asu.mcool \
--matrix-b Ath.mcool \
--resolution 40000 \
--name-a Asu \
--name-b Ath \
--prepare-args "--max-distance 5000000000 --inter" \
--liftcontacts-args "--model balanced --dups-filter coverage --nthreads 8" \
--metric-args "--frames 8 --metric pbad" \
--out-prefix run_allFor .hic input:
python -m pip install -e ".[hic]"
coolsecture run-all \
--genome-a hg38.fa \
--genome-b mm10.fa \
--matrix-a GM12878.hic \
--matrix-b mESC.hic \
--resolution 100000 \
--name-a GM12878 \
--name-b mESC \
--out-prefix run_all_hicrun-all accepts one resolution. Standalone prepare also supports comma-separated resolutions for .hic, for example --resolution 40000,100000.
minimap2 (default):
coolsecture asm2link \
--genome-a Asu.fa \
--genome-b Ath.fa \
-x asm10 \
--out-prefix step0/Asu_Athmummer4:
coolsecture asm2link \
--genome-a Asu.fa \
--genome-b Ath.fa \
-a mummer4 \
--mummer-filter 1-to-1 \
--out-prefix step0/Asu_Athminimap2 outputs:
step0/Asu_Ath.pafstep0/Asu_Ath.link
mummer4 outputs:
step0/Asu_Ath.deltastep0/Asu_Ath.filter.delta(omitted with--mummer-filter none)step0/Asu_Ath.coords.tsvstep0/Asu_Ath.link
If you already have a UCSC .chain, skip this step.
From .link:
coolsecture link2mark \
--link step0/Asu_Ath.link \
--thr-len 300 \
--step-len 150 \
--out-prefix step0/Asu_AthFrom UCSC .chain:
coolsecture link2mark \
--chain hg38ToMm10.over.chain \
--thr-len 300 \
--step-len 150 \
--out-prefix step0/hg38_mm10Output:
*.mark
Single-resolution .cool or .mcool::resolutions/RES:
coolsecture prepare \
--matrix Asu.mcool::resolutions/40000 \
--max-distance 5000000000 \
--inter \
--nthreads 8 \
--out-prefix step1/Asu/AsuMulti-resolution .mcool:
coolsecture prepare \
--matrix Asu.mcool \
--resolution 40000,100000 \
--max-distance 5000000000 \
--inter \
--summary \
--nthreads 8 \
--out-prefix step1/Asu/Asu.hic input:
coolsecture prepare \
--matrix GM12878.hic \
--resolution 100000 \
--max-distance 5000000000 \
--inter \
--out-prefix step1/GM12878/GM12878Main outputs:
*.contacts.tsv*.stats.tsv*.r<resolution>.contacts.tsvand*.r<resolution>.stats.tsvin multi-resolution mode*.multi_resolution.summary.tsvand.pdfwith--summary
Before ranking, counts are normalized using the first available vector in this order:
KR > VC_SQRT > VC > weight
KR/VC-type vectors are divisive; Cooler weight is multiplicative. Contacts touching bins with missing or non-positive weights are removed. Matrices without a supported weight column are rejected.
coolsecture liftcontacts \
--contact-a step1/Asu/Asu.r40000.contacts.tsv \
--contact-b step1/Ath/Ath.r40000.contacts.tsv \
--fadix-a step0/Asu.fa.fai \
--fadix-b step0/Ath.fa.fai \
--mark-ab step0/Asu_Ath.mark \
--model balanced \
--dups-filter coverage \
--agg-frame 400000 \
--nthreads 8 \
--out-prefix step2/Asu_Ath/Asu_Ath.r40000For larger files:
--tmp-dir .snakemake/tmp/liftcontracts
--spill-threshold-mb 256
--hash-shards 64
--pbad-mode auto
--pbad-auto-threshold-mb 1024Main outputs:
*.AtoB.liftContacts*.BtoA.liftContacts*.Merged.liftContacts*.bidirectional.summary.tsv*.bidirectional.tags.tsvunless--no-tagsis used
--model balanced divides aggregated values by summed synteny remapping weight. --model raw skips this adjustment. When one source contact maps to multiple target positions, --dups-filter controls which mapping is retained; discarded mappings are written to .discarded_dups.tsv.
coolsecture contact-stat \
--liftover step2/Asu_Ath/Asu_Ath.r40000.Merged.liftContacts \
--fadix step0/Asu.fa.fai \
--stats-a step1/Asu/Asu.r40000.stats.tsv \
--stats-b step1/Ath/Ath.r40000.stats.tsv \
--bins 400 \
--cmap RdBu_r \
--max-dist-mb 5000 \
--format pdf \
--out-prefix step3/Asu_Ath.r40000Outputs:
*.percentile_heatmap.pdf*.distance_heatmap.pdf*.ratio_scatter.pdf
The randomized null is generated by shuffling target percentile ranks. Use --seed <int> for reproducibility.
coolsecture metric \
--liftover step2/Asu_Ath/Asu_Ath.r40000.Merged.liftContacts \
--fadix step0/Asu.fa.fai \
--frames 8 \
--metric pbad \
--format pdf \
--out-prefix step3/Asu_Ath.r40000Outputs:
*.pbad.8frame.bedGraph*.pbad.8frame.stat.pdf
Supported metrics: pbad, log, stripe, pearsone, and spearman. spearman requires the [stats] extra.
P-BAD is a windowed divergence between source and target percentile ranks. The PDF compares the observed distribution with the randomized null.
coolsecture lift2matrix \
--liftover step2/Asu_Ath/Asu_Ath.r40000.Merged.liftContacts \
--fadix step0/Asu.fa.fai \
--format cool \
--out-prefix step3/Asu_Ath.r40000Outputs:
*.Observed.cool*.Target.cool
Use --format hic or --format both to also write .hic. This requires Juicer Tools on PATH, or:
--juicer-tools "java -jar /path/to/juicer_tools.jar"Matrix values are 0–99 percentile ranks in source coordinates.
coolsecture similarity \
--matrix-a step3/Asu_Ath.r40000.Observed.cool \
--matrix-b step3/Asu_Ath.r40000.Target.cool \
--max-dist-mb 10 \
--format pdf \
--out-prefix step3/Asu_Ath.r40000Outputs:
*.scc-like.tsv*.scc-like.summary.tsv*.scc-like.pdf
The score is a Pearson correlation computed within genomic-distance strata and averaged using stratum pixel counts as weights. Because it does not include HiCRep's 2-D smoothing step, it is reported as SCC-like rather than SCC.
multiscale separately summarizes PBAD stability across resolutions.
coolsecture plot-cross \
--liftover step2/Asu_Ath/Asu_Ath.r40000.Merged.liftContacts \
--fadix step0/Asu.fa.fai \
--locus chr1:0-10000000 \
--heat obs-tgt \
--format pdf \
--out-prefix step3/Asu_Ath.r40000Two workflow templates are included:
example1/— plant example using.mcool+.linkexample2/— mammalian example using.hic+ UCSC.chain
Each uses config.yaml:
cd example1
snakemake -n -s Snakefile --cores 1
snakemake -s Snakefile --cores 8Edit config.yaml to point to your local matrix, synteny, and .fai files. Large matrices and generated step1..3/ outputs should not be committed; see .gitignore.
The following commands can emit Plotly HTML in addition to static plots:
prepare --summary --interactive auto|on|offliftcontacts --interactive auto|on|offmultiscale --interactive auto|on|off
Install the visualization extra first:
python -m pip install -e ".[viz]"The example Snakemake workflows target PDF outputs and may remove Plotly HTML to keep outputs predictable.
Six columns, 0-based half-open:
chromA startA endA chromB startB endB
Columns 1–3 are ascending on genome A. For reverse alignments, genome B coordinates are written in reverse order (startB > endB), so orientation is encoded by the sign of endB - startB. There is no separate strand column.
Eight columns:
chromA startA endA chromB startB endB direction block_id
link2mark generates .mark from .link or .chain. Long collinear blocks are densified at --step-len spacing (default 150 bp); blocks shorter than --thr-len (default 300 bp) are kept intact. direction is +1 or -1. Rows with <id>_gap mark gaps between adjacent source blocks.
Fourteen columns:
chrom1 start1 end1 bin1 chrom2 start2 end2 bin2 rank strict weak cov1 cov2 dist_bins
rank,strict,weak— normalized contact percentile ranks within each distance stratum, on a 0–99 integer scale.cov1,cov2— total raw Hi-C read coverage incident on each bin.dist_bins— genomic distance in bins;-1indicates inter-chromosomal contacts.
The companion .stats.tsv reports n, p05, p50, p95, and percentile quantiles p001–p100 for each distance bin.
Sixteen columns:
chr1_observed pos1_observed chr2_observed pos2_observed
remap1_target remap2_target
observed_contacts target_contacts
observed_deviations target_deviations
observed_coverages_pos1 observed_coverages_pos2
target_coverages_pos1 target_coverages_pos2
target_contact_distances remapping_coverages
observed_*— source-genome coordinates and values.target_*/remap*— corresponding values after liftover.observed_contacts,target_contacts— 0–99 percentile ranks.observed_deviations,target_deviations— percentile-rank uncertainty, calculated asmax(weak-rank, rank-strict).target_contact_distances— target-genome span in bins;-1indicates inter-chromosomal contacts.remapping_coverages— summed synteny weight; a one-to-one mapping is approximately 1.0.
- Current software version: 0.3.5 (see
pyproject.toml). - CI (
.github/workflows/ci.yml) runs on each push/PR, installs the package on Python 3.10, runspython -m compileall src, and checkspython -m coolsecture -h. - No formal test suite is included yet. The Snakemake examples (
example1/,example2/) serve as end-to-end integration runs.
- Added mummer4 support to
asm2link(-a mummer4;nucmer+delta-filter+show-coords). minimap2 remains the default. - Added
--mummer-filter {1-to-1,mutual-best,none}(default1-to-1),--mummer-min-idy, and--mummer-min-len. - Added
run-all --asm-alignerand--asm-mummer-filter. - Fixed several CLI help strings, including
prepare,liftcontacts --contact-a,--dups-filter,--model, and duplicated(default: auto)text.
- Switched static plots to editable PDF/SVG text with Carlito-preferred fonts.
- Added multi-resolution
.hicsupport toprepareandrun-all. - Added chromosome-name mapping output when aliases are used during liftover matrix generation.
- Added automatic parameter selection with
run-all --autoandauto_params.tsv. - Added automatic
plot-crossregion selection for top differential/conserved 2 Mb PBAD-ranked regions.
If you use Coolsecture in your research, please cite the paper.
# Peer-reviewed paper
Zhu P. et al. Coolsecture: an easy to use and improved framework for cross species Hi C contact map comparison. Bioinformatics (Accepted). doi: <DOI>