library(gplots)
options( warn = 1 )


dataTableTryptone <- read.table(paste('experimentalData','ecoliGrowthData_20120229_Tryptone_40min.txt', sep= .Platform$file.sep), sep='\t', header = TRUE)


# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

tLimInHours <- 20/60

dataTableRI <- read.table(paste('simulationsText','tryptoneInfectedSimulation.txt', sep= .Platform$file.sep), sep='\t', header = TRUE)
dataTableRI <- subset(dataTableRI, t<tLimInHours)
hostTableRI <- subset(dataTableRI, hostFlag ==1)


dataTableRI$t <- dataTableRI$t*60


postscript(paste('figureOutput',"figureAuthSumB.eps", sep= .Platform$file.sep), width = 3.25, height = 1.0, horizontal = FALSE, onefile = FALSE, paper = "special", pointsize = 7)
# note that this will be a 7 in wide figure, but need to add ylabel
layout( matrix( (1:4), byrow = TRUE, ncol = 4) )

par( mar= c(2, 2, 1, 0.25), pointsize = 7, cex = 1, cex.axis=1,cex.main=1 , xpd = NA)

colorUse <- 'coral1'

# rich

# plot(dataTableRI$t,dataTableRI$CONCvMRNA1Ref, col = 'grey70' , lty = 'dashed', type = 'l',   axes = FALSE, xlab='Time From Infection (min)')
# lines(dataTableRI$t,dataTableRI$CONCvMRNA1, col = colorUse )
# title(main="mRNA Gene 1", font.main = 1 )
# axis(1, at = seq(from = 0, to = 20, by = 5), label = c('0', ' ','10',' ','20'))
# axis(2)
# 
# plot(dataTableRI$t,dataTableRI$CONCvGP1Ref, col = 'grey70' , lty = 'dashed', type = 'l', bty='n',axes = FALSE)
# lines(dataTableRI$t,dataTableRI$CONCvGP1, col = colorUse )
# title(main="Gene Product 1", font.main = 1 )
# axis(1, at = seq(from = 0, to = 20, by = 5), label = c('0', ' ','10',' ','20'))
# axis(2)
# 
plot(dataTableRI$t,dataTableRI$CONCvMRNA10ARef, col = 'grey70' , lty = 'dashed',   bty='n' , type = 'l',ylim = c(0,130),axes = FALSE)
lines(dataTableRI$t,dataTableRI$CONCvMRNA10A, col = colorUse)
title(main="mRNA Gene 10A", font.main = 1 )
axis(1, at = seq(from = 0, to = 20, by = 5), label = c('0', NA,'10',NA,'20'))
axis(2)

# legend(x=0, y=500, legend=c('T7 only', 'T7 & FBA'),  pch = c(NULL, NULL), lty = c( 1,1), lwd = c(2,1),col=c( 'gray70' ,'coral1'), bty="n")

plot(dataTableRI$t,dataTableRI$CONCvGP10ARef, col = 'grey70' , lty = 'dashed', type = 'l',   bty='n' ,axes = FALSE,ylab = '')
lines(dataTableRI$t,dataTableRI$CONCvGP10A, col = colorUse )
title(main="Gene Product 10A", font.main = 1 )
axis(1, at = seq(from = 0, to = 20, by = 5), label = c('0', NA,'10',NA,'20'))
axis(2)

plot(dataTableRI$t,dataTableRI$CONCvPROCAPSIDRef, col = 'grey70' , lty = 'dashed', type = 'l',   bty='n' ,axes = FALSE,ylab = '')
lines(dataTableRI$t,dataTableRI$CONCvPROCAPSID, col = colorUse )
title(main="Procapsid", font.main = 1 )
axis(1, at = seq(from = 0, to = 20, by = 5), label = c('0',NA,'10',NA,'20'),axes = FALSE)
axis(2)

