Skip to contents

This function creates a gene track visualization from genomic annotations, supporting various input formats including GTF/GFF files, TxDb objects, and data frames. It automatically handles gene structure visualization with exons, introns, and strand information.

By default, when y = "strand", genes are colored by strand: plus strand uses "darkgreen" and minus strand uses "orange2". To use uniform colors instead, explicitly set exon_color, exon_fill, and intron_color.

Usage

ez_gene(
  data,
  region,
  exon_height = 0.2,
  intron_width = 0.6,
  exon_color = NULL,
  exon_fill = NULL,
  intron_color = NULL,
  gene_id = "gene_id",
  gene_name = "gene_name",
  y = "strand",
  label = "gene_name",
  label_size = 3,
  label_color = NULL,
  ...
)

Arguments

data

Input data source, which can be:

  • A file path to a GTF/GFF file

  • A TxDb object from the GenomicFeatures package

  • A data frame with gene annotation data

region

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

exon_height

Relative height of exons (0 to 1). Default: 0.4

intron_width

Line width for introns. Default: 0.4

exon_color

Border color for exons. Default: NULL (uses strand-based colors when y = "strand", otherwise "gray50")

exon_fill

Fill color for exons. Default: NULL (uses strand-based colors when y = "strand", otherwise "gray50")

intron_color

Color for intron lines. Default: NULL (uses strand-based colors when y = "strand", otherwise "gray50")

gene_id

Column name for gene identifiers. Default: "gene_id"

gene_name

Column name for gene symbols/names. Default: "gene_name"

y

Column name for the y-axis grouping variable. Default: "strand"

label

Column name to use for text labels. If NULL (default), no labels are displayed. Set to a column name (e.g., "gene_name") to show labels.

label_size

Size of text labels. Default: 3

label_color

Color of text labels. If NULL (default), uses strand-based colors when y = "strand", otherwise uses exon_fill color.

...

Additional arguments passed to geom_gene(). Note that color and colour arguments are ignored; use exon_color, exon_fill, and intron_color instead.

Value

A ggplot2 object representing the gene track.

Details

The function automatically processes different input types:

  • For GTF/GFF files: Uses rtracklayer to import and process the data

  • For TxDb objects: Extracts gene models using GenomicFeatures

  • For data frames: Expects columns for chromosome, start, end, strand, and type

The visualization includes:

  • Exons as filled rectangles

  • Introns as connecting lines

  • Strand information with arrowheads

  • Automatic y-axis separation by the specified y variable

Examples

# From a data frame
data(example_genes)
ez_gene(example_genes, "chr1:11869-14409")
#> Warning: Ignoring unknown parameters: `arrow_length`, `arrow_type`, `exon_colour`,
#> `intron_colour`, and `clip_to_region`
#> Warning: Ignoring unknown aesthetics: fill
#> Error in `$<-.data.frame`(`*tmp*`, label_x, value = numeric(0)): replacement has 0 rows, data has 5