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

Nate D. Olson

2019-01-04

Overview

MgDb objects for 16S rRNA sequence reference databases can be used to explore sequnce and phylogenetic diversity of taxonomic groups of interest. In this vignette we will explore the 16S rRNA diversity for the Enterobacteriace family. The Greengenes 16S rRNA database version 13.8 clusted at the 85% threshold will be used in this vignette. A MgDb object with this database (gg85) is included in the metagenomeFeatures package. We will first load the MgDb class object, then select the taxa of interest, and finally provide a explor the phylogenetic and sequence diversity and taxonomic composition of the Enterobacteriace family.

The database exploration will consist of four parts.

  1. Loading and subsetting the database.
  2. Taxonomic analysis.
  3. Phylogenetic diversity.
  4. Sequence diversity.

Loading and subsetting the database

First we need to load the metagenomeFeatues package. The tidyverse packages, dplyr, tidyr, and ggplot are used display the results.

library(metagenomeFeatures) 
library(tidyverse)

The gg85 database is loaded using get_gg13.8_85MgDb().

gg85 <- get_gg13.8_85MgDb()

Other databases are avilable as Bioconductor AnnotationData.

Next the mgDb_select() function is first 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 select function returns single object with a subset of the database taxonomic, sequence, or phylogenetic data, as well as a named list with any two or all three data types.

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

Taxonomic Analysis

We want to know how many genera in the Order Enterobacteriaceae there are sequences for in the Greengenes 85% OTU database as well as how many sequences are assigned to each genera. We will first create a dataframe with the desired information then a plot to summarize 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 
total_otus <- sum(gamma_df$Count)
no_genus_assignment <- gamma_df$Count[gamma_df$Genus == "g__"]
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 76 to 1 @ref(fig:generaCount). 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 the genera is represented in the database. For example no sequences present in the database are assigned to the genus Shigella and only 1 are assigned to Escherichia. OTUs only assigned to the family, g__, is the most abundant group, 154, many of which are likely from these two genera. Next we will use the phylogenetic information to evaluate this assumption.

 ggplot(gamma_trim_df) + 
    geom_bar(aes(x = Genus, y = Count), stat = "identity") + 
    labs(y = "Number of OTUs") + 
    coord_flip() + 
    theme_bw() 
Number of seqeunces assigned to genera in the Class Gammaproteobacteria. Only Genera with more than one assigned sequence are shown.

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

Phylogenetic Diversity

We will use the ggtree package to visualize the phylogenetic tree and annotate the tips with Genera information. A number of OTUs unassigned at the genus level are in the same clade as OTUs assigned to the Genera Escherichia and a related Genera Salmonella @ref(fig:annoTree).

library(ggtree)

genus_anno_df <- gamma_16S$taxa %>% 
    group_by(Genus) %>% 
    mutate(Count = n()) %>% 
    ungroup() %>% 
    mutate(Genus_lab = if_else(Genus %in% paste0("g__", c("","Escherichia", "Salmonella")), Genus, ""))

ggtree(gamma_16S$tree) %<+% 
    genus_anno_df + 
    geom_tippoint(aes(color = Genus_lab), size = 3) + 
    scale_color_manual(values = c("#FF000000","darkorange","blue", "darkgreen")) + 
    theme(legend.position = "bottom") + 
    labs(color = "Genus")
Phylogenetic tree for Gammaproteobacteria class OTU representative sequences. OTUs not classified to the genus level are annotated with orange dots, and Escherichia and Salmonella OTUs are annotated with blue and green dots respectively.

Phylogenetic tree for Gammaproteobacteria class OTU representative sequences. OTUs not classified to the genus level are annotated with orange dots, and Escherichia and Salmonella OTUs are annotated with blue and green dots respectively.

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.

gamma_16S$seq
#>   A DNAStringSet instance of length 247
#>       width seq                                        names               
#>   [1]  1503 AGAGTTTGATCCTGGCTCAG...GTGAAGTCGTAACAAGGTA 1111561
#>   [2]  1526 AGAGTTTGATCATGGCTCAC...TTGTAACAAGGTAGCCGTA 1110088
#>   [3]  1502 TAGAGTTTGATCCTGGCTCA...GTCGTAACAAGGTAGCCGT 1107824
#>   [4]  1366 ATTGAACGCTGGCGGCAGGC...TGAATACGTTCCCGGGCCT 1047956
#>   [5]  1365 TGAACGCTGGCGGCAGGCCT...TGAATACGTTCCCGGGCCT 1047401
#>   ...   ... ...
#> [243]  1540 AGAGTTTGATCCTGGCTCAG...AAGTCGTAACAAGGTAACC 4466628
#> [244]  1486 ATTGAACCCTGGCGGCAGGC...GTGAAGTCGTAACAAGGTA 4472725
#> [245]  1575 GCGGAAACGATGGTAGCTTG...GCTTAACCTTCGGGGAGGC 4481079
#> [246]  1501 AGAGTTTGTTCCTGGCTCAG...AAGTCGTAACAAGGTAACC 4481801
#> [247]  1508 TGAGTTTGATCCTGGCTCAG...GGGGTGAAGTCGTAACAAG 4482291

