Skip to contents

Assigns each peak in a GRanges object to the chromatin state with which it has the largest overlap from a ChromHMM GRanges annotation. Supports filtering by both absolute and fractional overlap requirements.

Usage

AnnotatePeaks(
  peaks_gr,
  chromHMM_states,
  state_col = "name",
  keep_unannotated = FALSE,
  min_overlap = 1,
  min_overlap_frac = NULL,
  verbose = TRUE
)

Arguments

peaks_gr

A GRanges object of peak regions to annotate.

chromHMM_states

A GRanges object of ChromHMM state annotations. Must contain a metadata column (default "name") specifying state names.

state_col

Character string specifying the metadata column in chromHMM_states containing state labels. Default = "name".

keep_unannotated

Logical; if TRUE, peaks without qualifying overlaps to any ChromHMM state are retained with NA in their annotation column. If FALSE (default), unannotated peaks are dropped.

min_overlap

Numeric; minimum overlap width (in bp) required for a peak to be assigned to a ChromHMM state. Default = 1 (any overlap).

min_overlap_frac

Optional numeric; minimum fraction of a peak's length that must overlap a ChromHMM state for assignment. Must be between 0 and 1. If NULL (default), no fraction filter is applied.

verbose

Logical; if TRUE (default), prints a summary message about peaks removed due to overlap thresholds.

Value

A GRanges object of peaks with added metadata columns:

  • annotation — the ChromHMM state label.

  • overlap_width — width of overlap between the peak and its assigned ChromHMM state.

  • overlap_frac — fraction of the peak length overlapping the state.

Details

For each peak:

  1. The function finds all overlaps between peaks and ChromHMM states.

  2. It computes the absolute overlap width and fractional overlap relative to peak length.

  3. It assigns each peak to the state with the largest overlap, subject to min_overlap and min_overlap_frac thresholds.

  4. Overlap statistics are stored in new metadata columns.

  5. Peaks that fail the filters are optionally retained (keep_unannotated) or dropped (default).