Skip to contents

A GPU-accelerated Hi-C chromatin contact map. The matrix is normalized to an 8-bit texture and drawn as one WebGL quad (via regl), with the colormap 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", "ltc", "ltcdiv"),
  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, a positive number; used to label axes in bp/kb/Mb. NULL (or NA) labels axes by bin index.

chrom

Optional chromosome name shown as the axis title.

colormap

Colormap for intensity: sequential "viridis" (the default) or "ltc" (an earthy teal to sand to rust ramp), or diverging "rdbu" or "ltcdiv" (its counterpart, neutral cream at the midpoint).

transform

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

vmax

Upper clip of the intensity scale: a finite number greater than vmin, and greater than 0 with the log transform. NULL (or NA) auto-picks a high percentile.

vmax_percentile

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

vmin

Lower clip of the intensity scale, a finite number. NULL (or NA) uses 0. With the log transform, or when vmin is 0 or more, values at or below it are drawn as background. With the linear transform and a negative vmin (for example observed/expected log2 ratios), values below it take the lowest color.

symmetric

Mirror sparse i/j/v entries across the diagonal: TRUE or FALSE.

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. Its padding entry is the space in px between the edge of the widget and the plot: one number for every side, or numbers named top, right, bottom and left in a list or vector, a side left out keeping the default of 10. A colour given as a CSS custom property, such as background = "var(--bg)", takes the value the page gives it when the plot draws. After the page changes the property, what the plot drew on a canvas keeps the old colour until it draws again: resize the widget or render it again.

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")