Note: if you haven’t checked out the beta diversity ordinations vignette yet, I recommend looking at that one first.
While the beta diversity ordinations of gradient fractions provides a nice overview of isotope incorporation at the whole-community level, it doesn’t provide a good idea of the magnitude of this BD shift (ie., was there a lot of isotope incorporation or a little for each labeled-treatment?).
Let’s assume that the gradient fraction communities of a labeled-treatment and its corresponding unlabled-control would be (approximately) the same at the same buoyant densities if no incorperation occured. If so, then the pairwise beta diversity between gradient fractions of the treatment vs control would (e.g., the beta diversity between the 13C & 12C communities at a BD of 1.75 g/ml^1) would be ~0 (no differentiation) across the BD range. However, if some taxa incorporated isotope in the labeled-treatment, then they would shift to heavier buoyant densities, which would change the labeled-communities at the buoyant densities where the taxa used to be if unlabeled and the buoyant densities where the taxa have shifted to due to isotope incorporation.
In other words, if we make pairwise treatment-vs-control beta diversity calculations between gradient fraction communities, then we should see evidence of community-level BD shifts in the form of ‘spikes’ in beta diversity.
The only major issue with this approach is that the BD range of each gradient fraction varies from gradient to gradient. So, gradient fractions between gradients usually only partially overlap. To deal with this issue, we have taken the approach of weighting the beta diversity based on gradient fraction overlap. For instance, if 2 labeled-treatment fractions overlapped 1 control fraction by 40% and 60%, then the final beta diversity value would be the weighted average of treatment fraction 1 (40% weight) and treatment fraction 2 (60% weight). Note that this makes all beta diversity values (and their associated buoyant densities) relative to the control.
The following analysis measures these community-wide BD shifts with the following:
First, let’s load some packages including HTSSIP
.
library(dplyr)
library(tidyr)
library(ggplot2)
library(HTSSIP)
Also let’s get an overview of the phyloseq object that we’re going to use.
physeq_S2D2
## phyloseq-class experiment-level object
## otu_table() OTU Table: [ 10001 taxa and 139 samples ]
## sample_data() Sample Data: [ 139 samples by 17 sample variables ]
## tax_table() Taxonomy Table: [ 10001 taxa by 8 taxonomic ranks ]
## phy_tree() Phylogenetic Tree: [ 10001 tips and 10000 internal nodes ]
As with the beta diversity ordinations, we are going to split up the dataset into individual labeled-treamtent + corresponding unlabeled-control comparisons. Treatment-control correspondence is based on the day from substrate addition. So, we have to parse the dataset by Substrate & Day.
params = get_treatment_params(physeq_S2D2, c('Substrate', 'Day'))
params = dplyr::filter(params, Substrate!='12C-Con')
ex = "(Substrate=='12C-Con' & Day=='${Day}') | (Substrate=='${Substrate}' & Day == '${Day}')"
physeq_S2D2_l = phyloseq_subset(physeq_S2D2, params, ex)
physeq_S2D2_l
## $`(Substrate=='12C-Con' & Day=='3') | (Substrate=='13C-Cel' & Day == '3')`
## phyloseq-class experiment-level object
## otu_table() OTU Table: [ 10001 taxa and 46 samples ]
## sample_data() Sample Data: [ 46 samples by 17 sample variables ]
## tax_table() Taxonomy Table: [ 10001 taxa by 8 taxonomic ranks ]
## phy_tree() Phylogenetic Tree: [ 10001 tips and 10000 internal nodes ]
##
## $`(Substrate=='12C-Con' & Day=='14') | (Substrate=='13C-Cel' & Day == '14')`
## phyloseq-class experiment-level object
## otu_table() OTU Table: [ 10001 taxa and 46 samples ]
## sample_data() Sample Data: [ 46 samples by 17 sample variables ]
## tax_table() Taxonomy Table: [ 10001 taxa by 8 taxonomic ranks ]
## phy_tree() Phylogenetic Tree: [ 10001 tips and 10000 internal nodes ]
##
## $`(Substrate=='12C-Con' & Day=='14') | (Substrate=='13C-Glu' & Day == '14')`
## phyloseq-class experiment-level object
## otu_table() OTU Table: [ 10001 taxa and 47 samples ]
## sample_data() Sample Data: [ 47 samples by 17 sample variables ]
## tax_table() Taxonomy Table: [ 10001 taxa by 8 taxonomic ranks ]
## phy_tree() Phylogenetic Tree: [ 10001 tips and 10000 internal nodes ]
##
## $`(Substrate=='12C-Con' & Day=='3') | (Substrate=='13C-Glu' & Day == '3')`
## phyloseq-class experiment-level object
## otu_table() OTU Table: [ 10001 taxa and 46 samples ]
## sample_data() Sample Data: [ 46 samples by 17 sample variables ]
## tax_table() Taxonomy Table: [ 10001 taxa by 8 taxonomic ranks ]
## phy_tree() Phylogenetic Tree: [ 10001 tips and 10000 internal nodes ]
Now, let’s just measure BD shift for just 1 subset (1 item in the list of phyloseq objects).
Note: we are just going to use 5 permutations to speed up the analysis.
wmean1 = BD_shift(physeq_S2D2_l[[2]], nperm=5)
cat('Subset:', names(physeq_S2D2_l)[2], '\n')
## Subset: (Substrate=='12C-Con' & Day=='14') | (Substrate=='13C-Cel' & Day == '14')
wmean1 %>% head(n=3)
## perm_id sample.x sample.y distance IS__CONTROL.x
## 1 0 12C-Con.D14.R1_F12 13C-Cel.D14.R1_F12 0.2615498 TRUE
## 2 0 12C-Con.D14.R1_F13 13C-Cel.D14.R1_F12 0.2570687 TRUE
## 3 0 12C-Con.D14.R1_F23 13C-Cel.D14.R1_F22 0.1537309 TRUE
## BD_min.x BD_max.x BD_range.x IS__CONTROL.y BD_min.y BD_max.y BD_range.y
## 1 1.736237 1.739516 0.003279 FALSE 1.735145 1.739516 0.004371
## 2 1.730773 1.736237 0.005464 FALSE 1.735145 1.739516 0.004371
## 3 1.692527 1.695805 0.003278 FALSE 1.694712 1.699083 0.004371
## perc_overlap n_over_fracs wmean_dist wmean_dist_CI_low_global
## 1 100.00000 1 0.2615498 0.1250074
## 2 19.98536 2 0.2670791 0.1250074
## 3 33.34350 2 0.1083092 0.1250074
## wmean_dist_CI_high_global wmean_dist_CI_low wmean_dist_CI_high
## 1 0.3813896 0.2388716 0.3609715
## 2 0.3813896 0.1698731 0.2733860
## 3 0.3813896 0.2205503 0.2893900
Note that the sample.x
column is all 12C-Con control samples, while the comparison column (sample.y
) is the treatment gradient fraction samples.
OK. Let’s plot the results!
x_lab = 'Buoyant density (g/ml^-1)'
y_lab = 'Weighted mean of\nweighted-Unifrac distances'
ggplot(wmean1, aes(BD_min.x, wmean_dist)) +
geom_point() +
labs(x=x_lab, y=y_lab, title='Beta diversity of 13C-treatment relative to 12C-Con') +
theme_bw()
Each point represents the weighted mean of beta diversity values between all 13C-treatment fractions that overlap a particular 12C-control fraction, so there should be 1 point per 12C-control gradient fraction.
Note the 2 spikes in beta diversity. The 2nd spike is larger than the first, which is likely due to more taxa at the ‘light’ gradient fractions (1st spike), so a loss of a few taxa (due to BD shifting) impacts beta diveristy less than at ‘heavy’ gradient fractions, where there’s less taxa.
Now let’s run BD_shift()
on all phyloseq objects in our list. We’ll use plyr::ldply()
for this because it preserves the list names in the resulting data.frame (list names are assigned to .id
by default).
wmean = plyr::ldply(physeq_S2D2_l, BD_shift, nperm=5)
wmean %>% head(n=3)
## .id
## 1 (Substrate=='12C-Con' & Day=='3') | (Substrate=='13C-Cel' & Day == '3')
## 2 (Substrate=='12C-Con' & Day=='3') | (Substrate=='13C-Cel' & Day == '3')
## 3 (Substrate=='12C-Con' & Day=='3') | (Substrate=='13C-Cel' & Day == '3')
## perm_id sample.x sample.y distance IS__CONTROL.x
## 1 0 12C-Con.D3.R3_F19 13C-Cel.D3.R1_F21 0.08867784 TRUE
## 2 0 12C-Con.D3.R3_F13 13C-Cel.D3.R1_F15 0.12424811 TRUE
## 3 0 12C-Con.D3.R3_F14 13C-Cel.D3.R1_F15 0.13054131 TRUE
## BD_min.x BD_max.x BD_range.x IS__CONTROL.y BD_min.y BD_max.y BD_range.y
## 1 1.705640 1.710011 0.004371 FALSE 1.70564 1.706186 0.000546
## 2 1.728588 1.732959 0.004371 FALSE 1.72531 1.734052 0.008742
## 3 1.724217 1.728588 0.004371 FALSE 1.72531 1.734052 0.008742
## perc_overlap n_over_fracs wmean_dist wmean_dist_CI_low_global
## 1 12.49142 2 0.1179129 0.1011089
## 2 100.00000 1 0.1242481 0.1011089
## 3 74.99428 2 0.1240763 0.1011089
## wmean_dist_CI_high_global wmean_dist_CI_low wmean_dist_CI_high
## 1 0.3711546 0.17833728 0.4215999
## 2 0.3711546 0.08994969 0.2386819
## 3 0.3711546 0.10878941 0.2571881
Alright, let’s plot the data!
# formatting the treatment names to look a bit better as facet labels
wmean = wmean %>%
mutate(Substrate = gsub('.+(13C-[A-z]+).+', '\\1', .id),
Day = gsub('.+Day ==[ \']*([0-9]+).+', 'Day \\1', .id),
Day = Day %>% reorder(gsub('Day ', '', Day) %>% as.numeric))
# plotting, with facetting by 13C-treatment
ggplot(wmean, aes(BD_min.x, wmean_dist)) +
geom_point() +
geom_line() +
labs(x=x_lab, y=y_lab,
title='Beta diversity of 13C-treatments relative to 12C-Con') +
facet_grid(Day ~ Substrate) +
theme_bw() +
theme(axis.text.x = element_text(angle=45, hjust=1))
As you can see, the ‘heavy’ beta diversity spike is stronger for 13C-Glucose at Day 3 versus 13C-Cellulose, but this pattern reverses at Day 14 of the substrate incubation. These results are to be expected, given that glucose is more labile than cellulose.
sessionInfo()
## R version 3.3.3 (2017-03-06)
## Platform: x86_64-pc-linux-gnu (64-bit)
## Running under: Ubuntu 16.04.2 LTS
##
## locale:
## [1] LC_CTYPE=en_US.UTF-8 LC_NUMERIC=C
## [3] LC_TIME=en_US.UTF-8 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] phyloseq_1.19.1 HTSSIP_1.2.0 ggplot2_2.2.1 tidyr_0.6.1
## [5] dplyr_0.5.0
##
## loaded via a namespace (and not attached):
## [1] reshape2_1.4.2 splines_3.3.3 lattice_0.20-35
## [4] rhdf5_2.18.0 colorspace_1.3-2 htmltools_0.3.5
## [7] stats4_3.3.3 yaml_2.1.14 mgcv_1.8-17
## [10] survival_2.41-3 DBI_0.6-1 BiocGenerics_0.20.0
## [13] foreach_1.4.3 plyr_1.8.4 stringr_1.2.0
## [16] zlibbioc_1.20.0 Biostrings_2.42.1 munsell_0.4.3
## [19] gtable_0.2.0 codetools_0.2-15 evaluate_0.10
## [22] labeling_0.3 Biobase_2.34.0 knitr_1.15.1
## [25] permute_0.9-4 IRanges_2.8.2 biomformat_1.2.0
## [28] parallel_3.3.3 Rcpp_0.12.10 scales_0.4.1
## [31] backports_1.0.5 vegan_2.4-3 S4Vectors_0.12.2
## [34] jsonlite_1.4 XVector_0.14.1 digest_0.6.12
## [37] stringi_1.1.5 grid_3.3.3 ade4_1.7-6
## [40] rprojroot_1.2 tools_3.3.3 magrittr_1.5
## [43] lazyeval_0.2.0 tibble_1.3.0 cluster_2.0.6
## [46] ape_4.1 MASS_7.3-45 Matrix_1.2-8
## [49] data.table_1.10.4 assertthat_0.2.0 rmarkdown_1.4
## [52] iterators_1.0.8 R6_2.2.0 multtest_2.30.0
## [55] igraph_1.0.1 nlme_3.1-131 compiler_3.3.3