comparison RnBeadsGalaxy.R @ 0:d1d0d07a8af4 draft

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