annotate RnBeadsGalaxy.R @ 11:ce411254e4a9 draft

Uploaded
author pavlo-lutsik
date Sat, 20 Apr 2013 07:14:22 -0400
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
11
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
1 msg.file<-file("RnBeads.messages.out")
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
2 sink(file=open(msg.file, "w"))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
3
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
4 suppressWarnings(suppressPackageStartupMessages(library(RnBeads)))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
5 suppressWarnings(suppressPackageStartupMessages(library(getopt)))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
6
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
7 #all.opts<-names(rnb.options())
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
8 opt.class<-RnBeads:::OPTION.TYPES[-28]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
9 all.opts<-names(opt.class)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
10 #all.opts<-paste("--", all.opts, sep="")
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
11 #all.opts<-gsub("\\.([a-z])", "\\U\\1", all.opts, perl=TRUE)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
12 all.opts<-gsub("\\.","-", all.opts)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
13 #opt.class<-sapply(rnb.options(), class)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
14
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
15 rnb.opt.spec<-data.frame(
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
16 Long=all.opts,
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
17 Short=as.character(1:length(all.opts)),
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
18 Mask=c(1,2)[as.integer((opt.class=="logical"))+1],
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
19 Type=opt.class)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
20
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
21 ### automated xml file preparation
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
22 #xml.strings<-apply(rnb.opt.spec,1, function(row){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
23 #
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
24 # opt.lab<-gsub("-", ".", row[1])
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
25 # opt.def.val<-rnb.getOption(opt.lab)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
26 # opt.name<-gsub("-([0-9a-z])", "\\U\\1", row[1], perl=TRUE)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
27 # tf.opt<-"\t\t\t<option value=\"True\">True</option>\n\t\t\t<option value=\"False\">False</option>"
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
28 # opt.lab<-paste(opt.lab, gsub("\\."," ", row[4]), sep=", ")
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
29 # if(row[4]=="logical"){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
30 # opt.type<-'select'
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
31 # if(!is.null(opt.def.val) && opt.def.val)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
32 # opt.def.val<-"1" else
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
33 # opt.def.val<-"0"
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
34 # string<-sprintf("\t\t<param name=\"%s\" type=\"%s\" label=\"%s\" value=\"%s\">\n%s\n\t\t</param>\n", opt.name, opt.type, opt.lab, opt.def.val, tf.opt)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
35 # }else{
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
36 # opt.type<-'text'
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
37 # if(!is.null(opt.def.val) && opt.def.val!="")
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
38 # opt.def.val<-paste(opt.def.val, collapse=",") else
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
39 # opt.def.val<-""
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
40 # string<-sprintf("\t\t<param name=\"%s\" type=\"%s\" label=\"%s\" value=\"%s\"/>\n", opt.name, opt.type, opt.lab, opt.def.val)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
41 # }
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
42 # string
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
43 # })
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
44 #
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
45 #cat(xml.strings, sep="", file="automated.settings.xml.txt")
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
46 #
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
47 #opt.def.strings<-apply(rnb.opt.spec,1, function(row){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
48 #
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
49 # opt.name<-gsub("-([0-9a-z])", "\\U\\1", row[1], perl=TRUE)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
50 # opt.long<-row[1]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
51 # opt.short<-row[2]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
52 #
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
53 # if(row[4]=="logical"){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
54 # def.string<-sprintf("#if str( $options.%s ) == \"True\"\n\t--%s\n#end if\n", opt.name, opt.long)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
55 # }else{
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
56 # def.string<-sprintf("#if str( $options.%s ) != \"\"\n\t--%s=\"$options.%s\" \n#end if\n", opt.name, opt.long, opt.name)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
57 # }
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
58 # def.string
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
59 #
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
60 # })
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
61 #cat(opt.def.strings, sep="", file="automated.option.assignments.txt")
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
62
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
63
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
64 rnb.opt.spec$Type<-gsub("\\.vector", "", rnb.opt.spec$Type)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
65 rnb.opt.spec$Type<-gsub("numeric", "double", rnb.opt.spec$Type)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
66 rnb.opt.spec<-rbind(data.frame(
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
67 Long=c("data-type", "pheno", "idat-dir","idat-files","bed-files", "gs-report", "geo-series", "betas", "pvals","output-file", "report-dir"),
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
68 Short=c("d","s","a","i","f","g","e","b","p","r","o"),
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
69 Mask=c(1,2,2,2,2,2,2,2,2,1,1),
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
70 Type=c("character","character","character","character","character","character","character","character","character","character", "character")),
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
71 rnb.opt.spec)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
72
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
73 opts<-getopt(as.matrix(rnb.opt.spec))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
74 #opts<-getopt(as.matrix(rnb.opt.spec), opt=list("--data-type=idats","--report-dir=dir", "--idats=file1\tfile2"))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
75 print(opts)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
76
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
77 if(opts[["data-type"]]=="idatDir"){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
78
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
79 data.source<-list()
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
80 data.type<-"idat.dir"
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
81 data.source[["idat.dir"]]<-opts[["idat-dir"]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
82 data.source[["sample.sheet"]]<-opts[["pheno"]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
83
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
84 }else if(opts[["data-type"]]=="idatFiles"){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
85
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
86 data.type<-"idat.dir"
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
87 files<-strsplit(opts[["idat-files"]], "\t")[[1]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
88 idat.dir<-mkdir(file.path(opts[["report-dir"]], "idats"))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
89 file.copy(as.list(files), idat.dir)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
90 data.source<-list()
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
91 data.source[["idat.dir"]]<-idat.dir
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
92 data.source[["sample.sheet"]]<-opts[["pheno"]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
93
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
94
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
95 }else if(opts[["data-type"]]=="GS.report"){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
96
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
97 data.type<-"GS.report"
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
98 data.source<-opts[["gs-report"]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
99
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
100 }else if(opts[["data-type"]]=="GEO"){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
101
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
102 data.type<-"GEO"
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
103 data.source<-opts[["geo-series"]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
104
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
105 }else if(opts[["data-type"]]=="data.files"){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
106
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
107 data.type<-"GEO"
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
108 data.source<-opts[["geo-series"]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
109
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
110 }else if(opts[["data-type"]]=="data.files"){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
111
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
112 data.type<-"data.files"
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
113 data.source<-c(opts[["pheno"]], opts[["betas"]])
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
114 if(!is.null(opts[["pvals"]]))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
115 data.source<-c(data.source, opts[["pvals"]])
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
116
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
117 }else if(opts[["data-type"]]=="beds"){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
118
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
119 data.type<-"idat.dir"
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
120 files<-strsplit(opts[["bed-files"]], "\t")[[1]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
121 bed.dir<-mkdir(file.path(opts[["report-dir"]], "beds"))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
122 file.copy(as.list(files), bed.dir)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
123 data.source<-list()
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
124 data.source[["bed.dir"]]<-bed.dir
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
125 data.source[["sample.sheet"]]<-opts[["pheno"]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
126
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
127 }
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
128
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
129 dump<-sapply(names(opt.class), function(on){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
130 getoptname<-gsub("-", "\\.","-",on)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
131 if(getoptname %in% names(opts)){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
132 if(opt.class[on]=="logical"){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
133 ov<-TRUE
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
134 }else if(opt.class %in% c("character","character.vector")){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
135 ov<-opts[[getoptname]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
136 ov<-gsub("\"", "", ov)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
137 if(opt.class=="character.vector"){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
138 ov<-as.character(strsplit(ov,","))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
139 }
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
140
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
141 }else if(opt.class %in% c("integer","numeric","integer.vector","numeric.vector")){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
142 ov<-opts[[getoptname]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
143 ov<-gsub("\"", "", ov)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
144 if(opt.class %in% c("integer.vector","numeric.vector")){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
145 ov<-as.character(strsplit(ov,","))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
146 }
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
147 }
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
148 eval(parse(text=sprintf("rnb.options(%s=ov)",on)))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
149 }
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
150 })
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
151
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
152
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
153 logical.opts<-names(opt.class[opt.class=="logical"])
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
154 logical.opts.false<-logical.opts[!logical.opts %in% gsub("-",".",names(opts))]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
155
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
156 dump<-sapply(logical.opts.false, function(on){
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
157 eval(parse(text=sprintf("rnb.options(%s=FALSE)",on)))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
158 })
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
159
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
160 #report.out.dir<-sprintf("%s_rnbReport", tempdir())
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
161 report.out.dir<-opts[["report-dir"]]
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
162 suppressMessages(suppressWarnings(rnb.run.analysis(data.source=data.source, dir.report=report.out.dir, data.type=data.type)))
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
163
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
164 #file.symlink(paste(report.out.dir, "index.html", sep="/"), opts[["output-file"]])
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
165
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
166 outfile<-file(opts[["output-file"]],open="w")
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
167 cat(sprintf("<html>\n<body>\n<a href=\"index.html\">RnBeads report</a>\n</body>\n</html>",report.out.dir),file=outfile)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
168 close(outfile)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
169
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
170 sink(file=NULL)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
171 flush(msg.file)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
172 close(msg.file)
ce411254e4a9 Uploaded
pavlo-lutsik
parents:
diff changeset
173