# ggmsa-Getting Started

# Install package

    if (!require("BiocManager"))
        install.packages("BiocManager")
    BiocManager::install("ggmsa")

# Introduction

ggmsa is a package designed to plot multiple sequence alignments.

This package implements functions to visualize publication-quality multiple sequence alignments (protein/DNA/RNA) in R extremely simple and powerful. It uses module design to annotate sequence alignments and allows to accept other data sets for diagrams combination.

In this tutorial, we’ll work through the basics of using ggmsa.

    library(ggmsa)

# Importing MSA data

We’ll start by importing some example data to use throughout this tutorial. Expect FASTA files, some of the objects in R can also as input. `available_msa()` can be used to list MSA objects currently available.

     available_msa()
    #> 1.files currently available:
    #> .fasta
    #> 2.XStringSet objects from 'Biostrings' package:
    #> DNAStringSet RNAStringSet AAStringSet BStringSet DNAMultipleAlignment RNAMultipleAlignment AAMultipleAlignment
    #> 3.bin objects:
    #> DNAbin AAbin

     protein_sequences <- system.file("extdata", "sample.fasta",
                                      package = "ggmsa")
     miRNA_sequences <- system.file("extdata", "seedSample.fa",
                                    package = "ggmsa")
     nt_sequences <- system.file("extdata", "LeaderRepeat_All.fa",
                                 package = "ggmsa")

# Basic use: MSA Visualization

The most simple code to use ggmsa:

    ggmsa(protein_sequences, 300, 350, color = "Clustal",
          font = "DroidSansMono", char_width = 0.5, seq_name = TRUE )

## Color Schemes

ggmsa predefines several color schemes for rendering MSA are shipped in the package. In the same ways, using `available_msa()` to list color schemes currently available. Note that amino acids (protein) and nucleotides (DNA/RNA) have different names.

    available_colors()
    #> 1.color schemes for nucleotide sequences currently available:
    #> Chemistry_NT Shapely_NT Taylor_NT Zappo_NT
    #> 2.color schemes for AA sequences currently available:
    #> ClustalChemistry_AA Shapely_AA Zappo_AA Taylor_AA LETTER CN6 Hydrophobicity

## Font

Several predefined fonts are shipped ggmsa. Users can use `available_fonts()` to list the font currently available.

    available_fonts()
    #> font families currently available:
    #> helvetical mono TimesNewRoman DroidSansMono

# MSA Annotation

ggmsa supports annotations for MSA. Similar to the ggplot2, it implements annotations by `geom` and users can perform annotation with `+` , like this: `ggmsa() + geom_*()`. Automatically generated annotations that containing colored labels and symbols are overlaid on MSAs to indicate potentially conserved or divergent regions.

For example, visualizing multiple sequence alignment with sequence logo and bar chart:

    ggmsa(protein_sequences, 221, 280, seq_name = TRUE, char_width = 0.5) +
      geom_seqlogo(color = "Chemistry_AA") + geom_msaBar()

This table shows the annnotation layers supported by ggmsa as following:

Annotation modules | Type | Description
--- | --- | ---
geom_seqlogo() | geometric layer | automatically generated sequence logos for a MSA
geom_GC() | annotation module | shows GC content with bubble chart
geom_seed() | annotation module | highlights seed region on miRNA sequences
geom_msaBar() | annotation module | shows sequences conservation by a bar chart
geom_helix() | annotation module | depicts RNA secondary structure as arc diagrams(need extra data)

# Learn more

Check out the guides for learning everything there is to know about all the different features:

- Getting Started
- Annotations
- Color Schemes and Font Families
- Theme
- Other Modules
- View Modes

