annotate preprocess_datasets/Affymetrix_Preprocessing.R @ 28:183b24bc8574 draft

Uploaded
author proteomisc
date Mon, 04 Dec 2023 12:47:12 +0000
parents b5eac045873c
children d0f05795e9b0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
27
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
1 options(show.error.messages=F,warn=-1, error=function(){cat(geterrmessage(),file=stderr());q("no",1,F)})
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
2 sink(stdout(), type = "message")
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
3 sink(stdout() ,type = "output")
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
4 suppressWarnings(suppressMessages(library(affy)))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
5 suppressWarnings(suppressMessages(library(affyPLM)))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
6 suppressWarnings(suppressMessages(library(batch)))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
7 suppressWarnings(suppressMessages(library(annotate)))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
8 suppressWarnings(suppressMessages(library(limma)))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
9 suppressWarnings(suppressMessages(library(markdown)))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
10 suppressWarnings(suppressMessages(library(knitr)))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
11 source_local <- function(fname){
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
12 argv <- commandArgs(trailingOnly = FALSE)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
13 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
14 source(paste(base_dir, fname, sep="/"))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
15 }
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
16 file_path <- function(fname){
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
17 argv <- commandArgs(trailingOnly = FALSE)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
18 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
19 pato <- paste(base_dir, fname, sep="/")
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
20 return(pato)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
21 }
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
22 base_dir <- function(){
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
23 argv <- commandArgs(trailingOnly = FALSE)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
24 base_dir <- dirname(substring(argv[grep("--file=", argv)], 8))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
25 return(base_dir)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
26 }
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
27 source_local("Affymetrix_Preprocessing_Functions.R")
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
28 listArguments = parseCommandArgs(evaluate=FALSE)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
29 thefunctions=listArguments[["thefunctions"]]
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
30 listArguments[["thefunctions"]]=NULL
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
31 h=listArguments[["h"]]
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
32 listArguments[["h"]]=NULL
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
33 w=listArguments[["w"]]
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
34 listArguments[["w"]]=NULL
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
35 if (!is.null(listArguments[["image"]])){
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
36 load(listArguments[["image"]])
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
37 listArguments[["image"]]=NULL
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
38 }
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
39 listArguments[["rawdata"]]=MicroArray_Object$affy_object
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
40 if(datasetsource=="intern"){
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
41 designo<-MicroArray_Object$designo
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
42 }
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
43
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
44 if(datasetsource=="extern"){
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
45 listArguments<-append(listArguments,list(datasetsource=datasetsource,listfullnames=listfullnames))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
46 }
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
47 Prepro_object<-do.call(thefunctions,listArguments)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
48 if(datasetsource=="extern"){
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
49 rownames(Prepro_object$data.bg@phenoData@data)<-listfullnames
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
50 colnames(exprs(Prepro_object$data.bg))<-listfullnames
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
51 colnames(exprs(Prepro_object$data.sm))<-listfullnames
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
52 colnames(exprs(Prepro_object$data.norm))<-listfullnames
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
53 colnames(exprs(Prepro_object$data.bg))<-listfullnames
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
54 colnames(exprs(Prepro_object$data.norm))<-listfullnames
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
55 rownames(Prepro_object$data.norm@phenoData@data)<-listfullnames
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
56 rownames(Prepro_object$data.norm@protocolData@data)<-listfullnames
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
57 }
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
58
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
59 png(filename ="boxplot_before_NM.png",width = w, height = h, units = "px", pointsize = 14, bg = "white")
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
60 boxplot((na.omit(as.data.frame(exprs(Prepro_object$data.bg)))), main="Boxplot of intensities before Normalization",col="red",las=2,mar=c(15,2,1,1))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
61 invisible(dev.off())
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
62
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
63 png(filename ="boxplot_after_NM.png",width = w, height = h, units = "px", pointsize = 14, bg = "white")
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
64 boxplot((na.omit(as.data.frame(exprs(Prepro_object$data.sm)))), main="Boxplot of intensities After Normalization",col="red",ylab="(intensities)",las=2,mar=c(15,2,1,1))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
65 invisible(dev.off())
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
66
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
67 png(filename ="MA_plot.png",width = w, height = h)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
68 MAplot((Prepro_object$data.norm) ,
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
69 show.statistics = F, span = 2/3, family.loess = "gaussian",
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
70 cex = 2, plot.method = as.character("smoothScatter"),
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
71 azdd.loess = TRUE, lwd = 1, lty = 1, loess.col = "red")
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
72
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
73 invisible(dev.off())
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
74
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
75 png(filename = "densities_plot_before_NM.png",width = w, height = h)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
76 plotDensities(exprs(Prepro_object$data.bg),log=T)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
77 invisible(dev.off())
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
78
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
79 png(filename = "densities_plot_after_NM.png",width = w, height = h)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
80 plotDensities(exprs(Prepro_object$data.norm),log=T)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
81 invisible(dev.off())
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
82
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
83 AffymetrixRmd=file_path("Affymetrix.Rmd")
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
84 Style=file_path("look.css")
28
183b24bc8574 Uploaded
proteomisc
parents: 27
diff changeset
85 suppressWarnings(suppressMessages(markdownToHTML(AffymetrixRmd,output="PreprocessingPlots.html", stylesheet=Style)))
27
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
86 #suppressWarnings(suppressMessages(knit2html(AffymetrixRmd,output="PreprocessingPlots.html",quiet = T)))
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
87 rm(listArguments)
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
88 save.image("MicroArray.Preprocessing.RData")
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
89 sink()
b5eac045873c Uploaded
proteomisc
parents:
diff changeset
90 sink()