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