comparison MetaMA.R @ 9:328f4031e5d3 draft

planemo upload commit f882a5ba78afeb368605beb3986936e86c485cbb-dirty
author sblanck
date Wed, 10 May 2017 08:12:48 -0400
parents 93451f832736
children 56267e3293b2
comparison
equal deleted inserted replaced
8:7f74250a083d 9:328f4031e5d3
1 library(metaMA) 1 #!/usr/bin/env Rscript
2 library(affy) 2 # setup R error handling to go to stderr
3 library(annaffy) 3 options( show.error.messages=F, error = function () { cat( geterrmessage(), file=stderr() ); q( "no", 1, F ) } )
4 library(VennDiagram) 4
5 library(GEOquery) 5 # we need that to not crash galaxy with an UTF8 error on German LC settings.
6 6 loc <- Sys.setlocale("LC_MESSAGES", "en_US.UTF-8")
7 cargs<-commandArgs() 7
8 cargs<-cargs[(which(cargs=="--args")+1):length(cargs)] 8 library("optparse")
9 9
10 nbargs=length(cargs) 10 ##### Read options
11 option_list=list(
12 make_option("--input",type="character",default="NULL",help="list of rdata objects containing eset objects"),
13 make_option("--htmloutput",type="character",default=NULL,help="Output html report"),
14 make_option("--htmloutputpath",type="character",default="NULL",help="Path of output html report"),
15 make_option("--htmltemplate",type="character",default=NULL,help="html template)")
16 );
17
18 opt_parser = OptionParser(option_list=option_list);
19 opt = parse_args(opt_parser);
20
21 if(is.null(opt$input)){
22 print_help(opt_parser)
23 stop("input required.", call.=FALSE)
24 }
25
26 #loading libraries
27
28 suppressPackageStartupMessages(require(metaMA))
29 suppressPackageStartupMessages(require(affy))
30 suppressPackageStartupMessages(require(annaffy))
31 suppressPackageStartupMessages(require(VennDiagram))
32 suppressPackageStartupMessages(require(GEOquery))
33
34 listInput <- trimws( unlist( strsplit(trimws(opt$input), ",") ) )
35
11 rdataList=list() 36 rdataList=list()
12 condition1List=list() 37 condition1List=list()
13 condition2List=list() 38 condition2List=list()
14 39 for (input in listInput)
15 for (i in 1:(nbargs-5)) 40 {
16 { 41 load(input)
17 Rdata=cargs[[i]]
18 #condition1=cargs[[i+1]]
19 #condition2=cargs[[i+2]]
20 load(Rdata)
21 42
22 rdataList=c(rdataList,(eset)) 43 rdataList=c(rdataList,(eset))
23 #condition1List=c(condition1List,condition1)
24 #condition2List=c(condition2List,condition2)
25 condition1List=c(condition1List,saveConditions[1]) 44 condition1List=c(condition1List,saveConditions[1])
26 condition2List=c(condition2List,saveConditions[2]) 45 condition2List=c(condition2List,saveConditions[2])
27 46
28 } 47 }
29 48
30 #tables<-cargs[[1]] 49 result.html<-htmloutput
31 #tech<-cargs[[2]] 50 result.path<-htmloutputpath
32 result.html<-cargs[[nbargs-4]] 51 result.template<-htmltemplate
33 result.path<-cargs[[nbargs-3]]
34 #result.venn<-cargs[[nbargs-3]]
35 result.template<-cargs[[nbargs-2]]
36
37 #sink("/dev/null")
38 #dir.create(temp.files.path,recursive=TRUE)
39 #file.conn=file(diag.html,open="w")
40
41 #writeLines(c("<html><body bgcolor='lightgray'>"),file.conn)
42 52
43 showVenn<-function(res,file) 53 showVenn<-function(res,file)
44 { 54 {
45 venn.plot<-venn.diagram(x = c(res[c(1:(length(res)-3))],meta=list(res$Meta)), 55 venn.plot<-venn.diagram(x = c(res[c(1:(length(res)-3))],meta=list(res$Meta)),
46 filename = NULL, col = "black", 56 filename = NULL, col = "black",
48 margin=0.05, alpha = 0.6) 58 margin=0.05, alpha = 0.6)
49 jpeg(file) 59 jpeg(file)
50 grid.draw(venn.plot) 60 grid.draw(venn.plot)
51 dev.off() 61 dev.off()
52 } 62 }
53
54 63
55 library("org.Hs.eg.db") 64 library("org.Hs.eg.db")
56 x <- org.Hs.egUNIGENE 65 x <- org.Hs.egUNIGENE
57 mapped_genes <- mappedkeys(x) 66 mapped_genes <- mappedkeys(x)
58 link <- as.list(x[mapped_genes]) 67 link <- as.list(x[mapped_genes])
103 if (LogC) { ex[which(ex <= 0)] <- NaN 112 if (LogC) { ex[which(ex <= 0)] <- NaN
104 return (log2(ex)) } else { 113 return (log2(ex)) } else {
105 return (ex) 114 return (ex)
106 } 115 }
107 } 116 }
108
109
110 117
111 118
112 filterCondition<-function(gset,condition1, condition2){ 119 filterCondition<-function(gset,condition1, condition2){
113 selected=c(which((tolower(as.character(pData(gset)["source_name_ch1"][,1]))==condition1)), 120 selected=c(which((tolower(as.character(pData(gset)["source_name_ch1"][,1]))==condition1)),
114 which(tolower(as.character(pData(gset)["source_name_ch1"][,1]))==condition2)) 121 which(tolower(as.character(pData(gset)["source_name_ch1"][,1]))==condition2))