#this R code recreates the ODE models and associated figures from #Green et al, 2024: Working together to control mutation: how collective peroxide detoxification determines microbial mutation rate plasticity # Opening packages ------------------------------------------------------- #Packages with # are cited in main text. library(ggrepel) library(ggpubr) library(cowplot)# library(patchwork) library(deSolve)# library(gridExtra)# library(magrittr)# library(parallel)# library(foreach)# library(tidyverse)# library(nlme)# library(doParallel)# parallel::detectCores() registerDoParallel(cores=6) #16 cores originally run library(RColorBrewer)# library(emdbook)# library(magick) library(DiagrammeR)# library(DiagrammeRsvg) library(xml2) library(rsvg) library(clipr) library(ggeffects)# library(plyr) N_Runs<-5e1 #number of sensitivity test runs, 50,000 originally run theme_set(theme_bw(base_size=24)) # Flow diagram Fig.1A ----------------------------------------------------- grViz(" digraph GTP_Oxidiation { # a 'graph' statement graph [layout=dot,overlap = true, fontsize = 24, fontname = Helvetica] # several 'node' statements node [shape = circle, fontname = Helvetica style = filled, color = '#A6CEE3', fontsize=18, fontcolor = black, fixedsize = 'true', width = 1, height = 1] eGlc;iGlc; Sink; ROS; dGTP; DNA node [shape = circle, fontname = Helvetica style = filled, fontsize=18, color = '#A6CEE3', fixedsize = 'true', width = 1, height = 1] wtCell node [shape = circle, fixedsize = true, width = 0.9, fontsize=18, fontname = Helvetica color = '#FB9A99', fixedsize = 'true', width = 1, height = 1] odGTP; mDNA node [shape = circle, fixedsize = true, width = 0.9, fontsize=18, fontname = Helvetica color = '#FB9A99', fixedsize = 'true', width = 1, height = 1] // sets as circles mCell nodesep=0.7; # several 'edge' statements eGlc->iGlc [penwidth = 2, fontsize = 9, label=' 1',fontsize=28,fontname=Helvetica,color='#1b9e77',fontcolor='#1b9e77'] iGlc-> {Sink } [penwidth = 2, fontsize = 9] iGlc-> { ROS} [penwidth = 2, fontsize = 9, label=' 2',fontsize=28,fontname=Helvetica,color='#1b9e77',fontcolor='#1b9e77'] iGlc-> {dGTP} [penwidth = 2, fontsize = 9] ROS -> {odGTP}[penwidth = 2, fontsize = 9] ROS -> {Sink} [penwidth = 2, fontsize = 9, label='3',fontsize=28,fontname=Helvetica,color='#1b9e77',fontcolor='#1b9e77'] dGTP -> {odGTP}[penwidth = 2, fontsize = 9] dGTP -> {DNA} [penwidth = 2, fontsize = 9] odGTP -> {DNA}[penwidth = 2, fontsize = 9] odGTP -> {Sink} [penwidth = 2, fontsize = 9, label='4',fontsize=28,fontname=Helvetica,color='#1b9e77',fontcolor='#1b9e77'] odGTP -> {mDNA} [penwidth = 2, fontsize = 9] DNA -> wtCell[penwidth = 2, fontsize = 9] mDNA -> {DNA} [penwidth = 2, fontsize = 9] mDNA -> {wtCell} [penwidth = 2, fontsize = 9] mDNA -> {mCell} [penwidth = 2, fontsize = 9] } ") ->GRAPHmodA GRAPHmodA %>% export_svg() %>% read_xml() %>% write_xml("Flowgraph.svg") GRAPHmodA %>% export_svg %>% charToRaw %>% rsvg_png("Flowgraph.png") # Creating baseline model (A) ------------------------------------------ #from my lab data mutation rate of BW at glc 250 should be 16.5(/80) *1e-9.bp.gen = 2e-10 VV close to 1.94e-10 in Foster et al #at glc 500 MG is 16.13 -- = 2e-10 #mutation rate at glc 250 should be 2e-10 // 0.2*1e9 #tweak o2 to fit mod 1 to this properly modA <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * (Gcell) * eGlc/(eGlc + Ks) #eGlc is mmol/ml total (molar conc) diGlc_cyt <- (U1 * (Gcell) * eGlc/(eGlc + Ks))/cytVol - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt - dGTP_cyt * ROS * O2 dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA + R1 * odGTP dGcell <- (D1 * GDNA_cyt + R2 * mGDNA)*cytVol #6.02*10^20 is the number of molecules in 1mL of the given molarity dscale_Gcell2 <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol)* 6.02e20 / 2357528 # 2357528 is the number of GC base pairs e coli MG1655 ACCESSION U00096 VERSION U00096.3 DBLINK BioProject: PRJNA225 BioSample: SAMN02604091 dcytVol <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol * 6.02e20 / 2357528)* CellVol #number cells x ml/cell dROS <- M1 * r * iGlc_cyt - dGTP_cyt * ROS * O2 - O3 * ROS dodGTP <- dGTP_cyt * ROS * O2 - C1 * odGTP - I2 * odGTP - R1 * odGTP dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA - R2 * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol, dROS,dodGTP,dmGDNA,dmGcell,dscale_mGcell)) }) } CellVol=1.0325e-12 #kubitsheke & friske 1986 (in mL) times<-seq(0,1e5,by=10) parameters <- c(U1=0.2657562, #fitted to Ks Dykhuzien & Growth Jain M1=2.69e-04, #fitted to growth data Ks=3.974e-5, #Dykhuzien I1 = 6.9e-3, #fitted to cytoplasmic dGTP conc of 92uM Buckstein D1 = 6.9e-3, #given the same value as I1 O2 = 11.99985, #titrated to mutation rate of 2e-10 (lab data + Foster 2015) I2 = 6.9e-3*(7.7e-8/2.1e-6), #relative efficiency of oG binding to A compared to G binding to c (I1) is 7.7e-8:2.1e-6 (Maki) D2 = 6.9e-3*(0.029), #rate of c pairing opposite an oG relative to C:G is 6e-8:2.1e-6 (Maki) C1 = 2.8, #kcat measured ex vivo Xia et al, 2005 C2 = 3.5e-4, #lu et al, 1996 R1 = 6.9e-3*(0.029), #rate of oG pairing with C is = D2 S = 0.02582221, #fitted to give mutS KO mut rate 40x wt (Swings et al) r=17.3, #titrated to known H2O2 production rate of 14uM/second Seaver & Imlay - may be closer to 10, good enough O3 = 56, # fitted to give standing ROS conc of 1.9e-7 (Gonzalez-Fletcha) R2 = 6.9e-3*(7.7e-8/2.1e-6), # relative efficiency of oG binding to A compared to G binding to c (I1) is 7.7e-8:2.1e-6 (Maki) Met1=1545,# fitted to reach expected carrying capacity from given glucose? CellVol=1.0325e-12)#Kubitschek&Friske, 1986, mean of measurements in minimal media in exponential growth log_glc <- lseq(3.1e-4,62e-4,5) y = c( "time" , "eGlc" , "iGlc_cyt" , "dGTP_cyt" , "GDNA_cyt" , "Gcell" ,"scale_Gcell2", "cytVol" , "ROS" , "odGTP" , "mGDNA" , "mGcell" , "scale_mGcell" ,"glucose" ) # Fig. S13 Fit to Jain Data -------------------------------------------------------- #need to set initial glucose to Jain value (3800mg.L) and initial cell density to 1.579846e8 1.579846e8/ (6.02e20 / 2357528)->InitialCells#initial cells Molar dGTP out.basic <- lsode(y = c(eGlc =3800/180e3, iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= InitialCells, scale_Gcell2 = 1.579846e8, cytVol = CellVol*1.579846e8,ROS=0,odGTP=0,mGDNA=0,mGcell=0,scale_mGcell=0), times = times, func = modA, parms = parameters) out.basic%>%as.data.frame()->out.df out.df%>%select(eGlc,scale_Gcell2,time)%>% pivot_longer(cols=1:2,names_to="Variable",values_to="Value")->ModelData d3 <- read.csv("S12_data.txt") as.data.frame(c(d3$Glc_M,d3$cells_per_ml))->JainData names(JainData)<-"Value" JainData$time<-c(d3$time_s,d3$time_s) JainData$Variable<-c(rep("eGlc",18),rep("scale_Gcell2",18)) # New facet label names for supp variable supp.labs <- c("External Glucose (M)", "Cells per mL") names(supp.labs) <- c("eGlc", "scale_Gcell2") ggplot(ModelData,aes(time/3600,Value))+ facet_wrap(~Variable,scales="free_y",labeller = labeller(Variable = supp.labs))+theme_bw()+geom_line()+ geom_point(data=JainData,shape=1,size=3)+xlab("Time (hrs)")->JainPlot ggsave("FigS13.tiff", JainPlot,width=8,height=5,units="in",device="tiff") # DAMP estimating function ------------------------------------------------ #simulate 1e5 seconds (27 hrs) of e coli growth in each of 5 glc conditions to get DAMP DAMP.slope <- function (CHOSENPARAMETERS,CHOSENMODEL,label,starts) { times <- seq(0, 1e5, by = 10) glc.data <- function (x) {as.data.frame(lsode(y = c(eGlc = x, starts), times = times, func = CHOSENMODEL, parms = CHOSENPARAMETERS))} data.1 <- glc.data(log_glc[1]) data.2 <- glc.data(log_glc[2]) data.3 <- glc.data(log_glc[3]) data.4 <- glc.data(log_glc[4]) data.5 <- glc.data(log_glc[5]) mutants <- function(dataframe){dataframe$mGcell[10001]} CELLS <- function(dataframe){dataframe$Gcell[10001]} wt<- c(CELLS(data.1), CELLS(data.2), CELLS(data.3), CELLS(data.4), CELLS(data.5)) mt <- c(mutants(data.1), mutants(data.2), mutants(data.3), mutants(data.4), mutants(data.5)) mr<-mt/(wt+mt) df<-as.data.frame(cbind(wt,mt,mr)) return(df) } #make a test of all model fits for all models Fit.test <- function (CHOSENPARAMETERS,CHOSENMODEL,starts) { times <- seq(0, 1e5, by = 10) as.data.frame(lsode(y = c(eGlc = log_glc[3], starts), times = times, func = CHOSENMODEL, parms = CHOSENPARAMETERS))->dfODE #first test max growth rate ~0.6/hr mod1 <- try(nls(scale_Gcell2~SSlogis(time/3600, A, xmid, scal),data=dfODE)) try(mod1$m$getPars())->m1 try(m1[3]*100/0.65->JainError) try(print(paste0("Growth rate is " ,formatC(JainError,digits=1,format="f"),"% of expected value from Jain, 2009"))) (dfODE$dGTP_cyt%>%max()*1e6)*100/92->BuckError print(paste0("dGTP concentration is " ,formatC(BuckError,digits=1,format="f"),"% of expected value from Buckstein, 2008")) dfODE$scale_mGcell[10001]/(dfODE$scale_Gcell2[10001]+dfODE$scale_mGcell[10001])->mr mr*100/2e-10->mrError print(paste0("Mutation rate is " ,formatC(mrError,digits=1,format="f"),"% of expected value from Foster, 2015")) max(2.690000e-04 *1.730000e+01 * dfODE$iGlc_cyt)*1e6*100/14->SeaverError print(paste0("H2O2 production rate is " ,formatC(SeaverError,digits=1,format="f"),"% of expected value from Seaver, 2001")) max(dfODE$ROS)*100/1.9e-7->GonzalezError print(paste0("H2O2 standing concentration is " ,formatC(GonzalezError,digits=1,format="f"), "% of expected value from Gonzalez-flecha, 1997")) CHOSENPARAMETERS["S"]<-0 as.data.frame(lsode(y = c(eGlc = log_glc[3], starts), times = times, func = CHOSENMODEL, parms = CHOSENPARAMETERS))->dfmutS dfmutS$scale_mGcell[10001]/dfmutS$scale_Gcell2[10001]->mr2 mr2/mr->mutS_change print(paste0("A mutS knockout has mutation rate increase of ",formatC(mutS_change,digits=1,format="f")," fold. This should =40.")) } # Simulate modA ----------------------------------------------------------- startsA<-c(iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= 8.510873e-12,scale_Gcell2 = 0, cytVol = CellVol*2175,ROS=0,odGTP=0,mGDNA=0,mGcell=0,scale_mGcell=0) parameters->parA DAMP.slope(parA,modA,"Model A",startsA)->A Fit.test(parA,modA,startsA) # Fig.1B-E plotting variables over time in modA---------------------------------------------------------------- crossglctable<-function(model,parameters,starts){ glc.range<-as.data.frame(matrix(nrow=1,ncol=length(starts)+3)) names(glc.range)<-c("time","eGlc",names(starts),"glucose") for(i in 1:5){ out.basic <- lsode(y = c(eGlc =log_glc[i], starts), times = times, func = model, parms = parameters) out.basic%>%as.data.frame()->out.df out.df$glucose<-log_glc[i]*180e3 rbind(glc.range,out.df)->glc.range } return(glc.range[-1,]) } crossglctable(modA,parA,startsA)->glc.range glc.range%<>%mutate(Glucose_mg_per_L=eGlc*180e3) glc.range%<>%mutate(Time_Hrs=time/3600) glc.range%<>%mutate(MR_cumulative=mGcell/(Gcell+mGcell)) ggplot(glc.range,aes(time/3600,eGlc*180e3,colour=glucose))+ geom_point()+theme_bw(base_size=24)+theme(legend.position="none")+ ylab(expression(paste("External Glucose ( mg ", L^{ -1 }, ")")))+ xlab("Time (hrs)")+scale_y_continuous(breaks=c(0,250,500,750,1000))+ scale_x_continuous(breaks=c(0,6,12,18,24))+ scale_colour_gradient(low=brewer.pal(3,"Paired")[1], high=brewer.pal(3,"Paired")[2])->glcPlot ggplot(glc.range,aes(time/3600,scale_Gcell2,colour=glucose))+ geom_point()+theme_bw(base_size=24)+ ylab(expression(paste("Population Density ( CFU ", mL^{ -1 }, ")")))+ xlab("Time (hrs)")+ theme(legend.text=element_text(size=14), plot.tag=element_text(size=40))+ scale_y_continuous(breaks=c(0,5e8,1e9))+ scale_x_continuous(breaks=c(0,6,12,18,24))+ scale_colour_gradient(low=brewer.pal(3,"Paired")[1], high=brewer.pal(3,"Paired")[2], name="Glucose (mg/L)", breaks=c(55,120,250,525,1100), trans="log", limits=c(50,1200))->celPlot get_legend(celPlot)->leg celPlot+theme(legend.position="none")->celPlot ggplot(glc.range,aes(time/3600,mGcell/(Gcell+mGcell),colour=glucose))+ geom_point()+theme_bw(base_size=24)+theme(legend.position="none")+ ylab(expression(paste("Mutation Rate ( ", bp^{ -1 }," ",gen^{ -1 }, ")")))+ xlab("Time (hrs)")+ scale_x_continuous(breaks=c(0,6,12,18,24))+ # scale_y_log10( # breaks=c(2e-10,4e-10,7e-10) # )+ scale_colour_gradient(low=brewer.pal(3,"Paired")[1], high=brewer.pal(3,"Paired")[2])->mutPlot ggplot(glc.range,aes(time/3600,ROS,colour=glucose))+ geom_point()+theme_bw(base_size=24)+theme(legend.position="none")+ ylab(expression(paste("Internal ROS (M)")))+ xlab("Time (hrs)")+ scale_x_continuous(breaks=c(0,6,12,18,24))+ #scale_y_log10( # breaks=c(2e-10,4e-10,7e-10) #)+ scale_colour_gradient(low=brewer.pal(3,"Paired")[1], high=brewer.pal(3,"Paired")[2])->rosPlot glc.range%>%write_csv("SecondRevision/S1_Data.csv") ggsave("GlcPlot.png", glcPlot,width=6,height=5,units="in") ggsave("CELLPlot.png", celPlot,width=6,height=5,units="in") ggsave("mutPlot.png", mutPlot,width=6,height=5,units="in") ggsave("rosPlot.png", rosPlot,width=6,height=5,units="in") ggsave("legend.png", leg,width=6,height=10,units="in") #go and crop this and save as legendCroped.png flowpng <- image_read("Flowgraph.png") ggplot() + background_image(flowpng) +theme_minimal()->flow ggplot()+theme_minimal()->space grid.arrange(flow,space,widths=c(10,2))->flow2 ggsave("FlowSpace.png",flow2,units="in",width=9.3,height=20) flowpng <- image_read("FlowSpace.png") ggplot() + background_image(flowpng) +theme_minimal()->flow2 legpng <- image_read("legendCroped.png") ggplot() + background_image(legpng)+coord_fixed() +theme_minimal()->legbig fig1<-(flow2 )+ ((glcPlot )/(rosPlot )/(celPlot )/(mutPlot ))+ (plot_spacer()/(legbig )/plot_spacer()) fig1 + plot_layout(ncol=3,widths = c(1.2, 1,0.8))->fig1 ggsave("fig1.png",fig1,units="in",width=28,height=20) img <- image_read("fig1.png") c(0:10)%>%as.data.frame()->df cbind(df,df)->df colnames(df)<-c("x","y") ggplot(data=df,aes(x,y)) + geom_point()+ background_image(img) +theme_minimal()+ annotate(geom="text", x=-Inf, y=Inf, label="A", color="black",size=28, hjust=-0.5,vjust=1.1)+ annotate(geom="text", x=3.25, y=Inf,vjust=1.1, label="B", color="black",size=28)+ annotate(geom="text", x=3.25, y=7.35, label="C", color="black",size=28)+ annotate(geom="text", x=3.25, y=4.6, label="D", color="black",size=28)+ annotate(geom="text", x=3.25, y=1.9, label="E", color="black",size=28)+ scale_x_continuous(name="",breaks=c())+ scale_y_continuous(name="",breaks=c())->p1 ggsave("Fig1.tiff",p1,units="in",width=28,height=20) # Second Appendix Plot All Model A variables over time----------------------------------------------------- glc.range%>%subset(glucose>230&glucose<270)->glc.range250 glc.range250%<>%pivot_longer(cols=c( "eGlc" , "iGlc_cyt" , "dGTP_cyt" , "GDNA_cyt" , "Gcell" , "scale_Gcell2", "cytVol" , "ROS" , "odGTP" , "mGDNA" , "mGcell" , "scale_mGcell"), values_to = "Concentration",names_to = "Variable") head(glc.range250) Var_names <- c( "eGlc" = "eGlc" , "iGlc_cyt" = "iGlc", "dGTP_cyt" ="dGTP" , "GDNA_cyt"="GDNA" , "Gcell" ="wtCell" , "scale_Gcell2"="scale_wtCell", "cytVol" = "cytVol" , "ROS" = "ROS" , "odGTP" = "odGTP" , "mGDNA"="mGDNA" , "mGcell"="mCell" , "scale_mGcell"= "scale_mCell" ) glc.range250$Var_names<-NA for(i in 1:nrow(glc.range250)){Var_names[glc.range250$Variable[i]]->glc.range250$Var_names[i]} ggplot(glc.range250,aes(time/3600,Concentration))+ geom_point()+facet_wrap(~Var_names,scales="free_y",ncol=3)+ xlab("Time (hrs)")+ylab("Concentration (M)")->plotA2 ggsave("plotA2.png",plotA2,units="in",width=12,height=15) # Fig. S15 Fit to Krasovec 2017 data ----------------------------------------------- d <- read_csv("S13_data.csv") mod1 <- lme(CellsPerV ~Glc_mmol_1ml-1, data=d, random= ~1|set/plate_ID) modb <- lme(CellsPerV ~Glc_mmol_1ml-1, data=d, random= ~1|set/plate_ID, weights=varComb(varIdent(form = ~1 | set), varPower(form = ~environment_Glc))) anova(mod1,modb) ggpredict(modb, "Glc_mmol_1ml") %>% plot(rawdata = T, dot.alpha = 0.2)+ geom_point( data=d,aes(y=CellsPerV, x=Glc_mmol_1ml))+ ylab(expression(paste("Population Density ", "(CFU mL"^-1,")")))+ xlab(expression(paste("Glucose Concentration ", "(mg L"^-1,")")))+ scale_x_continuous(breaks=seq(50,250,by=50)/180e3, labels=seq(50,250,by=50))+ ggtitle("")+theme_bw()+ geom_point(shape=8,size=5,col="red",data=glc.range%>% filter(as.character(time)=="1e+05"& glucose<250), aes(glucose/180e3,scale_Gcell2))->FitKrasovec ggsave("FigS14.tiff", FitKrasovec,width=8,height=5,units="in") # Creating the 10 extra variant ODE models -------------------------------- modB <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * Gcell * ((U2-eGlc)/(U2-eGlc+K2)) #eGlc is mmol/ml total (molar conc) if(eGlc <= 0) deGlc <- 0 diGlc_cyt <-( U1 * Gcell* ((U2-eGlc)/(U2-eGlc+K2)))/cytVol- Met1 * M1 * iGlc_cyt # * (4.3e-3-eGlc)/(4.3e-3-eGlc+K2)) if(eGlc <= 0) diGlc_cyt <- - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt - dGTP_cyt * ROS * O2 dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA + R1 * odGTP dGcell <- (D1 * GDNA_cyt + R2 * mGDNA)*cytVol dscale_Gcell2 <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol)* 6.02e20 / 2357528 dcytVol <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dROS <- M1 * r * iGlc_cyt - dGTP_cyt * ROS * O2 - O3 * ROS dodGTP <- dGTP_cyt * ROS * O2 - C1 * odGTP - I2 * odGTP - R1 * odGTP dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA - R2 * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol,dROS,dodGTP,dmGDNA,dmGcell,dscale_mGcell)) }) } parB<-c(parameters,K2=1.818264e-4,U2=6.7e-3) startsB<-c(iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= 8.510873e-12,scale_Gcell2 = 0, cytVol = CellVol*2175, ROS=0,odGTP=0, mGDNA=0,mGcell=0,scale_mGcell=0) DAMP.slope(parB,modB,"Model B",startsB)->B Fit.test(parB,modB,startsB) # Illustrate modB -------------------------------------- glc.range2<-crossglctable(modB,parB,startsB) glc.range$Model<-"Model A" glc.range2$Model<-"Model B" glc.range$U1<-parA["U1"] glc.range$Ks<-parA["Ks"] glc.range2$U1<-parB["U1"] glc.range2$U2<-parB["U2"] glc.range2$K2<-parB["K2"] glc.range%<>%mutate(GlucoseUptake=U1*(eGlc/(eGlc+Ks))) glc.range2%<>%mutate(GlucoseUptake=U1*((U2-eGlc)/(U2-eGlc+K2))) rbind.fill(glc.range,glc.range2)->AB ggplot(AB%>%subset(glucose>1000),aes(eGlc,(GlucoseUptake/ 6.02e20 * 2357528),colour=Model))+ geom_line(lwd=1)+theme_bw(base_size=20)+ ylab(expression(paste("Per cell glucose uptake rate (mmol per sec)")))+ xlab("External Glucose (M)")+ scale_y_continuous(breaks = c(1e-20,4e-16,8e-16,1.2e-15), limits=c(1e-20,1.2e-15))+ ggtitle("Variant B reverses the relationship between\neGlc and glucose uptake rate")+ scale_color_brewer(palette="Set1")-> ModBPlot ggsave("modB.png",ModBPlot,units = "in",width=15,height=9) modC <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * (Gcell) * eGlc/(eGlc + Ks) #eGlc is mmol/ml total (molar conc) diGlc_cyt <- (U1 * (Gcell) * eGlc/(eGlc + Ks))/cytVol - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt - dGTP_cyt * ROSC * O2 dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA + R1 * odGTP dGcell <- (D1 * GDNA_cyt + R2 * mGDNA)*cytVol dscale_Gcell2 <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol)* 6.02e20 / 2357528 dcytVol <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dodGTP <- dGTP_cyt * ROSC * O2 - C1 * odGTP - I2 * odGTP - R1 * odGTP dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA - R2 * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol,dodGTP,dmGDNA,dmGcell,dscale_mGcell)) }) } parC<-c(parameters,ROSC=1.8e-07) startsC<-c(iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= 8.510873e-12,scale_Gcell2 = 0, cytVol = CellVol*2175,odGTP=0, #ROS=0, mGDNA=0,mGcell=0,scale_mGcell=0) Fit.test(parC,modC,startsC) DAMP.slope(parC,modC,"Model C",startsC)->C # Illustrate modC --------------------------------------------------------- rosPlot+geom_hline(yintercept=1.8e-07,lwd=1)+ ggtitle("Model C sets a constant internal ROS concentration", subtitle="Blue points show ROS in model A (as in fig 1E),\nblack line shows ROS in model C")+ theme_bw(base_size = 20)-> modCP ggsave("modC.png",modCP,units = "in",width=15,height=9) modD2 <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * (Gcell) * eGlc/(eGlc + Ks) #eGlc is mmol/ml total (molar conc) diGlc_cyt <- (U1 * (Gcell) * eGlc/(eGlc + Ks))/cytVol - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt- dGTP_cyt * ROS * O2 dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA + R1 * odGTP dGcell <- (D1 * GDNA_cyt + R2 * mGDNA)*cytVol dscale_Gcell2 <- ((D1 * GDNA_cyt+ R2 * mGDNA)*cytVol)* 6.02e20 / 2357528 dcytVol <- ((D1 * GDNA_cyt+ R2 * mGDNA)*cytVol * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dROS <- - dGTP_cyt * ROS * O2 - O3 * ROS - kdiff*(ROS-ROS_ext) dROS_ext <- ROSC2 + (ROS - ROS_ext)*kdiff*(cytVol/(1-cytVol)) dodGTP <- dGTP_cyt * ROS * O2 - C1 * odGTP - I2 * odGTP - R1 * odGTP dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA - R2 * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol,dROS,dROS_ext,dodGTP,dmGDNA,dmGcell,dscale_mGcell)) }) } startsD2<-c(iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= 8.510873e-12, scale_Gcell2 = 0,cytVol = CellVol*2175,ROS=0,ROS_ext=0,odGTP=0,mGDNA=0,mGcell=0, scale_mGcell=0) parD2 <- c(parameters,ROSC2=6e-11) parD2["kdiff"]<-70 parD2["O2"]<-4e+01 Fit.test(parD2,modD2,startsD2)#h2o2 conc is high because this takes a transitory maximum # Test the effect of differing diffusion coefficient on DAMP slope -------- listofK<-lseq(0.1,600,length=10) DAMP.slope(parD2,modD2,"Model D2",startsD2)->D2 D2$kdiff<-70 for(i in 1:10){ parD2->parD2a parD2a["kdiff"]<-listofK[i] DAMP.slope(parD2a,modD2,"Model D2",startsD2)->addD addD$kdiff<-listofK[i] rbind(D2,addD)->D2 } D2$kdiffF<-factor(as.character(signif(D2$kdiff,3)), levels=as.character(unique(signif(D2$kdiff,3))[order(unique(signif(D2$kdiff,3)))])) ggplot(D2%>%subset(kdiffF%in%levels(D2$kdiffF)[c(2,3,4,6,8,10)]), aes(wt* 6.02e20 / 2357528,mr,col=kdiff))+theme_bw(base_size = 18)+ scale_x_log10()+scale_y_log10()+ geom_smooth(method="lm",se=F,col="grey",aes(group=kdiffF))+ ylab("Mutation Rate")+geom_point(size=3)+xlab("Population Density")+scale_color_distiller(palette="Spectral", breaks=c(0.25,0.7,1.82,12.6,70,228), limits=c(0.2,250), name="Coefficient of Diffusion", trans="log")->p1 ggsave("Diffusion.png",p1,units="in",width=12,height=12) crossglctable(modD2,parD2,startsD2)->glc.rangeD2 ggplot(glc.rangeD2,aes(time/3600,ROS_ext*1e6,col=glucose,group=glucose))+ geom_point()+theme_bw()+ scale_colour_gradient(low=brewer.pal(3,"Paired")[1], high=brewer.pal(3,"Paired")[2], breaks=c(55,120,250,525,1100), limits=c(50,1200), name="Glucose (mg/L)", trans="log")+ ylab("External ROS (micromolar)")+xlab("Time (hrs)")->Ax ggplot(glc.rangeD2,aes(time/3600,ROS*1e6,col=glucose,group=glucose))+ geom_point()+theme_bw()+ scale_colour_gradient(low=brewer.pal(3,"Paired")[1], high=brewer.pal(3,"Paired")[2], breaks=c(55,120,250,525,1100), limits=c(50,1200), name="Glucose (mg/L)", trans="log")+ ylab("Internal ROS (micromolar)")+xlab("Time (hrs)")->Bx ggplot(glc.rangeD2%>%subset(time>900),aes(time/3600,ROS_ext/ROS,col=glucose,group=glucose))+ geom_point()+theme_bw()+ scale_colour_gradient(low=brewer.pal(3,"Paired")[1], high=brewer.pal(3,"Paired")[2], breaks=c(55,120,250,525,1100), limits=c(50,1200), name="Glucose (mg/L)", trans="log")+ ylab("External : Internal ROS Conc")+xlab("Time (hrs)")->Cx grid.arrange(Ax+labs(tag="A"),Bx+labs(tag="B"),Cx+labs(tag="C"))->modD2p ggsave("modD.png",modD2p,units="in",width=10,height=8) # hpx Knockout results of model D2 -------------------------------------------- parD2->parhpx parhpx["O3"] = 0 #no ROS degradation "S5_data.csv" %>% read_csv() -> raw_data # hpx coculture ----------------------------------------------------------- modD2_coculture <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * (Gcell) * eGlc/(eGlc + Ks) -U1 * (Gcell_hpx) * eGlc/(eGlc + Ks) #eGlc is mmol/ml total (molar conc) diGlc_cyt <- (U1 * (Gcell) * eGlc/(eGlc + Ks))/cytVol - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt- dGTP_cyt * ROS * O2 dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA + R1 * odGTP dGcell <- (D1 * GDNA_cyt + R2 * mGDNA)*cytVol dscale_Gcell2 <- ((D1 * GDNA_cyt+ R2 * mGDNA)*cytVol)* 6.02e20 / 2357528 dcytVol <- ((D1 * GDNA_cyt+ R2 * mGDNA)*cytVol * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dROS <- - dGTP_cyt * ROS * O2 - ROS*O3 - kdiff*(ROS-ROS_ext) diGlc_cyt_hpx <- (U1 * (Gcell_hpx) * eGlc/(eGlc + Ks))/cytVol_hpx - Met1 * M1 * iGlc_cyt_hpx ddGTP_cyt_hpx <- M1 * iGlc_cyt_hpx - I1 * dGTP_cyt_hpx- dGTP_cyt_hpx * ROS_hpx * O2 dGDNA_cyt_hpx <- I1 * dGTP_cyt_hpx - D1 * GDNA_cyt_hpx + C2 * mGDNA_hpx + S * mGDNA_hpx + R1 * odGTP_hpx dGcell_hpx <- (D1 * GDNA_cyt_hpx + R2 * mGDNA_hpx)*cytVol_hpx dscale_Gcell2_hpx <- ((D1 * GDNA_cyt_hpx+ R2 * mGDNA_hpx)*cytVol_hpx)* 6.02e20 / 2357528 dcytVol_hpx <- ((D1 * GDNA_cyt_hpx+ R2 * mGDNA_hpx)*cytVol_hpx * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dROS_hpx <- - dGTP_cyt_hpx * ROS_hpx * O2 - kdiff*(ROS_hpx-ROS_ext) dROS_ext <- ROSC2 + (ROS - ROS_ext)*kdiff*(cytVol/(1-cytVol-cytVol_hpx)) + (ROS_hpx - ROS_ext)*kdiff*(cytVol_hpx/(1-cytVol_hpx-cytVol)) dodGTP <- dGTP_cyt * ROS * O2 - C1 * odGTP - I2 * odGTP - R1 * odGTP dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA - R2 * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 dodGTP_hpx <- dGTP_cyt_hpx * ROS_hpx * O2 - C1 * odGTP_hpx - I2 * odGTP_hpx - R1 * odGTP_hpx dmGDNA_hpx <- I2 * odGTP_hpx - D2 * mGDNA_hpx - C2 * mGDNA_hpx - S * mGDNA_hpx - R2 * mGDNA_hpx dmGcell_hpx <- D2 * mGDNA_hpx * cytVol_hpx dscale_mGcell_hpx <- ((D2 * mGDNA_hpx)*cytVol_hpx)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol,dROS, diGlc_cyt_hpx, ddGTP_cyt_hpx,dGDNA_cyt_hpx,dGcell_hpx,dscale_Gcell2_hpx,dcytVol_hpx,dROS_hpx, dROS_ext,dodGTP,dmGDNA,dmGcell,dscale_mGcell, dodGTP_hpx,dmGDNA_hpx,dmGcell_hpx,dscale_mGcell_hpx)) }) } startsD2_hpx<-c(iGlc_cyt=0, dGTP_cyt=0,GDNA_cyt=0,Gcell=8.510873e-12,scale_Gcell2=0,cytVol=2.245688e-09,ROS=0, iGlc_cyt_hpx=0, dGTP_cyt_hpx=0,GDNA_cyt_hpx=0,Gcell_hpx=8.510873e-12,scale_Gcell2_hpx=0,cytVol_hpx=2.245688e-09,ROS_hpx=0, ROS_ext=0,odGTP=0,mGDNA=0,mGcell=0,scale_mGcell=0, odGTP_hpx=0,mGDNA_hpx=0,mGcell_hpx=0,scale_mGcell_hpx=0) crossglctable(modD2_coculture,parD2,startsD2_hpx)->glc.range_d2co crossglctable(modD2,parhpx,startsD2)->glc.range_d2hpx glc.range_d2co%>%subset(time==1e5)->wtco wtco%>%select(scale_Gcell2,scale_mGcell)->coTable coTable$Treatment<- "BW25113 + hpx LB" glc.range_d2co%>%subset(time==1e5)%>%select(scale_Gcell2_hpx,scale_mGcell_hpx)->hco hco$Treatment<- "hpx (NalR) + BW25113 LB" names(hco)<-c("scale_Gcell2", "scale_mGcell", "Treatment" ) glc.rangeD2%>%subset(time==1e5)%>%select(scale_Gcell2,scale_mGcell)->wtmonoTable wtmonoTable$Treatment<-"BW25113 LB" glc.range_d2hpx%>%subset(time==1e5)%>%select(scale_Gcell2,scale_mGcell)->hpxmonoTable hpxmonoTable$Treatment<-"hpx (NalR) LB" rbind(coTable,wtmonoTable,hpxmonoTable,hco)->coTable coTable$Treatment%>%unique()%>%as.data.frame()->Slopes names(Slopes)<-"Treatment" Slopes$sd<-NA Slopes$slope<-NA coTable$Treatment%<>%as.factor() for(i in 1:4){ coTable <- within(coTable, Treatment <- relevel(Treatment, ref = Slopes$Treatment[i])) lm(log(scale_mGcell/(scale_mGcell+scale_Gcell2))~log(scale_mGcell+scale_Gcell2)*Treatment,data=coTable)->modeledCo modeledCo%>%summary()->s print(Slopes$Treatment[i]) print(s) s$coefficients[2,1]->Slopes$slope[i] s$coefficients[2,2]->Slopes$sd[i] } read_csv("S1_table.csv")%>%subset(Treatment%in%Slopes$Treatment)->labData labData%<>%dplyr::rename(slope=Slope) ggplot(Slopes,aes(x=Treatment,y=slope))+ geom_point(size=3,aes(col="ODE Model"),position=position_nudge(x=0.1))+ geom_errorbar(aes(ymin=slope-sd*1.96,ymax=slope+sd*1.96, col="ODE Model"),width=0, position=position_nudge(x=0.1))+ theme_bw()+geom_hline(yintercept=0)+ geom_point(data=labData,aes(col="Lab"),size=3)+ scale_x_discrete(breaks=c("BW25113 + hpx LB" , "BW25113 LB" , "hpx (NalR) LB" , "hpx (NalR) + BW25113 LB"), labels=c(expression(paste("BW25113 + Hpx"^"-"," LB")), "BW25113 LB", expression(paste("Hpx"^"-",""[nalR]," LB")) , expression(paste("Hpx"^"-",""[nalR]," + BW25113 LB"))))+ geom_errorbar(data=labData, aes(ymin=slope-Slope_CI95, ymax=slope+Slope_CI95,col="Lab"), width=0)+ylab("Slope")+labs(col="Data")+ scale_color_brewer(palette="Set1")->coODE ggsave("FigS11.tiff",coODE,units="in",width=8,height=6) modE <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * (Gcell) * eGlc/(eGlc + Ks) #eGlc is mmol/ml total (molar conc) diGlc_cyt <- (U1 * (Gcell) * eGlc/(eGlc + Ks))/cytVol - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt - dGTP_cyt * ROS * O2 dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA + R1 * odGTP dGcell <- (D1 * GDNA_cyt + R2 * mGDNA)*cytVol dscale_Gcell2 <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol)* 6.02e20 / 2357528 dcytVol <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dROS <- M1 * r * iGlc_cyt - dGTP_cyt * ROS * O2 - O3 * ROS * ((iGlc_cyt)/(iGlc_cyt+ C3)) #trying to make cells with more iGlc remove more ROS - more resources for making enzymes? dodGTP <- dGTP_cyt * ROS * O2 - C1 * odGTP - I2 * odGTP - R1 * odGTP dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA - R2 * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol,dROS,dodGTP,dmGDNA,dmGcell,dscale_mGcell)) }) } parE<-c(parameters,C3=1.5e-4) startsE<-c(iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= 8.510873e-12,scale_Gcell2 = 0, cytVol = CellVol*2175, ROS=0,odGTP=0, mGDNA=0,mGcell=0,scale_mGcell=0) Fit.test(parE,modE,startsE) DAMP.slope(parE,modE,"Model E",startsE)->E #if we square the ros removal factor this slope is still ~0.08 # Illustrate modE --------------------------------------------------------- glc.range->glc.rangeA crossglctable(modE,parE,startsE)->glc.rangeE glc.rangeE%<>%mutate(rosRemoval=parE["O3"]*(iGlc_cyt/(iGlc_cyt+parE["C3"]))) glc.rangeA%<>%mutate(rosRemoval=parA["O3"]) glc.rangeE%<>%mutate(rosRemovalFactor=iGlc_cyt/(iGlc_cyt+parE["C3"])) glc.rangeE$Model<-"Model E" rbind.fill(glc.rangeA,glc.rangeE)->AE ggplot(AE%>%subset(glucose>1000),aes(iGlc_cyt,rosRemoval,col=Model))+geom_point()+ theme_bw(base_size=20)+ ylab("Internal ROS removal rate (per sec)")+ xlab("Internal Glc (M)")+ ggtitle("Model E makes ROS degradation rate dependant\non internal glucose concentration")-> modEP ggsave("modE.png",modEP,units = "in",width=15,height=9) #,subtitle="However, given the existing corellation between iGlc and ROS,\nROS degradation rate already depends on iGlc indirectly" modF <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * (Gcell) * eGlc/(eGlc + Ks) #eGlc is mmol/ml total (molar conc) diGlc_cyt <- (U1 * (Gcell) * eGlc/(eGlc + Ks))/cytVol - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt #- dGTP_cyt * ROS * O2 dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA + R1 * odGTP dGcell <- (D1 * GDNA_cyt + R2 * mGDNA)*cytVol dscale_Gcell2 <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol)* 6.02e20 / 2357528 dcytVol <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dROS <- M1 * r * iGlc_cyt - dGTP_cyt * ROS * O2 - ROS*scale_Gcell2*C3a dodGTP <- dGTP_cyt * ROS * O2 - C1 * odGTP - I2 * odGTP - R1 * odGTP dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA - R2 * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol,dROS,dodGTP,dmGDNA,dmGcell,dscale_mGcell)) }) } parF<-c(parameters,C3a=3.5e-6) startsF<-c(iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= 8.510873e-12,scale_Gcell2 = 0, cytVol = CellVol*2175,ROS=0,odGTP=0, mGDNA=0,mGcell=0,scale_mGcell=0) Fit.test(parF,modF,startsF) DAMP.slope(parF,modF,"Model F",startsF)->Fm # Illustrate modF --------------------------------------------------------- crossglctable(modF,parF,startsF)->glc.rangeF glc.rangeF$Model<-"Model F" glc.rangeF%<>%mutate(rosRemoval=(6.02e20/2357528)*Gcell*parF["C3a"]) rbind.fill(glc.rangeA,glc.rangeF)->AF glc.rangeF$rosRemoval/glc.rangeA$rosRemoval->FrelA ggplot(AF%>%subset(glucose>1000),aes(scale_Gcell2,rosRemoval,col=Model))+geom_point()+ theme_bw(base_size=20)+ ylab("ROS removal rate (per sec)")+ xlab("Population Density (CFU per mL")+ ggtitle("Model F makes ROS degradation rate dependant\non population density", )->modFP ggsave("modF.png",modFP,units = "in",width=15,height=9) modG <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * (Gcell) * eGlc/(eGlc + Ks) #eGlc is mmol/ml total (molar conc) diGlc_cyt <- (U1 * (Gcell) * eGlc/(eGlc + Ks))/cytVol - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt - dGTP_cyt * ROS * O2 dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA + R1 * odGTP dGcell <- (D1 * GDNA_cyt + R2 * mGDNA)*cytVol dscale_Gcell2 <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol)* 6.02e20 / 2357528 dcytVol <- ((D1 * GDNA_cyt + R2 * mGDNA)*cytVol * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dROS <- M1 * r * iGlc_cyt - dGTP_cyt * ROS * O2 - O3 * ROS dodGTP <- dGTP_cyt * ROS * O2 - C1 * odGTP/ (1-(iGlc_cyt/C3G)) - I2 * odGTP - R1 * odGTP dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA - R2 * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol,dROS,dodGTP,dmGDNA,dmGcell,dscale_mGcell)) }) } parG<-c(parameters,C3G=0.0026) parG["O2"]<-70 #altered to bring mut rate up to normal levels startsG<-c(iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= 8.510873e-12,scale_Gcell2 = 0, cytVol = CellVol*2175, ROS=0,odGTP=0, mGDNA=0,mGcell=0,scale_mGcell=0) DAMP.slope(parG,modG,"Model G",startsG)->G Fit.test(parG,modG,startsG) # Illustrate modG --------------------------------------------------------- crossglctable(modG,parG,startsG)->glc.rangeG glc.rangeG$Model<-"Model G" glc.rangeG%<>%mutate(odGTPRemovalRate=parG["C1"]/(1-iGlc_cyt/parG["C3G"])) glc.rangeA%<>%mutate(odGTPRemovalRate=parA["C1"]) ggplot(rbind.fill(glc.rangeA,glc.rangeG)%>%subset(glucose>1000), aes(iGlc_cyt,odGTPRemovalRate,col=Model))+ geom_point()+theme_bw(base_size=20)+ ylab("odGTP degradation rate (per second)")+xlab("Internal Glucose (M)")+ ggtitle("Model G makes odGTP degradation rate dependent\non internal glucose concentration")-> modGP ggsave("modG.png",modGP,units = "in",width=15,height=9) modH <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * (Gcell) * eGlc/(eGlc + Ks) #eGlc is mmol/ml total (molar conc) diGlc_cyt <- (U1 * (Gcell) * eGlc/(eGlc + Ks))/cytVol - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA dGcell <- (D1 * GDNA_cyt)*cytVol dscale_Gcell2 <- ((D1 * GDNA_cyt)*cytVol)* 6.02e20 / 2357528 dcytVol <- ((D1 * GDNA_cyt)*cytVol * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dROS <- M1 * r * iGlc_cyt - dGTP_cyt * ROS * O2 - O3 * ROS dodGTP <- dGTP_cyt * ROS * O2 - C1 * odGTP/ (1-(odGTP/C3b)) - I2 * odGTP dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA - R1 * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol,dROS,dodGTP,dmGDNA,dmGcell,dscale_mGcell)) }) } parH<-c(parameters,C3b=8e-10) startsH<-c(iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= 8.510873e-12,scale_Gcell2 = 0, cytVol = CellVol*2175,ROS=0,odGTP=0, mGDNA=0,mGcell=0,scale_mGcell=0) DAMP.slope(parH,modH,"Model H",startsH)->H Fit.test(parH,modH,startsH) # Illustrate modH --------------------------------------------------------- crossglctable(modH,parH,startsH)->glc.rangeH glc.rangeH$Model<-"Model H" glc.rangeH%<>%mutate(odGTPRemovalRate=parH["C1"]/(1-odGTP/parH["C3b"])) glc.rangeA%<>%mutate(odGTPRemovalRate=parA["C1"]) ggplot(rbind.fill(glc.rangeA,glc.rangeH)%>%subset(glucose>1000&odGTP>0&odGTP<1e-10), aes(odGTP,odGTPRemovalRate,col=Model))+ geom_point()+theme_bw(base_size=20)+ ylab("odGTP degradation rate (per second)")+xlab("odGTP (M)")+ ggtitle("Model H makes odGTP degradation rate\ndependent on odGTP concentration")->modHP ggsave("modH.png",modHP,units = "in",width=15,height=9) modI <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * (Gcell) * eGlc/(eGlc + Ks) #eGlc is mmol/ml total (molar conc) diGlc_cyt <- (U1 * (Gcell) * eGlc/(eGlc + Ks))/cytVol - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA dGcell <- (D1 * GDNA_cyt)*cytVol dscale_Gcell2 <- ((D1 * GDNA_cyt)*cytVol)* 6.02e20 / 2357528 dcytVol <- ((D1 * GDNA_cyt)*cytVol * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dROS <- M1 * r * iGlc_cyt - dGTP_cyt * ROS * O2 - O3 * ROS dodGTP <- dGTP_cyt * ROS * O2 - C1 * odGTP/ (1-(ROS/C3c)) - I2 * odGTP #if(odGTP <= 0) dodGTP <- dGTP_cyt * ROS * O2 dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA - R1 * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol,dROS,dodGTP,dmGDNA,dmGcell,dscale_mGcell)) }) } parI<-c(parameters,C3c=2.01e-7) parI["O2"]<-150 startsI<-c(iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= 8.510873e-12,scale_Gcell2 = 0, cytVol = CellVol*2175, ROS=0,odGTP=0, mGDNA=0,mGcell=0,scale_mGcell=0) DAMP.slope(parI,modI,"Model I",startsI)->I Fit.test(parI,modI,startsI) # Illustrate modI --------------------------------------------------------- crossglctable(modI,parI,startsI)->glc.rangeI glc.rangeI%<>%mutate(odGTPRemovalRate=parI["C1"]/(1-ROS/parI["C3c"])) glc.rangeI$Model<-"Model I" ggplot(rbind.fill(glc.rangeA,glc.rangeI)%>%subset(glucose>1000), aes(ROS,odGTPRemovalRate,col=Model))+ geom_point()+theme_bw(base_size=20)+ ylab("odGTP degradation rate (per second)")+xlab("ROS (M)")+ ggtitle("Model I makes odGTP degradation rate\ndependent on ROS concentration")->modIP ggsave("modI.png",modIP,units = "in",width=15,height=9) modJ <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * (Gcell) * eGlc/(eGlc + Ks) #eGlc is mmol/ml total (molar conc) diGlc_cyt <- (U1 * (Gcell) * eGlc/(eGlc + Ks))/cytVol - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA dGcell <- (D1 * GDNA_cyt)*cytVol dscale_Gcell2 <- ((D1 * GDNA_cyt)*cytVol)* 6.02e20 / 2357528 dcytVol <- ((D1 * GDNA_cyt)*cytVol * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dROS <- M1 * r * iGlc_cyt - dGTP_cyt * ROS * O2 - O3 * ROS dodGTP <- dGTP_cyt * ROS * O2 - C1 * odGTP * (odGTP/(odGTP+Kt)) - I2 * odGTP dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA - R1 * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol,dROS,dodGTP,dmGDNA,dmGcell,dscale_mGcell)) }) } parJ<-c(parameters,Kt=4.8e7) parJ["O2"]<-parA["O2"]*0.000053 startsJ<-c(iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= 8.510873e-12,scale_Gcell2 = 0, cytVol = CellVol*2175,ROS=0,odGTP=0, mGDNA=0,mGcell=0,scale_mGcell=0) DAMP.slope(parJ,modJ,"Model J",startsJ)->J Fit.test(parJ,modJ,startsJ) # Illustrate model J ------------------------------------------------------ crossglctable(modJ,parJ,startsJ)->glc.rangeJ glc.rangeJ%<>%mutate(odGTPRemovalRate=parJ["C1"]*odGTP/(odGTP+parJ["Kt"])) glc.rangeJ$Model<-"Model J" seq(0,7e-11,length=100)->odGTP as.data.frame(odGTP)->SIM SIM$odGTPRemovalRate<-odGTP*parJ["C1"]/(odGTP+parJ["Kt"]) ggplot(rbind.fill(glc.rangeJ)%>%subset(glucose>1000), aes(odGTP,odGTPRemovalRate))+ scale_y_continuous(breaks=c(0,1e-18,2e-18,3e-18))+ geom_point(aes(col=Model))+theme_bw(base_size=20)+ ylab("odGTP degradation rate (mmol per second)")+xlab("odGTP (M)")+ ggtitle("Model J introduces michaelis menten kinetics in\nthe odGTP degradation activity of MutT")-> modJP ggsave("modJ.png",modJP,units = "in",width=15,height=9) modK <- function(t,state, parameters){ with(as.list(c(state, parameters)),{ deGlc <- -U1 * (Gcell) * eGlc/(eGlc + Ks) #eGlc is mmol/ml total (molar conc) diGlc_cyt <- (U1 * (Gcell) * eGlc/(eGlc + Ks))/cytVol - Met1 * M1 * iGlc_cyt ddGTP_cyt <- M1 * iGlc_cyt - I1 * dGTP_cyt dGDNA_cyt <- I1 * dGTP_cyt - D1 * GDNA_cyt + C2 * mGDNA + S * mGDNA + R1 * odGTP dGcell <- (D1 * GDNA_cyt)*cytVol dscale_Gcell2 <- ((D1 * GDNA_cyt)*cytVol)* 6.02e20 / 2357528 dcytVol <- ((D1 * GDNA_cyt)*cytVol * 6.02e20 / 2357528)*CellVol #number cells x ml/cell dROS <- M1 * r * iGlc_cyt - dGTP_cyt * ROS * O2 - ((kAhp * ROS)/(ROS+kmAhp)) - ((kKat * ROS)/(ROS+kmKat)) - kdiff*(ROS-ROS_ext) dROS_ext <- (ROS - ROS_ext)*kdiff*(cytVol/(1-cytVol)) dodGTP <- dGTP_cyt * ROS * O2 - C1 * odGTP - I2 * odGTP - R1 * odGTP dmGDNA <- I2 * odGTP - D2 * mGDNA - C2 * mGDNA - S * mGDNA dmGcell <- D2 * mGDNA * cytVol dscale_mGcell <- ((D2 * mGDNA)*cytVol)* 6.02e20 / 2357528 list(c(deGlc, diGlc_cyt, ddGTP_cyt,dGDNA_cyt,dGcell,dscale_Gcell2,dcytVol,dROS,dROS_ext,dodGTP,dmGDNA,dmGcell,dscale_mGcell)) }) } parK <- c(parameters, kAhp = 6.6e-4, kmAhp = 1.2e-6, kKat = 4.9e-1, kmKat = 5.9e-3) parK["kdiff"]<-70 parK["r"]<-175 startsK<-c(iGlc_cyt=0,dGTP_cyt=0, GDNA_cyt=0,Gcell= 8.510873e-12, scale_Gcell2 = 0,cytVol = CellVol*2175,ROS=0,ROS_ext=0,odGTP=0,mGDNA=0,mGcell=0, scale_mGcell=0) Fit.test(parK,modK,startsK) DAMP.slope(parK,modK, "Model K",startsK)->K #DAMP= 0.124 # Test stopping growth early in all models... ----------------------------- DAMP.slope(parD2,modD2,"Model D2",startsD2)->D2 rbind(A,B,C,D2,E,Fm,G,H,I,J,K)->df df$Model<-rep(LETTERS[1:11],each=5) df%>%write_csv("SecondRevision/S2_data.csv") df$Hours<-(1e5/3600) graphics.off() par(mfrow = c(3, 4)) DAMP.slope.18hrs <- function (CHOSENPARAMETERS,CHOSENMODEL,label,starts) { times <- seq(0, 1e5, by = 10)#time steps of 18 hours glc.data <- function (x) {as.data.frame(lsode(y = c(eGlc = x, starts), times = times, func = CHOSENMODEL, parms = CHOSENPARAMETERS))} data.1 <- glc.data(log_glc[1]) data.2 <- glc.data(log_glc[2]) data.3 <- glc.data(log_glc[3]) data.4 <- glc.data(log_glc[4]) data.5 <- glc.data(log_glc[5]) (data.5$time/3600)->timelist plot(data.5$scale_Gcell2~timelist,main=label,log="y") abline(v=16,col="red") lines(timelist,data.1$scale_Gcell2,lwd=3,col="magenta") mutants <- function(dataframe){dataframe$mGcell[5761]} CELLS <- function(dataframe){dataframe$Gcell[5761]} wt<- c(CELLS(data.1), CELLS(data.2), CELLS(data.3), CELLS(data.4), CELLS(data.5)) mt <- c(mutants(data.1), mutants(data.2), mutants(data.3), mutants(data.4), mutants(data.5)) mr<-mt/(wt+mt) Model<-rep(label,5) df<-as.data.frame(cbind(wt,mt,mr,Model)) return(df) } list(parA,parB,parC,parD2,parE,parF,parG,parH,parI,parJ,parK)->par_list list(modA,modB,modC,modD2,modE,modF,modG,modH,modI,modJ,modK)->mod_list list(startsA,startsB,startsC,startsD2,startsE,startsF,startsG,startsH,startsI,startsJ,startsK)->starts_list DAMP.slope.18hrs(par_list[[1]],mod_list[[1]],LETTERS[1],starts_list[[1]])->data_18 for(i in 2:11){ DAMP.slope.18hrs(par_list[[i]],mod_list[[i]],LETTERS[i],starts_list[[i]])->data rbind(data_18,data)->data_18 } data_18$Hours<-16 rbind(df,data_18)->compare rep(c(LETTERS[1:11]),2)->Model Hours<-rep(c(16,1e5/3600),each=11) cbind(Model,Hours)%>%as.data.frame()->DAMP_table compare$Hours%<>%as.character() compare$wt%<>%as.numeric() compare$mt%<>%as.numeric() compare$mr%<>%as.numeric() DAMP_table$Slope<-NA DAMP_table$stdE<-NA for(i in 1:nrow(DAMP_table)){ subset(compare,Hours==DAMP_table$Hours[i]&Model==DAMP_table$Model[i])->sub lm(log(sub$mr)~log(sub$wt+sub$mt))->mod coef(summary(mod))[2,2]->DAMP_table$stdE[i] mod$coefficients[2]->DAMP_table$Slope[i] } DAMP_table%>%pivot_wider(names_from=Hours,values_from=c(Slope,stdE))->WIDER ggplot(WIDER,aes(Slope_16,Slope_27.7777777777778))+geom_point()+ geom_abline(slope=1,intercept=0,lty=2)+ geom_text_repel(aes(label=Model),col="navy")+ ylab("DAMP slope - Stationary Phase")+ xlab("DAMP slope - Exponential Phase")+ geom_errorbar(aes(ymax=Slope_27.7777777777778+1.96*stdE_27.7777777777778, ymin=Slope_27.7777777777778-1.96*stdE_27.7777777777778))+ geom_errorbarh(aes(xmin=Slope_16-1.96*stdE_16, xmax=Slope_16+1.96*stdE_16))->comparewith16 ggsave("DAMPODE_16hrs.png",comparewith16,units="in",width=8,height=6) # Illustrate modK --------------------------------------------------------- times2<-seq(0,1e5,by=1)#finer timesteps to avoid transients crossglctable2<-function(model,parameters,starts){ glc.range<-as.data.frame(matrix(nrow=1,ncol=length(starts)+3)) names(glc.range)<-c("time","eGlc",names(starts),"glucose") for(i in c(1,5)){ out.basic <- lsode(y = c(eGlc =log_glc[i], starts), times = times2, func = model, parms = parameters) out.basic%>%as.data.frame()->out.df out.df$glucose<-log_glc[i]*180e3 rbind(glc.range,out.df)->glc.range } return(glc.range[-1,]) } crossglctable2(modK,parK,startsK)->glc.rangeK ggplot(glc.rangeK,aes(time/3600,ROS_ext*1e6,col=glucose,group=glucose))+ geom_point()+theme_bw()+ scale_colour_gradient(low=brewer.pal(3,"Paired")[1], high=brewer.pal(3,"Paired")[2], breaks=c(55,120,250,525,1100), limits=c(50,1200), name="Glucose (mg/L)", trans="log")+ ylab("External ROS (micromolar)")+xlab("Time (hrs)")->Ax ggplot(glc.rangeK,aes(time/3600,ROS*1e6,col=glucose,group=glucose))+ geom_point()+theme_bw()+ scale_colour_gradient(low=brewer.pal(3,"Paired")[1], high=brewer.pal(3,"Paired")[2], breaks=c(55,120,250,525,1100), limits=c(50,1200), name="Glucose (mg/L)", trans="log")+ ylab("Internal ROS (micromolar)")+xlab("Time (hrs)")->Bx ggplot(glc.rangeK,aes(time/3600,ROS_ext/ROS,col=glucose,group=glucose))+ geom_point()+theme_bw()+ scale_colour_gradient(low=brewer.pal(3,"Paired")[1], high=brewer.pal(3,"Paired")[2], breaks=c(55,120,250,525,1100), limits=c(50,1200), name="Glucose (mg/L)", trans="log")+ ylab("External : Internal ROS Conc")+xlab("Time (hrs)")->Cx grid.arrange(Ax+labs(tag="A"),Bx+labs(tag="B"),Cx+labs(tag="C"))->modKp glc.rangeK%>%arrange(ROS)%>%head(25) ggsave("modK.png",modKp,units="in",width=10,height=8) # Fig.2A ------------------------------------------------------------------ rbind(A,B,C,D2,E,Fm,G,H,I,J,K)->df df$model<-c(rep(LETTERS[1:11],each=5)) df%>%mutate(wt=wt*( 6.02e20 / 2357528))%>% mutate(mt=mt*( 6.02e20 / 2357528))->df2 "S5_data.csv" %>% read_csv() -> raw_data raw_data%<>%subset(Experimentor=="RG"& External_Treatment=="Control"& Oxygen=="+"&genotype=="ancestor"& coculture=="n"&GlcMedia=="y") lme(data=raw_data,log((mutation_rate_genotype/79)/1e9,base=2)~log(D_genotype,base=2), random = ~ 1 | block / plate_ID)->modSB GetRandomVarianceTable<-function(modelName){ VarCorr(modelName)->VC class(VC) = "matrix" as.data.frame(VC)%>%write_clip() } GetRandomVarianceTable(modSB) 2^(predict(modSB,level=0))->raw_data$preds anova(modSB)%>%as.data.frame()%>%signif(3)%>%write_clip() raw_data%>%select(c(D_genotype,m_genotype,mutation_rate_genotype))->RawD RawD$model<-"Lab Data" names(RawD)<-names(df2) RawD$mr<-(RawD$mr/79)/1e9#Rif target size ~79 rbind(df2,RawD)->df1 df1$model%<>%as.factor() df1$model<-factor(df1$model,levels=c(rev(c("Lab Data","A","B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" )))) df1%>%filter(model!="Lab Data")->dffilt dffilt <- within(dffilt, model <- relevel(model, ref = "A")) lm(log2(mr)~log2(wt)*model,data=dffilt)->modelmodels modelmodels%>%anova()%>%as.data.frame()%>%signif(3)%>%write_clip() modSA.stdres <- rstandard(modelmodels) png("modSA_RES.png") plot(fitted(modelmodels), modSA.stdres, ylab="Standardized Residuals", xlab="Fitted Values", ) abline(0, 0) dev.off() png("modSA_QQ.png") plot(modelmodels,which=2) dev.off() 2^predict(modelmodels)->preds nrow(df1)-length(preds)->nas df1$pred<-c(preds,rep(NA,nas)) ggplot(df1,aes(wt,mr,colour=model,shape=model,lty=model))+ geom_line(lwd=1,aes(y=pred))+ theme_bw(base_size=24)+ geom_point(alpha=0.5,size=3,data=RawD)+ scale_x_log10()+ scale_y_log10(limits=c(3e-11,1e-9), breaks=c(3e-11,1e-10,3e-10,1e-9))+ scale_colour_manual(values=c("black","red",brewer.pal(name="Dark2",n=8)[-8], brewer.pal("Paired",n=12)[c(1,2)],brewer.pal("Set1",n=9)[5],"black"), breaks=c( "Lab Data","A","B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" ), labels=c("Lab Data","A ","B [1]" , "C [2]" , "D [2]" , "E [3]" , "F [3]" , "G [4]" , "H [4]" , "I [4]" , "J [4]" , "K [3]" ) )+ ylab(expression(paste("Mutation Rate ( ", bp^{-1}," ", gen^{-1},")")))+ xlab(expression(paste("Population Density ( ", CFU^{}," ", mL^{-1},")")))+ scale_shape_manual(values=c(rep(19,19)), breaks=c( "Lab Data","A","B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" ), labels=c("Lab Data","A ","B [1]" , "C [2]" , "D [2]" , "E [3]" , "F [3]" , "G [4]" , "H [4]" , "I [4]" , "J [4]" , "K [3]" ))+ scale_linetype_manual(values=c(0,rep(1,11),0), breaks=c( "Lab Data","A","B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" ), labels=c("Lab Data","A ","B [1]" , "C [2]" , "D [2]" , "E [3]" , "F [3]" , "G [4]" , "H [4]" , "I [4]" , "J [4]" , "K [3]" ))+ geom_line(data=raw_data,aes(D_genotype,preds),lty=2,lwd=1,inherit.aes = F)+ labs(colour="Model",shape="Model",lty="Model",tag="A")->Fig2A # Saving slopes of models with original parameters (Regression 1) ------------------------ dffilt$model%<>%as.character() dffilt$model%<>%as.factor() matrix(nrow=length(levels(dffilt$model)),ncol=5)%>%as.data.frame()->BASES names(BASES)<-c("Model","Slope","CI_95","Intercept","Intercept_95") ORD<-LETTERS[1:11] for(i in 1:11){ dffilt <- within(dffilt, model <- relevel(model, ref = ORD[i])) lm(log2(mr)~log2(wt)*model,data=dffilt)->model model%>%summary()%>%coef()->co confint(model, level=0.95)->int ORD[i]->BASES$Model[i] co[1,1]%>%signif(3)->BASES$Intercept[i] co[2,1]%>%signif(3)->BASES$Slope[i] ((int[1,2]-co[1,1])/2)%>%signif(3)->BASES$Intercept_95[i] ((int[2,2]-co[2,1])/2)%>%signif(3)->BASES$CI_95[i] } signif3<-function(number){signif(number,digits=3)} BASES%>%mutate_if(is.numeric, signif3)%>%write_csv("BaselineSlopes.csv") # # Global Sensitivity Analysis (Output of this section available as S3A_data.7z )--------------------------------------------- # This section is comutationally intensive and using the provided zip file instead is recommended list(parA,parB,parC,parD2,parE,parF,parG,parH,parI,parJ,parK)->par_list list(modA,modB,modC,modD2,modE,modF,modG,modH,modI,modJ,modK)->mod_list list(startsA,startsB,startsC,startsD2,startsE,startsF,startsG,startsH,startsI,startsJ,startsK)->starts_list DAMP.slopeS <- function (CHOSENPARAMETERS,CHOSENMODEL, starts){ times <- seq(0, 1e5, by = 10) glc.data <- function (x) {as.data.frame(lsode(y = c(eGlc = x, starts), times = times, func = CHOSENMODEL, parms = CHOSENPARAMETERS))->dataframe} data.1 <- try(glc.data(log_glc[1]),silent=TRUE) data.2 <- try(glc.data(log_glc[2]),silent=TRUE) data.3 <- try(glc.data(log_glc[3]),silent=TRUE) data.4 <- try(glc.data(log_glc[4]),silent=TRUE) data.5 <- try(glc.data(log_glc[5]),silent=TRUE) mutants <- function(dataframe){(dataframe$mGcell[10001])/(dataframe$mGcell[10001] + dataframe$Gcell[10001])} CELLS <- function(dataframe){dataframe$Gcell[10001]} x <- c(CELLS(data.1), CELLS(data.2), CELLS(data.3), CELLS(data.4), CELLS(data.5)) list(NA,NA)->result if (as.numeric(is.na(x)==FALSE)%>%sum()>4) { y <- c(mutants(data.1), mutants(data.2), mutants(data.3), mutants(data.4), mutants(data.5)) stat <- function(dataframe){ lm(dataframe$scale_Gcell2[9000:10000]~c(9000:10000))->g return(as.numeric(g$coefficients[2])) } STAT <- as.list(c(stat(data.1),stat(data.2),stat(data.3),stat(data.4),stat(data.5))) DAMP.lm <-lm(log(y) ~ log(x+y)) #result=lm,stationary,wt,mr list(DAMP.lm,STAT,as.list(x),as.list(y))->result} result } rep(NA,11)->parN for(i in 1:length(par_list)){length(par_list[[i]])->parN[i]} max(parN)->maxPars multipliers <- as.data.frame(matrix(nrow=N_Runs,ncol=maxPars)) multipliers[1,]<-1 set.seed(1143) for(i in 1:maxPars){ multipliers[2:N_Runs,i]<-sample(lseq(0.1,10,N_Runs-1)) } output_list <- vector(mode='list', length=length(par_list)) format<-function(data){ for(i in c((ncol(data)-14):ncol(data))){ list<-c(rep(NA,N_Runs)) for(j in 1:N_Runs){ data[j,i]%>%unlist()%>%as.character()%>%as.numeric()->val if (is_empty(val)==TRUE){NA->list[j]} else (val->list[j]) } list->data[,i] } return(data) } foreach (i=1:11, .packages=c("tidyverse","magrittr","deSolve","emdbook"), .combine='c') %dopar% { length(par_list[[i]])->nPars multipliers[,1:nPars]->nMult nMult$ParSet<-1:N_Runs par_list[[i]]->modPars for(j in 1:nPars){ names(modPars)[j]->names(nMult)[j] modPars[j]*nMult[,j]->nMult[,j] } nMult%>% tibble() %>% rowwise()-> sensitivity sensitivity %>% group_by(ParSet) %>% nest() -> sens.nest sens.nest%>%add_column(Intercept = NA) ->sens.nest sens.nest%>%add_column(Gradient = NA) ->sens.nest sens.nest%>%add_column(Stationary = NA) ->sens.nest sens.nest%>%add_column(Tried = NA)->sens.nest sens.nest%<>%add_column(CellsWT = NA) sens.nest%<>%add_column(CellsMR = NA) sens.nest%<>%add_column(MaxStat = NA) for (k in seq(1,N_Runs,by=1)) { try(DAMP.slopeS(sens.nest[[2]][[k]], mod_list[[i]],starts_list[[i]]),silent=TRUE) -> mod "Yes"->sens.nest$Tried[k] if(class(mod) == "try-error"){next} if(is.na(mod[1])==TRUE){next} mod[1]->model model[[1]]$coefficients[1] -> sens.nest$Intercept[k] model[[1]]$coefficients[2] -> sens.nest$Gradient[k] mod[3]->sens.nest$CellsWT[k] mod[4]->sens.nest$CellsMR[k] mod[2]-> sens.nest$Stationary[k] mod[[2]]%>%as.numeric()%>%abs()%>%max()->sens.nest$MaxStat[k] mod<-list(NA,NA) } sens.nest %>% unnest(CellsWT) %>% group_by(ParSet) %>% mutate(col=seq_along(ParSet)) %>% mutate(col=paste0("WT",col))%>%#add a column indicator spread(key=col, value=CellsWT)->sens.nest sens.nest %>% unnest(CellsMR) %>% group_by(ParSet) %>% mutate(col=seq_along(ParSet)) %>% mutate(col=paste0("MR",col))%>%#add a column indicator spread(key=col, value=CellsMR)->sens.nest sens.nest %>% unnest(Stationary) %>% group_by(ParSet) %>% mutate(col=seq_along(ParSet)) %>% mutate(col=paste0("Stat",col))%>%#add a column indicator spread(key=col, value=Stationary)->sens.nest return(list(sens.nest%>%unnest(data)%>%format())) }->output_LIST for( modelN in 1:length(output_LIST)){ paste0("model_",LETTERS[modelN],"sens.csv")->name write.csv(output_LIST[[modelN]],name) } # Reading in and analysing sensitivity output ----------------------------- #Set working directory to unzipped S3 Data df <- list.files(pattern = "model_*") %>% map_df(~read_csv(.)) N_Runs<-5e4 df$Model<-rep(LETTERS[c(1:11)],each=N_Runs) df%>%subset(!is.na(Gradient))->success success%>%nrow()/(N_Runs*11) table(success$Model)%>%t()%>%t()->Noughth_filter success%<>%mutate(ReachStat= (MaxStat<1&MR1>0&MR2>0&MR3>0&MR4>0&MR5>0)) success%>%subset(MaxStat<1&MR1>0&MR2>0&MR3>0&MR4>0&MR5>0)->stationary table(stationary$Model)%>%t()%>%t()->First_filter cbind(Noughth_filter,First_filter)->filters stationary%>%subset(WT1*6.02e20/2356491>1e7& WT1*6.02e20/2356491<1e10& WT2*6.02e20/2356491>1e7& WT2*6.02e20/2356491<1e10& WT3*6.02e20/2356491>1e7& WT3*6.02e20/2356491<1e10& WT4*6.02e20/2356491>1e7& WT4*6.02e20/2356491<1e10& WT5*6.02e20/2356491>1e7& WT5*6.02e20/2356491<1e10)->goodNt table(goodNt$Model)%>%t()%>%t()->Sec_filter cbind(filters,Sec_filter)->filters goodNt%>%filter(WT1orderNt table(orderNt$Model)%>%t()%>%t()->Third_filter cbind(filters,Third_filter)->filters orderNt%>%filter(MR1<2e-8&MR2<2e-8& MR3<2e-8&MR4<2e-8&MR5<2e-8)->LowMR LowMR%>%filter(MR1>2e-12&MR2>2e-12& MR3>2e-12&MR4>2e-12&MR5>2e-12)->HighMR table(HighMR$Model)%>%t()%>%t()->Four_filter cbind(filters,Four_filter)->filters FIND_RSQ<-function(MR1,MR2,MR3,MR4,MR5, WT1,WT2,WT3,WT4,WT5){ lm(log(as.numeric(c(MR1,MR2,MR3,MR4,MR5)))~ log(as.numeric(c(WT1,WT2,WT3,WT4,WT5))))->mo return(summary(mo)$adj.r.squared) } HighMR$rsq<-NA for (i in 1:nrow(HighMR)){ FIND_RSQ(HighMR$MR1[i],HighMR$MR2[i],HighMR$MR3[i],HighMR$MR4[i],HighMR$MR5[i], HighMR$WT1[i],HighMR$WT2[i],HighMR$WT3[i],HighMR$WT4[i],HighMR$WT5[i])->HighMR$rsq[i] } HighMR%>%filter(rsq>0.5)->rsqT table(rsqT$Model)%>%t()%>%t()->Five_filter cbind(filters,Five_filter)->filters colnames(filters)<-c("Sucessful Run",paste0("Filter ",c(1:5))) filters%<>%as.data.frame() filters$Model<-LETTERS[1:11] filters%>%write.csv("FilteredRuns.csv")#table of runs per model after filter rsqT%>% group_by(Model)%>% dplyr::summarize(q25=quantile(Gradient,probs=0.25), q50=quantile(Gradient,probs=0.5), q75=quantile(Gradient,probs=0.75), max=max(Gradient), min=min(Gradient), count=n())%>% as.data.frame()->summaryt write_csv(summaryt,"SensSummary.csv") write_csv(rsqT,"CombinedModels.csv") OG<-c(rep(NA,11)) for(i in 1:11){ subset(df1,model==LETTERS[i])->sub lm(log(sub$mr)~log(sub$wt))->mod mod$coefficients[2]->OG[i] } summaryt$OG<-OG modSB%>%summary()%>%coef()%>%as.data.frame()->LAB ggplot(summaryt,aes(Model,q50,colour=Model,ymin=q25,ymax=q75))+ geom_rect(col=NA,fill="grey", ymin=LAB[2,1]-1.96*LAB[2,2], ymax=LAB[2,1]+1.96*LAB[2,2], xmin=-Inf, xmax=Inf, alpha=0.03)+ scale_y_continuous(breaks=c(-1,-0.75,-0.5,-0.25,0,0.25),limits=c(-1,0.25))+ geom_hline(yintercept=0,lty=1)+ scale_shape_manual(values=c(rep(19,11),17))+ geom_point(size=3,colour="black",shape=4)+ geom_point(size=4,aes(y=OG),alpha=0.8)+ theme_bw(base_size = 24)+ theme(legend.position="none")+ ylab("Slope")+ geom_errorbar(width=0.1,colour="black")+ scale_colour_manual(values=c("red",brewer.pal(name="Dark2",n=8)[-8], brewer.pal("Paired",n=12)[c(1,2,10)],"black"), breaks=c( "A","B" , "C" , "D" , "E" , "F" , "G" , "H" , "I" , "J" , "K" ))+ geom_hline(yintercept=LAB[2,1],lty=2)+labs(tag="B")->SENS grid.arrange(Fig2A+theme(legend.text.align=1),SENS,ncol=2,widths=c(4,3))->f2 ggsave("Fig2.tiff",f2,width=20,height=9,device="png",units="in") # Fig. S2 Spearman's rank correlation -------------------------------------------- rsqT%>%subset(Model=="A")->df_A names(df_A) df_A%<>%pivot_longer(cols=c(3:19),names_to = "Parameter",values_to="Value") df_A$Parameter%<>%as.factor() df_A$Model%<>%as.factor() df_A$Parameter%>%levels()%>%length()->npar rho <- as.data.frame(matrix(nrow=1,ncol=4)) names(rho)<-c("Parameter","Model","SpRho","pValue") for(i in c(1:npar)){ df_A%>%subset(Parameter==levels(df_A$Parameter)[i])->df3 corr <- cor.test(x=log(df3$Value), y=df3$Gradient, method = 'spearman', alternative = "two.sided",exact=FALSE) c(levels(df_A$Parameter)[i],"A",corr$estimate,corr$p.value)->l rho%<>%rbind(l) } rho%>%arrange(abs(as.numeric(SpRho)))->ar rho$Parameter<-factor(rho$Parameter,levels=ar$Parameter) ggplot(rho[-1,],aes(Parameter,abs(as.numeric(SpRho)),colour=as.numeric(pValue)<0.05, fill=SpRho>0))+ geom_point(size=4.5,shape=21,stroke=1.5)+ scale_colour_manual(values = c("white","black"),name="P < 0.05")+ theme_bw()+ ylab("Absolute Spearman's Rho")+ scale_fill_manual(name="Correlation", breaks=c(TRUE,FALSE), labels=c("Positive","Negative"), values=c(brewer.pal("Dark2",n=8)[c(1,2)]))+ ggtitle("DAMP")->DAMPplot #for mutrate rhoMR <- as.data.frame(matrix(nrow=1,ncol=4)) names(rhoMR)<-c("Parameter","Model","SpRhoMR","pValueMR") for(i in c(1:npar)){ df_A%>%subset(Parameter==levels(df_A$Parameter)[i])->df3 corr <- cor.test(x=df3$Value, y=df3$MR3, method = 'spearman', alternative = "two.sided",exact=FALSE) c(levels(df_A$Parameter)[i],"A",corr$estimate,corr$p.value)->l rhoMR%<>%rbind(l) } rho$SpRho%<>%as.numeric() rhoMR$SpRhoMR%<>%as.numeric() rho$Parameter%<>%as.character() cbind(rho[-1,],rhoMR[-1,])->RHO subset(RHO,pValue<0.05&pValueMR<0.05) rhoMR%>%arrange(abs(as.numeric(SpRhoMR)))->ar rhoMR$Parameter<-factor(rhoMR$Parameter,levels=ar$Parameter) ggplot(rhoMR[-1,],aes(Parameter,abs(as.numeric(SpRhoMR)), colour=as.numeric(pValueMR)<0.05, fill=SpRhoMR>0))+ ggtitle("Mutation Rate")+ geom_point(size=4.5,shape=21,stroke=1.5)+ scale_colour_manual(values = c("white","black"),name="P < 0.05")+ ylab("Absolute Spearman's Rho")+ scale_fill_manual(name="Correlation", breaks=c(TRUE,FALSE), labels=c("Positive","Negative"), values=c(brewer.pal("Dark2",n=8)[c(1,2)]))+ theme_bw()->MRplot grid.arrange(DAMPplot+labs(tag="A")+theme_bw(base_size = 20), MRplot+labs(tag="B")+theme_bw(base_size = 20),ncol=2)->RHOplot ggsave("FigS2.tiff",RHOplot,device="png",width=27,height=10,units="in") write_csv(RHO,"SPRHOTABLE.csv") # Fig. S3 Supplementary iGlc figure ----------------------------------------------- ggplot(glc.range,aes(time/3600,iGlc_cyt*180e3,colour=glucose))+ geom_point()+theme_bw(base_size=24)+ ylab(expression(paste("Internal Glucose ( mg ", L^{ -1 }, ")")))+ xlab("Time (hrs)")+ scale_x_continuous(breaks=c(0,6,12,18,24))+ scale_colour_gradient(low=brewer.pal(3,"Paired")[1], high=brewer.pal(3,"Paired")[2], breaks=c(55,120,250,525,1100), limits=c(50,1200), name="Glucose (mg/L)", trans="log")->iGlcPlot ggsave("FigS3.tiff", iGlcPlot,width=8,height=5,units="in") # Flow diagrams for all mods Fig. A1 (this was annotated in powerpoint for publication) ----------------------------------------------- grViz(" digraph GTP_Oxidiation { # a 'graph' statement graph [layout=dot,overlap = true, fontsize = 24, fontname = Helvetica, nodesep = 1] subgraph cluster_main { # several 'node' statements node [shape = circle, fontname = Helvetica, style = filled, color = '#A6CEE3', fontsize=18, fontcolor = black, fixedsize = 'true', width = 1, height = 1]; iGlc; Sink; ROS; dGTP; DNA node [shape = circle, fontname = Helvetica, style = filled, color = '#FB9A99', fontsize=18, fontcolor = black, fixedsize = 'true', width = 1, height = 1]; odGTP; mDNA } node [shape = circle, fontname = Helvetica, style = filled, fontsize=18, color = '#A6CEE3', fixedsize = 'true', width = 1, height = 1]; eGlc; wtCell; node [shape = circle, fontname = Helvetica, style = filled, fontsize=18, color = '#C1E1C1', fixedsize = 'true', width = 1, height = 1]; ROSext node [shape = circle, fontname = Helvetica, style = filled, fontsize=18, color = '#FB9A99', fixedsize = 'true', width = 1, height = 1]; mCell; # several 'edge' statements eGlc->iGlc [penwidth = 2, fontsize = 9]; iGlc-> {Sink } [penwidth = 2, fontsize = 9]; iGlc-> { ROS} [penwidth = 2, fontsize = 9]; iGlc-> {dGTP} [penwidth = 2, fontsize = 9]; ROS -> {odGTP}[penwidth = 2, fontsize = 9]; ROS -> {Sink} [penwidth = 2, fontsize = 9]; dGTP -> {odGTP}[penwidth = 2, fontsize = 9]; dGTP -> {DNA} [penwidth = 2, fontsize = 9]; odGTP -> {DNA}[penwidth = 2, fontsize = 9]; odGTP -> {Sink} [penwidth = 2, fontsize = 9]; odGTP -> {mDNA} [penwidth = 2, fontsize = 9]; DNA -> wtCell[penwidth = 2, fontsize = 9]; mDNA -> {DNA} [penwidth = 2, fontsize = 9]; mDNA -> {wtCell} [penwidth = 2, fontsize = 9]; mDNA -> {mCell} [penwidth = 2, fontsize = 9]; iGlc -> ROS [penwidth = 1, color='white', arrowhead='none']; } ") ->GRAPHmodA GRAPHmodA # Appendix Figure A3 -------------------------------------------------------- crossglctable_name<-function(model,parameters,starts,name){ glc.range<-as.data.frame(matrix(nrow=1,ncol=length(unlist(starts))+4)) names(glc.range)<-c("time","eGlc",names(unlist(starts)),"glucose","model") for(i in 1:5){ out.basic <- lsode(y = c(eGlc =log_glc[i], unlist(starts)), times = times, func = unlist(model)[[1]], parms = unlist(parameters)) out.basic%>%as.data.frame()->out.df out.df$glucose<-log_glc[i]*180e3 out.df$model<-name rbind(glc.range,out.df)->glc.range } return(glc.range[-1,]) } crossglctable_name(mod_list[1],par_list[1],starts_list[1],LETTERS[1])->CrossGlcAll for(j in 1:11){ rbind.fill(CrossGlcAll, crossglctable_name(mod_list[j],par_list[j],starts_list[j],LETTERS[j]))->CrossGlcAll } ggplot(CrossGlcAll%>%subset(glucose>240&glucose<260), aes(time/3600,mGcell/(mGcell+Gcell)))+ geom_point()+ theme_bw()+facet_wrap(~model,scales="free_y")