annotate Analyse.R @ 4:58052f8bc987 draft

planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 8d4651e98155855108d1c4574392d503cc04bc95
author sblanck
date Thu, 01 Mar 2018 05:22:24 -0500
parents 1024245abc70
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
1 #!/usr/bin/env Rscript
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
2 # setup R error handling to go to stderr
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
3 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
4
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
5 # we need that to not crash galaxy with an UTF8 error on German LC settings.
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
6 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
7
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
8 library("optparse")
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
9
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
10 ##### Read options
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
11 option_list=list(
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
12 make_option("--rdatainput",type="character",default="NULL",help="rdata object containing eset object"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
13 make_option("--conditions",type="character",default=NULL,help="Text file summarizing conditions of the experiment (required)"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
14 make_option("--selectcondition1",type="character",default=NULL,help="log2 transformation"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
15 # make_option("--condition1",type="character",default=NULL,help="A table containing the expression data"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
16 make_option("--selectcondition2",type="character",default="NULL",help="rdata object containing eset object"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
17 # make_option("--condition2",type="character",default=NULL,help="Text file summarizing conditions of the experiment (required)"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
18 make_option("--nbresult",type="character",default=NULL,help="number of result displayed results"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
19 make_option("--rdataoutput",type="character",default="NULL",help="output rdata object containing eset object"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
20 make_option("--htmloutput",type="character",default=NULL,help="Output html report"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
21 make_option("--htmloutputpath",type="character",default="NULL",help="Path of output html report"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
22 make_option("--tabularoutput",type="character",default=NULL,help="Output text file"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
23 make_option("--htmltemplate",type="character",default=NULL,help="html template)"),
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
24 make_option("--tooldirectory",type="character",default=NULL,help="tool directory)")
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
25
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
26
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
27 );
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
28
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
29 opt_parser = OptionParser(option_list=option_list);
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
30 opt = parse_args(opt_parser);
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
31
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
32 if(is.null(opt$rdatainput)){
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
33 print_help(opt_parser)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
34 stop("rData input required.", call.=FALSE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
35 }
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
36
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
37 if(is.null(opt$conditions)){
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
38 print_help(opt_parser)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
39 stop("conditions input required.", call.=FALSE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
40 }
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
41
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
42
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
43 #loading libraries
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
44 suppressPackageStartupMessages(require(GEOquery))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
45 suppressPackageStartupMessages(require(Biobase))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
46 suppressPackageStartupMessages(require(GEOquery))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
47 suppressPackageStartupMessages(require(GEOmetadb))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
48 suppressPackageStartupMessages(require(limma))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
49 suppressPackageStartupMessages(require(jsonlite))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
50 suppressPackageStartupMessages(require(affy))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
51 suppressPackageStartupMessages(require(dplyr))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
52
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
53 load(opt$rdatainput)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
54 targetFile=opt$conditions
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
55 condition1Name=opt$selectcondition1
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
56 #condition1=opt$condition1
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
57 condition2Name=opt$selectcondition2
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
58 #condition2=opt$condition2
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
59 nbresult=opt$nbresult
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
60 result_export_eset=opt$rdataoutput
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
61 result=opt$htmloutput
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
62 result.path=opt$htmloutputpath
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
63 result.tabular=opt$tabularoutput
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
64 result.template=opt$htmltemplate
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
65 tooldirectory=opt$tooldirectory
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
66
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
67 targets <- read.table(targetFile,sep="\t",stringsAsFactors=FALSE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
68
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
69 #condition1_tmp <- strsplit(condition1,",")
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
70 condition1 <-targets[which(targets$V2==condition1Name),1]
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
71
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
72 #condition2_tmp <- strsplit(condition2,",")
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
73 #condition2<-unlist(condition2_tmp)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
74 condition2 <-targets[which(targets$V2==condition2Name),1]
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
75
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
76 conditions=c(condition1,condition2)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
77
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
78 dir.create(result.path, showWarnings = TRUE, recursive = FALSE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
79
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
80 eset=eset[,which(rownames(eset@phenoData@data) %in% conditions)]
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
81
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
82 eset@phenoData@data$source_name_ch1=""
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
83 eset@phenoData@data$source_name_ch1[which(rownames(eset@phenoData@data) %in% condition1)]=condition1Name
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
84 eset@phenoData@data$source_name_ch1[which(rownames(eset@phenoData@data) %in% condition2)]=condition2Name
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
85
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
86 condNames=paste0("G",as.numeric(as.character(pData(eset)["source_name_ch1"][,1])!=condition1Name))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
87
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
88 f <- as.factor(condNames)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
89
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
90 design <- model.matrix(~ 0+f)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
91
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
92 colnames(design) <- levels(f)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
93
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
94 fit <- lmFit(eset, design)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
95
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
96 cont.matrix <- makeContrasts(G0-G1, levels=design)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
97
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
98 fit2 <- contrasts.fit(fit, cont.matrix)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
99 fit2 <- eBayes(fit2)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
100
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
101 tT <- topTable(fit2, adjust="fdr", sort.by="B", number=nbresult)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
102
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
103 #head(exprs(eset))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
104
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
105 gpl <- annotation(eset)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
106 if (substr(x = gpl,1,3)!="GPL"){
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
107 #if the annotation info does not start with "GPL" we retrieve the corresponding GPL annotation
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
108 mapping=read.csv(paste0(tooldirectory,"/gplToBioc.csv"),stringsAsFactors=FALSE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
109 gpl=mapping[which(mapping$bioc_package==annotation(eset)),]$gpl
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
110 gpl=gpl[1]
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
111
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
112 annotation(eset)=gpl
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
113
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
114 platf <- getGEO(gpl, AnnotGPL=TRUE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
115 ncbifd <- data.frame(attr(dataTable(platf), "table"))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
116
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
117 fData(eset)["ID"]=row.names(fData(eset))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
118 fData(eset)=merge(x=fData(eset),y=ncbifd,all.x = TRUE, by = "ID")
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
119 colnames(fData(eset))[4]="ENTREZ_GENE_ID"
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
120 row.names(fData(eset))=fData(eset)[,"ID"]
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
121
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
122 tT <- add_rownames(tT, "ID")
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
123
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
124 } else {
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
125
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
126 gpl <- annotation(eset)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
127 platf <- getGEO(gpl, AnnotGPL=TRUE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
128 ncbifd <- data.frame(attr(dataTable(platf), "table"))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
129
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
130 if (!("ID" %in% colnames(tT))){
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
131 tT <- add_rownames(tT, "ID")}
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
132
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
133 }
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
134
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
135 tT <- merge(tT, ncbifd, by="ID")
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
136 tT <- tT[order(tT$P.Value), ]
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
137 tT <- subset(tT, select=c("Platform_SPOTID","ID","adj.P.Val","P.Value","t","B","logFC","Gene.symbol","Gene.title","Gene.ID","Chromosome.annotation","GO.Function.ID"))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
138 tT<-format(tT, digits=2, nsmall=2)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
139 head(tT)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
140 colnames(tT)=gsub(pattern = "\\.",replacement = "_",colnames(tT))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
141 matrixtT=as.matrix(tT)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
142 datajson=toJSON(matrixtT,pretty = TRUE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
143
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
144 htmlfile=readChar(result.template, file.info(result.template)$size)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
145 htmlfile=gsub(x=htmlfile,pattern = "###DATAJSON###",replacement = datajson, fixed = TRUE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
146 dir.create(result.path, showWarnings = TRUE, recursive = FALSE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
147
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
148 boxplot="boxplot.png"
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
149 png(boxplot,width=800,height = 400)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
150 par(mar=c(7,5,1,1))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
151 boxplot(exprs(eset),las=2,outline=FALSE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
152 dev.off()
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
153 htmlfile=gsub(x=htmlfile,pattern = "###BOXPLOT###",replacement = boxplot, fixed = TRUE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
154 file.copy(boxplot,result.path)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
155
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
156 histopvalue="histopvalue.png"
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
157
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
158 png(histopvalue,width=800,height = 400)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
159 par(mfrow=c(1,2))
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
160 hist(fit2$F.p.value,nclass=100,main="Histogram of p-values", xlab="p-values",ylab="frequency")
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
161 volcanoplot(fit2,coef=1,highlight=10,main="Volcano plot")
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
162 htmlfile=gsub(x=htmlfile,pattern = "###HIST###",replacement = histopvalue, fixed = TRUE)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
163 dev.off()
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
164 file.copy(histopvalue,result.path)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
165
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
166 saveConditions=c(condition1Name,condition2Name)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
167 save(eset,saveConditions,file=result_export_eset)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
168 write.table(x=tT[,-1],file=result.tabular,quote=FALSE,row.names=FALSE,col.names=TRUE,sep="\t")
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
169 write(htmlfile,result)
1024245abc70 planemo upload for repository https://github.com/sblanck/smagexp/tree/master/smagexp_tools commit 5974f806f344dbcc384b931492d7f023bfbbe03b
sblanck
parents:
diff changeset
170