# Exploring sequence and phylogenetic diversity for a taxonomic group of interest.

Nathan D. Olson1

1National Institute of Standards and Technology, Maryland, USA

#### 7 April 2020

#### Package

metagenomeFeatures 2.7.1

# 1 Vignette overview

16S rRNA reference databases are most often used to annotate OTUs or sequence variants from marker-gene survey datasets. The reference databases are also used to study the diversity of specific taxonomic groups. As such, `MgDb-class` objects for 16S rRNA sequence reference databases can be used to explore the sequence and phylogenetic diversity of taxonomic groups of interest. In this vignette, we will explore the 16S rRNA diversity of the Gammaproteobaceria class using the Greengenes 16S rRNA database version 13.8 clustered at 85% similarity. A `MgDb-class` object with the greengenes database version 13.8 85% similarity OTUs (`gg85`) is included in the metagenomeFeatures package.

Other databases are available as Bioconductor AnnotationData.

- Greengenes Release 13.5: greengenesMgDb13.5
- Ribosomal Database Project Release 11.5: ribosomaldatabaseproject11.5MgDb
- Silva 128.1: silva128.1MgDb

We will first load the `MgDb-class` object, then select the taxa of interest, and finally explore the Gammaproteobaceria class phylogenetic diversity, and taxonomic composition. In addition to using the metagenomeFeatures package, the vignette uses tidyverse packages dplyr and tidyr for data manipulation, ggplot2 and for data visualization. The ggtree Bioconductor package is used to plot the phylogenetic tree.

    library(metagenomeFeatures)
    library(dplyr)
    library(forcats)
    library(ggplot2)
    library(ggtree)

# 2 Loading and subsetting the database

The `gg85` database is loaded using `get_gg13.8_85MgDb()`.
Next the `mgDb_select()` function is used to subset the database, the `key` arguments is used to define the taxonmic group(s) of interest and `keytype` is used to define the taxonomic level for the group(s) of interest. With the subsetted database you can analyze the taxonomy, sequences, and phylogeny for the taxonomic group of interest. The `mgDb_select()` function returns a subset of the database taxonomic, sequence, or phylogenetic data, as well as a named list with any two or all three data types.

    gg85 <- get_gg13.8_85MgDb()
    #> Found more than one class "phylo" in cache; using the first, from namespace 'metagenomeFeatures'
    #> Also defined by 'tidytree'
    #> Found more than one class "phylo" in cache; using the first, from namespace 'metagenomeFeatures'
    #> Also defined by 'tidytree'
    #> Found more than one class "phylo" in cache; using the first, from namespace 'metagenomeFeatures'
    #> Also defined by 'tidytree'
    #> Found more than one class "phylo" in cache; using the first, from namespace 'metagenomeFeatures'
    #> Also defined by 'tidytree'

    gamma_16S <- mgDb_select(gg85,
                              type = "all",
                              keys = "Gammaproteobacteria",
                              keytype = "Class")

# 3 Taxonomic Analysis

We want to know how many genera are in the Class Gammaproteobacteria and how many 85% similarity OTUs are in each genera in the Greengenes 13.8 85% database. We first create a data frame with the desired information then plot the results.

    ## Per genus count data
    gamma_df <- gamma_16S$taxa %>%
        group_by(Genus) %>%
        summarise(Count = n()) %>%
        ungroup() %>%
        mutate(Genus = fct_reorder(Genus, Count))

    ## Count info for text
    escherichia_count <- gamma_df$Count[gamma_df$Genus == "g__Escherichia"]

    ## excluding unassigned genera and genera with only one assigned sequence
    gamma_trim_df <- gamma_df %>% filter(Genus != "g__", Count > 1)

For the Greengenes database there are a total of 247 OTUs assigned to 56 genera in the Class Gammaproteobacteria. The number of OTUs assigned to specific genera, range from 9 to 1 (Fig. 1). As this database is preclustered to 85% similarity the number of OTUs per genus is more of an indicator of genera diversity than how well a genus is represented in the database. For example no sequences present in the database are assigned to the genus Shigella and only 1 is assigned to Escherichia. OTUs only assigned to the family, `g__`, is the most abundant group, 154.

     ggplot(gamma_trim_df) +
        geom_bar(aes(x = Genus, y = Count), stat = "identity") +
        labs(y = "Number of OTUs") +
        coord_flip() +
        theme_bw()

Figure 1: Number of seqeunces assigned to genera in the Class Gammaproteobacteria
Only Genera with more than one assigned sequence are shown.

# 4 Phylogenetic Diversity

We will use the ggtree package to visualize the phylogenetic tree and annotate the tips with Genera information. Of the genera with more than 3 representative OTUs Stenotrophomonas is the only genus with unclassified and other OTUs within the clade (Fig. 2).

    genus_lab <- paste0("g__", c("","Stenotrophomonas", "Pseudomonas"))
    genus_anno_df <- gamma_16S$taxa %>%
        group_by(Genus) %>%
        mutate(Count = n()) %>%
        ungroup() %>%
        mutate(Genus_lab = if_else(Count > 3, Genus, ""))

    ggtree(gamma_16S$tree) %<+%
        genus_anno_df +
        ## Add taxa name for unlabeled Stenotrophomonas branch
        geom_tippoint(aes(color = Genus_lab), size = 3) +
        scale_color_manual(values = c("#FF000000","darkorange", "blue", "green", "tan", "black")) +
        theme(legend.position = "bottom") +
        labs(color = "Genus")

