Relative Abundancy
tax_table<-as.data.frame(tax_tab)
row.names(tax_table) <- tax_table$OTU
tax_table <- tax_table[, -1]
tax_table<- tax_table[order(rownames(tax_table)),]
# create microeco file
meco_fungi <- microtable$new(sample_table = sample_info_no_R, otu_table = filt_count_tab, tax_table = tax_table)
mycol <- c("#A6CEE3" ,"#1F78B4" ,"#B2DF8A" ,"#33A02C" ,"#FB9A99", "#E31A1C" ,"#FDBF6F" ,"#FF7F00" ,"#CAB2D6" ,
"#6A3D9A" ,"#FFFF99" ,"#B15928" , "#6fdc8c", "green4", "#004144")
t1 <- trans_abund$new(dataset = meco_fungi, taxrank = "Phylum", ntaxa = 6)
## No taxa_abund list found. Calculate relative abundance with cal_abund function ...
## The result is stored in object$taxa_abund ...
## The transformed abundance data is stored in object$data_abund ...
t2 <- trans_abund$new(dataset = meco_fungi, taxrank = "Class", ntaxa = 11)
## The transformed abundance data is stored in object$data_abund ...
t3 <- trans_abund$new(dataset = meco_fungi, taxrank = "Order", ntaxa = 11)
## The transformed abundance data is stored in object$data_abund ...
t4 <- trans_abund$new(dataset = meco_fungi, taxrank = "Family", ntaxa = 11)
## The transformed abundance data is stored in object$data_abund ...
t5 <- trans_abund$new(dataset = meco_fungi, taxrank = "Genus", ntaxa = 12)
## The transformed abundance data is stored in object$data_abund ...
p1<-t1$plot_bar(xtext_keep = TRUE, xtext_angle = 90,facet = "Plot",xtext_size = 6, barwidth = 1, color_values = mycol)
p2<-t2$plot_bar(xtext_keep = TRUE, xtext_angle = 90,facet = "Plot",xtext_size = 6, barwidth = 1,color_values = mycol)
p3<-t3$plot_bar(xtext_keep = TRUE, xtext_angle = 90,facet = "Plot",xtext_size = 6, barwidth = 1,color_values = mycol)
p4<-t4$plot_bar(xtext_keep = TRUE, xtext_angle = 90,facet = "Plot",xtext_size = 6, barwidth = 1,color_values = mycol)
library(gridExtra)
##
## Attaching package: 'gridExtra'
## The following object is masked from 'package:dplyr':
##
## combine
## The following object is masked from 'package:Biobase':
##
## combine
## The following object is masked from 'package:BiocGenerics':
##
## combine
grid.arrange(p1, p2, p3, p4, ncol = 1)

Relative abundane - Genus
t5$plot_bar(xtext_keep = TRUE, xtext_angle = 90,facet = "Plot",xtext_size = 6, barwidth = 1,color_values = mycol)

Prediction of the RAF composition (only ECM OTUs): Variance
partitioning
meta <- as(sample_data(vst_physeq), "data.frame")
keep <- complete.cases(meta[, c("Age","pH","Habitat","Site")])
vst_mat <- as.data.frame(t(otu_table(vst_physeq)))
vst_mat_clean <- vst_mat[keep, ]
meta_clean <- meta[keep, ]
tax_data <- tax_tab
tax_data_ECM <- tax_data[tax_data$Guild == "Ectomycorrhizal", ]
vst_mat_clean_ECM <- vst_mat_clean[, colnames(vst_mat_clean) %in% tax_data_ECM$OTU]
# List of predictors
env <- meta_clean[, c("pH", "Habitat")]
env$Habitat <- as.factor(env$Habitat)
space <- data.frame(Site = as.factor(meta_clean$Site))
growth <- meta_clean$Age
# Variance partitioning
vp <- varpart(vst_mat_clean_ECM, ~ pH, ~ Habitat, ~ Site, ~ Age, data = meta_clean)
vals <- vp$part$indfract$Adj.R.square[1:4]
plot(vp, Xnames = c("pH", "Habitat","Site", "Age"), bg = c("#EE7733","#5E4FA2","#337538" ,"#33BBEE"), cex = 1, digits = 2)