plot(dataTableRI$t,dataTableRI$CONCvGENOMERef,  bty='n' , type = 'l', col = 'grey70' , lty = 'dashed' ,ylim = c(0,200),axes = FALSE,ylab = '')
lines(dataTableRI$t,dataTableRI$CONCvGENOME,col = colorUse)
title(main="T7 Genome", font.main = 1 )
axis(1, at = seq(from = 0, to = 20, by = 5), label = c('0',NA,'10',NA,'20'),axes = FALSE)
axis(2)

# plot(dataTableRI$t,dataTableRI$CONCvT7Ref, col = 'grey70', lty = 'dashed' , type = 'l',   bty='n' ,axes = FALSE,ylab = '')
# lines(dataTableRI$t,dataTableRI$CONCvT7, col = colorUse )
# title(main="T7 Phage", font.main = 1 )
# axis(1, at = seq(from = 0, to = 20, by = 5), label = c('0',NA,'10',NA,'20'),axes = FALSE)
# axis(2)

dev.off()



# - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - 

# get averages and standard deviations for phage timecourse data

dataTablePhageRich <- read.table( paste('experimentalData','phageTimecourse_20110826_TB.txt', sep= .Platform$file.sep), sep='\t', header = TRUE)
dataTablePhageRich <- subset( dataTablePhageRich, time < 0.28  )

sdPhageTryptone <- 0
avePhageTryptone <- 0
for (i in 1:length(dataTablePhageRich$phage1)) {
	sdPhageTryptone[i] <- sd( c(dataTablePhageRich$phage1[i], dataTablePhageRich$phage2[i], dataTablePhageRich$phage3[i]) )
	avePhageTryptone[i] <- mean( c(dataTablePhageRich$phage1[i], dataTablePhageRich$phage2[i], dataTablePhageRich$phage3[i]) )
}

xAxis <- c(0, 20)
yAxis <- c(0, 200)

xScale <- seq(from = 0, to = 15, by = 5)
yScale <- seq(from = 0, to = 200, by = 50)


postscript(paste('figureOutput',"figureAuthSumA.eps", sep= .Platform$file.sep), width = 3.4, height = 3.4, horizontal = FALSE, onefile = FALSE, paper = "special", pointsize = 7)
par( mar= (c(4, 4, 0, 0)+0.1) )

# Tryptone

plotCI( x = dataTablePhageRich$time*60, y = avePhageTryptone, uiw = sdPhageTryptone, col = 'coral3', barcol = 'lightsalmon' , xlab = 'Time From Infection (min)', 
xlim = xAxis, ylab = 'Phage T7 Produced (phage/infected host)', ylim = yAxis, axes = FALSE ,  cex = 1.5)
axis(1, at = xScale )
axis(2, at = yScale)

simTablePhageTryptoneHostControl <- read.table(paste('simulationsText','tryptoneInfectedSimulation.txt', sep= .Platform$file.sep), sep='\t', header = TRUE)
# simTablePhageTryptoneHostControl <- read.table('20120315_0658p_Ecoli_EB_T7_37Growth_EB__richTbrothUpdate_10s_VM2MDAHB_PL_RM.txt', sep='\t', header = TRUE)
simTablePhageTryptoneHostControl <- subset( simTablePhageTryptoneHostControl, hostFlag == 1 )
simTablePhageTryptoneHostControl <- subset( simTablePhageTryptoneHostControl, t < 0.29 )
lines( simTablePhageTryptoneHostControl$t*60, simTablePhageTryptoneHostControl$CONCvT7Ref, col = 'grey70', lty = 2 )
lines( simTablePhageTryptoneHostControl$t*60, simTablePhageTryptoneHostControl$CONCvT7, col = 'coral3', lty = 1  )

labelsLegend = c('Experimental Data','Integrated Simulation','T7 ODEs Alone')
legend(x=0, y=200, legend=labelsLegend,  pch = c(1,NA, NA), lty = c( NA, 1, 2), col=c( 'coral3' ,'coral3','grey70'), bty="n",pt.cex = c(1.5,NA,NA))
dev.off()