PanVizGenerator 1.22.0
Pangenomes are data structures used in comparative microbial genomics. In essence it is a grouping of genes across different genomes where each group should consist of orthologue genes (i.e. sequence similarity is in itself not enough). One of the standard representation of pangenomes is as a pangenome matrix, which is a presence/absence matrix with rows defining gene groups and columns defining genomes. This seemingly simple representation hides the fact that investigating pangenomes and try to understand the biological implications of the grouping can be a daunting task. PanViz is an interactive visualization tool, build using html and Javascript (relying heavily on D3.js), that empowers the user to investigate, query and understand their pangenomes in a fluid, beautiful and easy manner. PanViz visualizations are fully self-contained html files that can be shared with coworkers and viewed offline if needed. PanVizGenerator is the intended tool for creating PanViz visualizations from scratch using your own data. It provides both an easy and informative GUI (based on shiny), as well as a standard R interface. The GUI supports csv formatted pangenome matrices, while the programmatic interface in addition supports standard R matrix and data.frame representation as well as the class system provided by FindMyFriends.
PanViz relies on two different types of data for its visualization approach. The first is the pangenome matrix as described in the introduction while the second is a functional annotation of the gene groups in the pangenome based on gene ontology terms. In addition human readable gene group names as well as E.C. numbers will augment the quality of the end result.
How this data is supplied depends on the user. The standard Bioconductor approach to creating and working with pangenomes is the class system defined by FindMyFriends. FindMyFriends provides functionality for adding annotation to both the gene groups and genomes contained in a pangenome and if these facilities are used a PanViz can be created directly from that. If you wish to opt out of the FindMyFriends approach, or if the pangenome has been provided for you, PanVizGenerator can also accept standard matrix data, along with vector or list style annotation.
There is a third data source that is independent of the individual data sets but
required by PanViz none-the-less: The full gene ontology graph is embedded
within each PanViz file, allowing for visual navigation of the GO ontology as it
applies to your data. PanVizGenerator automatically fetches the gene ontology
when required and caches it for later use, so this is not something you, as a
user, should worry about. In order to force a fresh download of the gene
ontology for some reason, the getGO()
function is provided.
library(PanVizGenerator)
## Warning: Package 'PanVizGenerator' is deprecated and will be removed from
## Bioconductor version 3.15
getGO()
PanVizGenerator both supports a shiny-based GUI as well as the standard R based approach. The GUI does not offer the same flexibility but is intended for people less experience using R. Apart from the PanViz creation functionality it also contains an example video of a pangenome as well as a rundown of the features and thoughts in PanViz.
The GUI is started by using the eponymous PanVizGenerator()
function, which
opens the GUI in the default browser:
PanVizGenerator()
Running the above will present you with a view much like what is shown in the figure below.
The GUI is quite self-explanatory as it present limited functinality. The user can select a csv file containing their pangenome data, make some standard choices regarding the algorithms used for some of the data transformations, and then press the generate button. Once the data processing step has run its course a download button will appear for the user to click.
If the user is unsure about the formatting of the csv file an example file is available for download as reference. Apart from this the GUI is also a presentation of PanViz’ functionality, so even trained R users can benefit from opening the GUI at least once and read through it.
The most flexible approach to generating PanViz visualizations is to use the
panviz
method. In order to mimick the functionality of the GUI pass in a
string with the location of a csv file.
csvFile <- system.file('extdata', 'exampleData.csv',
package = 'PanVizGenerator')
outputDir <- tempdir()
# Generate the visualization
panviz(csvFile, location = outputDir)
A more flexible approach is to have your pangenome data in R and pass it in directly:
# Get data from csv
pangenome <- read.csv(csvFile, quote='', stringsAsFactors = FALSE)
name <- pangenome$name
go <- pangenome$go
ec <- pangenome$ec
pangenome <- pangenome[, !names(pangenome) %in% c('name', 'go', 'ec')]
# Annotation can come in many ways
# This is valid
head(go)
## [1] "GO:0017111; GO:0005524; GO:0006508; GO:0008233"
## [2] "GO:0006313; GO:0004803; GO:0003677; GO:0015074"
## [3] "GO:0006313; GO:0004803; GO:0003677"
## [4] "GO:0005215; GO:0006810"
## [5] "GO:0006261; GO:0003677; GO:0005524; GO:0003918; GO:0005694; GO:0006265; GO:0005737"
## [6] "GO:0006261; GO:0003677; GO:0005524; GO:0003918; GO:0000287; GO:0005694; GO:0006265; GO:0005737"
# And this is valid too
head(strsplit(go, '; '))
## [[1]]
## [1] "GO:0017111" "GO:0005524" "GO:0006508" "GO:0008233"
##
## [[2]]
## [1] "GO:0006313" "GO:0004803" "GO:0003677" "GO:0015074"
##
## [[3]]
## [1] "GO:0006313" "GO:0004803" "GO:0003677"
##
## [[4]]
## [1] "GO:0005215" "GO:0006810"
##
## [[5]]
## [1] "GO:0006261" "GO:0003677" "GO:0005524" "GO:0003918" "GO:0005694"
## [6] "GO:0006265" "GO:0005737"
##
## [[6]]
## [1] "GO:0006261" "GO:0003677" "GO:0005524" "GO:0003918" "GO:0000287"
## [6] "GO:0005694" "GO:0006265" "GO:0005737"
# Or another delimiter
head(gsub('; ', 'delimiter', go))
## [1] "GO:0017111delimiterGO:0005524delimiterGO:0006508delimiterGO:0008233"
## [2] "GO:0006313delimiterGO:0004803delimiterGO:0003677delimiterGO:0015074"
## [3] "GO:0006313delimiterGO:0004803delimiterGO:0003677"
## [4] "GO:0005215delimiterGO:0006810"
## [5] "GO:0006261delimiterGO:0003677delimiterGO:0005524delimiterGO:0003918delimiterGO:0005694delimiterGO:0006265delimiterGO:0005737"
## [6] "GO:0006261delimiterGO:0003677delimiterGO:0005524delimiterGO:0003918delimiterGO:0000287delimiterGO:0005694delimiterGO:0006265delimiterGO:0005737"
# Generate the visualization
panviz(pangenome, name=name, go=go, ec=ec, location=outputDir)
If you’re already working with your data in FindMyFriends it is even easier. Just make sure that you use the correct columns in groupInfo to store the annotation and PanVizGenerator takes care of the rest:
# Get an example pangenome with annotation
library(FindMyFriends)
pangenome <- .loadPgExample(withNeighborhoodSplit = TRUE)
annotation <- readAnnot(system.file('extdata',
'examplePG',
'example.annot',
package = 'FindMyFriends'))
head(annotation)
## name description
## 1 OG1 ismhp1 transposase
## 2 OG100 abc transporter
## 3 OG1000 2-oxoisovalerate dehydrogenase
## 4 OG1001 pyruvate dehydrogenase e1-alpha subunit
## 5 OG1002 amino acid permease
## 6 OG1008 excinuclease abc subunit a
## GO
## 1 GO:0003677, GO:0004803, GO:0006313
## 2 GO:0005886, GO:0016021, GO:0005215, GO:0006810
## 3 GO:0004739, GO:0055114, GO:0006094, GO:0006096, GO:0009097, GO:0009098, GO:0009099, GO:0045254
## 4 GO:0004739, GO:0055114, GO:0006094, GO:0006096, GO:0009097, GO:0009098, GO:0009099, GO:0045254
## 5 GO:0016021, GO:0015171, GO:0003333
## 6 GO:0005737, GO:0009380, GO:0003677, GO:0005524, GO:0008270, GO:0009381, GO:0016887, GO:0006289, GO:0009432, GO:0090305, GO:0006308
## EC
## 1
## 2
## 3 EC:1.2.4.1
## 4 EC:1.2.4.1
## 5
## 6 EC:3.6.1, EC:3.6.1.3, EC:3.1, EC:3.6.1.15
pangenome <- addGroupInfo(pangenome, annotation, key = 'name')
pangenome
## An object of class pgFullLoc
##
## The pangenome consists of 6802 genes from 5 organisms
## 3183 gene groups defined
##
## Core|
## Accessory|========================================:
## Singleton|=========:
##
## Genes are translated
# Generate the visualization
panviz(pangenome, location = outputDir)
The above show just the standard behavior which should match the need for most users. It is possible though to tailor the functionality a bit using some addition parameters:
panviz(pangenome, location = outputDir, consolidate = FALSE)
This tells PanVizGenerator to not merge data and JavaScript code into the PanViz.html file but instead keep it as separate files. This might be of interest for debugging or just poking around in the inards of PanViz. For regular use it is nice to have a single self-contained file though.
panviz(pangenome, location = outputDir, showcase = TRUE)
If you wish to inspect the result right away, you can ask PanVizGenerator to
open the html file in your default browser using browseURL()
. Setting
location = tempdir()
and showcase = TRUE
let you experiment with different
settings without getting a lot of PanViz.html files lying around (kind of like
using standard R plotting).
panviz(pangenome, location = outputDir, dist = 'binary', clust = 'complete',
center = FALSE, scale = FALSE)
To modify the look of the scatterplot and dendrogram used for navigating the genomes in the pangenome you can change the distance measure, clustering algorithm and whether data should be centered and scaled, using the parameters shown above. In general the defaults are set to produce a nice plot, but needs may vary.
Being an interactive web-based visualization, the result of all of the above can be difficult to showcase. Because of this a small video has been prepared - depending on where you read this vignette it might not show up though.
In case nothing shows, see the video at its Vimeo page
## R version 4.1.1 (2021-08-10)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 20.04.3 LTS
##
## Matrix products: default
## BLAS: /home/biocbuild/bbs-3.14-bioc/R/lib/libRblas.so
## LAPACK: /home/biocbuild/bbs-3.14-bioc/R/lib/libRlapack.so
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_GB LC_COLLATE=C
## [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
##
## attached base packages:
## [1] stats graphics grDevices utils datasets methods base
##
## other attached packages:
## [1] FindMyFriends_1.23.0 PanVizGenerator_1.22.0 BiocStyle_2.22.0
##
## loaded via a namespace (and not attached):
## [1] Biobase_2.54.0 ggdendro_0.1.22 sass_0.4.0
## [4] jsonlite_1.7.2 bslib_0.3.1 LiblineaR_2.10-12
## [7] shiny_1.7.1 assertthat_0.2.1 BiocManager_1.30.16
## [10] stats4_4.1.1 GenomeInfoDbData_1.2.7 yaml_2.2.1
## [13] pillar_1.6.4 lattice_0.20-45 glue_1.4.2
## [16] digest_0.6.28 promises_1.2.0.1 XVector_0.34.0
## [19] colorspace_2.0-2 htmltools_0.5.2 httpuv_1.6.3
## [22] Matrix_1.3-4 plyr_1.8.6 pkgconfig_2.0.3
## [25] bookdown_0.24 zlibbioc_1.40.0 xtable_1.8-4
## [28] purrr_0.3.4 scales_1.1.1 later_1.3.0
## [31] BiocParallel_1.28.0 tibble_3.1.5 proxy_0.4-26
## [34] generics_0.1.1 IRanges_2.28.0 ggplot2_3.3.5
## [37] ellipsis_0.3.2 BiocGenerics_0.40.0 magrittr_2.0.1
## [40] crayon_1.4.1 mime_0.12 evaluate_0.14
## [43] apcluster_1.4.8 fansi_0.5.0 MASS_7.3-54
## [46] class_7.3-19 tools_4.1.1 lifecycle_1.0.1
## [49] stringr_1.4.0 kebabs_1.28.0 S4Vectors_0.32.0
## [52] kernlab_0.9-29 munsell_0.5.0 Biostrings_2.62.0
## [55] pcaMethods_1.86.0 compiler_4.1.1 jquerylib_0.1.4
## [58] e1071_1.7-9 GenomeInfoDb_1.30.0 rlang_0.4.12
## [61] grid_4.1.1 RCurl_1.98-1.5 filehash_2.4-2
## [64] igraph_1.2.7 bitops_1.0-7 rmarkdown_2.11
## [67] gtable_0.3.0 DBI_1.1.1 reshape2_1.4.4
## [70] R6_2.5.1 knitr_1.36 dplyr_1.0.7
## [73] fastmap_1.1.0 utf8_1.2.2 stringi_1.7.5
## [76] parallel_4.1.1 Rcpp_1.0.7 vctrs_0.3.8
## [79] tidyselect_1.1.1 xfun_0.27