annotate preprocess_datasets/Affymetrix_Preprocessing.R @ 21:5d481ae1b76c draft

Uploaded
author proteomisc
date Sun, 03 Dec 2023 17:08:48 +0000
parents d05e52d7904d
children 2f468dd9ea39
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
21
5d481ae1b76c Uploaded
proteomisc
parents: 20
diff changeset
1 options(show.error.messages=F,warn=-1, error=function(){cat(geterrmessage(),file=stderr());q("no",1,F)})
0
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
2 sink(stdout(), type = "message")
21
5d481ae1b76c Uploaded
proteomisc
parents: 20
diff changeset
3 sink(stdout() ,type = "output")
0
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
4 suppressWarnings(suppressMessages(library(affy)))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
5 suppressWarnings(suppressMessages(library(affyPLM)))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
6 suppressWarnings(suppressMessages(library(batch)))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
7 suppressWarnings(suppressMessages(library(annotate)))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
8 suppressWarnings(suppressMessages(library(limma)))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
9 suppressWarnings(suppressMessages(library(markdown)))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
10 suppressWarnings(suppressMessages(library(knitr)))
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[["rawdata"]]=MicroArray_Object$affy_object
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
40 if(datasetsource=="intern"){
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
41 designo<-MicroArray_Object$designo
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
42 }
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
43
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
44 if(datasetsource=="extern"){
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
45 listArguments<-append(listArguments,list(datasetsource=datasetsource,listfullnames=listfullnames))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
46 }
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
47 Prepro_object<-do.call(thefunctions,listArguments)
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
48 if(datasetsource=="extern"){
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
49 rownames(Prepro_object$data.bg@phenoData@data)<-listfullnames
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
50 colnames(exprs(Prepro_object$data.bg))<-listfullnames
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
51 colnames(exprs(Prepro_object$data.sm))<-listfullnames
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
52 colnames(exprs(Prepro_object$data.norm))<-listfullnames
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
53 colnames(exprs(Prepro_object$data.bg))<-listfullnames
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
54 colnames(exprs(Prepro_object$data.norm))<-listfullnames
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
55 rownames(Prepro_object$data.norm@phenoData@data)<-listfullnames
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
56 rownames(Prepro_object$data.norm@protocolData@data)<-listfullnames
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
57 }
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
58 par(las=2,mar=c(15,2,1,1))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
59 png(filename ="boxplot_before_NM.png",width = w, height = h, units = "px", pointsize = 14, bg = "white")
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
60 par(las=2,mar=c(15,2,1,1))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
61 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
62
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
63 dev.off()
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
64
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
65
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
66
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
67 par(las=2,mar=c(15,2,1,1))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
68 png(filename ="boxplot_after_NM.png",width = w, height = h, units = "px", pointsize = 14, bg = "white")
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
69 par(las=2,mar=c(15,2,1,1))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
70 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
71
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
72 dev.off()
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
73 png(filename ="MA_plot.png",width = w, height = h)
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
74 MAplot((Prepro_object$data.norm) ,
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
75 show.statistics = F, span = 2/3, family.loess = "gaussian",
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
76 cex = 2, plot.method = as.character("smoothScatter"),
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
77 azdd.loess = TRUE, lwd = 1, lty = 1, loess.col = "red")
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
78
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
79 dev.off()
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
80 png(filename = "densities_plot_before_NM.png",width = w, height = h)
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
81 plotDensities(exprs(Prepro_object$data.bg),log=T)
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
82 dev.off()
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
83
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
84 png(filename = "densities_plot_after_NM.png",width = w, height = h)
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
85 plotDensities(exprs(Prepro_object$data.norm),log=T)
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
86 dev.off()
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
87 AffymetrixRmd=file_path("Affymetrix.Rmd")
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
88 Style=file_path("look.css")
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
89 suppressWarnings(suppressMessages(knit2html(AffymetrixRmd,output="PreprocessingPlots.html",quiet = T, stylesheet=Style)))
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
90 rm(listArguments)
ebf6607b4e6a Uploaded
proteomisc
parents:
diff changeset
91 save.image("MicroArray.Preprocessing.RData")
21
5d481ae1b76c Uploaded
proteomisc
parents: 20
diff changeset
92 sink()
5d481ae1b76c Uploaded
proteomisc
parents: 20
diff changeset
93 sink()