annotate preprocess_datasets/Affymetrix_Preprocessing.R @ 3:e13459f1aecb draft

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