library(ggplot2) library(multcomp) library(survminer) library(coxme) library(tidyverse) library(wrappedtools) library(growthcurver) library(rstatix) library(glmmADMB) FoodChoice <- read.delim("C:/") #set to file location attach(FoodChoice) #Testing for normal distribution and calculating medians as_tibble(FoodChoice) rawdata <- FoodChoice%>% mutate( Cohort=factor(Cohort), Day=factor(Day), Treatment=factor(Treatment, levels=c('U','W','L','H'), labels=c('Control','Sham', 'Low','High'))) %>% map_at(.at = vars(Ratio:EatenTotal), .f = as.numeric)%>% as_tibble() rawdata_day0<-filter(rawdata,Day=='0') ksnormal(rawdata_day0$Ratio) median(rawdata_day0$Ratio) mean(rawdata_day0$Ratio) rawdata_day1_C <- filter(rawdata, Day=='1' & Treatment=='Control') rawdata_day1_S <- filter(rawdata, Day=='1' & Treatment=='Sham') rawdata_day1_H <- filter(rawdata, Day=='1' & Treatment=='High') rawdata_day1_L <- filter(rawdata, Day=='1' & Treatment=='Low') ksnormal(rawdata_day1_C$Ratio) median(rawdata_day1_C$Ratio) mean(rawdata_day1_C$Ratio) ksnormal(rawdata_day1_S$Ratio) median(rawdata_day1_S$Ratio) mean(rawdata_day1_S$Ratio) ksnormal(rawdata_day1_L$Ratio) median(rawdata_day1_L$Ratio) mean(rawdata_day1_L$Ratio) ksnormal(rawdata_day1_H$Ratio) median(rawdata_day1_H$Ratio) mean(rawdata_day1_H$Ratio) ksnormal(rawdata_day0$Pproportion) median(rawdata_day0$Pproportion) mean(rawdata_day0$Pproportion) ksnormal(rawdata_day1_C$Pproportion) median(rawdata_day1_C$Pproportion) mean(rawdata_day1_C$Pproportion) ksnormal(rawdata_day1_S$Pproportion) median(rawdata_day1_S$Pproportion) mean(rawdata_day1_S$Pproportion) ksnormal(rawdata_day1_L$Pproportion) median(rawdata_day1_L$Pproportion) mean(rawdata_day1_L$Pproportion) ksnormal(rawdata_day1_H$Pproportion) median(rawdata_day1_H$Pproportion) mean(rawdata_day1_H$Pproportion) ksnormal(rawdata_day0$Cproportion) median(rawdata_day0$Cproportion) mean(rawdata_day0$Cproportion) ksnormal(rawdata_day1_C$Cproportion) median(rawdata_day1_C$Cproportion) mean(rawdata_day1_C$Cproportion) ksnormal(rawdata_day1_S$Cproportion) median(rawdata_day1_S$Cproportion) mean(rawdata_day1_S$Cproportion) ksnormal(rawdata_day1_L$Cproportion) median(rawdata_day1_L$Cproportion) mean(rawdata_day1_L$Cproportion) ksnormal(rawdata_day1_H$Cproportion) median(rawdata_day1_H$Cproportion) mean(rawdata_day1_H$Cproportion) ksnormal(rawdata_day0$CarbohydrateEaten) median(rawdata_day0$CarbohydrateEaten) mean(rawdata_day0$CarbohydrateEaten) ksnormal(rawdata_day1_C$CarbohydrateEaten) median(rawdata_day1_C$CarbohydrateEaten) mean(rawdata_day1_C$CarbohydrateEaten) ksnormal(rawdata_day1_S$CarbohydrateEaten) median(rawdata_day1_S$CarbohydrateEaten) mean(rawdata_day1_S$CarbohydrateEaten) ksnormal(rawdata_day1_L$CarbohydrateEaten) median(rawdata_day1_L$CarbohydrateEaten) mean(rawdata_day1_L$CarbohydrateEaten) ksnormal(rawdata_day1_H$CarbohydrateEaten) median(rawdata_day1_H$CarbohydrateEaten) mean(rawdata_day1_H$CarbohydrateEaten) ksnormal(rawdata_day0$ProteinEaten) median(rawdata_day0$ProteinEaten) mean(rawdata_day0$ProteinEaten) ksnormal(rawdata_day1_C$ProteinEaten) median(rawdata_day1_C$ProteinEaten) mean(rawdata_day1_C$ProteinEaten) ksnormal(rawdata_day1_S$ProteinEaten) median(rawdata_day1_S$ProteinEaten) mean(rawdata_day1_S$ProteinEaten) ksnormal(rawdata_day1_L$ProteinEaten) median(rawdata_day1_L$ProteinEaten) mean(rawdata_day1_L$ProteinEaten) ksnormal(rawdata_day1_H$ProteinEaten) median(rawdata_day1_H$ProteinEaten) mean(rawdata_day1_H$ProteinEaten) ksnormal(rawdata_day0$EatenTotal) median(rawdata_day0$EatenTotal) mean(rawdata_day0$EatenTotal) ksnormal(rawdata_day1_C$EatenTotal) median(rawdata_day1_C$EatenTotal) mean(rawdata_day1_C$EatenTotal) ksnormal(rawdata_day1_S$EatenTotal) median(rawdata_day1_S$EatenTotal) mean(rawdata_day1_S$EatenTotal) ksnormal(rawdata_day1_L$EatenTotal) median(rawdata_day1_L$EatenTotal) mean(rawdata_day1_L$EatenTotal) ksnormal(rawdata_day1_H$EatenTotal) median(rawdata_day1_H$EatenTotal) mean(rawdata_day1_H$EatenTotal) #Wilcox rank sum test on P:C ratios for the first day post-infection: FoodChoice <- read.delim("C:/") #set to file location attach(FoodChoice) day1<-subset(FoodChoice, Day==1) pairwise.wilcox.test(day1$Ratio,day1$Treatment, p.adj = "bonf") pairwise.wilcox.test(day1$ProteinEaten,day1$Treatment, p.adj = "bonf") pairwise.wilcox.test(day1$CarbohydrateEaten,day1$Treatment, p.adj = "bonf") pairwise.wilcox.test(day1$EatenTotal,day1$Treatment, p.adj = "bonf") #Calculation of W values of the Wilcox rank sum tests: high_low<-subset(day1, Treatment == "H" | Treatment =="L") wilcox.test(high_low$EatenTotal~high_low$Treatment) wilcox.test(high_low$ProteinEaten~high_low$Treatment) wilcox.test(high_low$CarbohydrateEaten~high_low$Treatment) wilcox.test(high_low$Ratio~high_low$Treatment) high_wounded<-subset(day1, Treatment == "H" | Treatment =="W") wilcox.test(high_wounded$EatenTotal~high_wounded$Treatment) wilcox.test(high_wounded$ProteinEaten~high_wounded$Treatment) wilcox.test(high_wounded$CarbohydrateEaten~high_wounded$Treatment) wilcox.test(high_wounded$Ratio~high_wounded$Treatment) high_unmanipulated<-subset(day1, Treatment == "H" | Treatment =="U") wilcox.test(high_unmanipulated$EatenTotal~high_unmanipulated$Treatment) wilcox.test(high_unmanipulated$ProteinEaten~high_unmanipulated$Treatment) wilcox.test(high_unmanipulated$CarbohydrateEaten~high_unmanipulated$Treatment) wilcox.test(high_unmanipulated$Ratio~high_unmanipulated$Treatment) low_wounded<-subset(day1, Treatment == "L" | Treatment =="W") wilcox.test(low_wounded$EatenTotal~low_wounded$Treatment) wilcox.test(low_wounded$ProteinEaten~low_wounded$Treatment) wilcox.test(low_wounded$CarbohydrateEaten~low_wounded$Treatment) wilcox.test(low_wounded$Ratio~low_wounded$Treatment) low_unmanipulated<-subset(day1, Treatment == "L" | Treatment =="U") wilcox.test(low_unmanipulated$EatenTotal~low_unmanipulated$Treatment) wilcox.test(low_unmanipulated$ProteinEaten~low_unmanipulated$Treatment) wilcox.test(low_unmanipulated$CarbohydrateEaten~low_unmanipulated$Treatment) wilcox.test(low_unmanipulated$Ratio~low_unmanipulated$Treatment) wounded_unmanipulated<-subset(day1, Treatment == "W" | Treatment =="U") wilcox.test(wounded_unmanipulated$EatenTotal~wounded_unmanipulated$Treatment) wilcox.test(wounded_unmanipulated$ProteinEaten~wounded_unmanipulated$Treatment) wilcox.test(wounded_unmanipulated$CarbohydrateEaten~wounded_unmanipulated$Treatment) wilcox.test(wounded_unmanipulated$Ratio~wounded_unmanipulated$Treatment) detach(FoodChoice) #GLMMs examine whether a response variable consisting of proportion of P consumed (amount of P eaten divided by the amount of diet available) or proportion of C (amount of C eaten divided by the amount of diet available) was influenced by treatment (high infection; low infection; wounded; and unmanipulated) and day post infection, as well as an interaction between treatment and day. FoodChoice <- read.delim("C:/") #set to file location FoodChoice$Cohort<-as.factor(FoodChoice$Cohort) FoodChoice$Individual<-as.factor(FoodChoice$Individual) FoodChoice$Day<-as.factor(FoodChoice$Day) FoodChoice$Treatment<-as.factor(FoodChoice$Treatment) attach(FoodChoice) choice.Ppro<-glmmadmb(Pproportion~Treatment+Day+(1|Individual)+(1|Cohort), family = "beta") ChoiceTukeyPpro<-glht(choice.Ppro, linfct = mcp(Treatment = "Tukey")) summary(ChoiceTukeyPpro, adjusted(type="bonferroni")) choice.Cpro<-glmmadmb(Cproportion~Treatment+Day+(1|Individual)+(1|Cohort), family = "beta") ChoiceTukeyCpro<-glht(choice.Cpro, linfct = mcp(Treatment = "Tukey")) summary(ChoiceTukeyCpro, adjusted(type="bonferroni")) detach(FoodChoice) #Survival analysis on enforced diet Survival_EnforcedDiet <- read.delim("C:/") #set to file location attach(Survival_EnforcedDiet) surv<-coxph(formula=Surv(Time, Status==1)~Treatment, data = Survival_EnforcedDiet) summary(surv) detach (Survival_EnforcedDiet) #Survival analysis on enforced diet followed by infection Survival_DeathsAdded <- read.delim("C:/") #set to file location attach(Survival_DeathsAdded) #Survival model surv<-coxph(formula=Surv(Time, Death==1)~Treatment, data = Survival_DeathsAdded) #Hazard ratio calculations in a for loop so that each treatment is compared to each other one #To achiev this a "1" is added infront of the treatment which should be compared to all the others treatment_list<-c("BC","WC","UC","BE","WE","UE","BP","WP","WU") for(i in treatment_list){ new_surv<-Survival_DeathsAdded for(y in 1:nrow(new_surv)){ if(new_surv$Treatment[y]==i){ new_surv$Treatment[y]<-paste0("1",i) } } print(coxph(formula=Surv(Time, Status==1)~Treatment, data = new_surv)) } #Multiple testing survMult.glht <- glht(surv,mcp(Treatment="Tukey")) #Correction for multiple testing summary(survMult.glht, test = adjusted(type = "bonferroni")) summary(survMult.glht, test = adjusted(type = "fdr")) detach(Survival_DeathsAdded) #Making a survival plot Survival_original <- read.delim("C:/") #set to file location attach(Survival_original) survival<-survfit(Surv(Time,Death==1)~Treatment, data = Survival_original) ggsurvplot(survival,censor=TRUE,legend = "bottom",xlab="Time [h]", legend.title = "Treatment:",ylim = c(0, 1.02),xlim = c(0,63),axes.offset = FALSE,ggtheme = theme_bw()) detach(Survival_original) #Bacterial growth inhibition data analysis using R package growthcruver with default settings d <- read.delim("path to file") # add patch to file gc_out <- SummarizeGrowthByPlate(d, plot_fit = TRUE,plot_file="plots.pdf") #save results in a new txt file and add treatment in a column #Stats on growthcurver results Results_growthcurver <- read.delim("path to file") # add patch to file attach(Results_growthcurver) ksnormal(Results_growthcurver$auc_e) tt_fdr<-pairwise_t_test(Results_growthcurver,auc_e~Treatment,pool.sd = FALSE,p.adjust.method = "fdr") tt_bonferroni<-pairwise_t_test(Results_growthcurver,auc_e~Treatment,pool.sd = FALSE,p.adjust.method = "bonferroni") detach(Results_growthcurver) #For inclusion of the supplementary inhibition data d <- read.delim("path to file") # add patch to file gc_out <- SummarizeGrowthByPlate(d, plot_fit = TRUE,plot_file="plots_combined.pdf") #save results in a new txt file and add treatment in a column growthcruver_results_combined <- read.delim("path to file") # add patch to file attach(growthcurver_results_combined) ksnormal(growthcurver_results_combined$auc_e) #Stats on growthcurver results anova<-aov(auc_e ~ Treatment * Cohort, data = growthcurver_results_combined) summary(anova)