MicroArray Analysis - 201
MicroArray Analysis - 201
## ---- setup,
include=FALSE-------------------------------------------------------
library(knitr)
knitr::opts_chunk$set(echo = TRUE, message = FALSE, warning = FALSE,
comment = NA, prompt = TRUE, tidy = FALSE,
fig.width = 7, fig.height = 7, fig_caption =
TRUE,
cache=FALSE)
Sys.setlocale("LC_TIME", "C")
##
echo=FALSE----------------------------------------------------------
if(!(require(printr))) {
install.packages(
'printr',
type = 'source',
repos = c('http://yihui.name/xran', 'http://cran.rstudio.com')
)
}
## ----CreateFolders, warning=FALSE,
eval=FALSE----------------------------------------------------------
## setwd(".")
## dir.create("data")
## dir.create("results")
##
ReadTargets---------------------------------------------------------
## install.packages("knitr")
## install.packages("colorspace")
## install.packages("gplots")
## install.packages("ggplot2")
## install.packages("ggrepel")
## install.packages("htmlTable")
## install.packages("prettydoc")
## install.packages("devtools")
## install.packages("BiocManager")
## BiocManager::install("oligo")
## BiocManager::install("pd.mogene.2.1.st")
## BiocManager::install("arrayQualityMetrics")
## BiocManager::install("pvca")
## # NOT NEEDED UNTIL ANALYSES ARE PERFORMED
## BiocManager::install("limma")
## BiocManager::install("genefilter")
## BiocManager::install("mogene21sttranscriptcluster.db")
## BiocManager::install("annotate")
## BiocManager::install("org.Mm.eg.db")
## BiocManager::install("ReactomePA")
## BiocManager::install("reactome.db")
library(oligo)
celFiles <- list.celfiles("./data", full.names = TRUE)
library(Biobase)
my.targets <-read.AnnotatedDataFrame(file.path("./
data","targets.csv"),
header = TRUE, row.names = 1,
sep=";")
rawData <- read.celfiles(celFiles, phenoData = my.targets)
##
ChangeName----------------------------------------------------------
my.targets@data$ShortName->rownames(pData(rawData))
colnames(rawData) <-rownames(pData(rawData))
head(rawData)
## ----QCRaw, message=FALSE, warning=FALSE,
eval=FALSE----------------------------------------------------------
## library(arrayQualityMetrics)
## arrayQualityMetrics(rawData)
##
library(ggplot2)
library(ggrepel)
plotPCA3 <- function (datos, labels, factor, title, scale,colores,
size = 1.5, glineas = 0.25) {
data <- prcomp(t(datos),scale=scale)
# plot adjustments
dataDf <- data.frame(data$x)
Group <- factor
loads <- round(data$sdev^2/sum(data$sdev^2)*100,1)
# main plot
p1 <- ggplot(dataDf,aes(x=PC1, y=PC2)) +
theme_classic() +
geom_hline(yintercept = 0, color = "gray70") +
geom_vline(xintercept = 0, color = "gray70") +
geom_point(aes(color = Group), alpha = 0.55, size = 3) +
coord_cartesian(xlim = c(min(data$x[,1])-5,max(data$x[,1])+5)) +
scale_fill_discrete(name = "Group")
# avoiding labels superposition
p1 + geom_text_repel(aes(y = PC2 + 0.25, label =
labels),segment.size = 0.25, size = size) +
labs(x =
c(paste("PC1",loads[1],"%")),y=c(paste("PC2",loads[2],"%"))) +
ggtitle(paste("Principal Component Analysis for: ",title,sep="
"))+
theme(plot.title = element_text(hjust = 0.5)) +
scale_color_manual(values=colores)
}
##
Normalization-------------------------------------------------------
## ----BatchDetection, message=FALSE,
warning=FALSE-------------------------------------------------------
## ----Filtering1, results='hide',
message=FALSE-------------------------------------------------------
library(genefilter)
library(mogene21sttranscriptcluster.db)
annotation(eset_rma) <- "mogene21sttranscriptcluster.db"
filtered <- nsFilter(eset_rma,
require.entrez = TRUE, remove.dupEntrez = TRUE,
var.filter=TRUE, var.func=IQR, var.cutoff=0.75,
filterByQuantile=TRUE, feature.exclude =
"^AFFX")
## ----FilterResults1, results='hide',
echo=FALSE----------------------------------------------------------
names(filtered)
class(filtered$eset)
##
FilterResults2------------------------------------------------------
print(filtered$filter.log)
eset_filtered <-filtered$eset
## ----SaveData1, results='hide',
message=FALSE-------------------------------------------------------
write.csv(exprs(eset_rma), file="./results/normalized.Data.csv")
write.csv(exprs(eset_filtered), file="./results/
normalized.Filtered.Data.csv")
save(eset_rma, eset_filtered, file="./results/normalized.Data.Rda")
##
LoadSavedData-------------------------------------------------------
## ---- DesignMatrix,
message=FALSE-------------------------------------------------------
library(limma)
designMat<- model.matrix(~0+Group, pData(eset_filtered))
colnames(designMat) <- c("KO.COLD", "KO.RT", "WT.COLD", "WT.RT")
print(designMat)
##
setContrasts--------------------------------------------------------
##
linearmodelfit------------------------------------------------------
library(limma)
fit<-lmFit(eset_filtered, designMat)
fit.main<-contrasts.fit(fit, cont.matrix)
fit.main<-eBayes(fit.main)
class(fit.main)
##
topTabs1------------------------------------------------------------
##
topTabs3------------------------------------------------------------
## ----GeneAnnotation, message=FALSE,
warning=FALSE-------------------------------------------------------
##
annotateTopTables---------------------------------------------------
## ---- annotatedTop,
echo=FALSE----------------------------------------------------------
short<- head(topAnnotated_KOvsWT.COLD[1:5,1:4])
# library(kableExtra)
# knitr::kable(
# short, booktabs = TRUE,
# caption = 'Annotations added to results "topTable" for the
comparison "KOvsWT.COLD"'
# )
show(short)
## ----saveVolcanos, echo=FALSE,
results='hide'------------------------------------------------------
pdf("figures/Volcanos.pdf")
for (i in colnames(cont.matrix)){
volcanoplot(fit.main, coef=i, highlight=4, names=SYMBOLS,
main=paste("Differentially expressed genes",i,
sep="\n"))
abline(v=c(-1,1))
}
dev.off()
##
decideTests.1-------------------------------------------------------
library(limma)
res<-decideTests(fit.main, method="separate", adjust.method="fdr",
p.value=0.1, lfc=1)
##
resumeDecideTests---------------------------------------------------
sum.res.rows<-apply(abs(res),1,sum)
res.selected<-res[sum.res.rows!=0,]
print(summary(res))
##
data4Heatmap--------------------------------------------------------
heatmap.2(HMdata,
Rowv = FALSE,
Colv = FALSE,
main = "Differentially expressed genes \n FDR < 0,1, logFC
>=1",
scale = "row",
col = my_palette,
sepcolor = "white",
sepwidth = c(0.05,0.05),
cexRow = 0.5,
cexCol = 0.9,
key = TRUE,
keysize = 1.5,
density.info = "histogram",
ColSideColors = c(rep("red",3),rep("blue",3),
rep("green",3), rep("yellow",3)),
tracecol = NULL,
dendrogram = "none",
srtCol = 30)
##
selectGenes---------------------------------------------------------
##
##
BiologicalSig-------------------------------------------------------
library(ReactomePA)
for (i in 1:length(listOfData)){
genesIn <- listOfData[[i]]
comparison <- comparisonsNames[i]
enrich.result <- enrichPathway(gene = genesIn,
pvalueCutoff = 0.05,
readable = T,
pAdjustMethod = "BH",
organism = "mouse",
universe = universe)
cat("##################################")
cat("\nComparison: ", comparison,"\n")
print(head(enrich.result))
if (length(rownames(enrich.result@result)) != 0) {
write.csv(as.data.frame(enrich.result),
file =paste0("./
results/","ReactomePA.Results.",comparison,".csv"),
row.names = FALSE)
pdf(file=paste0("./
results/","ReactomePABarplot.",comparison,".pdf"))
print(barplot(enrich.result, showCategory = 15, font.size = 4,
title = paste0("Reactome Pathway Analysis for ",
comparison,". Barplot")))
dev.off()
pdf(file = paste0("./
results/","ReactomePAcnetplot.",comparison,".pdf"))
print(cnetplot(enrich.result, categorySize = "geneNum",
schowCategory = 15,
vertex.label.cex = 0.75))
dev.off()
}
}
## ---- tableReacto,
echo=FALSE----------------------------------------------------------