Skip to contents

A GPU-accelerated Hi-C chromatin contact map. The matrix is uploaded once as a single-channel float texture and drawn as one WebGL quad (via regl), with the colormap and log/linear transform applied in the fragment shader, so pan/zoom stays smooth on very large matrices. A precomputed level-of-detail pyramid keeps interaction fast when zoomed out. Axes (genomic coordinate ticks) and the colorbar are drawn as crisp vector overlays. No tile server is required.

Usage

hic(
  mat,
  n = NULL,
  bin_size = NULL,
  chrom = NULL,
  colormap = c("viridis", "rdbu"),
  transform = c("log", "linear"),
  vmax = NULL,
  vmax_percentile = NULL,
  vmin = 0,
  symmetric = TRUE,
  label = NULL,
  theme = NULL,
  width = NULL,
  height = NULL,
  element_id = NULL
)

Arguments

mat

Either a square numeric matrix of contact counts, or a data frame / list giving a sparse COO triplet with integer columns i, j and a numeric v. When a triplet is supplied, n must be given (or inferable from max(i, j) + 1).

n

Number of bins per axis. Required for the sparse (i/j/v) form; ignored for a dense matrix (taken from nrow(mat)).

bin_size

Genomic bin size in base pairs; used to label axes in bp/kb/Mb. NULL labels axes by bin index.

chrom

Optional chromosome name shown as the axis title.

colormap

Sequential colormap for intensity: "viridis" or "rdbu".

transform

Intensity transform, "log" (default) or "linear".

vmax

Upper clip of the intensity scale; NULL auto-picks a high percentile.

vmax_percentile

Percentile in (0, 1] used to auto-pick vmax when vmax is NULL. NULL uses the component default.

vmin

Lower clip of the intensity scale.

symmetric

Mirror sparse i/j/v entries across the diagonal.

label

Axis title (overrides chrom when set).

theme

Optional named list of theme overrides (colors, fonts, ...) merged over the component defaults in the browser. NULL uses the default theme.

width, height

Widget dimensions (any valid CSS size).

element_id

Optional explicit DOM id.

Value

An htmlwidget object.

Examples

set.seed(1)
n <- 200
# distance-decay background contact matrix
d <- abs(outer(seq_len(n), seq_len(n), `-`))
m <- 1000 / (d + 1)^1.2 + matrix(runif(n * n), n, n)
m <- (m + t(m)) / 2 # symmetrize
hic(m, bin_size = 10000, chrom = "chr1")