###################################################
### chunk number 1: 
###################################################
library(maigesPack)
data(gastro)


###################################################
### chunk number 2:  eval=FALSE
###################################################
## gastro = loadData(fileConf="load_gastro.conf")


###################################################
### chunk number 3:  eval=FALSE
###################################################
## gastro = addGeneGrps(gastro, folder="geneGrps", ext="txt")
## gastro = addPaths(gastro, folder="geneNets", ext="tgf")


###################################################
### chunk number 4: 
###################################################
gastro.raw = createMaigesRaw(gastro, greenDataField="Ch1.Mean",
  greenBackDataField="Ch1.B.Mean", redDataField="Ch2.Mean",
  redBackDataField="Ch2.B.Mean", flagDataField="Flags",
  gLabelGrp="GeneName", gLabelPath="GeneName")


###################################################
### chunk number 5: WAplot1
###################################################
plot(gastro.raw[,1], bkgSub="none")


###################################################
### chunk number 6: image1
###################################################
image(gastro.raw[,1])


###################################################
### chunk number 7:  eval=FALSE
###################################################
## boxplot(gastro.raw[,2])
## boxplot(gastro.raw)


###################################################
### chunk number 8: hierRaw
###################################################
hierM(gastro.raw, rmGenes=c("BLANK","DAP","LYS","PHE", "Q_GENE","THR","TRP"),
              sLabelID="Sample", gLabelID="Name", doHeat=FALSE)


###################################################
### chunk number 9: 
###################################################
gastro.raw2 = selSpots(gastro.raw, sigNoise=1, rmFlag=NULL, gLabelsID="Name",
  remove=list(c("BLANK","DAP","LYS","PHE","Q_GENE","THR","TRP")))


###################################################
### chunk number 10: 
###################################################
gastro.norm = normLoc(gastro.raw2, span=0.4, method="loess")


###################################################
### chunk number 11:  eval=FALSE
###################################################
## gastro.norm = normOLIN(gastro.raw2)
## gastro.norm = normRepLoess(gastro.raw2)


###################################################
### chunk number 12:  eval=FALSE
###################################################
## gastro.norm = normScaleMarray(gastro.norm, norm="printTipMAD")


###################################################
### chunk number 13:  eval=FALSE
###################################################
## gastro.norm = normScaleMarray(gastro.norm, norm="globalMAD")


###################################################
### chunk number 14:  eval=FALSE
###################################################
## gastro.norm = normScaleLimma(gastro.norm, method="scale")


###################################################
### chunk number 15:  eval=FALSE
###################################################
## gastro.norm = normScaleLimma(gastro.raw2, method="vsn")


###################################################
### chunk number 16: WAplot1N
###################################################
plot(gastro.norm[,1])


###################################################
### chunk number 17: hierNorm
###################################################
hierM(gastro.norm, rmGenes=c("BLANK","DAP","LYS","PHE", "Q_GENE","THR","TRP"),
              sLabelID="Sample", gLabelID="Name", doHeat=FALSE)


###################################################
### chunk number 18: 
###################################################
gastro.summ = summarizeReplicates(gastro.norm, gLabelID="GeneName",
  sLabelID="Sample", funcS="mean", funcG="median",
  keepEmpty=FALSE, rmBad=FALSE)


###################################################
### chunk number 19: 
###################################################
gastro.ttest = deGenes2by2Ttest(gastro.summ, sLabelID="Type")
gastro.ttest


###################################################
### chunk number 20:  eval=FALSE
###################################################
## gastro.wilcox = deGenes2by2Wilcox(gastro.summ, sLabelID="Type")
## gastro.boot = deGenes2by2BootT(gastro.summ, sLabelID="Type")


###################################################
### chunk number 21:  eval=FALSE
###################################################
## plot(gastro.ttest)
## tablesDE(gastro.ttest)


###################################################
### chunk number 22: som20
###################################################
somMde(gastro.ttest, sLabelID="Type", adjP="BH", nDEgenes=20,
       xdim=2, ydim=1, topol="rect")


###################################################
### chunk number 23: 
###################################################
dev.off()


###################################################
### chunk number 24: 
###################################################
gastro.ANOVA = designANOVA(gastro.summ, factors="Tissue")


###################################################
### chunk number 25: 
###################################################
gastro.ANOVAfit = deGenesANOVA(gastro.ANOVA, retF=TRUE)
gastro.ANOVAfit


###################################################
### chunk number 26:  eval=FALSE
###################################################
## gastro.ANOVAfit = deGenesANOVA(gastro.ANOVA, retF=FALSE)


###################################################
### chunk number 27: Bplot
###################################################
boxplot(gastro.ANOVAfit, name="KLK13", gLabelID="GeneName", 
sLabelID="Tissue")


###################################################
### chunk number 28: 
###################################################
gastro.class = classifyLDA(gastro.summ, sLabelID="Type",
  gNameID="GeneName", nGenes=3, geneGrp=6)
gastro.class


###################################################
### chunk number 29:  eval=FALSE
###################################################
## gastro.class = classifyLDA(gastro.summ, sLabelID="Tissue",
##   gNameID="GeneName", nGenes=3, geneGrp=6,
##   facToClass=list(Norm=c("Neso","Nest"), Ade=c("Aeso","Aest")))


###################################################
### chunk number 30:  eval=FALSE
###################################################
## plot(gastro.class, idx=1)
## tableClass(gastro.class)


###################################################
### chunk number 31: 
###################################################
gastro.mod = activeMod(gastro.summ, sLabelID="Tissue", cutExp=1,
  cutPhiper=0.05)


###################################################
### chunk number 32:  eval=FALSE
###################################################
## plot(gastro.mod, "S", margins=c(15,3))


###################################################
### chunk number 33: Mod
###################################################
plot(gastro.mod, "C", margins=c(23,5))


###################################################
### chunk number 34:  eval=FALSE
###################################################
## gastro.net = relNetworkB(gastro.summ, sLabelID="Tissue", 
##   samples="Neso", geneGrp=1)


###################################################
### chunk number 35:  eval=FALSE
###################################################
## image(gastro.net)
## plot(gastro.net, cutPval=0.05)


###################################################
### chunk number 36:  eval=FALSE
###################################################
## gastro.net2 = relNetworkM(gastro.summ, sLabelID="Tissue", 
##   samples = list(Neso="Neso", Aeso="Aeso"), geneGrp=7)


###################################################
### chunk number 37:  eval=FALSE
###################################################
## image(gastro.net2)
## plot(gastro.net2, cutPval=0.05)


###################################################
### chunk number 38:  eval=FALSE
###################################################
## plotGenePair(gastro.net2, "KLK13", "EVPL")


###################################################
### chunk number 39: 
###################################################
gastro.net = activeNet(gastro.summ, sLabelID="Tissue")


###################################################
### chunk number 40: Score
###################################################
plot(gastro.net, type="score", margins=c(21,5))


###################################################
### chunk number 41: Pvalues
###################################################
plot(gastro.net, type="p-value", margins=c(21,5))