annotate RnBeadsGalaxy.R @ 5:609d1a687bff draft

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