17
|
1 #msg.file<-file("RnBeads.messages.out", open="w")
|
|
2 #sink(file=msg.file)
|
|
3
|
|
4 suppressWarnings(suppressPackageStartupMessages(library(RnBeads)))
|
|
5 suppressWarnings(suppressPackageStartupMessages(library(getopt)))
|
|
6
|
|
7 #all.opts<-names(rnb.options())
|
|
8 opt.class<-RnBeads:::OPTION.TYPES[-28]
|
|
9 all.opts<-names(opt.class)
|
|
10 #all.opts<-paste("--", all.opts, sep="")
|
|
11 #all.opts<-gsub("\\.([a-z])", "\\U\\1", all.opts, perl=TRUE)
|
|
12 all.opts<-gsub("\\.","-", all.opts)
|
|
13 #opt.class<-sapply(rnb.options(), class)
|
|
14
|
|
15 rnb.opt.spec<-data.frame(
|
|
16 Long=all.opts,
|
|
17 Short=as.character(1:length(all.opts)),
|
|
18 Mask=c(1,2)[as.integer((opt.class=="logical"))+1],
|
|
19 Type=opt.class)
|
|
20
|
|
21 ### automated xml file preparation
|
|
22 #xml.strings<-apply(rnb.opt.spec,1, function(row){
|
|
23 #
|
|
24 # opt.lab<-gsub("-", ".", row[1])
|
|
25 # opt.def.val<-rnb.getOption(opt.lab)
|
|
26 # opt.name<-gsub("-([0-9a-z])", "\\U\\1", row[1], perl=TRUE)
|
|
27 # tf.opt<-"\t\t\t<option value=\"True\">True</option>\n\t\t\t<option value=\"False\">False</option>"
|
|
28 # opt.lab<-paste(opt.lab, gsub("\\."," ", row[4]), sep=", ")
|
|
29 # if(row[4]=="logical"){
|
|
30 # opt.type<-'select'
|
|
31 # if(!is.null(opt.def.val) && opt.def.val)
|
|
32 # opt.def.val<-"1" else
|
|
33 # opt.def.val<-"0"
|
|
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)
|
|
35 # }else{
|
|
36 # opt.type<-'text'
|
|
37 # if(!is.null(opt.def.val) && opt.def.val!="")
|
|
38 # opt.def.val<-paste(opt.def.val, collapse=",") else
|
|
39 # opt.def.val<-""
|
|
40 # string<-sprintf("\t\t<param name=\"%s\" type=\"%s\" label=\"%s\" value=\"%s\"/>\n", opt.name, opt.type, opt.lab, opt.def.val)
|
|
41 # }
|
|
42 # string
|
|
43 # })
|
|
44 #
|
|
45 #cat(xml.strings, sep="", file="automated.settings.xml.txt")
|
|
46 #
|
|
47 #opt.def.strings<-apply(rnb.opt.spec,1, function(row){
|
|
48 #
|
|
49 # opt.name<-gsub("-([0-9a-z])", "\\U\\1", row[1], perl=TRUE)
|
|
50 # opt.long<-row[1]
|
|
51 # opt.short<-row[2]
|
|
52 #
|
|
53 # if(row[4]=="logical"){
|
|
54 # def.string<-sprintf("#if str( $options.%s ) == \"True\"\n\t--%s\n#end if\n", opt.name, opt.long)
|
|
55 # }else{
|
|
56 # def.string<-sprintf("#if str( $options.%s ) != \"\"\n\t--%s=\"$options.%s\" \n#end if\n", opt.name, opt.long, opt.name)
|
|
57 # }
|
|
58 # def.string
|
|
59 #
|
|
60 # })
|
|
61 #cat(opt.def.strings, sep="", file="automated.option.assignments.txt")
|
|
62
|
|
63
|
|
64 rnb.opt.spec$Type<-gsub("\\.vector", "", rnb.opt.spec$Type)
|
|
65 rnb.opt.spec$Type<-gsub("numeric", "double", rnb.opt.spec$Type)
|
|
66 rnb.opt.spec<-rbind(data.frame(
|
|
67 Long=c("data-type", "pheno", "idat-dir","idat-files","bed-files", "gs-report", "geo-series", "betas", "pvals","output-file", "report-dir"),
|
|
68 Short=c("d","s","a","i","f","g","e","b","p","r","o"),
|
|
69 Mask=c(1,2,2,2,2,2,2,2,2,1,1),
|
|
70 Type=c("character","character","character","character","character","character","character","character","character","character", "character")),
|
|
71 rnb.opt.spec)
|
|
72
|
|
73 opts<-getopt(as.matrix(rnb.opt.spec))
|
|
74 #opts<-getopt(as.matrix(rnb.opt.spec), opt=list("--data-type=idats","--report-dir=dir", "--idats=file1\tfile2"))
|
|
75 print(opts)
|
|
76
|
|
77 if(opts[["data-type"]]=="idatDir"){
|
|
78
|
|
79 data.source<-list()
|
|
80 data.type<-"idat.dir"
|
|
81 data.source[["idat.dir"]]<-opts[["idat-dir"]]
|
|
82 data.source[["sample.sheet"]]<-opts[["pheno"]]
|
|
83
|
|
84 }else if(opts[["data-type"]]=="idatFiles"){
|
|
85
|
|
86 data.type<-"idat.dir"
|
|
87 file.string<-gsub(" ","", opts[["idat-files"]])
|
|
88 files<-strsplit(file.string, ",")[[1]]
|
|
89 files<-files[files!=""]
|
|
90 bed.dir<-sprintf("%s_beds",opts[["report-dir"]])
|
|
91 dir.create(bed.dir)
|
|
92 file.copy(files, bed.dir)
|
|
93 for(dat.file in list.files(bed.dir, full.names = TRUE)){
|
|
94 file.rename(dat.file, gsub("\\.dat", ".bed", dat.file))
|
|
95 }
|
|
96 data.source<-list()
|
|
97 data.source[["bed.dir"]]<-bed.dir
|
|
98 data.source[["sample.sheet"]]<-opts[["pheno"]]
|
|
99
|
|
100
|
|
101 }else if(opts[["data-type"]]=="GS.report"){
|
|
102
|
|
103 data.type<-"GS.report"
|
|
104 data.source<-opts[["gs-report"]]
|
|
105
|
|
106 }else if(opts[["data-type"]]=="GEO"){
|
|
107
|
|
108 data.type<-"GEO"
|
|
109 data.source<-opts[["geo-series"]]
|
|
110
|
|
111 }else if(opts[["data-type"]]=="data.files"){
|
|
112
|
|
113 data.type<-"GEO"
|
|
114 data.source<-opts[["geo-series"]]
|
|
115
|
|
116 }else if(opts[["data-type"]]=="data.files"){
|
|
117
|
|
118 data.type<-"data.files"
|
|
119 data.source<-c(opts[["pheno"]], opts[["betas"]])
|
|
120 if(!is.null(opts[["pvals"]]))
|
|
121 data.source<-c(data.source, opts[["pvals"]])
|
|
122
|
|
123 }else if(opts[["data-type"]]=="bed.dir"){
|
|
124
|
|
125 data.type<-"bed.dir"
|
|
126 file.string<-gsub(" ","", opts[["bed-files"]])
|
|
127 files<-strsplit(file.string, ",")[[1]]
|
|
128 files<-files[files!=""]
|
|
129 bed.dir<-sprintf("%s_beds",opts[["report-dir"]])
|
|
130 dir.create(bed.dir)
|
|
131 file.copy(files, bed.dir)
|
|
132 for(dat.file in list.files(bed.dir, full.names = TRUE)){
|
|
133 file.rename(dat.file, gsub("\\.dat", ".bed", dat.file))
|
|
134 }
|
|
135 data.source<-list()
|
|
136 data.source[["bed.dir"]]<-bed.dir
|
|
137
|
|
138 logger.start(fname="NA")
|
|
139 sample.sheet<-rnb.read.annotation(opts[["pheno"]])
|
|
140 logger.close()
|
|
141 if(length(files) < nrow(sample.sheet))
|
|
142 stop("Not all bed files are present")
|
|
143
|
|
144 cn<-colnames(sample.sheet)
|
|
145 sample.sheet<-cbind(sample.sheet, gsub("\\.dat", ".bed", files))
|
|
146 colnames(sample.sheet)<-c(cn, "BED_files")
|
|
147 data.source[["sample.sheet"]]<-sample.sheet
|
|
148 }
|
|
149
|
|
150 if("logging" %in% names(opts)){ # TODO create a cleaner way of checking whether the full options set was supplied
|
|
151
|
|
152 dump<-sapply(names(opt.class), function(on){
|
|
153 getoptname<-gsub("-", "\\.","-",on)
|
|
154 if(getoptname %in% names(opts)){
|
|
155 if(opt.class[on]=="logical"){
|
|
156 ov<-TRUE
|
|
157 }else if(opt.class %in% c("character","character.vector")){
|
|
158 ov<-opts[[getoptname]]
|
|
159 ov<-gsub("\"", "", ov)
|
|
160 if(opt.class=="character.vector"){
|
|
161 ov<-as.character(strsplit(ov,","))
|
|
162 }
|
|
163
|
|
164 }else if(opt.class %in% c("integer","numeric","integer.vector","numeric.vector")){
|
|
165 ov<-opts[[getoptname]]
|
|
166 ov<-gsub("\"", "", ov)
|
|
167 if(opt.class %in% c("integer.vector","numeric.vector")){
|
|
168 ov<-as.character(strsplit(ov,","))
|
|
169 }
|
|
170 }
|
|
171 eval(parse(text=sprintf("rnb.options(%s=ov)",on)))
|
|
172 }
|
|
173 })
|
|
174
|
|
175 logical.opts<-names(opt.class[opt.class=="logical"])
|
|
176 logical.opts.false<-logical.opts[!logical.opts %in% gsub("-",".",names(opts))]
|
|
177
|
|
178
|
|
179 dump<-sapply(logical.opts.false, function(on){
|
|
180 eval(parse(text=sprintf("rnb.options(%s=FALSE)",on)))
|
|
181 })
|
|
182 }
|
|
183
|
|
184 print(rnb.options())
|
|
185
|
|
186 #report.out.dir<-sprintf("%s_rnbReport", tempdir())
|
|
187 report.out.dir<-opts[["report-dir"]]
|
|
188 #print("Starting RnBeads with the following inputs:")
|
|
189 #print(data.source)
|
|
190 #print(report.out.dir)
|
|
191 #print(data.type)
|
|
192 rnb.run.analysis(data.source=data.source, dir.report=report.out.dir, data.type=data.type)
|
|
193
|
|
194
|
|
195 #sink(file=NULL)
|
|
196 #flush(msg.file)
|
|
197 #close(msg.file) |