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