Skip to main content
Pre-release

This release is a pre-release and may not be stable for production use.

TADCLUST - Hierarchical clustering of TADs

Given any TAD annotation and a contact map, TADCLUST applies hierarchical clustering of the TADs based on TAD-level contact matrix. The clustering analysis identifies a higher-order organization of locally-defined TADs as trees, which is correlated to epigenetic states and chromosome compartmentalization.

Example TADCLUST tree for human HL-60 chr10

Install

TADCLUST is available on pypi as tadclust. You may use uvx to quickly try it out:

$ uvx tadclust -h

or docker:

$ docker run --rm ghcr.io/snsinfu/tadclust tadclust -h

To install a dev version to a uv/pixi project:

$ uv add git+https://github.com/snsinfu/tadclust.git
$ pixi add --pypi --git https://github.com/snsinfu/tadclust.git tadclust

Usage

Give an mcool contact matrix, a TAD annotation table, optionally an A/B feature track, and the output directory.

$ tadclust \
  --output-dir       out \
  --mcool            contact_map.mcool \
  --tad-table        tad_annotation.bed \
  --ab-feature-track active_signal.bedGraph

The TAD table can be any disjoint or hierarchical TAD annotation in the BED3+ format, or a TSV with chrom, start, end columns. TADCLUST selects an optimal set of sub-TADs for clustering if the annotation is hierarchical. --ab-feature-track is any 4-column, BedGraph-like table or BED5+ where the annotated score is larger in the A compartment (like ATAC, H4ac, and gene density). It is used to define the A/B compartment boundary, to enable A/B annotation of TADs and cluster nodes.

Options

option default description
--tree-branch-k K 2 Split count of recursive k-means.
--with-trans no Enable trans-chromosomal clustering (experimental and expensive).
--with-residuals no Fill gaps with residual pseudo-domains.
--cis-clustering-source oe Use (oe) log-O/E or (frequency) log-contact frequency for cis clustering. frequency retains sequential locality in the resulting tree.
--overwrite no Allow overwriting existing files in the output directory.
--workers N 1 Run analysis in parallel using N processes.
--seed N 0 Random seed for reproducibility.

Output

Results are stored as parquet/tsv tables and a json manifest in the output directory:

out/
├── cis_nodes.parquet
├── cis_nodes_ab.parquet        # optional
├── cis_leaves.parquet
├── cis_leaves.tsv
├── cis_leaves_ab.parquet       # optional
├── cis_leaves_ab.tsv           # optional
├── trans_nodes.parquet         # optional
└── manifest.json

Main output is cis_nodes.parquet which contains full tree nodes for all chromosomes. cis_leaves.{parquet,tsv} are leaf-only subsets created for convenience. _ab suffixed tables store the result for A/B-rooted clustering variant. A copy of manifest.json is stored in every parquet file as a parquet metadata keyed by "tadclust"; the manifest contains version info, algorithm params, and QC stats.

Columns in the main table:

column type description
chrom string The chromosome the node belongs to.
node_id int Unique ID of the node within the table.
parent_id int Parent's node_id or null.
child_ids int[] Children's node_ids or empty.
depth int Depth of the node, 0 = root.
is_leaf bool (leaf) True or (branch) false.
unit_id int (leaf) Unique ID of the clustered leaf unit or (branch) null.
unit_kind tad/residual/bin (leaf) Type of the unit or (branch) null.
unit_start int (leaf) Start coord of the unit or (branch) null.
unit_end int (leaf) End coord of the unit or (branch) null.
tad_table_row int (leaf) Row index of the TAD table or (branch/non-TAD) null.
root_label chrom/A/B/genome Root of the tree the node belongs to.
path int[] Branches to take to arrive at the node from the root, like [0,1,0,1,1,1].
path_label string Root + path as a dot-delimited string, like "chrom.0.1.0.1.1.1".
ab_label A/B A/B classification (ab_signal <=> 0) of the node.
ab_signal float A/B compartment-like signal for the node.
ab_frac_a float Fraction of A leaves under the node.
ab_frac_b float Fraction of B leaves under the node.
ab_purity float Max(ab_frac_a, ab_frac_b).
pc float[] (leaf) PC feature vector or (branch) centroid.
n_units int Number of units under the node.
n_working_bins int Number of working bins covered by the units under the node.
node_oe float Mean log2 O/E over all units and unit pairs under the node.
node_internal_sse float Feature-space SSE of leaves under the node.
node_split_gain float Relative SSE reduction of splitting at this node.
stop_reason degenerate Reason of abruptly stopped splitting or null.

Notes:

  • Node's children (.0 .1) are ordered by centroid PC1.
  • When --ab-feature-track is given, the PC1 axis itself is oriented towards higher A signal. So nodes are B-to-A ordered.
  • In the tsv outputs, array/list columns are not emitted, and nulls are replaced by (int) -1, (float) NaN, and (string) "NA".

