gggenomes

repository·main·Indexed 21 days ago

https://github.com/thackl/gggenomes

An R package that extends ggplot2 to provide a grammar of graphics for comparative genomics. It utilizes a track system and an automated global genome layout to visualize complex genomic architectures, including genes, syntenic regions, and sequences.

Tokens
981
Snippets
3
Records
4
Agent score
23%

What's inside gggenomes

  1. How gggenomes and its track system work

    main

    gggenomes implements a "grammar of graphics" for comparative genomics by extending ggplot2.

    Instead of using a single tidy data table, gggenomes uses a lightweight track system that manages multiple related data sets. These datasets are tied together through a global genome layout that is automatically computed from the input. This layout defines the positions of genomic sequences (chromosomes/contigs) and their associated features within the plot. This allows you to combine diverse data sources (genes, syntenic regions, etc.) into a single cohesive visualization.

  2. Install gggenomes

    main

    You can install the stable version of gggenomes from CRAN or the latest developmental version from GitHub.

    To install the stable version:

    install.packages("gggenomes")

    To install the latest developmental version using devtools:

    devtools::install_github("thackl/gggenomes")
    # Install from CRAN
    install.packages("gggenomes") 
    
    # Install latest developmental version from github
    devtools::install_github("thackl/gggenomes")
  3. Optionally install ggtree for phylogenetic plots

    main

    If you want to plot genomes next to phylogenetic trees, you should also install the ggtree package from Bioconductor.

    if (!requireNamespace("BiocManager", quietly = TRUE))
        install.packages("BiocManager")
    BiocManager::install("ggtree")
  4. Example: Visualizing viral genomes with gggenomes

    main

    This example demonstrates how to use gggenomes to compare the genomic architecture of six viral genomes using the built-in example data. It showcases the use of gggenomes() to initialize the plot, sync() to align genome directions, and various geom_* functions to layer genes, sequences, links, and features.

    Note: To use the example data, run data(package="gggenomes") after loading the library.

    library(gggenomes)
    
    # to inspect the example data shipped with gggenomes
    data(package="gggenomes")
    
    gggenomes(
      genes = emale_genes, seqs = emale_seqs, links = emale_ava,
      feats = list(emale_tirs, ngaros=emale_ngaros, gc=emale_gc)) |> 
      add_sublinks(emale_prot_ava) |>
      sync() + # synchronize genome directions based on links
      geom_feat(position="identity", size=6) +
      geom_seq() +
      geom_link(data=links(2)) +
      geom_bin_label() +
      geom_gene(aes(fill=name)) +
      geom_gene_tag(aes(label=name), nudge_y=0.1, check_overlap = TRUE) +
      geom_feat(data=feats(ngaros), alpha=.3, size=10, position="identity") +
      geom_feat_note(aes(label="Ngaro-transposon"), data=feats(ngaros),
          nudge_y=.1, vjust=0) +
      geom_wiggle(aes(z=score, linetype="GC-content"), feats(gc),
          fill="lavenderblush4", position=position_nudge(y=-.2), height = .2) +
      scale_fill_brewer("Genes", palette="Dark2", na.value="cornsilk3")
      
    ggsave("emales.png", width=8, height=4)