Redundance analyses - Only ECM
rda_env <- rda(vst_mat_clean_ECM ~ pH + Habitat + Condition(Site), data = meta_clean)
anova.cca(rda_env, by = "term", permutations = 9999)
## Permutation test for rda under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
##
## Model: rda(formula = vst_mat_clean_ECM ~ pH + Habitat + Condition(Site), data = meta_clean)
## Df Variance F Pr(>F)
## pH 1 68.88 3.8858 0.0001 ***
## Habitat 1 31.64 1.7853 0.0047 **
## Residual 103 1825.67
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
rda_space <- rda(vst_mat_clean_ECM ~ Site, data = meta_clean)
anova.cca(rda_space, permutations = 9999)
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 9999
##
## Model: rda(formula = vst_mat_clean_ECM ~ Site, data = meta_clean)
## Df Variance F Pr(>F)
## Model 2 367.73 10.023 1e-04 ***
## Residual 105 1926.19
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
rda_age <- rda(vst_mat_clean_ECM ~ Age + Condition(pH + Habitat + Site), data = meta_clean)
anova.cca(rda_age, by = "term", permutations = 9999)
## Permutation test for rda under reduced model
## Terms added sequentially (first to last)
## Permutation: free
## Number of permutations: 9999
##
## Model: rda(formula = vst_mat_clean_ECM ~ Age + Condition(pH + Habitat + Site), data = meta_clean)
## Df Variance F Pr(>F)
## Age 1 25.28 1.432 0.0386 *
## Residual 102 1800.40
## ---
## Signif. codes: 0 '***' 0.001 '**' 0.01 '*' 0.05 '.' 0.1 ' ' 1
Mantel test (all OTUs)
# test whether RAF community dissimilarity increases with the distance between
# trees inside a plot (distance decay), and whether such a pattern is explained
# by differences in soil pH between the trees
plots <- sort(unique(as.character(meta_clean$Plot))) # AF AT BF BT IF IT
set.seed(50)
# ---------- AF
sel <- which(as.character(meta_clean$Plot) == "AF" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_af <- data.frame(Plot = "AF", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
# ---------- AT
sel <- which(as.character(meta_clean$Plot) == "AT" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_at <- data.frame(Plot = "AT", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
# ---------- BF
sel <- which(as.character(meta_clean$Plot) == "BF" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_bf <- data.frame(Plot = "BF", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
# ---------- BT
sel <- which(as.character(meta_clean$Plot) == "BT" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_bt <- data.frame(Plot = "BT", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
# ---------- IF
sel <- which(as.character(meta_clean$Plot) == "IF" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_if <- data.frame(Plot = "IF", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
# ---------- IT
sel <- which(as.character(meta_clean$Plot) == "IT" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_it <- data.frame(Plot = "IT", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
mantel_res <- rbind(m_af, m_at, m_bf, m_bt, m_if, m_it)
# adjust the p-values across the six plots
mantel_res$p_geo_adj <- p.adjust(mantel_res$p_geo, method = "BH")
mantel_res$p_geo_pH_adj <- p.adjust(mantel_res$p_geo_pH, method = "BH")
mantel_res$p_pH_geo_adj <- p.adjust(mantel_res$p_pH_geo, method = "BH")
mantel_res
## Plot n r_geo p_geo r_geo_pH p_geo_pH r_pH_geo p_pH_geo
## 1 AF 19 -0.10913090 0.8051 -0.11086896 0.7990 -0.051944461 0.6309
## 2 AT 18 0.01586464 0.4168 0.01544612 0.4300 0.007359699 0.4622
## 3 BF 21 0.01627938 0.3815 0.03014043 0.3383 -0.024435790 0.5790
## 4 BT 20 -0.17570682 0.9821 -0.18561676 0.9859 -0.034464525 0.5789
## 5 IF 19 -0.12709225 0.8341 -0.13691800 0.8586 0.052928550 0.2925
## 6 IT 11 -0.06342222 0.6414 -0.06976820 0.6512 -0.200568892 0.9408
## p_geo_adj p_geo_pH_adj p_pH_geo_adj
## 1 0.9821 0.9859 0.75708
## 2 0.9821 0.9859 0.75708
## 3 0.9821 0.9859 0.75708
## 4 0.9821 0.9859 0.75708
## 5 0.9821 0.9859 0.75708
## 6 0.9821 0.9859 0.94080
Mantel test (ECM OTUs)
# test whether RAF community dissimilarity increases with the distance between
# trees inside a plot (distance decay), and whether such a pattern is explained
# by differences in soil pH between the trees
plots <- sort(unique(as.character(meta_clean$Plot))) # AF AT BF BT IF IT
set.seed(50)
# ---------- AF
sel <- which(as.character(meta_clean$Plot) == "AF" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean_ECM[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_af <- data.frame(Plot = "AF", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
# ---------- AT
sel <- which(as.character(meta_clean$Plot) == "AT" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean_ECM[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_at <- data.frame(Plot = "AT", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
# ---------- BF
sel <- which(as.character(meta_clean$Plot) == "BF" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean_ECM[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_bf <- data.frame(Plot = "BF", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
# ---------- BT
sel <- which(as.character(meta_clean$Plot) == "BT" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean_ECM[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_bt <- data.frame(Plot = "BT", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
# ---------- IF
sel <- which(as.character(meta_clean$Plot) == "IF" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean_ECM[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_if <- data.frame(Plot = "IF", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
# ---------- IT
sel <- which(as.character(meta_clean$Plot) == "IT" &
!is.na(meta_clean$Latitude) & !is.na(meta_clean$Longitude))
meta_plot <- meta_clean[sel, ]
lat_mean <- mean(meta_plot$Latitude)
x <- (meta_plot$Longitude - mean(meta_plot$Longitude)) * 111320 * cos(lat_mean * pi / 180)
y <- (meta_plot$Latitude - lat_mean) * 110540
dist_geo <- dist(cbind(x, y))
dist_com <- dist(vst_mat_clean_ECM[sel, ])
dist_pH <- dist(as.matrix(meta_plot$pH))
mt_geo <- mantel(dist_com, dist_geo, method = "pearson", permutations = 9999)
mt_geo_pH <- mantel.partial(dist_com, dist_geo, dist_pH, method = "pearson", permutations = 9999)
mt_pH_geo <- mantel(dist_pH, dist_geo, method = "pearson", permutations = 9999)
m_it <- data.frame(Plot = "IT", n = length(sel),
r_geo = mt_geo$statistic, p_geo = mt_geo$signif,
r_geo_pH = mt_geo_pH$statistic, p_geo_pH = mt_geo_pH$signif,
r_pH_geo = mt_pH_geo$statistic, p_pH_geo = mt_pH_geo$signif)
mantel_res_ECM <- rbind(m_af, m_at, m_bf, m_bt, m_if, m_it)
# adjust the p-values across the six plots
mantel_res_ECM$p_geo_adj <- p.adjust(mantel_res_ECM$p_geo, method = "BH")
mantel_res_ECM$p_geo_pH_adj <- p.adjust(mantel_res_ECM$p_geo_pH, method = "BH")
mantel_res_ECM$p_pH_geo_adj <- p.adjust(mantel_res_ECM$p_pH_geo, method = "BH")
mantel_res_ECM
## Plot n r_geo p_geo r_geo_pH p_geo_pH r_pH_geo p_pH_geo
## 1 AF 19 -0.15294587 0.9032 -0.15711127 0.9028 -0.051944461 0.6309
## 2 AT 18 -0.01924579 0.5235 -0.01970546 0.5334 0.007359699 0.4622
## 3 BF 21 -0.05018487 0.6531 -0.04453159 0.6406 -0.024435790 0.5790
## 4 BT 20 -0.16719714 0.9766 -0.17561797 0.9776 -0.034464525 0.5789
## 5 IF 19 -0.08476312 0.7312 -0.09241273 0.7518 0.052928550 0.2925
## 6 IT 11 -0.04301710 0.5891 -0.04022095 0.5735 -0.200568892 0.9408
## p_geo_adj p_geo_pH_adj p_pH_geo_adj
## 1 0.9766 0.9776 0.75708
## 2 0.9766 0.9776 0.75708
## 3 0.9766 0.9776 0.75708
## 4 0.9766 0.9776 0.75708
## 5 0.9766 0.9776 0.75708
## 6 0.9766 0.9776 0.94080
Prediction of Tree growth (rcsBAI) - all OTUs
meta2 <- as(sample_data(vst_physeq), "data.frame")
keep2 <- complete.cases(meta2[, c("Age","pH","Habitat","Site", "rcsBAI_5y", "rcsBAI_10y","rcsBAI_15y","rcsBAI_30y")])
vst_mat <- as.data.frame(t(otu_table(vst_physeq)))
vst_mat_clean2 <- vst_mat[keep2, ]
meta_clean2 <- meta2[keep2, ]
meta_clean2$rcsBAI_5y_trans <- log(meta_clean2$rcsBAI_5y)
meta_clean2$rcsBAI_10y_trans <- log(meta_clean2$rcsBAI_10y)
meta_clean2$rcsBAI_15y_trans <- log(meta_clean2$rcsBAI_15y)
meta_clean2$rcsBAI_30y_trans <- log(meta_clean2$rcsBAI_30y)
# PCA on OTU table
pca <- prcomp(vst_mat_clean2, scale. = TRUE)
pcs_df <- as.data.frame(pca$x[, 1:5])
# Add BAI and environmental predictors
pcs_df$rcsBAI_5y_trans <- meta_clean2$rcsBAI_5y_trans
pcs_df$rcsBAI_10y_trans <- meta_clean2$rcsBAI_10y_trans
pcs_df$rcsBAI_15y_trans <- meta_clean2$rcsBAI_15y_trans
pcs_df$rcsBAI_30y_trans <- meta_clean2$rcsBAI_30y_trans
pcs_df$pH <- meta_clean2$pH
pcs_df$Habitat <- meta_clean2$Habitat
pcs_df$Site <- meta_clean2$Site
# RDA using PCs + environmental variables
rda_comm <- rda(pcs_df$rcsBAI_5y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH),data = pcs_df)
anova(rda_comm, permutations = 9999)
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 9999
##
## Model: rda(formula = pcs_df$rcsBAI_5y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH), data = pcs_df)
## Df Variance F Pr(>F)
## Model 5 0.00514 0.1529 0.9787
## Residual 96 0.64578
RsquareAdj(rda_comm)
## $r.squared
## [1] 0.006007931
##
## $adj.r.squared
## [1] -0.03461367
rda_comm <- rda(pcs_df$rcsBAI_10y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH),data = pcs_df)
anova(rda_comm, permutations = 9999)
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 9999
##
## Model: rda(formula = pcs_df$rcsBAI_10y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH), data = pcs_df)
## Df Variance F Pr(>F)
## Model 5 0.00413 0.1241 0.9887
## Residual 96 0.63915
RsquareAdj(rda_comm)
## $r.squared
## [1] 0.004992691
##
## $adj.r.squared
## [1] -0.03663512
rda_comm <- rda(pcs_df$rcsBAI_15y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH),data = pcs_df)
anova(rda_comm, permutations = 9999)
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 9999
##
## Model: rda(formula = pcs_df$rcsBAI_15y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH), data = pcs_df)
## Df Variance F Pr(>F)
## Model 5 0.00413 0.127 0.9871
## Residual 96 0.62398
RsquareAdj(rda_comm)
## $r.squared
## [1] 0.005170612
##
## $adj.r.squared
## [1] -0.03696668
rda_comm <- rda(pcs_df$rcsBAI_30y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH),data = pcs_df)
anova(rda_comm, permutations = 9999)
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 9999
##
## Model: rda(formula = pcs_df$rcsBAI_30y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH), data = pcs_df)
## Df Variance F Pr(>F)
## Model 5 0.00754 0.2712 0.9279
## Residual 96 0.53365
RsquareAdj(rda_comm)
## $r.squared
## [1] 0.01094423
##
## $adj.r.squared
## [1] -0.03057621
Prediction of Tree growth (rcsBAI) - only ECM
tax_data <- tax_tab
tax_data_ECM <- tax_data[tax_data$Guild == "Ectomycorrhizal", ]
vst_mat_clean2_ECM <- vst_mat_clean2[, colnames(vst_mat_clean2) %in% tax_data_ECM$OTU]
# PCA on OTU table
pca_ECM <- prcomp(vst_mat_clean2_ECM, scale. = TRUE)
pcs_df_ECM <- as.data.frame(pca_ECM$x[, 1:5])
# Add BAI and environmental predictors
pcs_df_ECM$rcsBAI_5y_trans <- meta_clean2$rcsBAI_5y_trans
pcs_df_ECM$rcsBAI_10y_trans <- meta_clean2$rcsBAI_10y_trans
pcs_df_ECM$rcsBAI_15y_trans <- meta_clean2$rcsBAI_15y_trans
pcs_df_ECM$rcsBAI_30y_trans <- meta_clean2$rcsBAI_30y_trans
pcs_df_ECM$pH <- meta_clean2$pH
pcs_df_ECM$Habitat <- meta_clean2$Habitat
pcs_df_ECM$Site <- meta_clean2$Site
# RDA using PCs + environmental variables
rda_comm <- rda(pcs_df_ECM$rcsBAI_5y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH),data = pcs_df_ECM)
anova(rda_comm, permutations = 9999)
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 9999
##
## Model: rda(formula = pcs_df_ECM$rcsBAI_5y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH), data = pcs_df_ECM)
## Df Variance F Pr(>F)
## Model 5 0.02170 0.6621 0.6656
## Residual 96 0.62922
RsquareAdj(rda_comm)
## $r.squared
## [1] 0.02535657
##
## $adj.r.squared
## [1] -0.01345109
rda_comm <- rda(pcs_df_ECM$rcsBAI_10y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH),data = pcs_df_ECM)
anova(rda_comm, permutations = 9999)
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 9999
##
## Model: rda(formula = pcs_df_ECM$rcsBAI_10y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH), data = pcs_df_ECM)
## Df Variance F Pr(>F)
## Model 5 0.01974 0.6078 0.6986
## Residual 96 0.62355
RsquareAdj(rda_comm)
## $r.squared
## [1] 0.02385566
##
## $adj.r.squared
## [1] -0.01600374
rda_comm <- rda(pcs_df_ECM$rcsBAI_15y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH),data = pcs_df_ECM)
anova(rda_comm, permutations = 9999)
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 9999
##
## Model: rda(formula = pcs_df_ECM$rcsBAI_15y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH), data = pcs_df_ECM)
## Df Variance F Pr(>F)
## Model 5 0.01937 0.6108 0.6907
## Residual 96 0.60874
RsquareAdj(rda_comm)
## $r.squared
## [1] 0.02426958
##
## $adj.r.squared
## [1] -0.01607719
rda_comm <- rda(pcs_df_ECM$rcsBAI_30y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH),data = pcs_df_ECM)
anova(rda_comm, permutations = 9999)
## Permutation test for rda under reduced model
## Permutation: free
## Number of permutations: 9999
##
## Model: rda(formula = pcs_df_ECM$rcsBAI_30y_trans ~ PC1 + PC2 + PC3 + PC4 + PC5 + Condition(Site + Habitat + pH), data = pcs_df_ECM)
## Df Variance F Pr(>F)
## Model 5 0.01004 0.3628 0.877
## Residual 96 0.53115
RsquareAdj(rda_comm)
## $r.squared
## [1] 0.01457127
##
## $adj.r.squared
## [1] -0.02660913
OTU abundancy per Taxa per Site - treeline vs forest (age-adjusted):
Genus
# genus-level count matrix
rank <- "Genus"
tax_map <- as.data.frame(tax_tab[, c("OTU", rank)])
names(tax_map) <- c("OTU", "taxon")
tax_map <- tax_map[tax_map$taxon != "-" & !is.na(tax_map$taxon), ]
tax_map <- tax_map[tax_map$OTU %in% rownames(filt_count_tab_no_r), ]
taxon_counts <- rowsum(as.matrix(filt_count_tab_no_r[tax_map$OTU, ]),
group = tax_map$taxon)
# ---------- Alaska_Range
samples <- rownames(sample_info_no_R[sample_info_no_R$Site == "Alaska_Range", ])
samples <- samples[!is.na(sample_info_no_R[samples, "Age"])]
info <- sample_info_no_R[samples, ]
info$Habitat <- factor(info$Habitat, levels = c("forest", "treeline"))
info$Age_s <- as.numeric(scale(info$Age))
mat <- taxon_counts[, samples]
mat <- mat[rowSums(mat > 0) >= 3, ] # taxa in at least 3 trees
mat_ab <- mat[rowSums(mat > 0) >= ceiling(0.30 * ncol(mat)), ] # taxa in at least 30% of trees
dds <- DESeqDataSetFromMatrix(mat_ab, colData = info, design = ~ Age_s + Habitat)
dds <- estimateSizeFactors(dds, type = "poscounts")
res_hab <- results(DESeq(dds, test = "LRT", reduced = ~ Age_s, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
res_age <- results(DESeq(dds, test = "LRT", reduced = ~ Habitat, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
da_ar <- data.frame(Site = "Alaska_Range", taxon = rownames(res_hab),
log2FC = res_hab$log2FoldChange, p_adj = res_hab$padj,
log2FC_age = res_age$log2FoldChange, p_adj_age = res_age$padj)
occ_ar <- data.frame(Site = "Alaska_Range", taxon = rownames(mat),
n_forest = NA, n_treeline = NA, p = NA)
# one Fisher test per taxon
for (i in 1:nrow(mat)) {
tb <- table(factor(mat[i, ] > 0, levels = c(FALSE, TRUE)), info$Habitat)
occ_ar$n_forest[i] <- tb["TRUE", "forest"]
occ_ar$n_treeline[i] <- tb["TRUE", "treeline"]
occ_ar$p[i] <- fisher.test(tb)$p.value}
occ_ar$p_adj <- p.adjust(occ_ar$p, method = "BH")
occ_ar$p <- NULL
# ---------- Brooks_Range
samples <- rownames(sample_info_no_R[sample_info_no_R$Site == "Brooks_Range", ])
samples <- samples[!is.na(sample_info_no_R[samples, "Age"])]
info <- sample_info_no_R[samples, ]
info$Habitat <- factor(info$Habitat, levels = c("forest", "treeline"))
info$Age_s <- as.numeric(scale(info$Age))
mat <- taxon_counts[, samples]
mat <- mat[rowSums(mat > 0) >= 3, ] # taxa in at least 3 trees
mat_ab <- mat[rowSums(mat > 0) >= ceiling(0.30 * ncol(mat)), ] # taxa in at least 30% of trees
dds <- DESeqDataSetFromMatrix(mat_ab, colData = info, design = ~ Age_s + Habitat)
dds <- estimateSizeFactors(dds, type = "poscounts")
res_hab <- results(DESeq(dds, test = "LRT", reduced = ~ Age_s, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
res_age <- results(DESeq(dds, test = "LRT", reduced = ~ Habitat, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
da_br <- data.frame(Site = "Brooks_Range", taxon = rownames(res_hab),
log2FC = res_hab$log2FoldChange, p_adj = res_hab$padj,
log2FC_age = res_age$log2FoldChange, p_adj_age = res_age$padj)
occ_br <- data.frame(Site = "Brooks_Range", taxon = rownames(mat),
n_forest = NA, n_treeline = NA, p = NA)
# one Fisher test per taxon
for (i in 1:nrow(mat)) {
tb <- table(factor(mat[i, ] > 0, levels = c(FALSE, TRUE)), info$Habitat)
occ_br$n_forest[i] <- tb["TRUE", "forest"]
occ_br$n_treeline[i] <- tb["TRUE", "treeline"]
occ_br$p[i] <- fisher.test(tb)$p.value}
occ_br$p_adj <- p.adjust(occ_br$p, method = "BH")
occ_br$p <- NULL
# ---------- Interior
samples <- rownames(sample_info_no_R[sample_info_no_R$Site == "Interior", ])
samples <- samples[!is.na(sample_info_no_R[samples, "Age"])]
info <- sample_info_no_R[samples, ]
info$Habitat <- factor(info$Habitat, levels = c("forest", "treeline"))
info$Age_s <- as.numeric(scale(info$Age))
mat <- taxon_counts[, samples]
mat <- mat[rowSums(mat > 0) >= 3, ] # taxa in at least 3 trees
mat_ab <- mat[rowSums(mat > 0) >= ceiling(0.30 * ncol(mat)), ] # taxa in at least 30% of trees
dds <- DESeqDataSetFromMatrix(mat_ab, colData = info, design = ~ Age_s + Habitat)
dds <- estimateSizeFactors(dds, type = "poscounts")
res_hab <- results(DESeq(dds, test = "LRT", reduced = ~ Age_s, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
res_age <- results(DESeq(dds, test = "LRT", reduced = ~ Habitat, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
da_in <- data.frame(Site = "Interior", taxon = rownames(res_hab),
log2FC = res_hab$log2FoldChange, p_adj = res_hab$padj,
log2FC_age = res_age$log2FoldChange, p_adj_age = res_age$padj)
occ_in <- data.frame(Site = "Interior", taxon = rownames(mat),
n_forest = NA, n_treeline = NA, p = NA)
# one Fisher test per taxon
for (i in 1:nrow(mat)) {
tb <- table(factor(mat[i, ] > 0, levels = c(FALSE, TRUE)), info$Habitat)
occ_in$n_forest[i] <- tb["TRUE", "forest"]
occ_in$n_treeline[i] <- tb["TRUE", "treeline"]
occ_in$p[i] <- fisher.test(tb)$p.value}
occ_in$p_adj <- p.adjust(occ_in$p, method = "BH")
occ_in$p <- NULL
da_all <- rbind(da_ar, da_br, da_in)
occ_all <- rbind(occ_ar, occ_br, occ_in)
da_all[!is.na(da_all$p_adj) & da_all$p_adj < 0.05, ]
## Site taxon log2FC p_adj log2FC_age p_adj_age
## 2 Alaska_Range Beauveria 4.342565 4.150449e-07 4.342565 0.81476793
## 11 Alaska_Range Cryptocoryneum -3.939678 1.865102e-03 -3.939678 0.81476793
## 14 Alaska_Range Entomortierella -3.410494 1.957246e-03 -3.410494 0.81476793
## 23 Alaska_Range Kockovaella -3.216385 8.858492e-03 -3.216385 0.81476793
## 42 Alaska_Range Polyozellus 2.783391 2.110120e-04 2.783391 0.81476793
## 48 Alaska_Range Sistotrema -7.888183 8.858492e-03 -7.888183 0.81476793
## 50 Alaska_Range Tausonia 2.450374 1.705057e-02 2.450374 0.81476793
## 54 Alaska_Range Trechispora 3.088146 1.865102e-03 3.088146 0.81476793
## 62 Brooks_Range Capronia -2.787358 1.535374e-04 -2.787358 0.34258592
## 64 Brooks_Range Chromolaenicola -4.518377 1.349909e-02 -4.518377 0.81676531
## 65 Brooks_Range Cladophialophora -1.222143 6.299402e-03 -1.222143 0.19516946
## 69 Brooks_Range Cryptocoryneum -4.729571 1.512520e-02 -4.729571 0.58435677
## 71 Brooks_Range Epicoccum 2.532034 7.039523e-03 2.532034 0.90050251
## 72 Brooks_Range Exophiala 1.511187 1.538781e-02 1.511187 0.51429585
## 76 Brooks_Range Hygrophorus -5.093006 1.559046e-02 -5.093006 0.12208945
## 77 Brooks_Range Inocybe 2.065431 4.694431e-02 2.065431 0.64326468
## 84 Brooks_Range Morinia 3.788824 2.913600e-03 3.788824 0.12208945
## 88 Brooks_Range Mycenella 3.216261 4.739507e-02 3.216261 0.14633306
## 89 Brooks_Range Niesslia -2.020244 1.559046e-02 -2.020244 0.51429585
## 100 Brooks_Range Ramoconidiophora 2.634735 2.798298e-03 2.634735 0.01220521
## 109 Brooks_Range Tomentella 2.318341 2.798298e-03 2.318341 0.51429585
## 150 Interior Penicillium 1.456904 3.402592e-02 1.456904 0.90990698
occ_all[occ_all$p_adj < 0.05, ]
## Site taxon n_forest n_treeline p_adj
## 16 Alaska_Range Cryptocoryneum 17 3 0.0008353244
## 20 Alaska_Range Epicoccum 4 14 0.0375532922
## 124 Brooks_Range Lyomyces 0 11 0.0045718417
da_all[!is.na(da_all$p_adj_age) & da_all$p_adj_age < 0.05, ] # taxa driven by age
## Site taxon log2FC p_adj log2FC_age p_adj_age
## 100 Brooks_Range Ramoconidiophora 2.6347351 0.002798298 2.6347351 0.012205213
## 117 Interior Calonarius 0.9460503 0.483862591 0.9460503 0.007543203
res_all <- merge(da_all, occ_all, by = c("Site", "taxon"),
all = TRUE, suffixes = c("_abund", "_occ"))
res_all$log2FC <- signif(res_all$log2FC, 3) # signif, not round: keeps small p-values
res_all$p_adj_abund <- signif(res_all$p_adj_abund, 3)
res_all$log2FC_age <- signif(res_all$log2FC_age, 3)
res_all$p_adj_age <- signif(res_all$p_adj_age, 3)
res_all$p_adj_occ <- signif(res_all$p_adj_occ, 3)
write.csv(res_all, "Habitat_tests.csv", row.names = FALSE)
OTU abundancy per Taxa per Site - treeline vs forest (age-adjusted):
Species
# genus-level count matrix
rank <- "Species...14"
tax_map <- as.data.frame(tax_tab[, c("OTU", rank)])
names(tax_map) <- c("OTU", "taxon")
tax_map <- tax_map[tax_map$taxon != "-" & !is.na(tax_map$taxon), ]
tax_map <- tax_map[tax_map$OTU %in% rownames(filt_count_tab_no_r), ]
taxon_counts <- rowsum(as.matrix(filt_count_tab_no_r[tax_map$OTU, ]),
group = tax_map$taxon)
# ---------- Alaska_Range
samples <- rownames(sample_info_no_R[sample_info_no_R$Site == "Alaska_Range", ])
samples <- samples[!is.na(sample_info_no_R[samples, "Age"])]
info <- sample_info_no_R[samples, ]
info$Habitat <- factor(info$Habitat, levels = c("forest", "treeline"))
info$Age_s <- as.numeric(scale(info$Age))
mat <- taxon_counts[, samples]
mat <- mat[rowSums(mat > 0) >= 3, ] # taxa in at least 3 trees
mat_ab <- mat[rowSums(mat > 0) >= ceiling(0.30 * ncol(mat)), ] # taxa in at least 30% of trees
dds <- DESeqDataSetFromMatrix(mat_ab, colData = info, design = ~ Age_s + Habitat)
dds <- estimateSizeFactors(dds, type = "poscounts")
res_hab <- results(DESeq(dds, test = "LRT", reduced = ~ Age_s, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
res_age <- results(DESeq(dds, test = "LRT", reduced = ~ Habitat, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
da_ar <- data.frame(Site = "Alaska_Range", taxon = rownames(res_hab),
log2FC = res_hab$log2FoldChange, p_adj = res_hab$padj,
log2FC_age = res_age$log2FoldChange, p_adj_age = res_age$padj)
occ_ar <- data.frame(Site = "Alaska_Range", taxon = rownames(mat),
n_forest = NA, n_treeline = NA, p = NA)
# one Fisher test per taxon
for (i in 1:nrow(mat)) {
tb <- table(factor(mat[i, ] > 0, levels = c(FALSE, TRUE)), info$Habitat)
occ_ar$n_forest[i] <- tb["TRUE", "forest"]
occ_ar$n_treeline[i] <- tb["TRUE", "treeline"]
occ_ar$p[i] <- fisher.test(tb)$p.value}
occ_ar$p_adj <- p.adjust(occ_ar$p, method = "BH")
occ_ar$p <- NULL
# ---------- Brooks_Range
samples <- rownames(sample_info_no_R[sample_info_no_R$Site == "Brooks_Range", ])
samples <- samples[!is.na(sample_info_no_R[samples, "Age"])]
info <- sample_info_no_R[samples, ]
info$Habitat <- factor(info$Habitat, levels = c("forest", "treeline"))
info$Age_s <- as.numeric(scale(info$Age))
mat <- taxon_counts[, samples]
mat <- mat[rowSums(mat > 0) >= 3, ] # taxa in at least 3 trees
mat_ab <- mat[rowSums(mat > 0) >= ceiling(0.30 * ncol(mat)), ] # taxa in at least 30% of trees
dds <- DESeqDataSetFromMatrix(mat_ab, colData = info, design = ~ Age_s + Habitat)
dds <- estimateSizeFactors(dds, type = "poscounts")
res_hab <- results(DESeq(dds, test = "LRT", reduced = ~ Age_s, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
res_age <- results(DESeq(dds, test = "LRT", reduced = ~ Habitat, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
da_br <- data.frame(Site = "Brooks_Range", taxon = rownames(res_hab),
log2FC = res_hab$log2FoldChange, p_adj = res_hab$padj,
log2FC_age = res_age$log2FoldChange, p_adj_age = res_age$padj)
occ_br <- data.frame(Site = "Brooks_Range", taxon = rownames(mat),
n_forest = NA, n_treeline = NA, p = NA)
# one Fisher test per taxon
for (i in 1:nrow(mat)) {
tb <- table(factor(mat[i, ] > 0, levels = c(FALSE, TRUE)), info$Habitat)
occ_br$n_forest[i] <- tb["TRUE", "forest"]
occ_br$n_treeline[i] <- tb["TRUE", "treeline"]
occ_br$p[i] <- fisher.test(tb)$p.value}
occ_br$p_adj <- p.adjust(occ_br$p, method = "BH")
occ_br$p <- NULL
# ---------- Interior
samples <- rownames(sample_info_no_R[sample_info_no_R$Site == "Interior", ])
samples <- samples[!is.na(sample_info_no_R[samples, "Age"])]
info <- sample_info_no_R[samples, ]
info$Habitat <- factor(info$Habitat, levels = c("forest", "treeline"))
info$Age_s <- as.numeric(scale(info$Age))
mat <- taxon_counts[, samples]
mat <- mat[rowSums(mat > 0) >= 3, ] # taxa in at least 3 trees
mat_ab <- mat[rowSums(mat > 0) >= ceiling(0.30 * ncol(mat)), ] # taxa in at least 30% of trees
dds <- DESeqDataSetFromMatrix(mat_ab, colData = info, design = ~ Age_s + Habitat)
dds <- estimateSizeFactors(dds, type = "poscounts")
res_hab <- results(DESeq(dds, test = "LRT", reduced = ~ Age_s, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
res_age <- results(DESeq(dds, test = "LRT", reduced = ~ Habitat, fitType = "local", quiet = TRUE),
pAdjustMethod = "BH", independentFiltering = FALSE, cooksCutoff = FALSE)
da_in <- data.frame(Site = "Interior", taxon = rownames(res_hab),
log2FC = res_hab$log2FoldChange, p_adj = res_hab$padj,
log2FC_age = res_age$log2FoldChange, p_adj_age = res_age$padj)
occ_in <- data.frame(Site = "Interior", taxon = rownames(mat),
n_forest = NA, n_treeline = NA, p = NA)
# one Fisher test per taxon
for (i in 1:nrow(mat)) {
tb <- table(factor(mat[i, ] > 0, levels = c(FALSE, TRUE)), info$Habitat)
occ_in$n_forest[i] <- tb["TRUE", "forest"]
occ_in$n_treeline[i] <- tb["TRUE", "treeline"]
occ_in$p[i] <- fisher.test(tb)$p.value}
occ_in$p_adj <- p.adjust(occ_in$p, method = "BH")
occ_in$p <- NULL
da_all <- rbind(da_ar, da_br, da_in)
occ_all <- rbind(occ_ar, occ_br, occ_in)
da_all[!is.na(da_all$p_adj) & da_all$p_adj < 0.05, ]
## Site taxon log2FC p_adj
## 1 Alaska_Range Beauveria_pseudobassiana 3.649517 0.0002903636
## 16 Alaska_Range Cryptocoryneum_rosae -4.087998 0.0011466793
## 18 Alaska_Range Entomortierella_parvispora -3.798724 0.0005579081
## 25 Alaska_Range Kockovaella_prillingeri -3.426342 0.0056070119
## 33 Alaska_Range Mortierella_basiparvispora 1.880578 0.0110938764
## 47 Alaska_Range Penicillium_penicillioides 2.373798 0.0112795229
## 50 Alaska_Range Penicillium_zhuangii 2.952082 0.0003625886
## 53 Alaska_Range Piloderma_sphaerosporum 7.451743 0.0028908894
## 55 Alaska_Range Polyozellus_umbrinus 2.294560 0.0019527050
## 61 Alaska_Range Trechispora_stevensonii 3.220696 0.0259713585
## 69 Brooks_Range Capronia_rubiginosa -3.127476 0.0002653942
## 71 Brooks_Range Chromolaenicola_chiangraiensis -4.670736 0.0072783114
## 72 Brooks_Range Cladophialophora_humicola -2.749632 0.0253653950
## 80 Brooks_Range Epicoccum_pimprinum 2.537788 0.0072783114
## 87 Brooks_Range Inocybe_laurina 5.513002 0.0448568380
## 94 Brooks_Range Morinia_trachycarpi 3.828502 0.0027966485
## 98 Brooks_Range Mycena_metata -7.631310 0.0014818585
## 114 Brooks_Range Ramoconidiophora_euphorbiae 2.584934 0.0027966485
## 116 Brooks_Range Sebacina_epigaea 5.458064 0.0485076829
## 123 Brooks_Range Umbelopsis_ramanniana -3.494340 0.0052055625
## 152 Interior Inocybe_flocculosa 14.618793 0.0119182030
## 169 Interior Penicillium_aquadulcis 2.021580 0.0012831434
## 173 Interior Penicillium_monsserratidens 4.179226 0.0011387603
## 174 Interior Penicillium_raistrickii 2.450242 0.0150578861
## log2FC_age p_adj_age
## 1 3.649517 0.7246464746
## 16 -4.087998 0.6182380084
## 18 -3.798724 0.7145823689
## 25 -3.426342 0.7246464746
## 33 1.880578 0.5187994750
## 47 2.373798 0.5187994750
## 50 2.952082 0.5187994750
## 53 7.451743 0.5187994750
## 55 2.294560 0.7246464746
## 61 3.220696 0.5197813882
## 69 -3.127476 0.2000028228
## 71 -4.670736 1.0000000000
## 72 -2.749632 0.9995696864
## 80 2.537788 0.9995696864
## 87 5.513002 0.8365682379
## 94 3.828502 0.0757154193
## 98 -7.631310 0.5848784580
## 114 2.584934 0.0007831878
## 116 5.458064 0.8365682379
## 123 -3.494340 0.9995696864
## 152 14.618793 0.0925341429
## 169 2.021580 0.4796850033
## 173 4.179226 0.7883266662
## 174 2.450242 0.8738475504
occ_all[occ_all$p_adj < 0.05, ]
## Site taxon n_forest n_treeline p_adj
## 49 Alaska_Range Cryptocoryneum_rosae 17 3 0.001388853
## 52 Alaska_Range Epicoccum_pimprinum 4 14 0.041625336
## 108 Alaska_Range Piloderma_sphaerosporum 3 14 0.016130321
## 228 Brooks_Range Lyomyces_sambuci 0 11 0.008665235
da_all[!is.na(da_all$p_adj_age) & da_all$p_adj_age < 0.05, ] # taxa driven by age
## Site taxon log2FC p_adj log2FC_age
## 114 Brooks_Range Ramoconidiophora_euphorbiae 2.584934 0.002796649 2.584934
## 117 Brooks_Range Sebacina_incrustans 4.772042 0.138180141 4.772042
## p_adj_age
## 114 0.0007831878
## 117 0.0240692922
res_all <- merge(da_all, occ_all, by = c("Site", "taxon"),
all = TRUE, suffixes = c("_abund", "_occ"))
res_all$log2FC <- signif(res_all$log2FC, 3) # signif, not round: keeps small p-values
res_all$p_adj_abund <- signif(res_all$p_adj_abund, 3)
res_all$log2FC_age <- signif(res_all$log2FC_age, 3)
res_all$p_adj_age <- signif(res_all$p_adj_age, 3)
res_all$p_adj_occ <- signif(res_all$p_adj_occ, 3)
write.csv(res_all, "Habitat_tests_species.csv", row.names = FALSE)
OTU abundancy per Taxa per Site
tax_data <-tax_tab
tax_data <- tax_data[tax_data$OTU %in% rownames(filt_count_tab_no_r), ] # I used row counts
counts_tree <- as.data.frame(filt_count_tab_no_r)
counts_tree$OTU<-rownames(counts_tree)
rownames(counts_tree) <- NULL
# Combine tables sorting by OTU
Tax_otu_data <- left_join(tax_data, counts_tree, by = "OTU" )
Sites <- unique(sample_info_no_R$Site)
set.seed(50)
samples <- rownames(sample_info_no_R[sample_info_no_R$Site == "Alaska_Range", ])
obj_ar <- parse_tax_data(Tax_otu_data, class_cols = "taxonomy", class_sep = ";")
## New names:
## • `Species...4` -> `Species...5`
## • `Species...14` -> `Species...15`
obj_ar <- filter_taxa(obj_ar, taxon_names != "-")
obj_ar$data$tax_abund <- calc_taxon_abund(obj_ar, data = "tax_data", cols = samples)
## Summing per-taxon counts from 40 columns for 437 taxa
obj_ar$data$tax_abund$total_counts <- rowSums(obj_ar$data$tax_abund[, samples])
samples <- rownames(sample_info_no_R[sample_info_no_R$Site == "Brooks_Range", ])
obj_br <- parse_tax_data(Tax_otu_data, class_cols = "taxonomy", class_sep = ";")
## New names:
## • `Species...4` -> `Species...5`
## • `Species...14` -> `Species...15`
obj_br <- filter_taxa(obj_br, taxon_names != "-")
obj_br$data$tax_abund <- calc_taxon_abund(obj_br, data = "tax_data", cols = samples)
## Summing per-taxon counts from 41 columns for 437 taxa
obj_br$data$tax_abund$total_counts <- rowSums(obj_br$data$tax_abund[, samples])
samples <- rownames(sample_info_no_R[sample_info_no_R$Site == "Interior", ])
obj_in <- parse_tax_data(Tax_otu_data, class_cols = "taxonomy", class_sep = ";")
## New names:
## • `Species...4` -> `Species...5`
## • `Species...14` -> `Species...15`
obj_in <- filter_taxa(obj_in, taxon_names != "-")
obj_in$data$tax_abund <- calc_taxon_abund(obj_in, data = "tax_data", cols = samples)
## Summing per-taxon counts from 30 columns for 437 taxa
obj_in$data$tax_abund$total_counts <- rowSums(obj_in$data$tax_abund[, samples])
results <- list(Alaska_Range = obj_ar, Brooks_Range = obj_br, Interior = obj_in)
obj_loc <- results[["Alaska_Range"]]
obj_loc_D <- filter_taxa(obj_loc, n_obs > 1)
set.seed(50)
hD<-heat_tree(obj_loc_D, node_label = gsub(pattern = "\\[|\\]", replacement = "", taxon_names),
node_size = log(total_counts),
node_size_range = c(0.0005, 0.025),
node_color = log(total_counts), # one taxa with 0 counts
node_color_range = c("white","#33BBEE","#EE7733"),
node_label_size_range = c(0.01, 0.025),
node_color_axis_label = "Abundance log(count number)",
layout = "davidson-harel", initial_layout = "reingold-tilford")
## Warning: Infinite values found for "node_size". These will be graphed in the same way as the largest (Inf) or smallest (-Inf) real number supplied.
## Warning: Infinite values found for "edge_size". These will be graphed in the same way as the largest (Inf) or smallest (-Inf) real number supplied.
## Warning: Infinite values found for "node_label_size". These will be graphed in the same way as the largest (Inf) or smallest (-Inf) real number supplied.
## Warning: Infinite values found for "edge_label_size". These will be graphed in the same way as the largest (Inf) or smallest (-Inf) real number supplied.
plot(hD)

obj_loc <- results[["Brooks_Range"]]
obj_loc_B <- filter_taxa(obj_loc, n_obs > 1)
set.seed(50)
hB<-heat_tree(obj_loc_B, node_label = gsub(pattern = "\\[|\\]", replacement = "", taxon_names),
node_size = log(total_counts),
node_size_range = c(0.0005, 0.025),
node_color = log(total_counts), # no zeros
node_color_range = c("white","#33BBEE","#EE7733"),
node_label_size_range = c(0.01, 0.025),
node_color_axis_label = "Abundance log(count number)",
layout = "davidson-harel", initial_layout = "reingold-tilford")
plot(hB)

obj_loc <- results[["Interior"]]
obj_loc_I <- filter_taxa(obj_loc, n_obs > 1)
set.seed(50)
hI<-heat_tree(obj_loc_I, node_label = gsub(pattern = "\\[|\\]", replacement = "", taxon_names),
node_size = log(total_counts),
node_size_range = c(0.0005, 0.025),
node_color = log(total_counts), #three taxa with 0 counts
node_color_range = c("white","#33BBEE","#EE7733"),
node_label_size_range = c(0.01, 0.025),
node_color_axis_label = "Abundance log(count number)",
layout = "davidson-harel", initial_layout = "reingold-tilford")
## Warning: Infinite values found for "node_size". These will be graphed in the same way as the largest (Inf) or smallest (-Inf) real number supplied.
## Warning: Infinite values found for "edge_size". These will be graphed in the same way as the largest (Inf) or smallest (-Inf) real number supplied.
## Warning: Infinite values found for "node_label_size". These will be graphed in the same way as the largest (Inf) or smallest (-Inf) real number supplied.
## Warning: Infinite values found for "edge_label_size". These will be graphed in the same way as the largest (Inf) or smallest (-Inf) real number supplied.
plot(hI)

Species diversty (All OTUs): treeline vs forest
#Hill number = effective number of species. Hill numbers determines the measures’ sensitivity to species relative abundances. Hill numbers include the three most widely used species diversity measures as special cases: species richness (q = 0), Shannon diversity (q = 1, as the effective number of common species in the assemblage) and Simpson diversity (q = 2, effective number of dominant species in the assemblage)
#I used row counts of reads after removing of OTUs found in NTCs and technical replicates
count_tab <-filt_count_tab_no_r
count_tab <- as.data.frame(count_tab > 0) # to make presence/absence matrix
fD_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "forest" & sample_info_no_R$Site == "Alaska_Range",]
fD_counts_col <- count_tab[colnames(count_tab) %in% rownames(fD_info_rows) ]
tD_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "treeline" & sample_info_no_R$Site == "Alaska_Range", ]
tD_counts_col <- count_tab[colnames(count_tab) %in% rownames(tD_info_rows) ]
fI_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "forest" & sample_info_no_R$Site == "Interior",]
fI_counts_col <- count_tab[colnames(count_tab) %in% rownames(fI_info_rows) ]
tI_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "treeline" & sample_info_no_R$Site == "Interior", ]
tI_counts_col <- count_tab[colnames(count_tab) %in% rownames(tI_info_rows) ]
fB_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "forest" & sample_info_no_R$Site == "Brooks_Range",]
fB_counts_col <- count_tab[colnames(count_tab) %in% rownames(fB_info_rows) ]
tB_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "treeline" & sample_info_no_R$Site == "Brooks_Range", ]
tB_counts_col <- count_tab[colnames(count_tab) %in% rownames(tB_info_rows) ]
# create a dataframe with incidence data summed by rows within plots
inc_bytype<- cbind(rowSums(fD_counts_col), rowSums(tD_counts_col), rowSums(fI_counts_col), rowSums(tI_counts_col), rowSums(fB_counts_col), rowSums(tB_counts_col))
colnames(inc_bytype) <- c("A_Forest", "A_Treeline", "I_Forest", "I_Treeline","B_Forest", "B_Treeline")
inc_bytype<-as.data.frame(inc_bytype)
n_samples <-c(ncol(fD_counts_col), ncol(tD_counts_col), ncol(fI_counts_col), ncol(tI_counts_col), ncol(fB_counts_col), ncol(tB_counts_col))
rownames(inc_bytype)<-tax_data$OTU
inc_bytype <-rbind(n_samples, inc_bytype)
# Get the diversity estimates
out <- iNEXT(inc_bytype, q=c(0,1,2), datatype ="incidence_freq", se = TRUE)
# Plot the diversity estimates
# Sample-size-based rarefaction and extrapolation (R/E) curve (type=1). This curve plots diversity estimates with 95% confidence intervals (if se=TRUE) as a function of sample size up to double the reference sample size, by default, or a user‐specified endpoint:
ggiNEXT(out, type=1, facet.var="Order.q", se = TRUE, color.var="Assemblage")

ggiNEXT(out, type=2, facet.var="None", color.var="Assemblage", se = TRUE)

Species diversty (ECM OTUs): treeline vs forest
#I used row counts of reads after removing of OTUs found in NTCs and technical replicates
count_tab <-filt_count_tab_no_r
# filter OTU from tax_data:
tax_data <- tax_tab[tax_tab$OTU %in% rownames(count_tab), ]
tax_data_ECM <- tax_data[tax_data$Guild %in% "Ectomycorrhizal", ]
count_tab <- count_tab[rownames(count_tab) %in% tax_data_ECM$OTU, ]
count_tab <- as.data.frame(count_tab > 0) # presence/absence matrix
fD_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "forest" & sample_info_no_R$Site == "Alaska_Range",]
fD_counts_col <- count_tab[colnames(count_tab) %in% rownames(fD_info_rows) ]
tD_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "treeline" & sample_info_no_R$Site == "Alaska_Range", ]
tD_counts_col <- count_tab[colnames(count_tab) %in% rownames(tD_info_rows) ]
fI_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "forest" & sample_info_no_R$Site == "Interior",]
fI_counts_col <- count_tab[colnames(count_tab) %in% rownames(fI_info_rows) ]
tI_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "treeline" & sample_info_no_R$Site == "Interior", ]
tI_counts_col <- count_tab[colnames(count_tab) %in% rownames(tI_info_rows) ]
fB_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "forest" & sample_info_no_R$Site == "Brooks_Range",]
fB_counts_col <- count_tab[colnames(count_tab) %in% rownames(fB_info_rows) ]
tB_info_rows <- sample_info_no_R[sample_info_no_R$Habitat == "treeline" & sample_info_no_R$Site == "Brooks_Range", ]
tB_counts_col <- count_tab[colnames(count_tab) %in% rownames(tB_info_rows) ]
# create a dataframe with incidence data summed by rows within plots
inc_bytype<- cbind(rowSums(fD_counts_col), rowSums(tD_counts_col), rowSums(fI_counts_col), rowSums(tI_counts_col), rowSums(fB_counts_col), rowSums(tB_counts_col))
colnames(inc_bytype) <- c("A_Forest", "A_Treeline", "I_Forest", "I_Treeline","B_Forest", "B_Treeline")
inc_bytype<-as.data.frame(inc_bytype)
n_samples <-c(ncol(fD_counts_col), ncol(tD_counts_col), ncol(fI_counts_col), ncol(tI_counts_col), ncol(fB_counts_col), ncol(tB_counts_col))
inc_bytype <-rbind(n_samples, inc_bytype)
# Get the diversity estimates
out <- iNEXT(inc_bytype, q=c(0,1,2), datatype ="incidence_freq", se = TRUE)
# Plot the diversity estimates
# Sample-size-based rarefaction and extrapolation (R/E) curve (type=1). This curve plots diversity estimates with 95% confidence intervals (if se=TRUE) as a function of sample size up to double the reference sample size, by default, or a user‐specified endpoint:
ggiNEXT(out, type=1, facet.var="Order.q", se = TRUE, color.var="Assemblage")