System Information

s_info <- devtools::session_info()
print(s_info$platform)
#>  setting  value                       
#>  version  R version 3.5.2 (2018-12-20)
#>  os       Ubuntu 16.04.5 LTS          
#>  system   x86_64, linux-gnu           
#>  ui       X11                         
#>  language (EN)                        
#>  collate  C                           
#>  ctype    en_US.UTF-8                 
#>  tz       America/New_York            
#>  date     2019-01-04

Package Versions

s_info$packages
#>  package            * version date       lib source        
#>  ape                  5.2     2018-09-24 [2] CRAN (R 3.5.2)
#>  assertthat           0.2.0   2017-04-11 [2] CRAN (R 3.5.2)
#>  backports            1.1.3   2018-12-14 [2] CRAN (R 3.5.2)
#>  bindr                0.1.1   2018-03-13 [2] CRAN (R 3.5.2)
#>  bindrcpp           * 0.2.2   2018-03-29 [2] CRAN (R 3.5.2)
#>  Biobase            * 2.42.0  2019-01-04 [2] Bioconductor  
#>  BiocGenerics       * 0.28.0  2019-01-04 [2] Bioconductor  
#>  Biostrings           2.50.2  2019-01-04 [2] Bioconductor  
#>  bit                  1.1-14  2018-05-29 [2] CRAN (R 3.5.2)
#>  bit64                0.9-7   2017-05-08 [2] CRAN (R 3.5.2)
#>  blob                 1.1.1   2018-03-25 [2] CRAN (R 3.5.2)
#>  broom                0.5.1   2018-12-05 [2] CRAN (R 3.5.2)
#>  callr                3.1.1   2018-12-21 [2] CRAN (R 3.5.2)
#>  cellranger           1.1.0   2016-07-27 [2] CRAN (R 3.5.2)
#>  cli                  1.0.1   2018-09-25 [2] CRAN (R 3.5.2)
#>  colorspace           1.3-2   2016-12-14 [2] CRAN (R 3.5.2)
#>  crayon               1.3.4   2017-09-16 [2] CRAN (R 3.5.2)
#>  DBI                  1.0.0   2018-05-02 [2] CRAN (R 3.5.2)
#>  dbplyr               1.2.2   2018-07-25 [2] CRAN (R 3.5.2)
#>  DECIPHER             2.10.1  2019-01-04 [2] Bioconductor  
#>  desc                 1.2.0   2018-05-01 [2] CRAN (R 3.5.2)
#>  devtools             2.0.1   2018-10-26 [2] CRAN (R 3.5.2)
#>  digest               0.6.18  2018-10-10 [2] CRAN (R 3.5.2)
#>  dplyr              * 0.7.8   2018-11-10 [2] CRAN (R 3.5.2)
#>  evaluate             0.12    2018-10-09 [2] CRAN (R 3.5.2)
#>  fansi                0.4.0   2018-10-05 [2] CRAN (R 3.5.2)
#>  forcats            * 0.3.0   2018-02-19 [2] CRAN (R 3.5.2)
#>  fs                   1.2.6   2018-08-23 [2] CRAN (R 3.5.2)
#>  generics             0.0.2   2018-11-29 [2] CRAN (R 3.5.2)
#>  ggplot2            * 3.1.0   2018-10-25 [2] CRAN (R 3.5.2)
#>  ggtree             * 1.14.4  2019-01-04 [2] Bioconductor  
#>  glue                 1.3.0   2018-07-17 [2] CRAN (R 3.5.2)
#>  gtable               0.2.0   2016-02-26 [2] CRAN (R 3.5.2)
#>  haven                2.0.0   2018-11-22 [2] CRAN (R 3.5.2)
#>  highr                0.7     2018-06-09 [2] CRAN (R 3.5.2)
#>  hms                  0.4.2   2018-03-10 [2] CRAN (R 3.5.2)
#>  htmltools            0.3.6   2017-04-28 [2] CRAN (R 3.5.2)
#>  httr                 1.4.0   2018-12-11 [2] CRAN (R 3.5.2)
#>  IRanges              2.16.0  2019-01-04 [2] Bioconductor  
#>  jsonlite             1.6     2018-12-07 [2] CRAN (R 3.5.2)
#>  knitr                1.21    2018-12-10 [2] CRAN (R 3.5.2)
#>  labeling             0.3     2014-08-23 [2] CRAN (R 3.5.2)
#>  lattice              0.20-38 2018-11-04 [2] CRAN (R 3.5.2)
#>  lazyeval             0.2.1   2017-10-29 [2] CRAN (R 3.5.2)
#>  lubridate            1.7.4   2018-04-11 [2] CRAN (R 3.5.2)
#>  magrittr             1.5     2014-11-22 [2] CRAN (R 3.5.2)
#>  memoise              1.1.0   2017-04-21 [2] CRAN (R 3.5.2)
#>  metagenomeFeatures * 2.2.1   2019-01-04 [1] Bioconductor  
#>  modelr               0.1.2   2018-05-11 [2] CRAN (R 3.5.2)
#>  munsell              0.5.0   2018-06-12 [2] CRAN (R 3.5.2)
#>  nlme                 3.1-137 2018-04-07 [2] CRAN (R 3.5.2)
#>  pillar               1.3.1   2018-12-15 [2] CRAN (R 3.5.2)
#>  pkgbuild             1.0.2   2018-10-16 [2] CRAN (R 3.5.2)
#>  pkgconfig            2.0.2   2018-08-16 [2] CRAN (R 3.5.2)
#>  pkgload              1.0.2   2018-10-29 [2] CRAN (R 3.5.2)
#>  plyr                 1.8.4   2016-06-08 [2] CRAN (R 3.5.2)
#>  prettyunits          1.0.2   2015-07-13 [2] CRAN (R 3.5.2)
#>  processx             3.2.1   2018-12-05 [2] CRAN (R 3.5.2)
#>  ps                   1.3.0   2018-12-21 [2] CRAN (R 3.5.2)
#>  purrr              * 0.2.5   2018-05-29 [2] CRAN (R 3.5.2)
#>  R6                   2.3.0   2018-10-04 [2] CRAN (R 3.5.2)
#>  Rcpp                 1.0.0   2018-11-07 [2] CRAN (R 3.5.2)
#>  readr              * 1.3.1   2018-12-21 [2] CRAN (R 3.5.2)
#>  readxl               1.2.0   2018-12-19 [2] CRAN (R 3.5.2)
#>  remotes              2.0.2   2018-10-30 [2] CRAN (R 3.5.2)
#>  rlang                0.3.0.1 2018-10-25 [2] CRAN (R 3.5.2)
#>  rmarkdown            1.11    2018-12-08 [2] CRAN (R 3.5.2)
#>  rprojroot            1.3-2   2018-01-03 [2] CRAN (R 3.5.2)
#>  RSQLite              2.1.1   2018-05-06 [2] CRAN (R 3.5.2)
#>  rstudioapi           0.8     2018-10-02 [2] CRAN (R 3.5.2)
#>  rvcheck              0.1.3   2018-12-06 [2] CRAN (R 3.5.2)
#>  rvest                0.3.2   2016-06-17 [2] CRAN (R 3.5.2)
#>  S4Vectors            0.20.1  2019-01-04 [2] Bioconductor  
#>  scales               1.0.0   2018-08-09 [2] CRAN (R 3.5.2)
#>  sessioninfo          1.1.1   2018-11-05 [2] CRAN (R 3.5.2)
#>  stringi              1.2.4   2018-07-20 [2] CRAN (R 3.5.2)
#>  stringr            * 1.3.1   2018-05-10 [2] CRAN (R 3.5.2)
#>  testthat             2.0.1   2018-10-13 [2] CRAN (R 3.5.2)
#>  tibble             * 2.0.0   2019-01-04 [2] CRAN (R 3.5.2)
#>  tidyr              * 0.8.2   2018-10-28 [2] CRAN (R 3.5.2)
#>  tidyselect           0.2.5   2018-10-11 [2] CRAN (R 3.5.2)
#>  tidytree             0.2.1   2018-12-19 [2] CRAN (R 3.5.2)
#>  tidyverse          * 1.2.1   2017-11-14 [2] CRAN (R 3.5.2)
#>  treeio               1.6.1   2019-01-04 [2] Bioconductor  
#>  usethis              1.4.0   2018-08-14 [2] CRAN (R 3.5.2)
#>  utf8                 1.1.4   2018-05-24 [2] CRAN (R 3.5.2)
#>  withr                2.1.2   2018-03-15 [2] CRAN (R 3.5.2)
#>  xfun                 0.4     2018-10-23 [2] CRAN (R 3.5.2)
#>  xml2                 1.2.0   2018-01-24 [2] CRAN (R 3.5.2)
#>  XVector              0.22.0  2019-01-04 [2] Bioconductor  
#>  yaml                 2.2.0   2018-07-25 [2] CRAN (R 3.5.2)
#>  zlibbioc             1.28.0  2019-01-04 [2] Bioconductor  
#> 
#> [1] /tmp/RtmpESY947/Rinst716c2f67880b
#> [2] /home/biocbuild/bbs-3.8-bioc/R/library