### R code from vignette source 'vignettes/affycoretools/inst/doc/affycoretools.Rnw'

###################################################
### code chunk number 1: affycoretools.Rnw:101-102
###################################################
options(width = 70)


###################################################
### code chunk number 2: affycoretools.Rnw:105-112 (eval = FALSE)
###################################################
## library("affycoretools")
## pd <- new("AnnotatedDataFrame", 
##           data = read.table("pdata.txt", header = TRUE, row.names = 1))
## eset <- affystart(groups = rep(1:4, each = 3), 
##                   groupnames = unique(paste(pData(pd)[,1], 
##                   pData(pd)[,2], sep = "-")), 
##                   phenoData = pd)


###################################################
### code chunk number 3: affycoretools.Rnw:115-118
###################################################
library(affycoretools)
load("abatch.Rdata")
load("exprSet.Rdata")


###################################################
### code chunk number 4: affycoretools.Rnw:123-124
###################################################
plotHist(dat)


###################################################
### code chunk number 5: affycoretools.Rnw:132-133
###################################################
plotDeg(dat)


###################################################
### code chunk number 6: affycoretools.Rnw:141-147
###################################################
pd <- new("AnnotatedDataFrame", 
          data = read.table("pdata.txt", header = TRUE, row.names = 1))
sampleNames(pd) <- sampleNames(eset)
plotPCA(eset, groups = rep(1:4, each = 3), 
        groupnames = unique(paste(pData(pd)[,1], pData(pd)[,2], sep = "-")))
phenoData(eset) <- pd


###################################################
### code chunk number 7: affycoretools.Rnw:155-156
###################################################
plotPCA(eset, screeplot = TRUE)


###################################################
### code chunk number 8: affycoretools.Rnw:202-210 (eval = FALSE)
###################################################
## eset1 <- affystart(filenames = list.celfiles()[1:6], 
##                    plot = FALSE, pca = FALSE)
## eset2 <- affystart(filenames = list.celfiles()[7:12], 
##                    plot = FALSE, pca = FALSE)
## eset <- new("ExpressionSet", 
##             exprs = cbind(exprs(eset1), exprs(eset2)), 
##             phenoData = pd,
##             annotation = annotation(eset1))


###################################################
### code chunk number 9: affycoretools.Rnw:233-238
###################################################
library(genefilter)
f1 <- kOverA(3, 6)
filt <- filterfun(f1)
index <- genefilter(eset, filt)
eset <- eset[index,]


###################################################
### code chunk number 10: affycoretools.Rnw:246-259
###################################################
library(limma)
grps <- paste(pData(eset)[,1], 
              pData(eset)[,2], sep = ".")
design <- model.matrix(~ 0 + factor(grps))
colnames(design) <- levels(factor(grps))
ugrps <- unique(grps)
contrasts <- matrix(c(1, -1, 0, 0, 0, 0, 1, -1),
                    ncol = 2, dimnames = list(ugrps,
                              paste(ugrps[c(1,3)], ugrps[c(2,4)],
                                    sep = " - ")))
fit <- lmFit(eset, design)
fit2 <- contrasts.fit(fit, contrasts)
fit2 <- eBayes(fit2)


###################################################
### code chunk number 11: affycoretools.Rnw:264-266
###################################################
design
contrasts


###################################################
### code chunk number 12: affycoretools.Rnw:283-286
###################################################
rslt <- decideTests(fit2)
vc <- vennCounts2(rslt, method = "same")
vennDiagram(vc, cex = 0.8)


###################################################
### code chunk number 13: affycoretools.Rnw:291-292
###################################################
vennDiagram(vc, cex = 0.6)


###################################################
### code chunk number 14: affycoretools.Rnw:304-305 (eval = FALSE)
###################################################
## vennSelect(eset, design, rslt, contrasts, fit2)


###################################################
### code chunk number 15: affycoretools.Rnw:326-329 (eval = FALSE)
###################################################
## limma2annaffy(eset, fit2, design, 
##               contrasts, annotation(eset), 
##               pfilt = 0.05)


###################################################
### code chunk number 16: affycoretools.Rnw:352-364 (eval = FALSE)
###################################################
## index1 <- vennSelect(x = rslt, indices.only = TRUE)[[3]]
## probids <- unique(getLL(featureNames(eset)[index1], 
##                         annotation(eset)))
## univ <- unique(getLL(featureNames(eset),
##                      annotation(eset)))
## params <- new("GOHyperGParams", geneIds = probids,
##               universeGeneIds = univ, 
##               annotation = annotation(eset),
##               conditional = TRUE, ontology = "MF")
## hyp <- hyperGTest(params)
## htmlReport(hyp, file = "GO MF terms.html",
##            categorySize = 10)


