Workshop.R
- ----------------------------------------------------------------------------- #
- Setup
- ----------------------------------------------------------------------------- #
- Load add on package 'limma'
library(limma)
- Help documentation
limmaUsersGuide()
- Default working directory
getwd()
- Setting the working directory
setwd("C:/DATA/Microarray")
- Relative paths to directory containing GPR files and results
dataDir <- "GPR" resultsDir <- "Results"
- ----------------------------------------------------------------------------- #
- Reading in data
- ----------------------------------------------------------------------------- #
wt.flags <- function(x) {
as.numeric(x$Flags >= -50)
}
- Checking that weight function is working
x <- list() x$Flags <- c(0,-50,-75,-100) x wt.flags(x)
- Creating RGList object for experiment
RG <- read.maimages( dir(dataDir), path=dataDir, source="genepix.median",
wt.fun=wt.flags, other.columns="Flags")
- Structure of RG
dim(RG) summary(RG)
for(i in names(RG)) {
pad <- "--------------" print(paste(pad, i, pad)) str(RGi)
}
- Creating names for accessing each slide
slideNames <- rownames(RG$targets) slideNames
- ----------------------------------------------------------------------------- #
- Summary statistics and diagnostics
- ----------------------------------------------------------------------------- #
- Range of Intensity channels
summary(RG$R) summary(RG$Rb) summary(RG$G) summary(RG$Gb)
- Mapping of spot positions to annotation information
RG$genes[1:30,]
- Flags diagnostics
for( i in slideNames) {
pad <- "--------------" print(paste(pad, i, pad)) print(table(RG$other$Flags[,i]))
}
- Weights diagnostics
for( i in slideNames) {
pad <- "--------------" print(paste(pad, i, pad)) print(table(RG$weights[,i]))
}
- MA-plots
par(mfrow=c(2,2)) for( i in slideNames ) {
# the backgroundCorrect function stops automatic background subtraction plotMA(backgroundCorrect(RG, method="none"), array=i)
}
par(mfrow=c(2,2)) for( i in slideNames ) {
imageplot(RG$Rb[,i], layout=RG$printer, low="white", high="red", zlim=c(0,500))
} for( i in slideNames ) {
imageplot(RG$Gb[,i], layout=RG$printer, low="white", high="green", zlim=c(0,500))
}
- Density plot
plotDensities(backgroundCorrect(RG, method="none"))
- Padding out suspect spots
RG$R[RG$other$Flags == -75] <- NA RG$G[RG$other$Flags == -75] <- NA RG$R[RG$other$Flags == -100] <- NA RG$G[RG$other$Flags == -100] <- NA
- ----------------------------------------------------------------------------- #
- Normalization and Diagnostic images
- ----------------------------------------------------------------------------- #
- normalizing printtiploess with no background correction
MA <- normalizeWithinArrays(RG, method="printtiploess", bc.method="none") boxplot(MA$M~col(MA$M),names=colnames(MA$M))
- Checking range of M
summary(MA$M)
- Diagnostic images after normalization
par(mfrow=c(2,2)) for( i in slideNames ) {
plotMA(MA, array=i)
}
for( i in slideNames ) {
imageplot(MA$M[,i], layout=RG$printer)
}
plotDensities(MA)
- ----------------------------------------------------------------------------- #
- Analysis
- ----------------------------------------------------------------------------- #
- Dye swap design
design <- c(1,-1,-1,1)
fit <- lmFit(MA, design) fit <- eBayes(fit)
- The top 30 differentially expressed genes
N <- 30 topTable(fit, number=N)
- Number of genes with False discovery rate control (FDR) p < 0.05
sum(fit$p.value<0.05, na.rm=T)
- Checking results on an MA-plot
ord <- order(fit$lods,decreasing=TRUE) topN <- ord[1:N] plotMA(fit) points(fit$Amean[topN],fit$coef[topN],pch=16,col="red")
- ----------------------------------------------------------------------------- #
- Saving topTable results
- ----------------------------------------------------------------------------- #
- Create output directory
dir.create(resultsDir) write.table(topTable(fit, number=nrow(MA)), quote=F, sep="\t",
file=file.path(resultsDir,"genelist.txt"), row.names=F)