Figure 2: Phylogenetic tree of Gammaproteobacteria class OTU representative sequences

# 5 Sequence Diversity

The `mgDb_select()` function returns the subsetted sequence data as a biostring object. The sequence data can be used for additional analysis such as, multiple sequencing alignment, primer region extraction, or PCR primer design. When working with large subsets of the database or the full database, the Bioconductor package DECIPHER provides functions for analyzing sequences in an SQLite database. The `MgDb-class` uses DECIPHER to format the sequences as an SQLite database. The `MgDb-class` sequence slot is a connection to the SQLite database, therefore the DECIPHER package can be used to analyze the dataset reference sequence data as well.

    gamma_16S$seq
    #> DNAStringSet object of length 247:
    #>       width seq                                             names
    #>   [1]  1503 AGAGTTTGATCCTGGCTCAGAT...GGGGTGAAGTCGTAACAAGGTA 1111561
    #>   [2]  1526 AGAGTTTGATCATGGCTCACAT...AATTTGTAACAAGGTAGCCGTA 1110088
    #>   [3]  1502 TAGAGTTTGATCCTGGCTCAGA...GAAGTCGTAACAAGGTAGCCGT 1107824
    #>   [4]  1366 ATTGAACGCTGGCGGCAGGCCT...CGGTGAATACGTTCCCGGGCCT 1047956
    #>   [5]  1365 TGAACGCTGGCGGCAGGCCTAA...CGGTGAATACGTTCCCGGGCCT 1047401
    #>   ...   ... ...
    #> [243]  1540 AGAGTTTGATCCTGGCTCAGAT...GTGAAGTCGTAACAAGGTAACC 4466628
    #> [244]  1486 ATTGAACCCTGGCGGCAGGCTT...GGGGTGAAGTCGTAACAAGGTA 4472725
    #> [245]  1575 GCGGAAACGATGGTAGCTTGCT...ATAGCTTAACCTTCGGGGAGGC 4481079
    #> [246]  1501 AGAGTTTGTTCCTGGCTCAGAT...GTGAAGTCGTAACAAGGTAACC 4481801
    #> [247]  1508 TGAGTTTGATCCTGGCTCAGAT...ACTGGGGTGAAGTCGTAACAAG 4482291

# Session info

    #> R version 4.0.0 alpha (2020-04-05 r78150)
    #> Platform: x86_64-apple-darwin17.0 (64-bit)
    #> Running under: macOS Mojave 10.14.6
    #>
    #> Matrix products: default
    #> BLAS:   /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRblas.dylib
    #> LAPACK: /Library/Frameworks/R.framework/Versions/4.0/Resources/lib/libRlapack.dylib
    #>
    #> locale:
    #> [1] C/en_US.UTF-8/en_US.UTF-8/C/en_US.UTF-8/en_US.UTF-8
    #>
    #> attached base packages:
    #> [1] parallel  stats     graphics  grDevices utils     datasets  methods
    #> [8] base
    #>
    #> other attached packages:
    #> [1] forcats_0.5.0            ggplot2_3.3.0            dplyr_0.8.5
    #> [4] ggtree_2.1.5             metagenomeFeatures_2.7.1 Biobase_2.47.3
    #> [7] BiocGenerics_0.33.3      BiocStyle_2.15.6
    #>
    #> loaded via a namespace (and not attached):
    #>  [1] Rcpp_1.0.4.6        ape_5.3             lattice_0.20-41
    #>  [4] tidyr_1.0.2         Biostrings_2.55.7   assertthat_0.2.1
    #>  [7] digest_0.6.25       utf8_1.1.4          R6_2.4.1
    #> [10] stats4_4.0.0        RSQLite_2.2.0       evaluate_0.14
    #> [13] highr_0.8           pillar_1.4.3        zlibbioc_1.33.1
    #> [16] rlang_0.4.5         lazyeval_0.2.2      blob_1.2.1
    #> [19] magick_2.3          S4Vectors_0.25.15   rmarkdown_2.1
    #> [22] labeling_0.3        stringr_1.4.0       bit_1.1-15.2
    #> [25] munsell_0.5.0       compiler_4.0.0      xfun_0.12
    #> [28] pkgconfig_2.0.3     htmltools_0.4.0     tidyselect_1.0.0
    #> [31] tibble_3.0.0        bookdown_0.18       IRanges_2.21.8
    #> [34] fansi_0.4.1         crayon_1.3.4        dbplyr_1.4.2
    #> [37] withr_2.1.2         grid_4.0.0          nlme_3.1-145
    #> [40] jsonlite_1.6.1      gtable_0.3.0        lifecycle_0.2.0
    #> [43] DBI_1.1.0           magrittr_1.5        scales_1.1.0
    #> [46] tidytree_0.3.3      cli_2.0.2           stringi_1.4.6
    #> [49] farver_2.0.3        XVector_0.27.2      ellipsis_0.3.0
    #> [52] rvcheck_0.1.8       vctrs_0.2.4         DECIPHER_2.15.1
    #> [55] tools_4.0.0         treeio_1.11.2       bit64_0.9-7
    #> [58] glue_1.4.0          purrr_0.3.3         yaml_2.2.1
    #> [61] colorspace_1.4-1    BiocManager_1.30.10 aplot_0.0.4
    #> [64] memoise_1.1.0       knitr_1.28          patchwork_1.0.0