Mercurial > repos > fubar > edger_test
annotate edger_test-1212dc390f4f/rgedgeR/rgToolFactory.py @ 45:99e16f6d0bc8 draft
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
| author | fubar | 
|---|---|
| date | Mon, 08 Jul 2013 08:00:52 -0400 | 
| parents | |
| children | 
| rev | line source | 
|---|---|
| 
45
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
1 # rgToolFactory.py | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
2 # see https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
3 # | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
4 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
5 # | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
6 # all rights reserved | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
7 # Licensed under the LGPL | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
8 # suggestions for improvement and bug fixes welcome at https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
9 # | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
10 # January 2013 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
11 # problem pointed out by Carlos Borroto | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
12 # added escaping for <>$ - thought I did that ages ago... | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
13 # | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
14 # August 11 2012 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
15 # changed to use shell=False and cl as a sequence | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
16 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
17 # This is a Galaxy tool factory for simple scripts in python, R or whatever ails ye. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
18 # It also serves as the wrapper for the new tool. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
19 # | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
20 # you paste and run your script | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
21 # Only works for simple scripts that read one input from the history. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
22 # Optionally can write one new history dataset, | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
23 # and optionally collect any number of outputs into links on an autogenerated HTML page. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
24 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
25 # DO NOT install on a public or important site - please. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
26 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
27 # installed generated tools are fine if the script is safe. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
28 # They just run normally and their user cannot do anything unusually insecure | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
29 # but please, practice safe toolshed. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
30 # Read the fucking code before you install any tool | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
31 # especially this one | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
32 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
33 # After you get the script working on some test data, you can | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
34 # optionally generate a toolshed compatible gzip file | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
35 # containing your script safely wrapped as an ordinary Galaxy script in your local toolshed for | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
36 # safe and largely automated installation in a production Galaxy. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
37 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
38 # If you opt for an HTML output, you get all the script outputs arranged | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
39 # as a single Html history item - all output files are linked, thumbnails for all the pdfs. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
40 # Ugly but really inexpensive. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
41 # | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
42 # Patches appreciated please. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
43 # | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
44 # | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
45 # long route to June 2012 product | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
46 # Behold the awesome power of Galaxy and the toolshed with the tool factory to bind them | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
47 # derived from an integrated script model | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
48 # called rgBaseScriptWrapper.py | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
49 # Note to the unwary: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
50 # This tool allows arbitrary scripting on your Galaxy as the Galaxy user | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
51 # There is nothing stopping a malicious user doing whatever they choose | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
52 # Extremely dangerous!! | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
53 # Totally insecure. So, trusted users only | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
54 # | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
55 # preferred model is a developer using their throw away workstation instance - ie a private site. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
56 # no real risk. The universe_wsgi.ini admin_users string is checked - only admin users are permitted to run this tool. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
57 # | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
58 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
59 import sys | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
60 import shutil | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
61 import subprocess | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
62 import os | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
63 import time | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
64 import tempfile | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
65 import optparse | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
66 import tarfile | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
67 import re | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
68 import shutil | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
69 import math | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
70 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
71 progname = os.path.split(sys.argv[0])[1] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
72 myversion = 'V000.2 June 2012' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
73 verbose = False | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
74 debug = False | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
75 toolFactoryURL = 'https://bitbucket.org/fubar/galaxytoolfactory' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
76 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
77 def timenow(): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
78 """return current time as a string | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
79 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
80 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time())) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
81 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
82 cheetah_escape_table = { | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
83 "$": "\$" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
84 } | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
85 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
86 cheetah_unescape_table = { | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
87 "\$": "$" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
88 } | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
89 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
90 def html_escape(t): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
91 """Unescape \$ first in case already done | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
92 cheetah barfs if any $ without \ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
93 xml parsing is controlled with <![CDATA[...]]> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
94 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
95 text = t | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
96 for k in cheetah_unescape_table.keys(): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
97 text = text.replace(k,cheetah_unescape_table[k]) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
98 for k in cheetah_escape_table.keys(): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
99 text = text.replace(k,cheetah_escape_table[k]) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
100 return text | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
101 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
102 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
103 class ScriptRunner: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
104 """class is a wrapper for an arbitrary script | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
105 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
106 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
107 def __init__(self,opts=None,treatbashSpecial=True): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
108 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
109 cleanup inputs, setup some outputs | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
110 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
111 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
112 self.treatbashSpecial = treatbashSpecial | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
113 if opts.output_dir: # simplify for the tool tarball | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
114 os.chdir(opts.output_dir) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
115 self.thumbformat = 'jpg' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
116 self.opts = opts | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
117 self.toolname = re.sub('[^a-zA-Z0-9_]+', '', opts.tool_name) # a sanitizer now does this but.. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
118 self.toolid = self.toolname | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
119 self.myname = sys.argv[0] # get our name because we write ourselves out as a tool later | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
120 self.pyfile = self.myname # crude but efficient - the cruft won't hurt much | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
121 self.xmlfile = '%s.xml' % self.toolname | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
122 s = open(self.opts.script_path,'r').readlines() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
123 s = [x.rstrip() for x in s] # remove pesky dos line endings if needed | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
124 self.script = '\n'.join(s) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
125 fhandle,self.sfile = tempfile.mkstemp(prefix=self.toolname,suffix=".%s" % (opts.interpreter)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
126 tscript = open(self.sfile,'w') # use self.sfile as script source for Popen | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
127 tscript.write(self.script) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
128 tscript.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
129 self.escapedS = [html_escape(x) for x in s] # for restructured text in help | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
130 self.escapedScript = '\n'.join(self.escapedS) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
131 self.indentedScript = '\n'.join([' %s' % x for x in s]) # for restructured text in help | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
132 if opts.output_dir: # may not want these complexities | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
133 self.tlog = os.path.join(opts.output_dir,"%s_runner.log" % self.toolname) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
134 art = '%s.%s' % (self.toolname,opts.interpreter) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
135 artpath = os.path.join(self.opts.output_dir,art) # need full path | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
136 artifact = open(artpath,'w') # use self.sfile as script source for Popen | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
137 artifact.write(self.script) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
138 artifact.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
139 self.cl = [] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
140 self.html = [] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
141 a = self.cl.append | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
142 a(opts.interpreter) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
143 if self.treatbashSpecial and opts.interpreter in ['bash','sh']: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
144 a(self.sfile) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
145 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
146 a('-') # stdin | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
147 a(opts.input_tab) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
148 a(opts.output_tab) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
149 self.outFormats = 'tabular' # TODO make this an option at tool generation time | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
150 self.inputFormats = 'tabular' # TODO make this an option at tool generation time | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
151 self.test1Input = '%s_test1_input.xls' % self.toolname | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
152 self.test1Output = '%s_test1_output.xls' % self.toolname | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
153 self.test1HTML = '%s_test1_output.html' % self.toolname | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
154 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
155 def makeXML(self): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
156 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
157 Create a Galaxy xml tool wrapper for the new script as a string to write out | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
158 fixme - use templating or something less fugly than this example of what we produce | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
159 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
160 <tool id="reverse" name="reverse" version="0.01"> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
161 <description>a tabular file</description> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
162 <command interpreter="python"> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
163 reverse.py --script_path "$runMe" --interpreter "python" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
164 --tool_name "reverse" --input_tab "$input1" --output_tab "$tab_file" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
165 </command> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
166 <inputs> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
167 <param name="input1" type="data" format="tabular" label="Select a suitable input file from your history"/><param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="reverse"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
168 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
169 </inputs> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
170 <outputs> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
171 <data format="tabular" name="tab_file" label="${job_name}"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
172 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
173 </outputs> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
174 <help> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
175 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
176 **What it Does** | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
177 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
178 Reverse the columns in a tabular file | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
179 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
180 </help> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
181 <configfiles> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
182 <configfile name="runMe"> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
183 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
184 # reverse order of columns in a tabular file | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
185 import sys | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
186 inp = sys.argv[1] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
187 outp = sys.argv[2] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
188 i = open(inp,'r') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
189 o = open(outp,'w') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
190 for row in i: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
191 rs = row.rstrip().split('\t') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
192 rs.reverse() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
193 o.write('\t'.join(rs)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
194 o.write('\n') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
195 i.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
196 o.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
197 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
198 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
199 </configfile> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
200 </configfiles> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
201 </tool> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
202 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
203 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
204 newXML="""<tool id="%(toolid)s" name="%(toolname)s" version="%(tool_version)s"> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
205 %(tooldesc)s | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
206 %(command)s | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
207 <inputs> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
208 %(inputs)s | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
209 </inputs> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
210 <outputs> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
211 %(outputs)s | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
212 </outputs> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
213 <configfiles> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
214 <configfile name="runMe"> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
215 <![CDATA[ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
216 %(script)s | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
217 ]]> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
218 </configfile> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
219 </configfiles> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
220 %(tooltests)s | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
221 <help> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
222 <![CDATA[ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
223 %(help)s | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
224 ]]> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
225 </help> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
226 </tool>""" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
227 # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
228 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
229 newCommand="""<command interpreter="python"> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
230 %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
231 --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
232 </command>""" # may NOT be an input or htmlout | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
233 tooltestsTabOnly = """<tests><test> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
234 <param name="input1" value="%(test1Input)s" ftype="tabular"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
235 <param name="job_name" value="test1"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
236 <param name="runMe" value="$runMe"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
237 <output name="tab_file" file="%(test1Output)s" ftype="tabular"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
238 </test></tests>""" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
239 tooltestsHTMLOnly = """<tests><test> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
240 <param name="input1" value="%(test1Input)s" ftype="tabular"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
241 <param name="job_name" value="test1"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
242 <param name="runMe" value="$runMe"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
243 <output name="html_file" file="%(test1HTML)s" ftype="html" lines_diff="5"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
244 </test></tests>""" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
245 tooltestsBoth = """<tests><test> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
246 <param name="input1" value="%(test1Input)s" ftype="tabular"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
247 <param name="job_name" value="test1"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
248 <param name="runMe" value="$runMe"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
249 <output name="tab_file" file="%(test1Output)s" ftype="tabular" /> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
250 <output name="html_file" file="%(test1HTML)s" ftype="html" lines_diff="10"/> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
251 </test></tests>""" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
252 xdict = {} | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
253 xdict['tool_version'] = self.opts.tool_version | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
254 xdict['test1Input'] = self.test1Input | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
255 xdict['test1HTML'] = self.test1HTML | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
256 xdict['test1Output'] = self.test1Output | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
257 if self.opts.make_HTML and self.opts.output_tab <> 'None': | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
258 xdict['tooltests'] = tooltestsBoth % xdict | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
259 elif self.opts.make_HTML: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
260 xdict['tooltests'] = tooltestsHTMLOnly % xdict | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
261 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
262 xdict['tooltests'] = tooltestsTabOnly % xdict | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
263 xdict['script'] = self.escapedScript | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
264 # configfile is least painful way to embed script to avoid external dependencies | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
265 # but requires escaping of <, > and $ to avoid Mako parsing | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
266 if self.opts.help_text: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
267 xdict['help'] = open(self.opts.help_text,'r').read() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
268 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
269 xdict['help'] = 'Please ask the tool author for help as none was supplied at tool generation' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
270 coda = ['**Script**','Pressing execute will run the following code over your input file and generate some outputs in your history::\n'] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
271 coda.append(self.indentedScript) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
272 coda.append('\n\n') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
273 coda.append('**Attribution** This Galaxy tool was created by %s at %s\nusing the Galaxy Tool Factory.' % (self.opts.user_email,timenow())) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
274 coda.append('See %s for details of that project' % (toolFactoryURL)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
275 coda.append('Please cite: Creating re-usable tools from scripts: The Galaxy Tool Factory. Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team. ') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
276 coda.append('Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
277 xdict['help'] = '%s\n%s' % (xdict['help'],'\n'.join(coda)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
278 if self.opts.tool_desc: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
279 xdict['tooldesc'] = '<description>%s</description>' % self.opts.tool_desc | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
280 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
281 xdict['tooldesc'] = '' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
282 xdict['command_outputs'] = '' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
283 xdict['outputs'] = '' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
284 if self.opts.input_tab <> 'None': | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
285 xdict['command_inputs'] = '--input_tab "$input1" ' # the space may matter a lot if we append something | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
286 xdict['inputs'] = '<param name="input1" type="data" format="%s" label="Select a suitable input file from your history"/> \n' % self.inputFormats | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
287 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
288 xdict['command_inputs'] = '' # assume no input - eg a random data generator | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
289 xdict['inputs'] = '' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
290 xdict['inputs'] += '<param name="job_name" type="text" label="Supply a name for the outputs to remind you what they contain" value="%s"/> \n' % self.toolname | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
291 xdict['toolname'] = self.toolname | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
292 xdict['toolid'] = self.toolid | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
293 xdict['interpreter'] = self.opts.interpreter | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
294 xdict['scriptname'] = self.sfile | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
295 if self.opts.make_HTML: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
296 xdict['command_outputs'] += ' --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes" ' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
297 xdict['outputs'] += ' <data format="html" name="html_file" label="${job_name}.html"/>\n' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
298 if self.opts.output_tab <> 'None': | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
299 xdict['command_outputs'] += ' --output_tab "$tab_file"' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
300 xdict['outputs'] += ' <data format="%s" name="tab_file" label="${job_name}"/>\n' % self.outFormats | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
301 xdict['command'] = newCommand % xdict | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
302 xmls = newXML % xdict | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
303 xf = open(self.xmlfile,'w') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
304 xf.write(xmls) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
305 xf.write('\n') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
306 xf.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
307 # ready for the tarball | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
308 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
309 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
310 def makeTooltar(self): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
311 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
312 a tool is a gz tarball with eg | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
313 /toolname/tool.xml /toolname/tool.py /toolname/test-data/test1_in.foo ... | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
314 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
315 retval = self.run() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
316 if retval: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
317 print >> sys.stderr,'## Run failed. Cannot build yet. Please fix and retry' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
318 sys.exit(1) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
319 self.makeXML() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
320 tdir = self.toolname | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
321 os.mkdir(tdir) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
322 if self.opts.input_tab <> 'None': # no reproducible test otherwise? TODO: maybe.. | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
323 testdir = os.path.join(tdir,'test-data') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
324 os.mkdir(testdir) # make tests directory | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
325 shutil.copyfile(self.opts.input_tab,os.path.join(testdir,self.test1Input)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
326 if self.opts.output_tab <> 'None': | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
327 shutil.copyfile(self.opts.output_tab,os.path.join(testdir,self.test1Output)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
328 if self.opts.make_HTML: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
329 shutil.copyfile(self.opts.output_html,os.path.join(testdir,self.test1HTML)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
330 if self.opts.output_dir: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
331 shutil.copyfile(self.tlog,os.path.join(testdir,'test1_out.log')) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
332 op = '%s.py' % self.toolname # new name | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
333 outpiname = os.path.join(tdir,op) # path for the tool tarball | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
334 pyin = os.path.basename(self.pyfile) # our name - we rewrite ourselves (TM) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
335 notes = ['# %s - a self annotated version of %s generated by running %s\n' % (op,pyin,pyin),] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
336 notes.append('# to make a new Galaxy tool called %s\n' % self.toolname) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
337 notes.append('# User %s at %s\n' % (self.opts.user_email,timenow())) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
338 pi = open(self.pyfile,'r').readlines() # our code becomes new tool wrapper (!) - first Galaxy worm | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
339 notes += pi | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
340 outpi = open(outpiname,'w') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
341 outpi.write(''.join(notes)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
342 outpi.write('\n') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
343 outpi.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
344 stname = os.path.join(tdir,self.sfile) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
345 if not os.path.exists(stname): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
346 shutil.copyfile(self.sfile, stname) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
347 xtname = os.path.join(tdir,self.xmlfile) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
348 if not os.path.exists(xtname): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
349 shutil.copyfile(self.xmlfile,xtname) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
350 tarpath = "%s.gz" % self.toolname | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
351 tar = tarfile.open(tarpath, "w:gz") | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
352 tar.add(tdir,arcname=self.toolname) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
353 tar.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
354 shutil.copyfile(tarpath,self.opts.new_tool) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
355 shutil.rmtree(tdir) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
356 ## TODO: replace with optional direct upload to local toolshed? | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
357 return retval | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
358 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
359 def compressPDF(self,inpdf=None,thumbformat='png'): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
360 """need absolute path to pdf | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
361 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
362 assert os.path.isfile(inpdf), "## Input %s supplied to %s compressPDF not found" % (inpdf,self.myName) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
363 hf,hlog = tempfile.mkstemp(suffix="%s.log" % self.toolname) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
364 sto = open(hlog,'w') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
365 outpdf = '%s_compressed' % inpdf | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
366 cl = ["gs", "-sDEVICE=pdfwrite", "-dNOPAUSE", "-dBATCH", "-sOutputFile=%s" % outpdf,inpdf] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
367 x = subprocess.Popen(cl,stdout=sto,stderr=sto,cwd=self.opts.output_dir) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
368 retval1 = x.wait() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
369 if retval1 == 0: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
370 os.unlink(inpdf) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
371 shutil.move(outpdf,inpdf) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
372 outpng = '%s.%s' % (os.path.splitext(inpdf)[0],thumbformat) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
373 cl2 = ['convert', inpdf, outpng] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
374 x = subprocess.Popen(cl2,stdout=sto,stderr=sto,cwd=self.opts.output_dir) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
375 retval2 = x.wait() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
376 sto.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
377 retval = retval1 or retval2 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
378 return retval | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
379 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
380 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
381 def getfSize(self,fpath,outpath): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
382 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
383 format a nice file size string | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
384 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
385 size = '' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
386 fp = os.path.join(outpath,fpath) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
387 if os.path.isfile(fp): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
388 size = '0 B' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
389 n = float(os.path.getsize(fp)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
390 if n > 2**20: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
391 size = '%1.1f MB' % (n/2**20) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
392 elif n > 2**10: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
393 size = '%1.1f KB)' % (n/2**10) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
394 elif n > 0: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
395 size = '%d B' % (int(n)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
396 return size | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
397 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
398 def makeHtml(self): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
399 """ Create an HTML file content to list all the artifacts found in the output_dir | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
400 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
401 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
402 galhtmlprefix = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
403 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en"> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
404 <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
405 <meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" /> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
406 <title></title> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
407 <link rel="stylesheet" href="/static/style/base.css" type="text/css" /> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
408 </head> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
409 <body> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
410 <div class="toolFormBody"> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
411 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
412 galhtmlattr = """<hr/><div class="infomessage">This tool (%s) was generated by the <a href="https://bitbucket.org/fubar/galaxytoolfactory/overview">Galaxy Tool Factory</a></div><br/>""" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
413 galhtmlpostfix = """</div></body></html>\n""" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
414 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
415 flist = os.listdir(self.opts.output_dir) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
416 flist = [x for x in flist if x <> 'Rplots.pdf'] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
417 flist.sort() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
418 html = [] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
419 html.append(galhtmlprefix % progname) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
420 html.append('<div class="infomessage">Galaxy Tool "%s" run at %s</div><br/>' % (self.toolname,timenow())) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
421 fhtml = [] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
422 if len(flist) > 0: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
423 pdflist = [] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
424 npdf = len([x for x in flist if os.path.splitext(x)[-1].lower() == '.pdf']) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
425 nacross = 1 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
426 if npdf > 0: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
427 nacross = int(round(math.log(npdf,2))) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
428 nacross = max(1,nacross) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
429 width = min(400,int(1200/nacross)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
430 for rownum,fname in enumerate(flist): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
431 dname,e = os.path.splitext(fname) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
432 sfsize = self.getfSize(fname,self.opts.output_dir) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
433 if e.lower() == '.pdf' : # compress and make a thumbnail | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
434 thumb = '%s.%s' % (dname,self.thumbformat) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
435 pdff = os.path.join(self.opts.output_dir,fname) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
436 retval = self.compressPDF(inpdf=pdff,thumbformat=self.thumbformat) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
437 if retval == 0: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
438 pdflist.append((fname,thumb)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
439 if (rownum+1) % 2 == 0: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
440 fhtml.append('<tr class="odd_row"><td><a href="%s">%s</a></td><td>%s</td></tr>' % (fname,fname,sfsize)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
441 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
442 fhtml.append('<tr><td><a href="%s">%s</a></td><td>%s</td></tr>' % (fname,fname,sfsize)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
443 ntogo = nacross # counter for table row padding with empty cells | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
444 if len(pdflist) > 0: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
445 html.append('<div><table class="simple" cellpadding="2" cellspacing="2">\n<tr>') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
446 for i,paths in enumerate(pdflist): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
447 fname,thumb = paths | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
448 s= """<td><a href="%s"><img src="%s" title="Click to download a PDF of %s" hspace="5" width="%d" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
449 alt="Image called %s"/></a></td>\n""" % (fname,thumb,fname,width,fname) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
450 if ((i+1) % nacross == 0): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
451 s += '</tr>\n' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
452 ntogo = 0 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
453 if i < (npdf - 1): # more to come | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
454 s += '<tr>' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
455 ntogo = nacross | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
456 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
457 ntogo -= 1 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
458 html.append(s) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
459 if html[-1].strip().endswith('</tr>'): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
460 html.append('</table></div>\n') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
461 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
462 if ntogo > 0: # pad | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
463 html.append('<td> </td>'*ntogo) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
464 html.append('</tr></table></div>\n') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
465 if len(fhtml) > 0: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
466 fhtml.insert(0,'<div><table class="colored" cellpadding="3" cellspacing="3"><tr><th>Output File Name (click to view)</th><th>Size</th></tr>\n') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
467 fhtml.append('</table></div><br/>') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
468 html += fhtml # add all non-pdf files to the end of the display | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
469 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
470 html.append('<div class="warningmessagelarge">### Error - %s returned no files - please confirm that parameters are sane</div>' % self.opts.interpreter) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
471 rlog = open(self.tlog,'r').readlines() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
472 rlog = [x for x in rlog if x.strip() > ''] | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
473 if len(rlog) > 1: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
474 html.append('<div class="toolFormTitle">%s log</div><pre>\n' % self.opts.interpreter) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
475 html += rlog | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
476 html.append('</pre>\n') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
477 html.append(galhtmlattr % (self.toolname)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
478 html.append(galhtmlpostfix) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
479 htmlf = file(self.opts.output_html,'w') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
480 htmlf.write('\n'.join(html)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
481 htmlf.write('\n') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
482 htmlf.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
483 self.html = html | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
484 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
485 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
486 def run(self): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
487 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
488 scripts must be small enough not to fill the pipe! | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
489 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
490 if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
491 retval = self.runBash() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
492 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
493 if self.opts.output_dir: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
494 sto = open(self.tlog,'w') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
495 sto.write('## Toolfactory generated command line = %s\n' % ' '.join(self.cl)) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
496 sto.flush() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
497 p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=sto,stdin=subprocess.PIPE,cwd=self.opts.output_dir) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
498 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
499 p = subprocess.Popen(self.cl,shell=False,stdin=subprocess.PIPE) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
500 p.stdin.write(self.script) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
501 p.stdin.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
502 retval = p.wait() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
503 if self.opts.output_dir: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
504 sto.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
505 if self.opts.make_HTML: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
506 self.makeHtml() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
507 return retval | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
508 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
509 def runBash(self): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
510 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
511 cannot use - for bash so use self.sfile | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
512 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
513 if self.opts.output_dir: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
514 s = '## Toolfactory generated command line = %s\n' % ' '.join(self.cl) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
515 sto = open(self.tlog,'w') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
516 sto.write(s) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
517 sto.flush() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
518 p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=sto,cwd=self.opts.output_dir) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
519 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
520 p = subprocess.Popen(self.cl,shell=False) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
521 retval = p.wait() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
522 if self.opts.output_dir: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
523 sto.close() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
524 if self.opts.make_HTML: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
525 self.makeHtml() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
526 return retval | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
527 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
528 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
529 def main(): | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
530 u = """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
531 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
532 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript" | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
533 </command> | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
534 """ | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
535 op = optparse.OptionParser() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
536 a = op.add_option | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
537 a('--script_path',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
538 a('--tool_name',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
539 a('--interpreter',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
540 a('--output_dir',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
541 a('--output_html',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
542 a('--input_tab',default="None") | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
543 a('--output_tab',default="None") | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
544 a('--user_email',default='Unknown') | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
545 a('--bad_user',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
546 a('--make_Tool',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
547 a('--make_HTML',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
548 a('--help_text',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
549 a('--tool_desc',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
550 a('--new_tool',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
551 a('--tool_version',default=None) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
552 opts, args = op.parse_args() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
553 assert not opts.bad_user,'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to admin_users in universe_wsgi.ini' % (opts.bad_user,opts.bad_user) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
554 assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
555 assert opts.interpreter,'## Tool Factory wrapper expects an interpreter - eg --interpreter=Rscript' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
556 assert os.path.isfile(opts.script_path),'## Tool Factory wrapper expects a script path - eg --script_path=foo.R' | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
557 if opts.output_dir: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
558 try: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
559 os.makedirs(opts.output_dir) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
560 except: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
561 pass | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
562 r = ScriptRunner(opts) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
563 if opts.make_Tool: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
564 retcode = r.makeTooltar() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
565 else: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
566 retcode = r.run() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
567 os.unlink(r.sfile) | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
568 if retcode: | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
569 sys.exit(retcode) # indicate failure to job runner | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
570 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
571 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
572 if __name__ == "__main__": | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
573 main() | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
574 | 
| 
 
99e16f6d0bc8
Bjorn's r atlas not compiling on my laptop so revert to my crappy one
 
fubar 
parents:  
diff
changeset
 | 
575 | 
