Mercurial > repos > fubar > brokenandnotdeletablebyowneroradmin
comparison rgToolFactory.py @ 12:d12728e33c3d
Changed to deliver a gz file - requires a new datatypes_conf.xml entry:
<datatype extension="gz" type="galaxy.datatypes.binary:Binary" mimetype="multipart/x-gzip" subclass="True" />
There's some wierd shit going on with filter values and such but it now all appears to be working ok
author | ross lazarus ross.lazarus@gmail.com |
---|---|
date | Sun, 03 Jun 2012 15:39:20 +1000 |
parents | 71f2ac0eee95 |
children | 7725e4ab27e1 |
comparison
equal
deleted
inserted
replaced
11:a0a5d0757e39 | 12:d12728e33c3d |
---|---|
65 self.script = s | 65 self.script = s |
66 self.myname = sys.argv[0] # get our name because we write ourselves out as a tool later | 66 self.myname = sys.argv[0] # get our name because we write ourselves out as a tool later |
67 self.pyfile = self.myname # crude but efficient - the cruft won't hurt much | 67 self.pyfile = self.myname # crude but efficient - the cruft won't hurt much |
68 self.xmlfile = '%s.xml' % self.toolname | 68 self.xmlfile = '%s.xml' % self.toolname |
69 self.sfile = '%s.%s' % (self.toolname,opts.interpreter) | 69 self.sfile = '%s.%s' % (self.toolname,opts.interpreter) |
70 if opts.output_dir or self.opts.make_Tool: # may not want these complexities | 70 if opts.output_dir: # may not want these complexities |
71 self.tlog = os.path.join(opts.output_dir,"%s_runner.log" % self.toolname) | 71 self.tlog = os.path.join(opts.output_dir,"%s_runner.log" % self.toolname) |
72 artifactpath = os.path.join(opts.output_dir,'%s_run.script' % self.toolname) | 72 artifactpath = os.path.join(opts.output_dir,'%s_run.script' % self.toolname) |
73 artifact = open(artifactpath,'w') | 73 artifact = open(artifactpath,'w') |
74 artifact.write(self.script) | 74 artifact.write(self.script) |
75 artifact.write('\n') | 75 artifact.write('\n') |
76 artifact.close() | 76 artifact.close() |
77 if opts.make_Tool: # need this code and the user script for the tarball | |
77 localscript = open(self.sfile,'w') | 78 localscript = open(self.sfile,'w') |
78 localscript.write(self.script) | 79 localscript.write(self.script) |
79 localscript.close() | 80 localscript.close() |
80 shutil.copyfile(self.myname,'%s.py' % self.toolname) # for tool and for user | 81 shutil.copyfile(self.myname,'%s.py' % self.toolname) # for tool and for user |
81 localpy = open('%s.py' % self.toolname,'w') | |
82 localpy.write(open(self.myname,'r').read()) | |
83 self.cl = [] | 82 self.cl = [] |
84 self.html = [] | 83 self.html = [] |
85 a = self.cl.append | 84 a = self.cl.append |
86 a(opts.interpreter) | 85 a(opts.interpreter) |
87 a('-') # use stdin | 86 a('-') # use stdin |
88 if opts.input_tab: | 87 a(opts.input_tab) |
89 a(opts.input_tab) | 88 a(opts.output_tab) |
90 if opts.output_tab: | |
91 a(opts.output_tab) | |
92 self.outFormats = 'tabular' # TODO make this an option at tool generation time | 89 self.outFormats = 'tabular' # TODO make this an option at tool generation time |
93 self.inputFormats = 'tabular' # TODO make this an option at tool generation time | 90 self.inputFormats = 'tabular' # TODO make this an option at tool generation time |
94 | 91 |
95 | 92 |
96 def makeXML(self): | 93 def makeXML(self): |
132 xdict['tooldesc'] = '<description>%s</description>' % self.opts.tool_desc | 129 xdict['tooldesc'] = '<description>%s</description>' % self.opts.tool_desc |
133 else: | 130 else: |
134 xdict['tooldesc'] = '' | 131 xdict['tooldesc'] = '' |
135 xdict['command_outputs'] = '' | 132 xdict['command_outputs'] = '' |
136 xdict['outputs'] = '' | 133 xdict['outputs'] = '' |
137 if self.opts.input_tab: | 134 if self.opts.input_tab <> 'None': |
138 xdict['command_inputs'] = '--input_tab "$input1"' | 135 xdict['command_inputs'] = '--input_tab "$input1"' |
139 xdict['inputs'] = '<param name="input1" type="data" format="%s" label="Select a suitable input file from your history"/>' % self.inputFormats | 136 xdict['inputs'] = '<param name="input1" type="data" format="%s" label="Select a suitable input file from your history"/>' % self.inputFormats |
140 else: | 137 else: |
141 xdict['command_inputs'] = '' # assume no input - eg a random data generator | 138 xdict['command_inputs'] = '' # assume no input - eg a random data generator |
142 xdict['inputs'] = '' | 139 xdict['inputs'] = '' |
146 xdict['interpreter'] = self.opts.interpreter | 143 xdict['interpreter'] = self.opts.interpreter |
147 xdict['scriptname'] = self.sfile | 144 xdict['scriptname'] = self.sfile |
148 if self.opts.make_HTML: | 145 if self.opts.make_HTML: |
149 xdict['command_outputs'] += '--output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes"' | 146 xdict['command_outputs'] += '--output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes"' |
150 xdict['outputs'] += '<data format="html" name="html_file" label="${job_name}.html"/>\n' | 147 xdict['outputs'] += '<data format="html" name="html_file" label="${job_name}.html"/>\n' |
151 if self.opts.output_tab: | 148 if self.opts.output_tab <> 'None': |
152 xdict['command_outputs'] += '--output_tab "$tab_file"' | 149 xdict['command_outputs'] += '--output_tab "$tab_file"' |
153 xdict['outputs'] += '<data format="%s" name="tab_file" label="${job_name}"/>\n' % self.outFormats | 150 xdict['outputs'] += '<data format="%s" name="tab_file" label="${job_name}"/>\n' % self.outFormats |
154 xdict['command'] = newCommand % xdict | 151 xdict['command'] = newCommand % xdict |
155 xmls = newXML % xdict | 152 xmls = newXML % xdict |
156 xf = open(self.xmlfile,'w') | 153 xf = open(self.xmlfile,'w') |
170 print >> sys.stderr,'## Run failed. Cannot build yet. Please fix and retry' | 167 print >> sys.stderr,'## Run failed. Cannot build yet. Please fix and retry' |
171 sys.exit(1) | 168 sys.exit(1) |
172 self.makeXML() | 169 self.makeXML() |
173 tdir = self.toolname | 170 tdir = self.toolname |
174 os.mkdir(tdir) | 171 os.mkdir(tdir) |
175 if self.opts.input_tab: # we may have test data? | 172 if self.opts.input_tab <> 'None': # we may have test data? |
176 testdir = os.path.join(tdir,'test-data') | 173 testdir = os.path.join(tdir,'test-data') |
177 os.mkdir(testdir) # make tests directory | 174 os.mkdir(testdir) # make tests directory |
178 shutil.copyfile(self.opts.input_tab,os.path.join(testdir,'test1_in.tab')) | 175 shutil.copyfile(self.opts.input_tab,os.path.join(testdir,'test1_in.tab')) |
179 if self.opts.output_tab: | 176 if self.opts.output_tab <> 'None': |
180 shutil.copyfile(self.opts.output_tab,os.path.join(testdir,'test1_out.tab')) | 177 shutil.copyfile(self.opts.output_tab,os.path.join(testdir,'test1_out.tab')) |
181 if self.opts.make_HTML: | 178 if self.opts.make_HTML: |
182 shutil.copyfile(self.opts.output_html,os.path.join(testdir,'test1_out.html')) | 179 shutil.copyfile(self.opts.output_html,os.path.join(testdir,'test1_out.html')) |
183 shutil.copyfile(self.opts.tlog,os.path.join(testdir,'test1_out.log')) | 180 if self.opts.output_dir: |
181 shutil.copyfile(self.tlog,os.path.join(testdir,'test1_out.log')) | |
184 shutil.copyfile(self.xmlfile,os.path.join(tdir,self.xmlfile)) | 182 shutil.copyfile(self.xmlfile,os.path.join(tdir,self.xmlfile)) |
185 shutil.copyfile(self.pyfile,os.path.join(tdir,'%s.py' % self.toolname)) | 183 shutil.copyfile(self.pyfile,os.path.join(tdir,'%s.py' % self.toolname)) |
186 shutil.copyfile(self.sfile,os.path.join(tdir,self.sfile)) | 184 shutil.copyfile(self.sfile,os.path.join(tdir,self.sfile)) |
187 tarpath = "%s.gz" % self.toolname | 185 tarpath = "%s.gz" % self.toolname |
188 tar = tarfile.open(tarpath, "w:gz") | 186 tar = tarfile.open(tarpath, "w:gz") |
189 tar.add(tdir,arcname=self.toolname) | 187 tar.add(tdir,arcname=self.toolname) |
190 tar.close() | 188 tar.close() |
189 shutil.copy(tarpath,self.opts.new_tool) | |
191 shutil.rmtree(tdir) | 190 shutil.rmtree(tdir) |
192 self.makeHtml() # call this to return the new gzip inside the autogenerated html file | |
193 ## TODO: replace with optional direct upload to local toolshed? | 191 ## TODO: replace with optional direct upload to local toolshed? |
194 return retval | 192 return retval |
195 | 193 |
196 def compressPDF(self,inpdf=None,thumbformat='png'): | 194 def compressPDF(self,inpdf=None,thumbformat='png'): |
197 """need absolute path to pdf | 195 """need absolute path to pdf |
292 | 290 |
293 | 291 |
294 def run(self): | 292 def run(self): |
295 """ | 293 """ |
296 """ | 294 """ |
297 if self.opts.output_dir or self.opts.make_Tool: | 295 if self.opts.output_dir: |
298 sto = open(self.tlog,'w') | 296 sto = open(self.tlog,'w') |
299 p = subprocess.Popen(' '.join(self.cl),shell=True,stdout=sto,stderr=sto,stdin=subprocess.PIPE,cwd=self.opts.output_dir) | 297 p = subprocess.Popen(' '.join(self.cl),shell=True,stdout=sto,stderr=sto,stdin=subprocess.PIPE,cwd=self.opts.output_dir) |
300 else: | 298 else: |
301 p = subprocess.Popen(' '.join(self.cl),shell=True,stdin=subprocess.PIPE) | 299 p = subprocess.Popen(' '.join(self.cl),shell=True,stdin=subprocess.PIPE) |
302 p.stdin.write(self.script) | 300 p.stdin.write(self.script) |
303 p.stdin.close() | 301 p.stdin.close() |
304 retval = p.wait() | 302 retval = p.wait() |
305 if self.opts.make_HTML or self.opts.make_Tool: | 303 if self.opts.output_dir: |
306 sto.close() | 304 sto.close() |
305 if self.opts.make_HTML: | |
307 self.makeHtml() | 306 self.makeHtml() |
308 return retval | 307 return retval |
309 | 308 |
310 | 309 |
311 def main(): | 310 def main(): |
319 a('--script_path',default=None) | 318 a('--script_path',default=None) |
320 a('--tool_name',default=None) | 319 a('--tool_name',default=None) |
321 a('--interpreter',default=None) | 320 a('--interpreter',default=None) |
322 a('--output_dir',default=None) | 321 a('--output_dir',default=None) |
323 a('--output_html',default=None) | 322 a('--output_html',default=None) |
324 a('--input_tab',default=None) | 323 a('--input_tab',default="None") |
325 a('--output_tab',default=None) | 324 a('--output_tab',default="None") |
326 a('--user_email',default=None) | 325 a('--user_email',default=None) |
327 a('--bad_user',default=None) | 326 a('--bad_user',default=None) |
328 a('--make_Tool',default=None) | 327 a('--make_Tool',default=None) |
329 a('--make_HTML',default=None) | 328 a('--make_HTML',default=None) |
330 a('--help_text',default=None) | 329 a('--help_text',default=None) |
331 a('--tool_desc',default=None) | 330 a('--tool_desc',default=None) |
331 a('--new_tool',default=None) | |
332 opts, args = op.parse_args() | 332 opts, args = op.parse_args() |
333 assert not opts.bad_user,'%s is NOT authorized to use this tool. Please ask your friendly admin' % opts.bad_user | 333 assert not opts.bad_user,'%s is NOT authorized to use this tool. Please ask your friendly admin' % opts.bad_user |
334 assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq' | 334 assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq' |
335 assert opts.interpreter,'## Tool Factory wrapper expects an interpreter - eg --interpreter=Rscript' | 335 assert opts.interpreter,'## Tool Factory wrapper expects an interpreter - eg --interpreter=Rscript' |
336 assert os.path.isfile(opts.script_path),'## Tool Factory wrapper expects a script path - eg --script_path=foo.R' | 336 assert os.path.isfile(opts.script_path),'## Tool Factory wrapper expects a script path - eg --script_path=foo.R' |