download code
## Chunk 1
library("Biobase")
library("ALL")
library("hgu95av2.db")
library("annotate")
library("genefilter")
library("GOstats")
library("RColorBrewer")
library("xtable")
library("Rgraphviz")
## Chunk 2
data(ALL)
bcell = grep("^B", as.character(ALL$BT))
types = c("NEG", "BCR/ABL")
moltyp = which(as.character(ALL$mol.biol) %in% types)
ALL_bcrneg = ALL[, intersect(bcell, moltyp)]
ALL_bcrneg$mol.biol = factor(ALL_bcrneg$mol.biol)
  (solution chunk)
  (solution chunk)
## Chunk 5
varCut = 0.5
filt_bcrneg = nsFilter(ALL_bcrneg, require.entrez=TRUE,
    require.GOBP=TRUE, remove.dupEntrez=TRUE,
    var.func=IQR, var.cutoff=varCut, 
    feature.exclude="^AFFX")
names(filt_bcrneg)
ALLfilt_bcrneg = filt_bcrneg$eset
  (solution chunk)
## Chunk 7
hasSymbol = sapply(mget(featureNames(ALLfilt_bcrneg),
    envir=hgu95av2SYMBOL), function(x) 
    !(length(x) == 1 && is.na(x)))
ALLfilt_bcrneg = ALLfilt_bcrneg[hasSymbol, ]
## Chunk 8
affyUniverse = featureNames(ALLfilt_bcrneg)
entrezUniverse = unlist(mget(affyUniverse, 
    hgu95av2ENTREZID))
  (solution chunk)
## Chunk 10
ttestCutoff = 0.05
ttests = rowttests(ALLfilt_bcrneg, "mol.biol")
smPV = ttests$p.value < ttestCutoff
pvalFiltered = ALLfilt_bcrneg[smPV, ]
selectedEntrezIds = unlist(mget(featureNames(pvalFiltered),
    hgu95av2ENTREZID))
  (solution chunk)
## Chunk 12
## ## if you are following along with your own data...
## entrezUniverse = unlist(mget(featureNames(yourData),
##     hgu95av2ENTREZID))
## pvalFiltered = yourData[hasSmallPvalue, ]
## selectedEntrezIds = unlist(mget(featureNames(pvalFiltered),
##     hgu95av2ENTREZID))
## Chunk 13
hgCutoff = 0.001
params = new("GOHyperGParams", geneIds=selectedEntrezIds,
    universeGeneIds=entrezUniverse, annotation="hgu95av2.db", 
    ontology="BP", pvalueCutoff=hgCutoff, conditional=FALSE,
    testDirection="over")
## Chunk 14
hgOver = hyperGTest(params)
## Chunk 15
hgOver
  (solution chunk)
  (solution chunk)
  (solution chunk)
## Chunk 19
htmlReport(hgOver, file="ALL_hgo.html")
  (solution chunk)
## Chunk 21
sigSub = termGraphs(hgOver)
  (solution chunk)
## Chunk 23
plotGOTermGraph(sigSub[[1]], hgOver, max.nchar=100)
## Chunk 24
paramsCond = params
conditional(paramsCond) = TRUE
## Chunk 25
hgCond = hyperGTest(paramsCond)
## Chunk 26
hgCond
  (solution chunk)
  (solution chunk)
## Chunk 29
terms = nodes(sigSub[[1]])
df = summary(hgCond, pvalue=0.5)[ , c("Term", "Pvalue")]
df$Pvalue = round(df$Pvalue, 3)
df$Term = sapply(df$Term, function(x) {
    if (nchar(x) <= 20) x
    else paste(substr(x, 1, 20), "...", sep="")
})
df[terms, ]
  (solution chunk)
  (solution chunk)
  (solution chunk)
  (solution chunk)
  (solution chunk)
  (solution chunk)
  (solution chunk)
  (solution chunk)
  (solution chunk)