Method notes

TAD-level L2-normalized log-O/E is diagonalized (without centering; zero is the natural center for log-O/E) to produce principal components in the oe mode. This PC feature space is hierarchically clustered like CALDER. The first branch gives a similar result to the conventional compartment analysis, and deeper branches describe subcompartment organization. Because O/E drops information on seqence separation, clustered TADs are not necessarily physically proximal. Deeper branches are generally not informative.

TAD-level L2-normalized, double-centered log-contact frequency is diagonalized to produce PCs, and herarchically clustered, in the frequency mode. Double-centering here means that the log-contact frequency for a unit pair i, j is centered to the means of the i-th and the j-th units, so baseline frequency excepting for the distance decay is removed. Since it retains distance decay, resulting clusters emphasize sequential proximity, so deeper branches tend to group neighboring TADs. Well-compartmentalized genomes still show a clear A/B split near the root of the tree even in this mode.

When hierarchical TAD annotation is given (i.e., there are nested intervals), the optimal levels of sub-TAD hierarchies are decided by dynamic programming so that within-TAD variance (among sub-TADs and gaps) is minimized in the feature space. The selected (sub-)TADs are output as leaf units with unit_kind = "tad". Besides clustering, this selection of the "most coherent" sub-TADs can be useful on its own.

Recursive K-means seems superior to other methods like Ward, HDBSCAN, spectral, etc. for clustering TADs. This is probably because the domains in the feature space are not cleanly separable (strong noise, broad lobes, and biological intermediates). Bisection (k=2) is good enough to maintain A/B coherence in subtree. k=3 performs similarly good.

For A/B compartment annotation, an auxiliary binary split of an augmented feature space is made. Bisection of the raw PC space does not reliably give a useful "A/B"-like clusters except for mammalian datasets, so the PC space needs to be augmented by a reference signal track (--ab-feature-track; ATAC, H4ac, and gene density tracks work well) to determine the A/B decision boundary and the orientation. Once the boundary is determined, it is projected onto the original PC space, and the TADs are A/B-annotated. This auxiliary split is done solely for annotation and it does not affect the cluster hierarchy.

The A/B signal is the 1D projection of the node's PC centroid onto the A-B axis in the PC space (the axis along the A and B centroids). This is a generalization of the conventional PC1 compartment signal to the bisected, higher-dimensional PC space. The magnitude of the signal is informative: it is the distance from the decision boundary, so close-to-zero signal indicates poor compartmentalization. The PC space is standardized in A/B analysis, so the typical values of the signal distribute in the ~3 sigma range, so the "normal" magnitude would be around ~1.

Genome-wide clustering (experimental) is also done when --with-trans flag is passed. Genome-wide, trans-chrom O/E is built using the cis-defined TADs as units, diagonalized, and recursively clustered. The trans tree tends to capture chromosome territories or telomere clustering rather than genome-wide A/B compartments. Still, the unit_id is shared between the cis table, so one can JOIN cis and trans tables to examine cis-determined A/B on the trans tree.

AI disclosure

LLM coding agent is used for development. Algorithm is designed and instructed by me, then implemented by AI, benchmarking on real datasets. I review every changeset and adjust it until it looks fine. This README is 100% human-written.

License

MIT

Metadata

Release files for tadclust 0.1.0a2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for tadclust 0.1.0a2
File Size Uploaded Provenance Actions
tadclust-0.1.0a2.tar.gz 79.3 kB With provenance Details for tadclust-0.1.0a2.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for tadclust 0.1.0a2
File Interpreter ABI Platform Actions
tadclust-0.1.0a2-py3-none-any.whl Python 3 none any Details for tadclust-0.1.0a2-py3-none-any.whl

Total release size: 136.8 kB

Release files / tadclust-0.1.0a2.tar.gz

Download URL tadclust-0.1.0a2.tar.gz
Size 79.3 kB
Tags Source
SHA-256 checksum
How to use checksums
24ed14c5699349daa63027b0934a396aafd55e8526a6f5493583479ef93ab40f
BLAKE2b-256 checksum
How to use checksums
614488657737550717ad584bf9eb35bd145881c17df132375394a645e4b0183d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Release files / tadclust-0.1.0a2-py3-none-any.whl

Download URL tadclust-0.1.0a2-py3-none-any.whl
Size 57.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
333275f69555ec0f49608940ce0bf1542f2774a176187639c894bf3f01e3cb89
BLAKE2b-256 checksum
How to use checksums
b7c3bd48b26f4fbbc0824bfef17781881a3b1ca9246b4a573a90a73311d69985
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

Security for tadclust 0.1.0a2

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for tadclust-0.1.0a2.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page