Skip to contents

This function creates a feature track visualization from genomic regions, such as peaks or other genomic annotations. It can read directly from BED files or work with data frames containing genomic coordinates.

Usage

ez_feature(
  input,
  region,
  color = "black",
  fill = "gray70",
  alpha = 0.7,
  height = 0.8,
  use_score = FALSE,
  ...
)

Arguments

input

Either a file path to a BED file or a data frame containing genomic coordinates with columns for chromosome, start, and end positions.

region

Genomic region to display in the format "chr:start-end". Example: "chr1:1000000-2000000"

color

Border color of the features. Default: "black"

fill

Fill color of the features. When use_score = TRUE, this will be used as the high value in the color gradient. Default: "gray70"

alpha

Transparency level of the features (0 = transparent, 1 = opaque). Default: 0.7

height

Height of the feature rectangles (0 to 1). Default: 0.8

use_score

Logical indicating whether to use the 'score' column for fill color. If TRUE, a gradient from white to the specified fill color will be used. Default: FALSE

...

Additional arguments passed to geom_feature()

Value

A ggplot2 object representing the feature track.

Details

This function creates a peak track visualization from a BED file or data frame. It is a wrapper around geom_feature that provides a simpler interface.

The function automatically handles both file paths and data frames as input. When a file path is provided, it reads the BED file and creates the track. When a data frame is provided, it should contain at least 'chrom', 'start', and 'end' columns. If 'score' column is present and use_score = TRUE, features will be colored by their score values.

Examples

# From a data frame with uniform coloring
features <- data.frame(
  seqnames = c("chr1", "chr1", "chr1"),
  start = c(1000, 3000, 5000),
  end = c(2000, 4000, 6000),
  name = c("peak1", "peak2", "peak3"),
  score = c(10, 30, 50)
)
track <- ez_feature(
  features,
  "chr1:1-10000",
  fill = "darkgreen",
  alpha = 0.8
)
#> Warning: Ignoring unknown parameters: `height`
#> Warning: Ignoring unknown aesthetics: ymin and ymax