uchrom.strc.tad¶
- class uchrom.strc.tad.DICallerParams(window: int = 50, smoothing_param: float = 0.1, min_size_frac: float = 0.05)[source]¶
Bases:
objectKnobs of
call_tads_di()(defaults =get_domains()).
- class uchrom.strc.tad.FISHnetParams(thresholds: ndarray | None = None, threshold_step: float | None = None, threshold_min: float | None = None, threshold_max: float | None = None, plateau_size: int = 4, window_size: int = 2, size_exclusion: int = 3, merge_tol: int = 3, n_louvain_runs: int = 20, resolution: float = 1.0, min_coverage: float = 0.6, max_thresholds: int = 200, impute: bool = True)[source]¶
Bases:
objectRuntime parameters for
call_domains_fishnet_trace().Defaults follow Patel et al. 2025.
- class uchrom.strc.tad.InsulationParams(window_bp: int | None = None, ignore_diags: int | None = None, statistic: str = 'mean', min_frac_valid_pixels: float = 0.66, min_dist_bad_bin: int = 0, threshold: str | float = 'li', balance: bool = True)[source]¶
Bases:
objectKnobs of
insulation_score()andcall_tads_insulation()(defaults: cooltoolsinsulation).- Variables:
window_bp (int, optional) – Side of the diamond, bp (a multiple of the bin size).
None: 100 kb in whole bins, at least 3 (20 bins at 5 kb, 10 at 10 kb, 4 at 25 kb, 3 at 50 kb) — the scale whose boundaries match the Rao 2014 Arrowhead domain edges best. On a map of variable-size bins the window isround(window_bp / median bin size)bins.ignore_diags (int, optional) – Pixels closer to the diagonal than this (in bins) are left out.
None: theignore_diagsthe map was balanced with (bins/weightattributes), else 2.statistic ({"mean", "sum"}) –
"mean": sum over the valid pixels /n_valid_pixels(cooltools, Crane et al. 2015);"sum": the sum alone (masked pixels then lower the score).min_frac_valid_pixels (float) – Bins whose diamond has fewer valid pixels than this fraction of a full diamond get no boundary strength (cooltools: 0.66).
min_dist_bad_bin (int) – Bins closer than this (in bins) to a masked bin get no score (0: keep all).
threshold ("li", "otsu" or float) – Rule for the boundary-strength cut, applied to all chromosomes of a call together: Li’s minimum cross-entropy threshold (default; as cooltools), Otsu’s threshold, or a fixed strength. The strengths are a long right tail of strong boundaries over many shallow noise minima, not two balanced classes: Otsu cuts high, Li lower — on Rao 2014 IMR90 / GM12878 (5-25 kb, 100 kb window) Li recovers 0.11-0.20 more of the Arrowhead domain edges at 0.01-0.12 less precision (higher F1 in every case).
balance (bool) – Use the balanced map (the cooler
weightcolumn);False/ an unbalanced map: raw counts.
- class uchrom.strc.tad.SingleCellBoundaryParams(rp: float = 0.05, window: int | str | None = 'auto', insulation_window: int | None = None, ignore_diags: int = 2, threshold: str | float = 'li', normalize: bool = False, consensus: str = 'insulation')[source]¶
Bases:
objectKnobs of
single_cell_boundaries().- Variables:
rp (float) – Restart probability of the imputation (SnapHiC’s 0.05).
window (int, "auto" or None) – Sliding window of the imputation, bp (
"auto": SnapHiC2’s rule;None: whole chromosomes).insulation_window (int, optional) – Side of the insulation diamond, bp; default that of
InsulationParams(100 kb, at least 3 bins).ignore_diags (int) – Diagonals left out of the diamond (2).
threshold ("li", "otsu" or float) – Boundary-strength cut per cell, and of the consensus.
normalize (bool) – Insulation of the per-diagonal z-scores (SnapHiC’s normalisation) instead of the RWR values.
consensus ({"insulation", "frequency"}) – Consensus boundaries from the minima of the cells’ mean insulation, or from the peaks of the boundary frequency.
- class uchrom.strc.tad.TADCallerParams(window_bp: float = 100000.0, fdr_cutoff: float = 0.1, method: str = 'pval', hierarchical: bool = True, min_tad_size: float = 0.0, max_levels: int | None = None, prominence: float | None = None, distance: int | None = None, k_sigma: float = 4.0, frac: float = 0.1)[source]¶
Bases:
objectRuntime parameters for
call_tads_by_pval()(ArcFISH’sTADCaller(method="pval")defaults).method:"pval"(the arc p-value test) or"insulation"(Su et al. 2020; module docstring).window_bp(ArcFISHwindow): the loci within this distance on each side of a locus form its left and right segments; loci closer thanwindow_bp / 2to either end of the chromosome are not tested.hierarchical(ArcFISHtree),min_tad_sizein bp.max_levels(U-Chrom): keep levels0 .. max_levels - 1only (None: all).prominence/distance: passed tofind_peaks(the authors’ parameters of the insulation method; also applied to"pval", where the authors use none).k_sigma/frac: the outlier filter and LOWESS span ofuchrom.fea.arc.filter_normalize().Before U-Chrom 0.3 (2026-10)
window_bpwas the whole window (half on each side), level 1 was the finest partition with up tomax_levels=4partitions, boundaries were peaks of the combined p-value and the FDR was computed over the peaks only; results differ from the authors’ (docs/source/reference/changelog.md).
- uchrom.strc.tad.boundary_frequency(cd, domains: str | DataFrame = 'tads.fishnet') DataFrame[source]¶
Per locus, the fraction of traces (alleles) with a domain boundary there — single-allele domain tables such as FISHnet’s.
- Parameters:
- Returns:
One row per locus of the chromosomes in the table:
bin_id, chrom, start, end, bin_index,n_traces(traces with domains on the chromosome) andfrequency.- Return type:
DataFrame
- uchrom.strc.tad.calc_directionality_index(contact_mat, window=50, device='auto')[source]¶
Calculate Directionality Index for each genomic bin.
- uchrom.strc.tad.call_domains_fishnet(cd, *args, chrom=None, trace_ids=None, cells=None, params: FISHnetParams | None = None, key_added: str | None = UNSET, ensemble_key: str | None = UNSET, copy: bool = False, verbose: bool = False, max_traces: int | None = None, store=UNSET, result_key=UNSET)[source]¶
Run FISHnet on every trace of the selected chromosome(s).
- Parameters:
cd (ChromData)
chrom (str, sequence of str, or None) –
None(default) runs every chromosome and merges the tables.trace_ids (sequence, optional) – Restrict to these traces / cells.
cells (sequence, optional) – Restrict to these traces / cells.
params (FISHnetParams, optional)
key_added (str or None) –
cd.resultskey of the per-trace domain table (default"tads.fishnet");Nonedoes not store.ensemble_key (str, optional) –
cd.resultskey of the ensemble domain mask (defaultf"{key_added}.ensemble"). Stored as a mapping{chrom: {"mask": (n_bins, n_bins) int64, "bin_ids": (n_bins, 2) int64 [start, end], "n_traces": int}}.copy (bool) –
True→ return a new ChromData holding the results.max_traces (int, optional) – Cap on the number of traces processed per chromosome (useful for previews — FISHnet is O(n_bins² · n_thresholds) per trace).
Notes
Each trace’s Louvain runs are seeded by
trace_seed()(its id), so its domains do not depend on the row order or on the other traces selected.- Returns:
One row per (trace, domain):
chrom, trace_id, domain_idx, start, end, start_bin, end_bin.- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
Notes
Deprecated 1.x forms (positional
chrom,store=,result_key=) still work with aDeprecationWarning; they keep the 1.x keys"fishnet_domains"/"fishnet_ensemble"and the 1.x single-chromosome ensemble layout{"chrom", "mask", "bin_ids", "n_traces"}.
- uchrom.strc.tad.call_domains_fishnet_trace(dist, params: FISHnetParams | None = None, seed_base: int | None = None, *, trace_id=None, chrom: str | None = None) dict[source]¶
Run FISHnet on one allele: a pairwise distance matrix, or a trace of a
ChromData.- Parameters:
dist (ndarray (n_bins, n_bins) or ChromData) – Symmetric pairwise distance matrix, NaN for missing spots; or a
ChromDatatogether withtrace_id: the matrix is then built over every locus of the trace’s chromosome (cd.bins; NaN for loci the trace did not detect, a locus seen twice keeps its last spot).params (FISHnetParams, optional) – Hyperparameters. Use defaults if
None.seed_base (int, optional) – Base seed of the Louvain runs (reproducibility). Default: 0 for a matrix;
trace_seed()of the trace for aChromData— the seedcall_domains_fishnet()uses, so the result equals that trace’s rows there (when every locus of the chromosome was detected in the traces called there).trace_id (optional) – The trace (with a
ChromData).chrom (str, optional) – Its chromosome, when the trace spans several.
- Returns:
domains: list of (start, end_exclusive) bin indices per plateau;boundaries: sorted list of canonical boundary bin indices;domain_mask: (n_bins, n_bins) int — count of plateaus in which bins i and j fall in the same domain (0 if never);n_plateaus: number of plateaus detected;coverage: fraction of bins with ≥1 non-NaN distance. With aChromDataalsodistances(the matrix),loci(bin_id, chrom, start, endof its rows) andtrace_id.- Return type:
- uchrom.strc.tad.call_tads_by_pval(cd, *args, chrom=None, trace_ids=None, cells=None, params: TADCallerParams | None = None, device: str = 'auto', key_added: str | None = UNSET, copy: bool = False, verbose: bool = False, streaming: bool | None = None, batch='auto', memory_budget=None, store=UNSET, result_key=UNSET)[source]¶
ArcFISH’s TAD caller (chromatin tracing; module docstring).
- Parameters:
cd (ChromData)
chrom (str, sequence of str, or None) – Chromosome(s) to call.
None(default) calls every chromosome with spots and merges the per-chromosome tables.trace_ids (sequence, optional) – Restrict the population to these traces / cells.
cells (sequence, optional) – Restrict the population to these traces / cells.
params (TADCallerParams, optional)
device (
'auto' | 'cpu' | 'cuda' | 'mps')key_added (str or None) –
cd.resultskey for the merged table (default"tads.arcfish");Nonedoes not store.copy (bool) –
True→ return a new ChromData with the result;cdis not modified.streaming (bool, optional) – Compute the axis-variance cube by streaming over the traces (
uchrom.fea.arc_stream.axis_cube_streaming(): exact medians per row band, memoryO(n_bins²)instead ofO(n_traces × n_bins²)). Default:Truefor a backedChromData. Results equal the in-memory path up to floating-point rounding of the variance sums.batch – Traces per batch (
"auto") and working-memory budget of the streaming path (defaultuchrom.settings.memory_budget).memory_budget – Traces per batch (
"auto") and working-memory budget of the streaming path (defaultuchrom.settings.memory_budget).
- Returns:
One row per domain (module docstring):
chrom, start, end, level, start1, end1, start2, end2, stat1, stat2. Level 0 is the finest partition (every boundary); withparams.hierarchicaleach further level is the domain merged by removing the next weakest boundary.- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
Notes
Deprecated 1.x forms still work with a
DeprecationWarning: positionalchrom,store=andresult_key=. When any of them is used andkey_addedis not given, the result is stored under the 1.x key"tads".
- uchrom.strc.tad.call_tads_di(cd, *, contacts='default', resolution: int | None = None, balance: bool = True, chrom=None, params: DICallerParams | None = None, device: str = 'auto', key_added: str | None = 'tads.di', copy: bool = False)[source]¶
Directionality-index TADs on a linked Hi-C contact matrix.
- Parameters:
cd (ChromData) – Holds the link (
cd.link_cool(path, key=...)) and receives the result.contacts (str) – Key of
cd.uns['linked_cool'](default"default") or a path to a.cool/.mcool.resolution (int, optional) – Required for
.mcool; checked against a.cool’s bin size.balance (bool) – Use the cooler
weightcolumn (falls back to raw counts, with a warning, when the file is not balanced).chrom (str, sequence of str, or None) –
None→ the chromosomes ofcd.spotsthat the cooler has, or every cooler chromosome whencdhas no spots on any of them (e.g. Hi-C-only data).params (DICallerParams, optional)
key_added (str or None) –
cd.resultskey (default"tads.di");Nonedoes not store.copy (bool) –
True→ return a new ChromData holding the result.
- Returns:
chrom, start, end, start_bin, end_bin— bin indices are per-chromosome,end_binexclusive, exactly as returned byget_domains(). (The kernel’s last domain stops one bin short of the chromosome end; this is kept as is.)- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
- uchrom.strc.tad.call_tads_insulation(cd, *, contacts=None, chrom=None, resolution: int | None = None, params: InsulationParams | None = None, key_added: str | None = 'tads.insulation', copy: bool = False)[source]¶
TAD boundaries and domains of a Hi-C map by the diamond insulation score.
Boundaries are the minima of the insulation score (Crane et al. 2015) whose boundary strength (the prominence of the minimum) passes Li’s minimum cross-entropy threshold, as cooltools
insulation(Open2C et al. 2024) calls them; seeinsulation_score(). Domains are the stretches between consecutive boundaries (and from the first / to the last scored bin of a chromosome); a domain never spanswindowor more consecutive bins without a score (masked regions such as centromeres), so the boundaries of the domain table (uchrom.strc.tad.tad_boundaries()) are exactly the called ones.- Parameters:
cd (ChromData, path or cooler.Cooler) – Holds the map (
cd.link_cool) and receives the result (a path / cooler: the domains are returned).contacts (str, optional) – Key of the linked map (
None: the only one) or the path of a map.chrom (str, sequence of str, or None) –
None: the chromosomes ofcd’s spots that the map has, else every chromosome of the map.resolution (int, optional) – The level of an
.mcool.params (InsulationParams, optional) –
window_bp(default 100 kb in whole bins, at least 3),threshold(default"li"), …key_added (str or None) –
cd.results/cd.intervalskey of the domains (default"tads.insulation";None: not stored). Also stored:f"{key_added}.boundaries"(results + apeakinterval table) and the per-bin trackf"{key_added}.score"(insulation_score()columns of the window).copy (bool) –
True: return a copy ofcdholding the result.
- Returns:
The domains:
chrom, start, end, start_bin, end_bin(map bins within the chromosome,end_binexclusive;startis the start of the boundary bin,endthe start of the next boundary bin) — the columns ofcall_tads_di(). The boundaries table haschrom, start, end(the boundary bin),bin_index,log2_insulation_scoreandboundary_strength.- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
- uchrom.strc.tad.compare_boundaries(cd, query: str | DataFrame, reference: str | DataFrame, *, tol: int = 1, level: int | None = None, contacts: str | None = None, resolution: int | None = None) Dict[str, float][source]¶
How often the boundaries of
queryfall withintolloci of a boundary ofreference, against what random loci would give.- Parameters:
cd (ChromData) – Its
binsare the loci both tables are placed on (tad_boundaries()).query (str or DataFrame) – Population domain tables (keys of
cd.resultsor tables), e.g. DI TADs on Hi-C and ArcFISH TADs on the imaging of the same loci, or insulation TADs and a published domain list.reference (str or DataFrame) – Population domain tables (keys of
cd.resultsor tables), e.g. DI TADs on Hi-C and ArcFISH TADs on the imaging of the same loci, or insulation TADs and a published domain list.tol (int) – Largest distance in loci (default 1: the same or a neighbouring locus).
level (int, optional) – Level of hierarchical tables (default the finest).
contacts (optional) – Place the boundaries on the bins of this linked contact map instead of
cd.bins(tad_boundaries());tolthen counts map bins.resolution (optional) – Place the boundaries on the bins of this linked contact map instead of
cd.bins(tad_boundaries());tolthen counts map bins.
- Returns:
n_query,n_reference(boundaries),fraction_near(of the query boundaries withintolloci of a reference boundary on the same chromosome),chance(the same fraction for every locus of the chromosomes with query boundaries) andenrichment(= fraction_near / chance).- Return type:
- uchrom.strc.tad.detect_tad_boundaries(di, min_size_frac=0.05)[source]¶
Detect TAD boundaries from sign changes (negative -> positive).
- uchrom.strc.tad.get_domains(contact_mat, smoothing_param=0.1, min_size_frac=0.05, window=50, device='auto')[source]¶
Identify TADs: DI calculation -> smoothing -> boundary detection.
- uchrom.strc.tad.insulation_score(cd, *, contacts=None, chrom=None, resolution: int | None = None, windows=None, params: InsulationParams | None = None, key_added: str | None = 'insulation', copy: bool = False)[source]¶
Diamond insulation score of a Hi-C map, with the boundary strength of its minima.
The insulation of Crane et al. (2015) as computed by cooltools
insulation(Open2C et al. 2024): the mean balanced contact in thew x wdiamond on the diagonal at each bin, over the diamond’s valid pixels (n_valid_pixels: both bins unmasked, separation>= ignore_diags), normalised by the chromosome median, log2. Every local minimum gets a boundary strength (its prominence; bins whose diamond is less thanmin_frac_valid_pixelsvalid are left out) andis_boundarymarks the minima above the threshold (Li by default), computed over all chromosomes of the call.- Parameters:
cd (ChromData, path or cooler.Cooler) – Holds the map (
cd.link_cool(path, key=...)) and receives the result; or the path of a.cool/.mcool, or an opencooler.Cooler(nothing is stored then).contacts (str, optional) – Key of the linked map (
None: the only one) or the path of a map.chrom (str, sequence of str, or None) –
None: the chromosomes ofcd’s spots that the map has, else every chromosome of the map.resolution (int, optional) – The level of an
.mcool.windows (int or sequence of int, optional) – Diamond sides in bp (multiples of the bin size); default
(params.window_bp,)(100 kb in whole bins, at least 3).params (InsulationParams, optional)
key_added (str or None) –
cd.resultskey (default"insulation";None: not stored). When stored, the log2 score of each window is also written on the loci ofcd(the map bin holding each locus’ midpoint) ascd.bin_tracks[f"{key_added}.log2_{window}"], ifcdhas loci on these chromosomes.copy (bool) –
True: return a copy ofcdholding the result.
- Returns:
One row per bin of the map:
chrom, start, end, bin_index(within the chromosome),is_bad_bin(masked by balancing) and per windowW(bp)log2_insulation_score_W,n_valid_pixels_W,boundary_strength_W(NaN off the minima) andis_boundary_W— the columns of cooltoolsinsulation.- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
- uchrom.strc.tad.single_cell_boundaries(cd, *, contacts: str = 'per_cell', cells: Sequence | None = None, chrom: None | str | Sequence[str] = None, params: SingleCellBoundaryParams | None = None, per_cell: bool = False, key_added: str | None = 'tads.single_cell', copy: bool = False, backend: str | None = None, n_threads: int = 0, timing: dict | None = None)[source]¶
Domain boundaries of every cell from its imputed map (insulation), and their frequency across cells.
- Parameters:
cd (ChromData) – With per-cell maps linked (
cd.link_scool) or embedded in its atlas store.contacts (str) – Key of the per-cell maps (or a
.scoolnamed by cell id).cells (sequence, optional) – Cells (default: every cell of
cd.cells).chrom (str or sequence, optional) – Chromosomes (default: the autosomes of the maps).
params (SingleCellBoundaryParams, optional)
per_cell (bool) – Also store every cell’s boundaries (
cd.results[key_added + ".cells"]:cell_id, chrom, start, end, strength).key_added (str or None) – The per-bin table goes to
cd.results[key_added], the consensus domains tocd.intervals[key_added + ".domains"](None: nothing stored).copy (bool) – Return a new
ChromDataholding the results.backend – Of the imputation (
uchrom.fea.impute_rwr.rwr_band()).n_threads – Of the imputation (
uchrom.fea.impute_rwr.rwr_band()).timing (dict, optional) – Seconds per step.
- Returns:
One row per bin:
chrom, start, end,n_cells(cells scored),frequency(share of them with a boundary at the bin),insulation(mean log2 insulation score),strength(mean strength where a cell has a boundary),consensus_strength(prominence of the mean insulation’s minimum, or of the frequency’s peak) andconsensus(above the threshold).- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
- uchrom.strc.tad.tad_boundaries(cd, domains: str | DataFrame = 'tads.arcfish', *, level: int | None = None, contacts: str | None = None, resolution: int | None = None) DataFrame[source]¶
The boundaries of a domain table, as loci of
cd.- Parameters:
cd (ChromData) – Its
binsare the loci the boundaries are placed on (or the bins ofcontacts).domains (str or DataFrame) – A key of
cd.results(default"tads.arcfish") or a table withchrom, start, end; with atrace_idcolumn (FISHnet), boundaries per trace.level (int, optional) – For hierarchical tables (a
levelcolumn): the level to use; default the lowest (the finest: level 0 ofuchrom.strc.tad.call_tads_by_pval()).contacts (optional) – Key of a contact map linked to
cd(and the level of an.mcool): its bins are the loci — for aChromDatathat holds only Hi-C maps (bin_idis then the map’s bin index).resolution (optional) – Key of a contact map linked to
cd(and the level of an.mcool): its bins are the loci — for aChromDatathat holds only Hi-C maps (bin_idis then the map’s bin index).
- Returns:
One row per boundary:
chrom, [trace_id],bin_index(the locus after the boundary, counted within the chromosome from 0),bin_id(cd.binsindex) andstart(its start, bp).- Return type:
DataFrame
- uchrom.strc.tad.trace_seed(trace_id) int[source]¶
Base seed of the Louvain runs of one trace: the CRC-32 of its id, so that an allele’s domains do not depend on the row order of the data or on which other alleles are called with it.
FISHnet (per-allele, graph-theory)¶
- class uchrom.strc.tad.fishnet.FISHnetParams(thresholds: ndarray | None = None, threshold_step: float | None = None, threshold_min: float | None = None, threshold_max: float | None = None, plateau_size: int = 4, window_size: int = 2, size_exclusion: int = 3, merge_tol: int = 3, n_louvain_runs: int = 20, resolution: float = 1.0, min_coverage: float = 0.6, max_thresholds: int = 200, impute: bool = True)[source]¶
Bases:
objectRuntime parameters for
call_domains_fishnet_trace().Defaults follow Patel et al. 2025.
- uchrom.strc.tad.fishnet.call_domains_fishnet(cd, *args, chrom=None, trace_ids=None, cells=None, params: FISHnetParams | None = None, key_added: str | None = UNSET, ensemble_key: str | None = UNSET, copy: bool = False, verbose: bool = False, max_traces: int | None = None, store=UNSET, result_key=UNSET)[source]¶
Run FISHnet on every trace of the selected chromosome(s).
- Parameters:
cd (ChromData)
chrom (str, sequence of str, or None) –
None(default) runs every chromosome and merges the tables.trace_ids (sequence, optional) – Restrict to these traces / cells.
cells (sequence, optional) – Restrict to these traces / cells.
params (FISHnetParams, optional)
key_added (str or None) –
cd.resultskey of the per-trace domain table (default"tads.fishnet");Nonedoes not store.ensemble_key (str, optional) –
cd.resultskey of the ensemble domain mask (defaultf"{key_added}.ensemble"). Stored as a mapping{chrom: {"mask": (n_bins, n_bins) int64, "bin_ids": (n_bins, 2) int64 [start, end], "n_traces": int}}.copy (bool) –
True→ return a new ChromData holding the results.max_traces (int, optional) – Cap on the number of traces processed per chromosome (useful for previews — FISHnet is O(n_bins² · n_thresholds) per trace).
Notes
Each trace’s Louvain runs are seeded by
trace_seed()(its id), so its domains do not depend on the row order or on the other traces selected.- Returns:
One row per (trace, domain):
chrom, trace_id, domain_idx, start, end, start_bin, end_bin.- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
Notes
Deprecated 1.x forms (positional
chrom,store=,result_key=) still work with aDeprecationWarning; they keep the 1.x keys"fishnet_domains"/"fishnet_ensemble"and the 1.x single-chromosome ensemble layout{"chrom", "mask", "bin_ids", "n_traces"}.
- uchrom.strc.tad.fishnet.call_domains_fishnet_trace(dist, params: FISHnetParams | None = None, seed_base: int | None = None, *, trace_id=None, chrom: str | None = None) dict[source]¶
Run FISHnet on one allele: a pairwise distance matrix, or a trace of a
ChromData.- Parameters:
dist (ndarray (n_bins, n_bins) or ChromData) – Symmetric pairwise distance matrix, NaN for missing spots; or a
ChromDatatogether withtrace_id: the matrix is then built over every locus of the trace’s chromosome (cd.bins; NaN for loci the trace did not detect, a locus seen twice keeps its last spot).params (FISHnetParams, optional) – Hyperparameters. Use defaults if
None.seed_base (int, optional) – Base seed of the Louvain runs (reproducibility). Default: 0 for a matrix;
trace_seed()of the trace for aChromData— the seedcall_domains_fishnet()uses, so the result equals that trace’s rows there (when every locus of the chromosome was detected in the traces called there).trace_id (optional) – The trace (with a
ChromData).chrom (str, optional) – Its chromosome, when the trace spans several.
- Returns:
domains: list of (start, end_exclusive) bin indices per plateau;boundaries: sorted list of canonical boundary bin indices;domain_mask: (n_bins, n_bins) int — count of plateaus in which bins i and j fall in the same domain (0 if never);n_plateaus: number of plateaus detected;coverage: fraction of bins with ≥1 non-NaN distance. With aChromDataalsodistances(the matrix),loci(bin_id, chrom, start, endof its rows) andtrace_id.- Return type:
F-test caller¶
- class uchrom.strc.tad.arc_pval.TADCallerParams(window_bp: float = 100000.0, fdr_cutoff: float = 0.1, method: str = 'pval', hierarchical: bool = True, min_tad_size: float = 0.0, max_levels: int | None = None, prominence: float | None = None, distance: int | None = None, k_sigma: float = 4.0, frac: float = 0.1)[source]¶
Bases:
objectRuntime parameters for
call_tads_by_pval()(ArcFISH’sTADCaller(method="pval")defaults).method:"pval"(the arc p-value test) or"insulation"(Su et al. 2020; module docstring).window_bp(ArcFISHwindow): the loci within this distance on each side of a locus form its left and right segments; loci closer thanwindow_bp / 2to either end of the chromosome are not tested.hierarchical(ArcFISHtree),min_tad_sizein bp.max_levels(U-Chrom): keep levels0 .. max_levels - 1only (None: all).prominence/distance: passed tofind_peaks(the authors’ parameters of the insulation method; also applied to"pval", where the authors use none).k_sigma/frac: the outlier filter and LOWESS span ofuchrom.fea.arc.filter_normalize().Before U-Chrom 0.3 (2026-10)
window_bpwas the whole window (half on each side), level 1 was the finest partition with up tomax_levels=4partitions, boundaries were peaks of the combined p-value and the FDR was computed over the peaks only; results differ from the authors’ (docs/source/reference/changelog.md).
- uchrom.strc.tad.arc_pval.call_tads_by_pval(cd, *args, chrom=None, trace_ids=None, cells=None, params: TADCallerParams | None = None, device: str = 'auto', key_added: str | None = UNSET, copy: bool = False, verbose: bool = False, streaming: bool | None = None, batch='auto', memory_budget=None, store=UNSET, result_key=UNSET)[source]¶
ArcFISH’s TAD caller (chromatin tracing; module docstring).
- Parameters:
cd (ChromData)
chrom (str, sequence of str, or None) – Chromosome(s) to call.
None(default) calls every chromosome with spots and merges the per-chromosome tables.trace_ids (sequence, optional) – Restrict the population to these traces / cells.
cells (sequence, optional) – Restrict the population to these traces / cells.
params (TADCallerParams, optional)
device (
'auto' | 'cpu' | 'cuda' | 'mps')key_added (str or None) –
cd.resultskey for the merged table (default"tads.arcfish");Nonedoes not store.copy (bool) –
True→ return a new ChromData with the result;cdis not modified.streaming (bool, optional) – Compute the axis-variance cube by streaming over the traces (
uchrom.fea.arc_stream.axis_cube_streaming(): exact medians per row band, memoryO(n_bins²)instead ofO(n_traces × n_bins²)). Default:Truefor a backedChromData. Results equal the in-memory path up to floating-point rounding of the variance sums.batch – Traces per batch (
"auto") and working-memory budget of the streaming path (defaultuchrom.settings.memory_budget).memory_budget – Traces per batch (
"auto") and working-memory budget of the streaming path (defaultuchrom.settings.memory_budget).
- Returns:
One row per domain (module docstring):
chrom, start, end, level, start1, end1, start2, end2, stat1, stat2. Level 0 is the finest partition (every boundary); withparams.hierarchicaleach further level is the domain merged by removing the next weakest boundary.- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
Notes
Deprecated 1.x forms still work with a
DeprecationWarning: positionalchrom,store=andresult_key=. When any of them is used andkey_addedis not given, the result is stored under the 1.x key"tads".
Insulation score (Hi-C maps)¶
Boundaries and domains of a linked contact map by the diamond insulation score (Crane et al. 2015, in cooltools’ formulation).
- class uchrom.strc.tad.insulation.InsulationParams(window_bp: int | None = None, ignore_diags: int | None = None, statistic: str = 'mean', min_frac_valid_pixels: float = 0.66, min_dist_bad_bin: int = 0, threshold: str | float = 'li', balance: bool = True)[source]¶
Bases:
objectKnobs of
insulation_score()andcall_tads_insulation()(defaults: cooltoolsinsulation).- Variables:
window_bp (int, optional) – Side of the diamond, bp (a multiple of the bin size).
None: 100 kb in whole bins, at least 3 (20 bins at 5 kb, 10 at 10 kb, 4 at 25 kb, 3 at 50 kb) — the scale whose boundaries match the Rao 2014 Arrowhead domain edges best. On a map of variable-size bins the window isround(window_bp / median bin size)bins.ignore_diags (int, optional) – Pixels closer to the diagonal than this (in bins) are left out.
None: theignore_diagsthe map was balanced with (bins/weightattributes), else 2.statistic ({"mean", "sum"}) –
"mean": sum over the valid pixels /n_valid_pixels(cooltools, Crane et al. 2015);"sum": the sum alone (masked pixels then lower the score).min_frac_valid_pixels (float) – Bins whose diamond has fewer valid pixels than this fraction of a full diamond get no boundary strength (cooltools: 0.66).
min_dist_bad_bin (int) – Bins closer than this (in bins) to a masked bin get no score (0: keep all).
threshold ("li", "otsu" or float) – Rule for the boundary-strength cut, applied to all chromosomes of a call together: Li’s minimum cross-entropy threshold (default; as cooltools), Otsu’s threshold, or a fixed strength. The strengths are a long right tail of strong boundaries over many shallow noise minima, not two balanced classes: Otsu cuts high, Li lower — on Rao 2014 IMR90 / GM12878 (5-25 kb, 100 kb window) Li recovers 0.11-0.20 more of the Arrowhead domain edges at 0.01-0.12 less precision (higher F1 in every case).
balance (bool) – Use the balanced map (the cooler
weightcolumn);False/ an unbalanced map: raw counts.
- uchrom.strc.tad.insulation.call_tads_insulation(cd, *, contacts=None, chrom=None, resolution: int | None = None, params: InsulationParams | None = None, key_added: str | None = 'tads.insulation', copy: bool = False)[source]¶
TAD boundaries and domains of a Hi-C map by the diamond insulation score.
Boundaries are the minima of the insulation score (Crane et al. 2015) whose boundary strength (the prominence of the minimum) passes Li’s minimum cross-entropy threshold, as cooltools
insulation(Open2C et al. 2024) calls them; seeinsulation_score(). Domains are the stretches between consecutive boundaries (and from the first / to the last scored bin of a chromosome); a domain never spanswindowor more consecutive bins without a score (masked regions such as centromeres), so the boundaries of the domain table (uchrom.strc.tad.tad_boundaries()) are exactly the called ones.- Parameters:
cd (ChromData, path or cooler.Cooler) – Holds the map (
cd.link_cool) and receives the result (a path / cooler: the domains are returned).contacts (str, optional) – Key of the linked map (
None: the only one) or the path of a map.chrom (str, sequence of str, or None) –
None: the chromosomes ofcd’s spots that the map has, else every chromosome of the map.resolution (int, optional) – The level of an
.mcool.params (InsulationParams, optional) –
window_bp(default 100 kb in whole bins, at least 3),threshold(default"li"), …key_added (str or None) –
cd.results/cd.intervalskey of the domains (default"tads.insulation";None: not stored). Also stored:f"{key_added}.boundaries"(results + apeakinterval table) and the per-bin trackf"{key_added}.score"(insulation_score()columns of the window).copy (bool) –
True: return a copy ofcdholding the result.
- Returns:
The domains:
chrom, start, end, start_bin, end_bin(map bins within the chromosome,end_binexclusive;startis the start of the boundary bin,endthe start of the next boundary bin) — the columns ofcall_tads_di(). The boundaries table haschrom, start, end(the boundary bin),bin_index,log2_insulation_scoreandboundary_strength.- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
- uchrom.strc.tad.insulation.insulation_score(cd, *, contacts=None, chrom=None, resolution: int | None = None, windows=None, params: InsulationParams | None = None, key_added: str | None = 'insulation', copy: bool = False)[source]¶
Diamond insulation score of a Hi-C map, with the boundary strength of its minima.
The insulation of Crane et al. (2015) as computed by cooltools
insulation(Open2C et al. 2024): the mean balanced contact in thew x wdiamond on the diagonal at each bin, over the diamond’s valid pixels (n_valid_pixels: both bins unmasked, separation>= ignore_diags), normalised by the chromosome median, log2. Every local minimum gets a boundary strength (its prominence; bins whose diamond is less thanmin_frac_valid_pixelsvalid are left out) andis_boundarymarks the minima above the threshold (Li by default), computed over all chromosomes of the call.- Parameters:
cd (ChromData, path or cooler.Cooler) – Holds the map (
cd.link_cool(path, key=...)) and receives the result; or the path of a.cool/.mcool, or an opencooler.Cooler(nothing is stored then).contacts (str, optional) – Key of the linked map (
None: the only one) or the path of a map.chrom (str, sequence of str, or None) –
None: the chromosomes ofcd’s spots that the map has, else every chromosome of the map.resolution (int, optional) – The level of an
.mcool.windows (int or sequence of int, optional) – Diamond sides in bp (multiples of the bin size); default
(params.window_bp,)(100 kb in whole bins, at least 3).params (InsulationParams, optional)
key_added (str or None) –
cd.resultskey (default"insulation";None: not stored). When stored, the log2 score of each window is also written on the loci ofcd(the map bin holding each locus’ midpoint) ascd.bin_tracks[f"{key_added}.log2_{window}"], ifcdhas loci on these chromosomes.copy (bool) –
True: return a copy ofcdholding the result.
- Returns:
One row per bin of the map:
chrom, start, end, bin_index(within the chromosome),is_bad_bin(masked by balancing) and per windowW(bp)log2_insulation_score_W,n_valid_pixels_W,boundary_strength_W(NaN off the minima) andis_boundary_W— the columns of cooltoolsinsulation.- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
Low-level kernels:
- uchrom.strc.tad.insulation.diamond_sums(i: ndarray, j: ndarray, values: ndarray, n: int, window: int, ignore_diags: int = 0, chunk: int = 2000000) Tuple[ndarray, ndarray][source]¶
Sum of
valuesover the diamond of every bin, and the number of finite pixels in it.Pixel
(i, j)(i <= j) lies in the diamond of binsmax(i, j - w + 1) .. min(j, i + w - 1)(a run whenj - i <= 2 (w - 1)), so each pixel adds its value at the first bin of its run and removes it after the last one; a cumulative sum gives the diamond sums. Pixels with a non-finite value or separation< ignore_diagsare left out.- Returns:
sums (ndarray (n,) float64) – 0 exactly where no pixel contributes.
nnz (ndarray (n,) int64) – The pixels that contribute (stored, finite) per diamond.
- uchrom.strc.tad.insulation.n_valid_pixels(valid: ndarray, window: int, ignore_diags: int = 0) ndarray[source]¶
The number of valid pixels in the
window x windowdiamond of every bin.The diamond of bin
kholds the pixels(k - a, k + b),0 <= a, b < window, inside the chromosome and witha + b >= ignore_diags; a pixel is valid when both its bins are. Counted as(valid bins in [k - w + 1, k]) * (valid bins in [k, k + w - 1])minus the pairs closer thanignore_diags, soO(n * ignore_diags**2).
- uchrom.strc.tad.insulation.full_diamond(window: int, ignore_diags: int = 0) int[source]¶
Pixels of a diamond with every bin valid (
window**2minus the pairs closer thanignore_diags).
- uchrom.strc.tad.insulation.boundary_strength(track: ndarray) ndarray[source]¶
Prominence of every local minimum of
track(NaN elsewhere), as cooltoolsfind_boundaries.NaN bins are skipped (a minimum is lower than its nearest finite neighbours). The prominence of a minimum is its depth below the higher of the two highest points between it and the nearest lower point on each side; a side with no lower point does not count; the deepest minimum is measured against the highest local maximum. (Topographic prominence of
-track; the sides viascipy.signal.peak_prominences().)
- uchrom.strc.tad.insulation.threshold_li(values: ndarray) float[source]¶
Li’s iterative minimum cross-entropy threshold (Li & Tam 1998) of the finite
values.The threshold
tis iterated as(m_b - m_f) / (ln m_b - ln m_f)from the mean, wherem_b/m_fare the means below / abovet(values shifted to start at 0), until it moves by less than half the smallest gap between distinct values — the float branch ofskimage.filters.threshold_li.
Single cells: boundaries of imputed maps¶
The insulation score of each cell’s imputed map (random walk with restart), its boundaries and the consensus over the cells.
- class uchrom.strc.tad.single_cell.SingleCellBoundaryParams(rp: float = 0.05, window: int | str | None = 'auto', insulation_window: int | None = None, ignore_diags: int = 2, threshold: str | float = 'li', normalize: bool = False, consensus: str = 'insulation')[source]¶
Bases:
objectKnobs of
single_cell_boundaries().- Variables:
rp (float) – Restart probability of the imputation (SnapHiC’s 0.05).
window (int, "auto" or None) – Sliding window of the imputation, bp (
"auto": SnapHiC2’s rule;None: whole chromosomes).insulation_window (int, optional) – Side of the insulation diamond, bp; default that of
InsulationParams(100 kb, at least 3 bins).ignore_diags (int) – Diagonals left out of the diamond (2).
threshold ("li", "otsu" or float) – Boundary-strength cut per cell, and of the consensus.
normalize (bool) – Insulation of the per-diagonal z-scores (SnapHiC’s normalisation) instead of the RWR values.
consensus ({"insulation", "frequency"}) – Consensus boundaries from the minima of the cells’ mean insulation, or from the peaks of the boundary frequency.
- uchrom.strc.tad.single_cell.single_cell_boundaries(cd, *, contacts: str = 'per_cell', cells: Sequence | None = None, chrom: None | str | Sequence[str] = None, params: SingleCellBoundaryParams | None = None, per_cell: bool = False, key_added: str | None = 'tads.single_cell', copy: bool = False, backend: str | None = None, n_threads: int = 0, timing: dict | None = None)[source]¶
Domain boundaries of every cell from its imputed map (insulation), and their frequency across cells.
- Parameters:
cd (ChromData) – With per-cell maps linked (
cd.link_scool) or embedded in its atlas store.contacts (str) – Key of the per-cell maps (or a
.scoolnamed by cell id).cells (sequence, optional) – Cells (default: every cell of
cd.cells).chrom (str or sequence, optional) – Chromosomes (default: the autosomes of the maps).
params (SingleCellBoundaryParams, optional)
per_cell (bool) – Also store every cell’s boundaries (
cd.results[key_added + ".cells"]:cell_id, chrom, start, end, strength).key_added (str or None) – The per-bin table goes to
cd.results[key_added], the consensus domains tocd.intervals[key_added + ".domains"](None: nothing stored).copy (bool) – Return a new
ChromDataholding the results.backend – Of the imputation (
uchrom.fea.impute_rwr.rwr_band()).n_threads – Of the imputation (
uchrom.fea.impute_rwr.rwr_band()).timing (dict, optional) – Seconds per step.
- Returns:
One row per bin:
chrom, start, end,n_cells(cells scored),frequency(share of them with a boundary at the bin),insulation(mean log2 insulation score),strength(mean strength where a cell has a boundary),consensus_strength(prominence of the mean insulation’s minimum, or of the frequency’s peak) andconsensus(above the threshold).- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
Directionality index¶
- class uchrom.strc.tad.di_caller.DICallerParams(window: int = 50, smoothing_param: float = 0.1, min_size_frac: float = 0.05)[source]¶
Bases:
objectKnobs of
call_tads_di()(defaults =get_domains()).
- uchrom.strc.tad.di_caller.call_tads_di(cd, *, contacts='default', resolution: int | None = None, balance: bool = True, chrom=None, params: DICallerParams | None = None, device: str = 'auto', key_added: str | None = 'tads.di', copy: bool = False)[source]¶
Directionality-index TADs on a linked Hi-C contact matrix.
- Parameters:
cd (ChromData) – Holds the link (
cd.link_cool(path, key=...)) and receives the result.contacts (str) – Key of
cd.uns['linked_cool'](default"default") or a path to a.cool/.mcool.resolution (int, optional) – Required for
.mcool; checked against a.cool’s bin size.balance (bool) – Use the cooler
weightcolumn (falls back to raw counts, with a warning, when the file is not balanced).chrom (str, sequence of str, or None) –
None→ the chromosomes ofcd.spotsthat the cooler has, or every cooler chromosome whencdhas no spots on any of them (e.g. Hi-C-only data).params (DICallerParams, optional)
key_added (str or None) –
cd.resultskey (default"tads.di");Nonedoes not store.copy (bool) –
True→ return a new ChromData holding the result.
- Returns:
chrom, start, end, start_bin, end_bin— bin indices are per-chromosome,end_binexclusive, exactly as returned byget_domains(). (The kernel’s last domain stops one bin short of the chromosome end; this is kept as is.)- Return type:
DataFrame (
copy=False) or ChromData (copy=True)
Low-level kernels:
- uchrom.strc.tad.di.calc_directionality_index(contact_mat, window=50, device='auto')[source]¶
Calculate Directionality Index for each genomic bin.
- uchrom.strc.tad.di.detect_tad_boundaries(di, min_size_frac=0.05)[source]¶
Detect TAD boundaries from sign changes (negative -> positive).
- uchrom.strc.tad.di.get_domains(contact_mat, smoothing_param=0.1, min_size_frac=0.05, window=50, device='auto')[source]¶
Identify TADs: DI calculation -> smoothing -> boundary detection.
Comparing boundaries¶
- uchrom.strc.tad.compare.tad_boundaries(cd, domains: str | DataFrame = 'tads.arcfish', *, level: int | None = None, contacts: str | None = None, resolution: int | None = None) DataFrame[source]¶
The boundaries of a domain table, as loci of
cd.- Parameters:
cd (ChromData) – Its
binsare the loci the boundaries are placed on (or the bins ofcontacts).domains (str or DataFrame) – A key of
cd.results(default"tads.arcfish") or a table withchrom, start, end; with atrace_idcolumn (FISHnet), boundaries per trace.level (int, optional) – For hierarchical tables (a
levelcolumn): the level to use; default the lowest (the finest: level 0 ofuchrom.strc.tad.call_tads_by_pval()).contacts (optional) – Key of a contact map linked to
cd(and the level of an.mcool): its bins are the loci — for aChromDatathat holds only Hi-C maps (bin_idis then the map’s bin index).resolution (optional) – Key of a contact map linked to
cd(and the level of an.mcool): its bins are the loci — for aChromDatathat holds only Hi-C maps (bin_idis then the map’s bin index).
- Returns:
One row per boundary:
chrom, [trace_id],bin_index(the locus after the boundary, counted within the chromosome from 0),bin_id(cd.binsindex) andstart(its start, bp).- Return type:
DataFrame
- uchrom.strc.tad.compare.compare_boundaries(cd, query: str | DataFrame, reference: str | DataFrame, *, tol: int = 1, level: int | None = None, contacts: str | None = None, resolution: int | None = None) Dict[str, float][source]¶
How often the boundaries of
queryfall withintolloci of a boundary ofreference, against what random loci would give.- Parameters:
cd (ChromData) – Its
binsare the loci both tables are placed on (tad_boundaries()).query (str or DataFrame) – Population domain tables (keys of
cd.resultsor tables), e.g. DI TADs on Hi-C and ArcFISH TADs on the imaging of the same loci, or insulation TADs and a published domain list.reference (str or DataFrame) – Population domain tables (keys of
cd.resultsor tables), e.g. DI TADs on Hi-C and ArcFISH TADs on the imaging of the same loci, or insulation TADs and a published domain list.tol (int) – Largest distance in loci (default 1: the same or a neighbouring locus).
level (int, optional) – Level of hierarchical tables (default the finest).
contacts (optional) – Place the boundaries on the bins of this linked contact map instead of
cd.bins(tad_boundaries());tolthen counts map bins.resolution (optional) – Place the boundaries on the bins of this linked contact map instead of
cd.bins(tad_boundaries());tolthen counts map bins.
- Returns:
n_query,n_reference(boundaries),fraction_near(of the query boundaries withintolloci of a reference boundary on the same chromosome),chance(the same fraction for every locus of the chromosomes with query boundaries) andenrichment(= fraction_near / chance).- Return type:
- uchrom.strc.tad.compare.boundary_frequency(cd, domains: str | DataFrame = 'tads.fishnet') DataFrame[source]¶
Per locus, the fraction of traces (alleles) with a domain boundary there — single-allele domain tables such as FISHnet’s.
- Parameters:
- Returns:
One row per locus of the chromosomes in the table:
bin_id, chrom, start, end, bin_index,n_traces(traces with domains on the chromosome) andfrequency.- Return type:
DataFrame