plotgardener

repository·devel·Indexed 18 days ago

https://github.com/phanstiellab/plotgardener

An R package for programmatic and flexible genomic data visualization. It utilizes a coordinate-based system and edge-to-edge containerized plotting to create precise, multi-panel, multi-omic figures. The package allows users to align different data tracks, such as Hi-C, ChIP-seq, and gene tracks, using a parameter object created via pgParams() to control genomic context and visual layout.

Tokens
1.3K
Snippets
3
Records
4
Agent score
13%

What's inside plotgardener

  1. How plotgardener's coordinate-based plotting works

    devel

    plotgardener uses a two-part system to generate multi-panel genomic figures:

    1. Coordinate-based plotting system: Grants precise control over the size, position, and arrangement of plots using specific coordinates.
    2. Edge-to-edge containerized data visualization: Plotting functions map data to user-specified containers. This ensures that when you stack plots vertically, the data remains aligned to the same genomic regions.

    This design allows for the creation of complex, multi-omic layouts where different data tracks (e.g., Hi-C, ChIP-seq, gene tracks) can be precisely aligned and arranged.

  2. Create a multi-panel genomic figure with plotgardener

    devel

    A typical workflow involves creating a page, defining genomic parameters using pgParams, and then adding various tracks (Hi-C, signal, genes, etc.) to that page.

    Key steps:

    1. Initialize a page: Use pageCreate() to set the overall dimensions.
    2. Define genomic regions: Use pgParams() to create a parameter object containing chrom, chromstart, chromend, assembly, and layout properties like x, width, and just.
    3. Add tracks: Use specialized functions like plotHicSquare(), plotHicTriangle(), plotSignal(), or plotGenes(). These functions take the params object to ensure correct genomic alignment.
    4. Add annotations: Use functions like plotText(), annoHeatmapLegend(), or annoGenomeLabel() to add context to your plots.
    library("plotgardener")
    library("plotgardenerData")
    
    # 1. Create a page
    pageCreate(width = 7, height = 4.25, default.units = "inches")
    
    # 2. Define genomic parameters
    params_a <- pgParams(chrom = "chr21", chromstart = 28000000, chromend = 30300000, 
                          assembly = "hg19",
                          x = 0.25, width = 2.75, just = c("left", "top"), default.units = "inches")
    
    # 3. Plot tracks (e.g., Hi-C and Genes)
    hicPlot_top <- plotHicSquare(data = GM12878_HiC_10kb, params = params_a, 
                                    zrange = c(0, 200), resolution = 10000, 
                                    half = "top", y = 0.5, height = 2.75)
    
    genes_a <- plotGenes(params = params_a, stroke = 1, fontsize = 6, 
                            y = 3.35, height = 0.4)
    
    # 4. Add annotations
    plotText(label = "A", fontsize = 12, x = 0.25, y = 0.25, just = "left", default.units = "inches")
    annoGenomeLabel(plot = genes_a, params = params_a, scale = "Mb", fontsize = 7, y = 3.85)
    
    # Hide page guides when finished
    pageGuideHide()
  3. Install plotgardener via Bioconductor

    devel

    To install plotgardener, use BiocManager to install version 3.19 (compatible with R version 4.4). You should also install plotgardenerData to access example datasets and files included with the package.

    if (!requireNamespace("BiocManager", quietly = TRUE))
        install.packages("BiocManager")
    
    BiocManager::install(version = "3.19")
    BiocManager::install("plotgardener")
    
    # To get example datasets
    BiocManager::install("plotgardenerData")
  4. Use pgParams to define genomic and layout parameters

    devel

    pgParams() is used to create a parameter object that controls both the genomic context (chromosome, range, assembly) and the visual layout (position, width, justification) of a plot. This object is passed to most plotting functions to ensure alignment.

    Common arguments:

    • chrom: Chromosome name.
    • chromstart / chromend: Genomic coordinates.
    • assembly: Genomic assembly (e.g., "hg19").
    • x, y: Position on the page.
    • width, height: Dimensions of the plot container.
    • just: Justification (e.g., c("left", "top")).
    • default.units: Units for measurements (e.g., "inches").
    params_a <- pgParams(chrom = "chr21", chromstart = 28000000, chromend = 30300000, 
                          assembly = "hg19",
                          x = 0.25, width = 2.75, just = c("left", "top"), 
                          default.units = "inches")