# Script to test whether birds from a WWTP have a more diverse resistome, and produce nice graphs. rm(list=ls(all=TRUE)) library(coin) library (rcompanion) library(ggplot2) variables <- read.csv("variables.csv") variables$Impact <- factor(variables$Impact,c("WTP","Other")) variables$Loc <- factor(variables$Loc,c("WTP","Yallock Creek","King Island","Innaminkca","Kopaitik","GGV")) variables$Order <- factor(variables$Order,c("Anseriformes","Charadriiformes","Sphenisciformes")) variables$Impact2 <- factor(variables$Impact2,c("High","Medium","Low")) #### Plots by pollution category #### bl <- "#4271AE" gr = "grey56" Impact.summary <- aggregate(. ~ Impact, mean, data=variables) plot_AMRg <- ggplot(variables, aes(x = Impact, y = AMR_genes, color = Impact)) + geom_jitter(width=0.2, size=10) + geom_crossbar(data=Impact.summary,aes(ymin = AMR_genes, ymax = AMR_genes), size=.7, width = .6) + theme_bw() + scale_color_grey(start=0, end=0.6) plot_AMRg plot_antib <- ggplot(variables, aes(x = Impact, y = Antibiotics, color = Impact)) + geom_jitter(width=0.2, size=10) + geom_crossbar(data=Impact.summary,aes(ymin = Antibiotics, ymax = Antibiotics), size=.7, width = .6) + theme_bw() + scale_color_grey(start=0, end=0.6) plot_antib plot_AMRabund <- ggplot(variables, aes(x = Impact, y = AMR_abundance, color = Impact)) + geom_jitter(width=0.2, size=10) + geom_crossbar(data=Impact.summary,aes(ymin = AMR_abundance, ymax = AMR_abundance), size=.7, width = .6) + theme_bw() + scale_color_grey(start=0, end=0.6) plot_AMRabund #### Plots by loc, using impact categories (low, medium and high) to draw median lines Impact2.summary <- aggregate(. ~ Impact2, mean, data=variables) #AMR genes x Loc ggplot(variables, aes(x = Loc, y = AMR_genes, color = Impact2)) + geom_jitter(width=0.2, size=10) + geom_crossbar(data=Impact2.summary, aes(ymin = AMR_genes, ymax = AMR_genes), size=.7, width = 1) + theme_bw() + scale_color_brewer(palette="Set1") # AMR Antibiotic claasses ggplot(variables, aes(x = Loc, y = Antibiotics, color = Impact2)) + geom_jitter(width=0.2, size=10) + geom_crossbar(data=Impact2.summary, aes(ymin = Antibiotics, ymax = Antibiotics), size=.7, width = 1) + theme_bw() + scale_color_brewer(palette="Set1") # AMR abundance ggplot(variables, aes(x = Loc, y = AMR_abundance, color = Impact2)) + geom_jitter(width=0.2, size=10) + geom_crossbar(data=Impact2.summary, aes(ymin = AMR_abundance, ymax = AMR_abundance), size=.7, width = 1) + theme_bw() + scale_color_brewer(palette="Set1") #### Plots by Bird Order #### Order.summary <- aggregate(. ~ Order, mean, data=variables) #AMR div ggplot(variables, aes(x = Order, y = AMR_genes, color = Order)) + geom_jitter(width=0.2, size=10) + geom_crossbar(data=Order.summary, aes(ymin = AMR_genes, ymax = AMR_genes), size=.7, width = 1) + theme_bw() + scale_color_brewer(palette="Accent") #AMR Antibiotic classes ggplot(variables, aes(x = Order, y = Antibiotics, color = Order)) + geom_jitter(width=0.2, size=10) + geom_crossbar(data=Order.summary, aes(ymin = Antibiotics, ymax = Antibiotics), size=.7, width = 1) + theme_bw() + scale_color_brewer(palette="Accent") #AMR Abundance ggplot(variables, aes(x = Order, y = AMR_abundance, color = Order)) + geom_jitter(width=0.2, size=10) + geom_crossbar(data=Order.summary, aes(ymin = AMR_abundance, ymax = AMR_abundance), size=.7, width = 1) + theme_bw() + scale_color_brewer(palette="Accent") ### Statistics ### ## Impact ## #kruskal-wallis test kw_AMR_genes <- kruskal.test(variables$AMR_genes ~ variables$Impact) kw_AMR_genes #data: variables$AMR_genes by variables$Impact #Kruskal-Wallis chi-squared = 7.1296, df = 1, p-value = 0.007582 kw_antib <- kruskal.test(variables$Antibiotics ~ variables$Impact) kw_antib #data: variables$Antibiotics by variables$Impact #Kruskal-Wallis chi-squared = 4.353, df = 1, p-value = 0.03694 kw_AMR_ab <- kruskal.test(variables$AMR_abundance ~ variables$Impact) kw_AMR_ab #data: variables$AMR_abundance by variables$Impact #Kruskal-Wallis chi-squared = 7, df = 1, p-value = 0.008151 ######## # Test for differences between 10 birds from the WWTP and 10 birds from PB # VRMarcelino - 13-Sep-2018 rm(list=ls(all=TRUE)) library(ggplot2) variables <- read.csv("00_AMRcounts.csv") rownames(variables) <- variables[,1] variables <- variables[,2:9] variables$Impact <- factor(variables$Impact,c("WWTP","Pristine")) ## Diversity of genes #kruskal-wallis test kw_AMR_genes <- kruskal.test(variables$AMR_diversity ~ variables$Impact) kw_AMR_genes # Kruskal-Wallis chi-squared = 9.2551, df = 1, p-value = 0.002348 ######## # Script to produce a PCoA of the pathways found in bird microbiome, # and test differences with random forest. # VRMarcelino - 06 - Feb - 2018 rm(list=ls(all=TRUE)) library(ggplot2) library(ape) # for pcoa function library(randomForest) library (rcompanion) # Read data paths_raw <- read.table("paths_ednames.tsv") paths_raw <- t(paths_raw) rownames(paths_raw) <- paths_raw[,1] colnames(paths_raw) <- paths_raw[1,] paths <- paths_raw[-1,-1] # Remove Unintegrated and unmapped: paths <- subset(paths, select = -c(UNINTEGRATED, UNMAPPED)) variables <- read.csv("variables.csv") rownames(variables) <- variables[,1] # Normalise for extreme distributions using the shifted logarithm (log2(n + 1)). class(paths) <- "numeric" paths_log <- log2(paths + 1) dm <- dist(paths_log) path.pcoa <- pcoa(dm) # Merge data PCi <- merge(data.frame(path.pcoa$vectors), variables, by="row.names") # Plot Bird order and Impact Order = PCi$Order Impact <- PCi$Impact # Order and Impact ggplot(PCi,aes(x=Axis.1,y=Axis.2,group = interaction(Order,Impact))) + geom_point(aes(colour = Order, shape = Impact),size=5,alpha=0.8) + theme_classic() # Random Forests # merge tables (make sure they are in order!) # Do not use logs (Random Forests does not require normalisation) paths_and_vars_ord <- cbind(Order=as.character(variables$Order), paths) paths_and_vars_imp <- cbind(Impact=as.character(variables$Impact), paths) ## Random Forest for Bird Order: set.seed(71) order_rf <- randomForest(Order ~ ., data = paths_and_vars_ord, ntree = 1000, importance=TRUE) print(order_rf) #calculate importance of pathways in discriminating between groups: imp_Order <- importance(order_rf,type=1) write.csv(imp_Order, "imp_Order.csv") ## Impact imp_rf <- randomForest(Impact ~ ., data = paths_and_vars_imp, ntree = 1000, importance=TRUE) print(imp_rf) imp_Impact <- importance(imp_rf,type=1) write.csv(imp_Impact, "imp_Impact.csv") ### Test correlation between bacterial reads and R genes: # for spearman / pearson test - replace ''pearson with spearman' ### Test correlation between library size and R genes ggscatter(variables, x = "lib_size", y = "AMR_genes", add = "reg.line", conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson", xlab = "lib_size", ylab = "AMR gene diversity") ggscatter(variables, x = "lib_size", y = "AMR_abundance", add = "reg.line", conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson", xlab = "lib_size", ylab = "AMR_abundance") ggscatter(variables, x = "lib_size", y = "Antibiotics", add = "reg.line", conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson", xlab = "lib_size", ylab = "Antibiotics") ### Test correlation between bacterial reads and R genes: ggscatter(variables, x = "bac_reads", y = "AMR_genes", add = "reg.line", conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson", xlab = "microbial_reads", ylab = "AMR gene diversity") ggscatter(variables, x = "bac_reads", y = "AMR_abundance", add = "reg.line", conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson", xlab = "microbial_reads", ylab = "AMR_abundance") ggscatter(variables, x = "bac_reads", y = "Antibiotics", add = "reg.line", conf.int = TRUE, cor.coef = TRUE, cor.method = "pearson", xlab = "microbial_reads", ylab = "Antibiotics") ####################### confounding tests: # Script to test for confounding effects of library size size (sequencing depth) rm(list=ls(all=TRUE)) library(ggplot2) library(lme4) library(ggpubr) variables <- read.csv("variables.csv") variables$Impact <- factor(variables$Impact,c("WTP","Other")) variables$Loc <- factor(variables$Loc,c("WTP","Yallock Creek","King Island","Innaminkca","Kopaitik","GGV")) variables$Order <- factor(variables$Order,c("Anseriformes","Charadriiformes","Sphenisciformes")) variables$Impact2 <- factor(variables$Impact2,c("High","Medium","Low")) ###### Nested model ###### #### AMR genes #### model1_no_conf <- lm(log(AMR_genes) ~ Impact, data=variables) summary(model1_no_conf) model1 <- lm(log(AMR_genes) ~ Impact + lib_size, data=variables) summary(model1) plot(model1) #### Abundance #### model2_no_conf <- lm(log(AMR_abundance) ~ Impact, data=variables) summary(model2_no_conf) model2 <- lm(log(AMR_abundance) ~ Impact + lib_size, data=variables) summary(model2) plot(model2) #### Antibiotic classes #### model3_no_conf <- lm(log(Antibiotics) ~ Impact, data=variables) summary(model3_no_conf) model3 <- lm(log(Antibiotics) ~ Impact + lib_size, data=variables) summary(model3) plot(model3)