annotate preprocess_datasets/Affymetrix_Preprocessing.R @ 41:8aaf6fdb06d6 draft

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