|
| 1 | +# Figure 2-6: (Include Red lysed dots) |
| 2 | + |
| 3 | +my.prop.test <- function(xThresh=0, x1, x2, y1, y2) |
| 4 | +{ |
| 5 | + lo.1 <- which(x1 < xThresh) |
| 6 | + hi.1 <- which(x1 >= xThresh) |
| 7 | + lo.2 <- which(x2 < xThresh) |
| 8 | + hi.2 <- which(x2 >= xThresh) |
| 9 | + |
| 10 | + n1.lo <- length(lo.1) |
| 11 | + n1.hi <- length(hi.1) |
| 12 | + n2.lo <- length(lo.2) |
| 13 | + n2.hi <- length(hi.2) |
| 14 | + |
| 15 | + mat <- as.matrix(data.frame(intact=c(n1.lo,n1.hi), lysed=c(n2.lo,n2.hi))) |
| 16 | + print(mat) |
| 17 | + ret <- prop.test(mat) |
| 18 | + return(list(matrix=mat, test=ret)) |
| 19 | +} |
| 20 | + |
| 21 | +######### Plot A ########## |
| 22 | + |
| 23 | +# a) x=Time.Delta.Delay y=Int.Max.R (only plot the negatives x's) (Use MaxInt Population) |
| 24 | +pop <- pop_MaxInt.Gp |
| 25 | +x <- pop[pop$Time.Delta.Delay <= 1000 & pop$Death == 1,]$Time.Delta.Delay |
| 26 | +y <- pop[pop$Time.Delta.Delay <= 1000 & pop$Death == 1,]$Int.Max.R |
| 27 | +x2 <- pop[pop$Time.Delta.Delay <= 1000 & pop$Death == 2,]$Time.Delta.Delay |
| 28 | +y2 <- pop[pop$Time.Delta.Delay <= 1000 & pop$Death == 2,]$Int.Max.R |
| 29 | +# cols <- getDensityColors(x,y) |
| 30 | +xcol <- 'black' |
| 31 | +ycol <- R |
| 32 | +xlim = c(min(c(x,x2)),max(c(x,x2))) |
| 33 | +ylim = c(min(c(y,y2)),max(c(y,y2))) |
| 34 | +pdf('Figure_11_a.pdf', height=0.9*H, width=0.9*W) |
| 35 | +paperParams(1,1,1) |
| 36 | +paperPlot(letter='b',xlimit=xlim, ylimit=ylim, xlabel='Host Reaction-Time [h]', ylabel='(Virus) Max-Intensity [au]', xcol=xcol, ycol=ycol) |
| 37 | +points(x, y, pch=21, col=rgb(0,0,0,0), bg=rgb(0,0,0,0.3), cex=0.85) |
| 38 | +points(x2, y2, pch=21, col=rgb(0,0,0,0), bg=rgb(0,0,0,0.3), cex=0.85) |
| 39 | +abline(v=0,lty=4) |
| 40 | +# text(mean(xlim), max(ylim), labels='when < 0, host activation\ndetected prior to infection', col = 'darkgreen', cex = 1, adj = c(0.5,1)) |
| 41 | +# arrows(x1=mean(xlim)-.1*(max(xlim)-min(xlim)),y0=0.75*max(ylim),x0=mean(xlim)+.1*(max(xlim)-min(xlim)), lwd=3, col='darkgreen') |
| 42 | +dev.off() |
| 43 | + |
| 44 | +######### Test A ########## |
| 45 | +duh <- summary(lm(y~x,data.frame(x=c(x,x2),y=log10(c(y,y2))))) |
| 46 | +duh |
| 47 | +duh <- cor.test(c(x,x2),log10(c(y,y2))) |
| 48 | +duh |
| 49 | +duh <- my.prop.test(xThresh=0,x1=x,x2=x2,y1=y,y2=y2) |
| 50 | +duh |
| 51 | + |
| 52 | +######### Plot B ########## |
| 53 | + |
| 54 | +# b) x=Time.Delta.Delay y=Int.Max.G (only plot the positive x's) |
| 55 | +pop <- pop_MaxInt.Gp |
| 56 | +x <- pop[pop$Time.Delta.Delay >= -1000 & pop$Death == 1,]$Time.Delta.Delay |
| 57 | +y <- pop[pop$Time.Delta.Delay >= -1000 & pop$Death == 1,]$Int.Max.G |
| 58 | +x2 <- pop[pop$Time.Delta.Delay >= -1000 & pop$Death == 2,]$Time.Delta.Delay |
| 59 | +y2 <- pop[pop$Time.Delta.Delay >= -1000 & pop$Death == 2,]$Int.Max.G |
| 60 | +# cols <- getDensityColors(x,y) |
| 61 | +xcol <- 'black' |
| 62 | +ycol <- G |
| 63 | +xlim = c(min(c(x,x2)),max(c(x,x2))) |
| 64 | +ylim = c(min(c(y,y2)),max(c(y,y2))) |
| 65 | +pdf('Figure_11_b.pdf', height=0.9*H, width=0.9*W) |
| 66 | +paperParams(1,1,1) |
| 67 | +paperPlot(letter='c',xlimit=xlim, ylimit=ylim, xlabel='Host Reaction-Time [h]', ylabel='(Host) Max-Intensity [au]', xcol=xcol, ycol=ycol) |
| 68 | +points(x, y, pch=21, col=rgb(0,0,0,0), bg=rgb(0,0,0,0.3), cex=0.85) |
| 69 | +points(x2, y2, pch=21, col=rgb(0,0,0,0), bg=rgb(0,0,0,0.3), cex=0.85) |
| 70 | +abline(v=0,lty=4) |
| 71 | +# text(mean(xlim), max(ylim), labels='when > 0, host activation\ndetected after infection', col = 'darkred', cex = 1, adj = c(0.5,1)) |
| 72 | +# arrows(x0=mean(xlim)-.1*(max(xlim)-min(xlim)),y0=0.75*max(ylim),x1=mean(xlim)+.1*(max(xlim)-min(xlim)), lwd=3, col='darkred') |
| 73 | +dev.off() |
| 74 | + |
| 75 | +######### Test B ########## |
| 76 | +duh <- summary(lm(y~x,data.frame(x=c(x,x2),y=log10(c(y,y2))))) |
| 77 | +duh |
| 78 | +duh <- cor.test(x=c(x,x2),y=log10(c(y,y2))) |
| 79 | +duh |
| 80 | +duh <- my.prop.test(xThresh=0,x1=x,x2=x2,y1=y,y2=y2) |
| 81 | +duh |
| 82 | + |
| 83 | +######### Plot C ########## |
| 84 | + |
| 85 | +# c) (Use the Max.Int population here) |
| 86 | +pop <- pop_MaxInt.Gp |
| 87 | +pop$Ratio.Max <- pop$Int.Max.R/pop$Int.Max.G |
| 88 | +pop$Ratio.Max.Log <- log10(pop$Ratio.Max) |
| 89 | +xlim <- c(min(pop$Time.Delta.Delay),max(pop$Time.Delta.Delay)) |
| 90 | +ylim <- c(min(pop$Ratio.Max),max(pop$Ratio.Max)) |
| 91 | +pdf('Figure_11_c.pdf', height=0.9*H, width=1.8*W) |
| 92 | +paperParams(1,1, labsize=1) |
| 93 | +par(mar = c(3.7,4.7,0.8,0.8)); # beyond plot frame [b,l,t,r] |
| 94 | +par(mgp = c(2.5,0.8,0)); # placement of axis labels [1], numbers [2] and symbols[3] |
| 95 | +paperPlot(letter='c',xlimit=xlim, ylimit=ylim, xlabel='Host Reaction-Time [h]', ylabel='(Virus Max-Int.) / (Host Max-Int.)', xcol='black', ycol='black', log='y', yticks=c('0.001', '0.01', '0.01', '0.1', '1', '10', '100', '1000')) |
| 96 | +points(pop[pop$Death == 1,]$Time.Delta.Delay, pop[pop$Death == 1,]$Ratio.Max, pch=21, cex=0.7, col='black', bg='black') |
| 97 | +points(pop[pop$Death == 2,]$Time.Delta.Delay, pop[pop$Death == 2,]$Ratio.Max, pch=21, cex=0.7, col='red', bg='red') |
| 98 | +X.1 <- seq(from=-15, to=0, by=0.5) |
| 99 | +X.2 <- seq(from=0, to=15, by=0.5) |
| 100 | +# dev.off() |
| 101 | +library(drc) |
| 102 | +fitResults <- data.frame(X_1=numeric(0), Y_1=numeric(0), X_2=numeric(0), Y_2=numeric(0), SSE=numeric(0)) |
| 103 | +for(x1 in X.1) |
| 104 | +{ |
| 105 | + for(x2 in X.2) |
| 106 | + { |
| 107 | + defs <- DefinePWFct(x1,x2) |
| 108 | + pNames.pw <- defs$a |
| 109 | + fct.pw <- defs$b |
| 110 | + ssfct.pw <- defs$c |
| 111 | + fctDef.pw <- defs$d |
| 112 | + pwModel <- drm(Ratio.Max.Log~Time.Delta.Delay,data=pop,pmodels=data.frame(1,1),fct=fctDef.pw,na.action=na.omit,separate=FALSE, type='continuous') |
| 113 | + # Gather results from the fitting into a more accesible table format |
| 114 | + temp <- coef(pwModel) # grab the fitted parameters from the model object |
| 115 | + fitResults <- rbind(fitResults, data.frame(X_1 = x1, Y_1 = temp[1], X_2 = x2, Y_2 = temp[2], SSE = sum(residuals(pwModel)^2))) |
| 116 | + } |
| 117 | +} |
| 118 | + |
| 119 | +# library(scatterplot3d) |
| 120 | +# scatterplot3d(fitResults$X_1, fitResults$X_2, fitResults$SSE, pch=20, highlight.3d=TRUE)#color=rgb(0,0,0,0), bg=rgb(0,0,0,0.5+fitResults$X_2/(2*min(fitResults$X_3)))) |
| 121 | + |
| 122 | +bestFit <- which(fitResults$SSE == min(fitResults$SSE)) |
| 123 | +bestFit <- fitResults[bestFit,] |
| 124 | +print(bestFit) |
| 125 | + |
| 126 | +# Reset starter function to be near gloabl min |
| 127 | +startDaFunc <- function(data) |
| 128 | +{ |
| 129 | + return(c(bestFit$Y_1, bestFit$Y_2, bestFit$X_1, bestFit$X_2)) |
| 130 | + # return(c(-4.711, -0.9105, 6, 1.181)) |
| 131 | +} |
| 132 | +daFuncDef <- list(name='pwlin',fct=daFunc, ssfct=startDaFunc, names=c('X_1','Y_1','X_2','Y_2')); |
| 133 | + |
| 134 | +# Fit all parameters to refine optimization |
| 135 | +pwModel <- drm(Ratio.Max.Log~Time.Delta.Delay,data=pop,pmodels=data.frame(1,1,1,1),fct=daFuncDef,na.action=na.omit,separate=FALSE, type='continuous') |
| 136 | +# duh <- daFunc2(pop$Time.Delta.Delay,coef(pwModel)) |
| 137 | +# duh2 <- daFunc2(pop$Time.Delta.Delay,startDaFunc()) |
| 138 | +# plot(pop$Time.Delta.Delay, pop$Ratio.Max.Log, type='p', col=rgb(0,0,0,0.5)) |
| 139 | +# points(pop$Time.Delta.Delay, duh, col='red') |
| 140 | +# points(pop$Time.Delta.Delay, duh2, col='green') |
| 141 | +summary(pwModel) |
| 142 | + |
| 143 | +# plot fit results and mean indicators over data |
| 144 | +from <- -40 |
| 145 | +to <- 40 |
| 146 | +lines(cbind(c(from,bestFit$X_1,bestFit$X_2,to),10^(c(bestFit$Y_1,bestFit$Y_1,bestFit$Y_2,bestFit$Y_2)))) |
| 147 | +lines(cbind(c(from,coef(bestFit)['x1:(Intercept)'],coef(bestFit)['x2:(Intercept)'],to),10^(c(coef(bestFit)['y1:(Intercept)'],coef(bestFit)['y1:(Intercept)'],coef(bestFit)['y2:(Intercept)'],coef(bestFit)['y2:(Intercept)'])))) |
| 148 | +abline(h=10^(mean(pop$Ratio.Max.Log)),lty=4) |
| 149 | +abline(v=mean(pop$Time.Delta.Delay),lty=4) |
| 150 | +abline(v=0,lty=1) |
| 151 | + |
| 152 | +text(0-1, 5*min(ylim), labels='host activation\ndetected prior to infection', col = 'darkgreen', cex = 1, adj = c(1,1)) |
| 153 | +text(0+1, 5*min(ylim), labels='host activation\ndetected after infection', col = 'darkred', cex = 1, adj = c(0,1)) |
| 154 | +arrows(x0=-1,y0=0.03,x1=-3, lwd=3, col='darkgreen') |
| 155 | +arrows(x0=1,y0=0.03, x1=3, lwd=3, col='darkred') |
| 156 | + |
| 157 | +1-bestFit$SSE/sum((pop$Ratio.Max.Log-mean(pop$Ratio.Max.Log))^2) |
| 158 | + |
| 159 | +# linFit <- lm(Ratio.Max.Log~Time.Delta.Delay, data=pop, na.action=na.omit) |
| 160 | +# abline(coef(linFit)) |
| 161 | + |
| 162 | +# Finish the plot |
| 163 | +dev.off() |
| 164 | + |
| 165 | + |
| 166 | + |
0 commit comments