# Session Info

    #> R version 4.6.0 (2026-04-24)
    #> Platform: x86_64-pc-linux-gnu
    #> Running under: Ubuntu 24.04.4 LTS
    #>
    #> Matrix products: default
    #> BLAS:   /usr/lib/x86_64-linux-gnu/openblas-pthread/libblas.so.3
    #> LAPACK: /usr/lib/x86_64-linux-gnu/openblas-pthread/libopenblasp-r0.3.26.so;  LAPACK version 3.12.0
    #>
    #> locale:
    #>  [1] LC_CTYPE=en_US.UTF-8       LC_NUMERIC=C
    #>  [3] LC_TIME=en_US.UTF-8        LC_COLLATE=en_US.UTF-8
    #>  [5] LC_MONETARY=en_US.UTF-8    LC_MESSAGES=en_US.UTF-8
    #>  [7] LC_PAPER=en_US.UTF-8       LC_NAME=C
    #>  [9] LC_ADDRESS=C               LC_TELEPHONE=C
    #> [11] LC_MEASUREMENT=en_US.UTF-8 LC_IDENTIFICATION=C
    #>
    #> time zone: Etc/UTC
    #> tzcode source: system (glibc)
    #>
    #> attached base packages:
    #> [1] stats     graphics  grDevices utils     datasets  methods   base
    #>
    #> other attached packages:
    #> [1] kableExtra_1.4.0  yulab.utils_0.2.4 ggplot2_4.0.3     ggmsa_1.19.0
    #> [5] prettydoc_0.4.1
    #>
    #> loaded via a namespace (and not attached):
    #>  [1] gtable_0.3.6            xfun_0.57               bslib_0.11.0
    #>  [4] htmlwidgets_1.6.4       lattice_0.22-9          vctrs_0.7.3
    #>  [7] tools_4.6.0             generics_0.1.4          stats4_4.6.0
    #> [10] parallel_4.6.0          tibble_3.3.1            pkgconfig_2.0.3
    #> [13] ggplotify_0.1.3         RColorBrewer_1.1-3      S7_0.2.2
    #> [16] S4Vectors_0.51.3        lifecycle_1.0.5         stringr_1.6.0
    #> [19] compiler_4.6.0          farver_2.1.2            textshaping_1.0.5
    #> [22] treeio_1.37.0           Biostrings_2.81.2       ggforce_0.5.0
    #> [25] Seqinfo_1.3.0           ggtree_4.3.0            fontLiberation_0.1.0
    #> [28] ggfun_0.2.0             fontquiver_0.2.1        htmltools_0.5.9
    #> [31] sys_3.4.3               buildtools_1.0.0        sass_0.4.10
    #> [34] yaml_2.3.12             lazyeval_0.2.3          pillar_1.11.1
    #> [37] crayon_1.5.3            jquerylib_0.1.4         tidyr_1.3.2
    #> [40] MASS_7.3-65             cachem_1.1.0            seqmagick_0.1.8
    #> [43] fontBitstreamVera_0.1.1 nlme_3.1-169            tidyselect_1.2.1
    #> [46] aplot_0.2.9             digest_0.6.39           stringi_1.8.7
    #> [49] dplyr_1.2.1             purrr_1.2.2             labeling_0.4.3
    #> [52] maketools_1.3.2         polyclip_1.10-7         fastmap_1.2.0
    #> [55] grid_4.6.0              cli_3.6.6               magrittr_2.0.5
    #> [58] patchwork_1.3.2         ape_5.8-1               withr_3.0.2
    #> [61] gdtools_0.5.1           scales_1.4.0            rappdirs_0.3.4
    #> [64] rmarkdown_2.31          XVector_0.53.0          evaluate_1.0.5
    #> [67] knitr_1.51              IRanges_2.47.2          viridisLite_0.4.3
    #> [70] gridGraphics_0.5-1      rlang_1.2.0             ggiraph_0.9.6
    #> [73] Rcpp_1.1.1-1.1          glue_1.8.1              R4RNA_1.41.0
    #> [76] tidytree_0.4.7          xml2_1.5.2              tweenr_2.0.3
    #> [79] BiocGenerics_0.59.6     svglite_2.2.2           rstudioapi_0.18.0
    #> [82] jsonlite_2.0.0          R6_2.6.1                systemfonts_1.3.2
    #> [85] fs_2.1.0