download code
## Chunk 1
apropos("mean")
find("mean")
## Chunk 2
## help.search("mean")
  (solution chunk)
  (solution chunk)
  (solution chunk)
## Chunk 6
## source("http://bioconductor.org/biocLite.R")
## biocLite(c("graph", "xtable"))
## Chunk 7
## source("http://bioconductor.org/biocLite.R")
## update.packages(repos=biocinstallRepos(), ask=FALSE)
  (solution chunk)
  (solution chunk)
  (solution chunk)
  (solution chunk)
  (solution chunk)
  (solution chunk)
## Chunk 14
sq1 = function(x) return(x*x)
sq2 = function(x) x*x
  (solution chunk)
## Chunk 16
library("hgu95av2.db")
hgu95av2MAP$"1001_at"
## Chunk 17
myPos = eapply(hgu95av2MAP, function(x) grep("^17p", x, 
    value=TRUE))
myPos = unlist(myPos)
length(myPos)
## Chunk 18
f17p = function(x) grep("^17p", x, value=TRUE)
myPos2 = eapply(hgu95av2MAP, f17p)
myPos2 = unlist(myPos2)
identical(myPos, myPos2)
  (solution chunk)
## Chunk 20
e1 = new.env(hash=TRUE)
e1$a = rnorm(10)
e1$b = runif(20)
ls(e1)
xx = as.list(e1)
names(xx)
rm(a, envir=e1)
  (solution chunk)
  (solution chunk)
  (solution chunk)
## Chunk 24
## library(convert)
## as(object, "ExpressionSet")
## Chunk 25
dataDirectory = system.file("extdata", package="Biobase")
exprsFile = file.path(dataDirectory, "exprsData.txt")
exprs = as.matrix(read.table(exprsFile, header=TRUE, 
    sep="\t", row.names=1, as.is=TRUE))
## Chunk 26
## exprsFile = "c:/path/to/exprsData.txt"
## Chunk 27
class(exprs)
dim(exprs)
colnames(exprs)
head(exprs)
## Chunk 28
pDataFile = file.path(dataDirectory, "pData.txt")
pData = read.table(pDataFile,
    row.names=1, header=TRUE, sep="\t")
dim(pData)
rownames(pData)
summary(pData)
## Chunk 29
all(rownames(pData) == colnames(exprs))
  (solution chunk)
  (solution chunk)
  (solution chunk)
  (solution chunk)
## Chunk 34
metadata = data.frame(labelDescription=c("Patient gender", 
    "Case/control status", "Tumor progress on XYZ scale"),
     row.names=c("gender", "type", "score"))
## Chunk 35
adf = new("AnnotatedDataFrame", data=pData, 
    varMetadata=metadata)
adf
## Chunk 36
head(pData(adf))
adf[c("A","Z"), "gender"]
pData(adf[adf$score > 0.8,])
## Chunk 37
annotation = "hgu95av2"
## Chunk 38
experimentData = new("MIAME", name="Pierre Fermat",
    lab="Francis Galton Lab", 
    contact="pfermat@lab.not.exist",
    title="Smoking-Cancer Experiment",
    abstract="An example ExpressionSet",
    url="www.lab.not.exist",
    other=list(notes="Created from text files"))
## Chunk 39
exampleSet = new("ExpressionSet", exprs=exprs, 
    phenoData=adf, experimentData=experimentData,
    annotation="hgu95av2")
## Chunk 40
minimalSet = new("ExpressionSet", exprs=exprs)
## Chunk 41
## help("ExpressionSet-class")
## Chunk 42
exampleSet
## Chunk 43
exampleSet$gender[1:5]
exampleSet$gender[1:5] == "Female"
## Chunk 44
featureNames(exampleSet)[1:5]
## Chunk 45
sampleNames(exampleSet)[1:5]
varLabels(exampleSet)
## Chunk 46
mat = exprs(exampleSet)
dim(mat)
adf = phenoData(exampleSet)
adf
## Chunk 47
vv = exampleSet[1:5, 1:3]
dim(vv)
featureNames(vv)
sampleNames(vv)
## Chunk 48
males = exampleSet[, exampleSet$gender == "Male"]
males
## Chunk 49
x = exprs(exampleSet[, 1])
y = exprs(exampleSet[, 3])
plot(x=x, y=y, log="xy")
  (solution chunk)
## Chunk 51
library("CLL")
library("matchprobes")
library("hgu95av2probe")
library("hgu95av2cdf")
library("RColorBrewer")
data("CLLbatch")
bases = basecontent(hgu95av2probe$sequence)
## Chunk 52
iab = with(hgu95av2probe, xy2indices(x, y, 
    cdf="hgu95av2cdf"))
probedata = data.frame(
    int=rowMeans(log2(exprs(CLLbatch)[iab, ])),
    gc=bases[, "C"] + bases[, "G"])
## Chunk 53
colorfunction = colorRampPalette(brewer.pal(9, "GnBu"))
mycolors = colorfunction(length(unique(probedata$gc)))
label = expression(log[2]~intensity)
boxplot(int ~ gc, data=probedata, col=mycolors, 
    outline=FALSE, xlab="Number of G and C", 
    ylab=label, main="")
## Chunk 54
tab = table(probedata$gc)
gcUse = as.integer(names(sort(tab, decreasing=TRUE)[1:10]))
gcUse
## Chunk 55
library("geneplotter")
multidensity(int ~ gc, data=subset(probedata, 
    gc %in% gcUse), xlim=c(6, 11), 
    col=colorfunction(12)[-(1:2)],
    lwd=2, main="", xlab=label)
  (solution chunk)