Displays gene models as annotation tracks below Hi-C heatmaps, showing gene structure with exons, introns, UTRs, and strand orientation. Gene annotations are automatically retrieved from GTF files or TxDb objects and positioned below the Hi-C plot with gene symbols labeled underneath. The function supports two visualization styles: "basic" (detailed exon/intron structure) and "arrow" (simplified arrow representation indicating strand direction).
Usage
geom_annotation(
mapping = NULL,
data = NULL,
stat = StatAnnotation,
position = "identity",
na.rm = FALSE,
show.legend = NA,
inherit.aes = TRUE,
txdb = NULL,
tx2gene = NULL,
gtf_path = NULL,
width_ratio = 1/50,
spacing_ratio = 1/3,
maxgap = -1,
include_ncrna = TRUE,
style = c("basic", "arrow"),
gene_symbols = NULL,
chrom_prefix = TRUE,
fontsize = 10,
colour = "#48CFCB",
fill = "#48CFCB",
draw_boundary = TRUE,
boundary_colour = "black",
linetype = "dashed",
...
)Arguments
- mapping
Set of aesthetic mappings created by
aes(). If specified andinherit.aes = TRUE(the default), it is combined with the default mapping at the top level of the plot. You must supplymappingif there is no plot mapping.- data
The data to be displayed in this layer. There are three options:
If
NULL, the default, the data is inherited from the plot data as specified in the call toggplot().A
data.frame, or other object, will override the plot data. All objects will be fortified to produce a data frame. Seefortify()for which variables will be created.A
functionwill be called with a single argument, the plot data. The return value must be adata.frame, and will be used as the layer data. Afunctioncan be created from aformula(e.g.~ head(.x, 10)).- stat
The statistical transformation to use on the data for this layer. When using a
geom_*()function to construct a layer, thestatargument can be used to override the default coupling between geoms and stats. Thestatargument accepts the following:A
Statggproto subclass, for exampleStatCount.A string naming the stat. To give the stat as a string, strip the function name of the
stat_prefix. For example, to usestat_count(), give the stat as"count".For more information and other ways to specify the stat, see the layer stat documentation.
- position
A position adjustment to use on the data for this layer. This can be used in various ways, including to prevent overplotting and improving the display. The
positionargument accepts the following:The result of calling a position function, such as
position_jitter(). This method allows for passing extra arguments to the position.A string naming the position adjustment. To give the position as a string, strip the function name of the
position_prefix. For example, to useposition_jitter(), give the position as"jitter".For more information and other ways to specify the position, see the layer position documentation.
- na.rm
If
FALSE, the default, missing values are removed with a warning. IfTRUE, missing values are silently removed.- show.legend
logical. Should this layer be included in the legends?
NA, the default, includes if any aesthetics are mapped.FALSEnever includes, andTRUEalways includes. It can also be a named logical vector to finely select the aesthetics to display. To include legend keys for all levels, even when no data exists, useTRUE. IfNA, all levels are shown in legend, but unobserved levels are omitted.- inherit.aes
If
FALSE, overrides the default aesthetics, rather than combining with them. This is most useful for helper functions that define both data and aesthetics and shouldn't inherit behaviour from the default plot specification, e.g.annotation_borders().- txdb
A TxDb object from the GenomicFeatures package containing transcript annotations. Must be provided together with
tx2geneifgtf_pathis not specified. Default isNULL.- tx2gene
A data frame or tibble mapping transcript information to gene information. Required if using
txdbparameter. Should include the following columns:chrom: Chromosome number or namegene_id: Entrez gene ID or unique gene identifiergene_symbol: Common gene symbol or name (e.g., "TP53", "BRCA1")tx_id: Entrez transcript ID or unique transcript identifiertx_name: Name of the transcriptgene_type: Gene biotype (e.g., "protein_coding", "lncRNA")tx_type: Transcript biotype Default isNULL.
- gtf_path
Character string specifying the path to a GTF/GFF file. The function will automatically parse the GTF file to generate
txdbandtx2geneobjects. Parsed data is cached to speed up subsequent calls. Eithergtf_pathor bothtxdbandtx2genemust be provided. Default isNULL.- width_ratio
Numeric value controlling the height of each gene track relative to the Hi-C plot height. Smaller values create thinner tracks. Default is
1/50(2% of Hi-C plot height).- spacing_ratio
Numeric value controlling the vertical spacing between gene tracks as a proportion of track height. Larger values increase spacing. Default is
1/3(33% of track height).- maxgap
Integer specifying the maximum genomic distance (in bp) between genes on the same horizontal line. Genes within this distance will be placed on separate lines to prevent overlap. Set to
-1for automatic spacing. Default is-1.- include_ncrna
Logical indicating whether to include non-coding RNA genes (lncRNA, miRNA, etc.) in the annotation track. Set to
FALSEto show only protein-coding genes. Default isTRUE.- style
Character string specifying the visualization style. Options:
"basic": Shows detailed gene structure with distinct exons (thick boxes), introns (thin lines with directional arrows), and UTRs (thin boxes)"arrow": Simplified representation showing each gene as a single arrow pointing in the direction of transcription (5' to 3') Default is"basic".
- gene_symbols
Character vector of specific gene symbols to display. When provided, only these genes will be shown in the annotation track. Useful for highlighting genes of interest. Default is
NULL(show all genes).- chrom_prefix
Logical indicating whether chromosome names include the "chr" prefix (e.g., "chr1" vs "1"). Should match the naming convention in your Hi-C data. Default is
TRUE.- fontsize
Numeric value specifying the font size for gene symbol labels. Default is
10.- colour
Character string specifying the outline color for gene features. Default is
"#48CFCB"(teal).- fill
Character string specifying the fill color for gene features (exons, UTRs, arrows). Default is
"#48CFCB"(teal).- draw_boundary
Logical indicating whether to draw vertical boundary lines between chromosomes in multi-chromosome displays. Default is
TRUE.- boundary_colour
Character string specifying the color of chromosome boundary lines. Default is
"black".- linetype
Character string or integer specifying the line type for chromosome boundaries. Default is
"dashed".- ...
Additional parameters (currently ignored).
Details
Required Aesthetics
This geom inherits aesthetics from the Hi-C data and requires:
seqnames1,seqnames2: Chromosome namesstart1,start2: Start positionsend1,end2: End positions
Gene Annotation Sources
Gene annotations can be provided in three ways:
GTF file via
gtf_path: Most convenient, automatically parsed and cachedTxDb + tx2gene: Pre-processed annotations for custom databases
Downloaded from online repositories (Ensembl, UCSC, GENCODE)
Visualization Styles
Basic Style (style = "basic")
Shows detailed gene structure:
Coding exons (CDS): Thick rectangles in full color
UTRs: Thinner rectangles showing 5' and 3' untranslated regions
Introns: Thin lines with small directional arrows indicating strand
ncRNAs: Thin rectangles for non-coding transcripts (if
include_ncrna = TRUE)
Gene Placement and Layout
Genes are automatically arranged on multiple horizontal lines to prevent overlap
Genes closer than
maxgapare placed on separate linesGene symbols are centered below each gene
Multiple tracks are vertically stacked with spacing controlled by
spacing_ratio
Multi-Chromosome Display
When displaying multiple chromosomes:
Coordinates are automatically adjusted for proper alignment
Vertical boundary lines separate chromosomes (if
draw_boundary = TRUE)Gene labels maintain proper positioning across chromosome boundaries
See also
gghic()for creating the base Hi-C plotgeom_hic()for the Hi-C heatmap layergeom_track()andgeom_track2()for genomic signal tracksgeom_ideogram()for chromosome ideograms
Examples
if (FALSE) { # \dontrun{
# Basic usage with GTF file
cc <- ChromatinContacts("path/to/cooler.cool", focus = "chr4") |>
import()
gtf_file <- "path/to/genes.gtf"
gghic(cc) + geom_annotation(gtf_path = gtf_file)
# Filter specific genes of interest
gghic(cc) +
geom_annotation(
gtf_path = gtf_file,
gene_symbols = c("BRCA1", "TP53", "MYC")
)
# Arrow style with custom colors
gghic(cc) +
geom_annotation(
gtf_path = gtf_file,
style = "arrow",
colour = "darkblue",
fill = "lightblue",
fontsize = 8
)
# Exclude non-coding RNAs for cleaner view
gghic(cc) +
geom_annotation(
gtf_path = gtf_file,
include_ncrna = FALSE
)
# Custom track dimensions
gghic(cc) +
geom_annotation(
gtf_path = gtf_file,
width_ratio = 1 / 40, # Taller tracks
spacing_ratio = 1 / 2 # More spacing
)
# Using TxDb object directly
library(TxDb.Hsapiens.UCSC.hg38.knownGene)
txdb <- TxDb.Hsapiens.UCSC.hg38.knownGene
tx2gene <- read.csv("tx2gene_mapping.csv")
gghic(cc) +
geom_annotation(txdb = txdb, tx2gene = tx2gene)
# Multiple genes with custom styling
candidates <- c("PDGFRA", "KIT", "KDR", "FLT1")
gghic(cc) +
geom_annotation(
gtf_path = gtf_file,
gene_symbols = candidates,
colour = "red",
fill = "pink",
fontsize = 12
)
# Without chromosome prefix (e.g., "1" instead of "chr1")
gghic(cc) +
geom_annotation(
gtf_path = gtf_file,
chrom_prefix = FALSE
)
# Multi-chromosome with boundaries
cc_multi <- ChromatinContacts("path/to/cooler.cool",
focus = c("chr4", "chr8")) |>
import()
gghic(cc_multi) +
geom_annotation(
gtf_path = gtf_file,
draw_boundary = TRUE,
boundary_colour = "gray50",
linetype = "dotted"
)
# Protein-coding genes only with arrow style
gghic(cc) +
geom_annotation(
gtf_path = gtf_file,
include_ncrna = FALSE,
style = "arrow",
fill = "#2E86AB"
)
} # }
