comparison rgToolFactory.py @ 30:fb3fa6a2874d draft

Citations added (thanks John!) and a few more output formats for Alistair Chilcott
author fubar
date Thu, 28 Aug 2014 02:22:39 -0400
parents bff4c9bfabc7
children
comparison
equal deleted inserted replaced
29:bff4c9bfabc7 30:fb3fa6a2874d
130 return "".join(html_escape_table.get(c,c) for c in text) 130 return "".join(html_escape_table.get(c,c) for c in text)
131 131
132 def cmd_exists(cmd): 132 def cmd_exists(cmd):
133 return subprocess.call("type " + cmd, shell=True, 133 return subprocess.call("type " + cmd, shell=True,
134 stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0 134 stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0
135
136
137 def parse_citations(citations_text):
138 """
139 """
140 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
141 citation_tuples = []
142 for citation in citations:
143 if citation.startswith("doi"):
144 citation_tuples.append( ("doi", citation[len("doi"):].strip() ) )
145 else:
146 citation_tuples.append( ("bibtex", citation[len("bibtex"):].strip() ) )
147 return citation_tuples
135 148
136 149
137 class ScriptRunner: 150 class ScriptRunner:
138 """class is a wrapper for an arbitrary script 151 """class is a wrapper for an arbitrary script
139 """ 152 """
262 <help> 275 <help>
263 276
264 %(help)s 277 %(help)s
265 278
266 </help> 279 </help>
280 <citations>
281 %(citations)s
282 <citation type="doi">10.1093/bioinformatics/bts573</citation>
283 </citations>
267 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto 284 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto
268 285
269 newCommand=""" 286 newCommand="""
270 %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" 287 %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s"
271 --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s """ 288 --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s """
301 </tests> 318 </tests>
302 """ 319 """
303 xdict = {} 320 xdict = {}
304 xdict['requirements'] = '' 321 xdict['requirements'] = ''
305 if self.opts.make_HTML: 322 if self.opts.make_HTML:
306 xdict['requirements'] = protorequirements 323 if self.opts.include_dependencies == "yes":
324 xdict['requirements'] = protorequirements
307 xdict['tool_version'] = self.opts.tool_version 325 xdict['tool_version'] = self.opts.tool_version
308 xdict['test1Input'] = self.test1Input 326 xdict['test1Input'] = self.test1Input
309 xdict['test1HTML'] = self.test1HTML 327 xdict['test1HTML'] = self.test1HTML
310 xdict['test1Output'] = self.test1Output 328 xdict['test1Output'] = self.test1Output
311 if self.opts.make_HTML and self.opts.output_tab <> 'None': 329 if self.opts.make_HTML and self.opts.output_tab <> 'None':
321 helptext = open(self.opts.help_text,'r').readlines() 339 helptext = open(self.opts.help_text,'r').readlines()
322 helptext = [html_escape(x) for x in helptext] # must html escape here too - thanks to Marius van den Beek 340 helptext = [html_escape(x) for x in helptext] # must html escape here too - thanks to Marius van den Beek
323 xdict['help'] = ''.join([x for x in helptext]) 341 xdict['help'] = ''.join([x for x in helptext])
324 else: 342 else:
325 xdict['help'] = 'Please ask the tool author (%s) for help as none was supplied at tool generation\n' % (self.opts.user_email) 343 xdict['help'] = 'Please ask the tool author (%s) for help as none was supplied at tool generation\n' % (self.opts.user_email)
344 if self.opts.citations:
345 citationstext = open(self.opts.citations,'r').read()
346 citation_tuples = parse_citations(citationstext)
347 citations_xml = ""
348 for citation_type, citation_content in citation_tuples:
349 citation_xml = """<citation type="%s">%s</citation>""" % (citation_type, html_escape(citation_content))
350 citations_xml += citation_xml
351 xdict['citations'] = citations_xml
352 else:
353 xdict['citations'] = ""
326 coda = ['**Script**','Pressing execute will run the following code over your input file and generate some outputs in your history::'] 354 coda = ['**Script**','Pressing execute will run the following code over your input file and generate some outputs in your history::']
327 coda.append('\n') 355 coda.append('\n')
328 coda.append(self.indentedScript) 356 coda.append(self.indentedScript)
329 coda.append('\n**Attribution**\nThis Galaxy tool was created by %s at %s\nusing the Galaxy Tool Factory.\n' % (self.opts.user_email,timenow())) 357 coda.append('\n**Attribution**\nThis Galaxy tool was created by %s at %s\nusing the Galaxy Tool Factory.\n' % (self.opts.user_email,timenow()))
330 coda.append('See %s for details of that project' % (toolFactoryURL)) 358 coda.append('See %s for details of that project' % (toolFactoryURL))
669 a('--user_email',default='Unknown') 697 a('--user_email',default='Unknown')
670 a('--bad_user',default=None) 698 a('--bad_user',default=None)
671 a('--make_Tool',default=None) 699 a('--make_Tool',default=None)
672 a('--make_HTML',default=None) 700 a('--make_HTML',default=None)
673 a('--help_text',default=None) 701 a('--help_text',default=None)
702 a('--citations',default=None)
674 a('--tool_desc',default=None) 703 a('--tool_desc',default=None)
675 a('--new_tool',default=None) 704 a('--new_tool',default=None)
676 a('--tool_version',default=None) 705 a('--tool_version',default=None)
677 a('--include_dependencies',default=None) 706 a('--include_dependencies',default=None)
678 opts, args = op.parse_args() 707 opts, args = op.parse_args()