annotate rgToolFactory.py @ 30:fb3fa6a2874d draft

Citations added (thanks John!) and a few more output formats for Alistair Chilcott
author fubar
date Thu, 28 Aug 2014 02:22:39 -0400
parents bff4c9bfabc7
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
29
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
1 # rgToolFactory.py
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
2 # see https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
3 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
4 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
5 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
6 # all rights reserved
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
7 # Licensed under the LGPL
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
8 # suggestions for improvement and bug fixes welcome at https://bitbucket.org/fubar/galaxytoolfactory/wiki/Home
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
9 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
10 # march 2014
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
11 # had to remove dependencies because cross toolshed dependencies are not possible - can't pre-specify a toolshed url for graphicsmagick and ghostscript
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
12 # grrrrr - night before a demo
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
13 # added dependencies to a tool_dependencies.xml if html page generated so generated tool is properly portable
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
14 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
15 # added ghostscript and graphicsmagick as dependencies
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
16 # fixed a wierd problem where gs was trying to use the new_files_path from universe (database/tmp) as ./database/tmp
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
17 # errors ensued
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
18 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
19 # august 2013
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
20 # found a problem with GS if $TMP or $TEMP missing - now inject /tmp and warn
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
21 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
22 # july 2013
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
23 # added ability to combine images and individual log files into html output
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
24 # just make sure there's a log file foo.log and it will be output
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
25 # together with all images named like "foo_*.pdf
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
26 # otherwise old format for html
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
27 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
28 # January 2013
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
29 # problem pointed out by Carlos Borroto
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
30 # added escaping for <>$ - thought I did that ages ago...
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
31 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
32 # August 11 2012
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
33 # changed to use shell=False and cl as a sequence
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
34
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
35 # This is a Galaxy tool factory for simple scripts in python, R or whatever ails ye.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
36 # It also serves as the wrapper for the new tool.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
37 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
38 # you paste and run your script
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
39 # Only works for simple scripts that read one input from the history.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
40 # Optionally can write one new history dataset,
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
41 # and optionally collect any number of outputs into links on an autogenerated HTML page.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
42
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
43 # DO NOT install on a public or important site - please.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
44
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
45 # installed generated tools are fine if the script is safe.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
46 # They just run normally and their user cannot do anything unusually insecure
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
47 # but please, practice safe toolshed.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
48 # Read the fucking code before you install any tool
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
49 # especially this one
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
50
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
51 # After you get the script working on some test data, you can
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
52 # optionally generate a toolshed compatible gzip file
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
53 # containing your script safely wrapped as an ordinary Galaxy script in your local toolshed for
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
54 # safe and largely automated installation in a production Galaxy.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
55
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
56 # If you opt for an HTML output, you get all the script outputs arranged
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
57 # as a single Html history item - all output files are linked, thumbnails for all the pdfs.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
58 # Ugly but really inexpensive.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
59 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
60 # Patches appreciated please.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
61 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
62 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
63 # long route to June 2012 product
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
64 # Behold the awesome power of Galaxy and the toolshed with the tool factory to bind them
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
65 # derived from an integrated script model
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
66 # called rgBaseScriptWrapper.py
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
67 # Note to the unwary:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
68 # This tool allows arbitrary scripting on your Galaxy as the Galaxy user
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
69 # There is nothing stopping a malicious user doing whatever they choose
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
70 # Extremely dangerous!!
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
71 # Totally insecure. So, trusted users only
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
72 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
73 # preferred model is a developer using their throw away workstation instance - ie a private site.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
74 # no real risk. The universe_wsgi.ini admin_users string is checked - only admin users are permitted to run this tool.
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
75 #
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
76
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
77 import sys
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
78 import shutil
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
79 import subprocess
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
80 import os
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
81 import time
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
82 import tempfile
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
83 import optparse
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
84 import tarfile
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
85 import re
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
86 import shutil
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
87 import math
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
88
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
89 progname = os.path.split(sys.argv[0])[1]
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
90 myversion = 'V001.1 March 2014'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
91 verbose = False
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
92 debug = False
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
93 toolFactoryURL = 'https://bitbucket.org/fubar/galaxytoolfactory'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
94
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
95 # if we do html we need these dependencies specified in a tool_dependencies.xml file and referred to in the generated
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
96 # tool xml
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
97 toolhtmldepskel = """<?xml version="1.0"?>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
98 <tool_dependency>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
99 <package name="ghostscript" version="9.10">
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
100 <repository name="package_ghostscript_9_10" owner="devteam" prior_installation_required="True" />
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
101 </package>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
102 <package name="graphicsmagick" version="1.3.18">
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
103 <repository name="package_graphicsmagick_1_3" owner="iuc" prior_installation_required="True" />
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
104 </package>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
105 <readme>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
106 %s
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
107 </readme>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
108 </tool_dependency>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
109 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
110
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
111 protorequirements = """<requirements>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
112 <requirement type="package" version="9.10">ghostscript</requirement>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
113 <requirement type="package" version="1.3.18">graphicsmagick</requirement>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
114 </requirements>"""
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
115
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
116 def timenow():
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
117 """return current time as a string
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
118 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
119 return time.strftime('%d/%m/%Y %H:%M:%S', time.localtime(time.time()))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
120
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
121 html_escape_table = {
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
122 "&": "&amp;",
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
123 ">": "&gt;",
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
124 "<": "&lt;",
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
125 "$": "\$"
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
126 }
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
127
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
128 def html_escape(text):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
129 """Produce entities within text."""
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
130 return "".join(html_escape_table.get(c,c) for c in text)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
131
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
132 def cmd_exists(cmd):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
133 return subprocess.call("type " + cmd, shell=True,
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
134 stdout=subprocess.PIPE, stderr=subprocess.PIPE) == 0
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
135
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
136
30
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
137 def parse_citations(citations_text):
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
138 """
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
139 """
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
140 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
141 citation_tuples = []
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
142 for citation in citations:
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
143 if citation.startswith("doi"):
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
144 citation_tuples.append( ("doi", citation[len("doi"):].strip() ) )
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
145 else:
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
146 citation_tuples.append( ("bibtex", citation[len("bibtex"):].strip() ) )
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
147 return citation_tuples
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
148
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
149
29
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
150 class ScriptRunner:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
151 """class is a wrapper for an arbitrary script
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
152 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
153
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
154 def __init__(self,opts=None,treatbashSpecial=True):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
155 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
156 cleanup inputs, setup some outputs
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
157
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
158 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
159 self.useGM = cmd_exists('gm')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
160 self.useIM = cmd_exists('convert')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
161 self.useGS = cmd_exists('gs')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
162 self.temp_warned = False # we want only one warning if $TMP not set
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
163 self.treatbashSpecial = treatbashSpecial
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
164 if opts.output_dir: # simplify for the tool tarball
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
165 os.chdir(opts.output_dir)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
166 self.thumbformat = 'png'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
167 self.opts = opts
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
168 self.toolname = re.sub('[^a-zA-Z0-9_]+', '', opts.tool_name) # a sanitizer now does this but..
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
169 self.toolid = self.toolname
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
170 self.myname = sys.argv[0] # get our name because we write ourselves out as a tool later
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
171 self.pyfile = self.myname # crude but efficient - the cruft won't hurt much
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
172 self.xmlfile = '%s.xml' % self.toolname
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
173 s = open(self.opts.script_path,'r').readlines()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
174 s = [x.rstrip() for x in s] # remove pesky dos line endings if needed
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
175 self.script = '\n'.join(s)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
176 fhandle,self.sfile = tempfile.mkstemp(prefix=self.toolname,suffix=".%s" % (opts.interpreter))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
177 tscript = open(self.sfile,'w') # use self.sfile as script source for Popen
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
178 tscript.write(self.script)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
179 tscript.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
180 self.indentedScript = '\n'.join([' %s' % html_escape(x) for x in s]) # for restructured text in help
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
181 self.escapedScript = '\n'.join([html_escape(x) for x in s])
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
182 self.elog = os.path.join(self.opts.output_dir,"%s_error.log" % self.toolname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
183 if opts.output_dir: # may not want these complexities
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
184 self.tlog = os.path.join(self.opts.output_dir,"%s_runner.log" % self.toolname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
185 art = '%s.%s' % (self.toolname,opts.interpreter)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
186 artpath = os.path.join(self.opts.output_dir,art) # need full path
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
187 artifact = open(artpath,'w') # use self.sfile as script source for Popen
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
188 artifact.write(self.script)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
189 artifact.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
190 self.cl = []
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
191 self.html = []
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
192 a = self.cl.append
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
193 a(opts.interpreter)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
194 if self.treatbashSpecial and opts.interpreter in ['bash','sh']:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
195 a(self.sfile)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
196 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
197 a('-') # stdin
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
198 a(opts.input_tab)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
199 a(opts.output_tab)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
200 self.outFormats = 'tabular' # TODO make this an option at tool generation time
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
201 self.inputFormats = 'tabular,txt' # TODO make this an option at tool generation time
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
202 self.test1Input = '%s_test1_input.xls' % self.toolname
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
203 self.test1Output = '%s_test1_output.xls' % self.toolname
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
204 self.test1HTML = '%s_test1_output.html' % self.toolname
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
205
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
206 def makeXML(self):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
207 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
208 Create a Galaxy xml tool wrapper for the new script as a string to write out
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
209 fixme - use templating or something less fugly than this example of what we produce
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
210
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
211 <tool id="reverse" name="reverse" version="0.01">
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
212 <description>a tabular file</description>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
213 <command interpreter="python">
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
214 reverse.py --script_path "$runMe" --interpreter "python"
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
215 --tool_name "reverse" --input_tab "$input1" --output_tab "$tab_file"
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
216 </command>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
217 <inputs>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
218 <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"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
219
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
220 </inputs>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
221 <outputs>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
222 <data format="tabular" name="tab_file" label="${job_name}"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
223
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
224 </outputs>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
225 <help>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
226
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
227 **What it Does**
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
228
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
229 Reverse the columns in a tabular file
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
230
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
231 </help>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
232 <configfiles>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
233 <configfile name="runMe">
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
234
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
235 # reverse order of columns in a tabular file
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
236 import sys
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
237 inp = sys.argv[1]
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
238 outp = sys.argv[2]
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
239 i = open(inp,'r')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
240 o = open(outp,'w')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
241 for row in i:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
242 rs = row.rstrip().split('\t')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
243 rs.reverse()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
244 o.write('\t'.join(rs))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
245 o.write('\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
246 i.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
247 o.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
248
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
249
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
250 </configfile>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
251 </configfiles>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
252 </tool>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
253
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
254 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
255 newXML="""<tool id="%(toolid)s" name="%(toolname)s" version="%(tool_version)s">
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
256 %(tooldesc)s
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
257 %(requirements)s
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
258 <command interpreter="python">
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
259 %(command)s
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
260 </command>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
261 <inputs>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
262 %(inputs)s
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
263 </inputs>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
264 <outputs>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
265 %(outputs)s
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
266 </outputs>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
267 <configfiles>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
268 <configfile name="runMe">
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
269 %(script)s
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
270 </configfile>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
271 </configfiles>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
272
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
273 %(tooltests)s
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
274
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
275 <help>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
276
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
277 %(help)s
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
278
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
279 </help>
30
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
280 <citations>
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
281 %(citations)s
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
282 <citation type="doi">10.1093/bioinformatics/bts573</citation>
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
283 </citations>
29
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
284 </tool>""" # needs a dict with toolname, toolid, interpreter, scriptname, command, inputs as a multi line string ready to write, outputs ditto, help ditto
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
285
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
286 newCommand="""
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
287 %(toolname)s.py --script_path "$runMe" --interpreter "%(interpreter)s"
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
288 --tool_name "%(toolname)s" %(command_inputs)s %(command_outputs)s """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
289 # may NOT be an input or htmlout - appended later
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
290 tooltestsTabOnly = """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
291 <tests>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
292 <test>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
293 <param name="input1" value="%(test1Input)s" ftype="tabular"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
294 <param name="job_name" value="test1"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
295 <param name="runMe" value="$runMe"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
296 <output name="tab_file" file="%(test1Output)s" ftype="tabular"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
297 </test>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
298 </tests>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
299 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
300 tooltestsHTMLOnly = """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
301 <tests>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
302 <test>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
303 <param name="input1" value="%(test1Input)s" ftype="tabular"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
304 <param name="job_name" value="test1"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
305 <param name="runMe" value="$runMe"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
306 <output name="html_file" file="%(test1HTML)s" ftype="html" lines_diff="5"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
307 </test>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
308 </tests>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
309 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
310 tooltestsBoth = """<tests>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
311 <test>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
312 <param name="input1" value="%(test1Input)s" ftype="tabular"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
313 <param name="job_name" value="test1"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
314 <param name="runMe" value="$runMe"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
315 <output name="tab_file" file="%(test1Output)s" ftype="tabular" />
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
316 <output name="html_file" file="%(test1HTML)s" ftype="html" lines_diff="10"/>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
317 </test>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
318 </tests>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
319 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
320 xdict = {}
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
321 xdict['requirements'] = ''
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
322 if self.opts.make_HTML:
30
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
323 if self.opts.include_dependencies == "yes":
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
324 xdict['requirements'] = protorequirements
29
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
325 xdict['tool_version'] = self.opts.tool_version
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
326 xdict['test1Input'] = self.test1Input
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
327 xdict['test1HTML'] = self.test1HTML
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
328 xdict['test1Output'] = self.test1Output
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
329 if self.opts.make_HTML and self.opts.output_tab <> 'None':
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
330 xdict['tooltests'] = tooltestsBoth % xdict
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
331 elif self.opts.make_HTML:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
332 xdict['tooltests'] = tooltestsHTMLOnly % xdict
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
333 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
334 xdict['tooltests'] = tooltestsTabOnly % xdict
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
335 xdict['script'] = self.escapedScript
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
336 # configfile is least painful way to embed script to avoid external dependencies
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
337 # but requires escaping of <, > and $ to avoid Mako parsing
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
338 if self.opts.help_text:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
339 helptext = open(self.opts.help_text,'r').readlines()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
340 helptext = [html_escape(x) for x in helptext] # must html escape here too - thanks to Marius van den Beek
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
341 xdict['help'] = ''.join([x for x in helptext])
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
342 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
343 xdict['help'] = 'Please ask the tool author (%s) for help as none was supplied at tool generation\n' % (self.opts.user_email)
30
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
344 if self.opts.citations:
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
345 citationstext = open(self.opts.citations,'r').read()
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
346 citation_tuples = parse_citations(citationstext)
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
347 citations_xml = ""
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
348 for citation_type, citation_content in citation_tuples:
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
349 citation_xml = """<citation type="%s">%s</citation>""" % (citation_type, html_escape(citation_content))
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
350 citations_xml += citation_xml
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
351 xdict['citations'] = citations_xml
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
352 else:
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
353 xdict['citations'] = ""
29
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
354 coda = ['**Script**','Pressing execute will run the following code over your input file and generate some outputs in your history::']
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
355 coda.append('\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
356 coda.append(self.indentedScript)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
357 coda.append('\n**Attribution**\nThis Galaxy tool was created by %s at %s\nusing the Galaxy Tool Factory.\n' % (self.opts.user_email,timenow()))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
358 coda.append('See %s for details of that project' % (toolFactoryURL))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
359 coda.append('Please cite: Creating re-usable tools from scripts: The Galaxy Tool Factory. Ross Lazarus; Antony Kaspi; Mark Ziemann; The Galaxy Team. ')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
360 coda.append('Bioinformatics 2012; doi: 10.1093/bioinformatics/bts573\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
361 xdict['help'] = '%s\n%s' % (xdict['help'],'\n'.join(coda))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
362 if self.opts.tool_desc:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
363 xdict['tooldesc'] = '<description>%s</description>' % self.opts.tool_desc
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
364 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
365 xdict['tooldesc'] = ''
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
366 xdict['command_outputs'] = ''
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
367 xdict['outputs'] = ''
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
368 if self.opts.input_tab <> 'None':
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
369 xdict['command_inputs'] = '--input_tab "$input1" ' # the space may matter a lot if we append something
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
370 xdict['inputs'] = '<param name="input1" type="data" format="%s" label="Select a suitable input file from your history"/> \n' % self.inputFormats
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
371 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
372 xdict['command_inputs'] = '' # assume no input - eg a random data generator
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
373 xdict['inputs'] = ''
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
374 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
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
375 xdict['toolname'] = self.toolname
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
376 xdict['toolid'] = self.toolid
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
377 xdict['interpreter'] = self.opts.interpreter
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
378 xdict['scriptname'] = self.sfile
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
379 if self.opts.make_HTML:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
380 xdict['command_outputs'] += ' --output_dir "$html_file.files_path" --output_html "$html_file" --make_HTML "yes"'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
381 xdict['outputs'] += ' <data format="html" name="html_file" label="${job_name}.html"/>\n'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
382 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
383 xdict['command_outputs'] += ' --output_dir "./"'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
384 if self.opts.output_tab <> 'None':
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
385 xdict['command_outputs'] += ' --output_tab "$tab_file"'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
386 xdict['outputs'] += ' <data format="%s" name="tab_file" label="${job_name}"/>\n' % self.outFormats
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
387 xdict['command'] = newCommand % xdict
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
388 xmls = newXML % xdict
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
389 xf = open(self.xmlfile,'w')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
390 xf.write(xmls)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
391 xf.write('\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
392 xf.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
393 # ready for the tarball
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
394
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
395
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
396 def makeTooltar(self):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
397 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
398 a tool is a gz tarball with eg
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
399 /toolname/tool.xml /toolname/tool.py /toolname/test-data/test1_in.foo ...
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
400 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
401 retval = self.run()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
402 if retval:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
403 print >> sys.stderr,'## Run failed. Cannot build yet. Please fix and retry'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
404 sys.exit(1)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
405 tdir = self.toolname
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
406 os.mkdir(tdir)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
407 self.makeXML()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
408 if self.opts.make_HTML:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
409 if self.opts.help_text:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
410 hlp = open(self.opts.help_text,'r').read()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
411 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
412 hlp = 'Please ask the tool author for help as none was supplied at tool generation\n'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
413 if self.opts.include_dependencies:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
414 tooldepcontent = toolhtmldepskel % hlp
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
415 depf = open(os.path.join(tdir,'tool_dependencies.xml'),'w')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
416 depf.write(tooldepcontent)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
417 depf.write('\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
418 depf.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
419 if self.opts.input_tab <> 'None': # no reproducible test otherwise? TODO: maybe..
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
420 testdir = os.path.join(tdir,'test-data')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
421 os.mkdir(testdir) # make tests directory
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
422 shutil.copyfile(self.opts.input_tab,os.path.join(testdir,self.test1Input))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
423 if self.opts.output_tab <> 'None':
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
424 shutil.copyfile(self.opts.output_tab,os.path.join(testdir,self.test1Output))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
425 if self.opts.make_HTML:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
426 shutil.copyfile(self.opts.output_html,os.path.join(testdir,self.test1HTML))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
427 if self.opts.output_dir:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
428 shutil.copyfile(self.tlog,os.path.join(testdir,'test1_out.log'))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
429 outpif = '%s.py' % self.toolname # new name
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
430 outpiname = os.path.join(tdir,outpif) # path for the tool tarball
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
431 pyin = os.path.basename(self.pyfile) # our name - we rewrite ourselves (TM)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
432 notes = ['# %s - a self annotated version of %s generated by running %s\n' % (outpiname,pyin,pyin),]
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
433 notes.append('# to make a new Galaxy tool called %s\n' % self.toolname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
434 notes.append('# User %s at %s\n' % (self.opts.user_email,timenow()))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
435 pi = open(self.pyfile,'r').readlines() # our code becomes new tool wrapper (!) - first Galaxy worm
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
436 notes += pi
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
437 outpi = open(outpiname,'w')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
438 outpi.write(''.join(notes))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
439 outpi.write('\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
440 outpi.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
441 stname = os.path.join(tdir,self.sfile)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
442 if not os.path.exists(stname):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
443 shutil.copyfile(self.sfile, stname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
444 xtname = os.path.join(tdir,self.xmlfile)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
445 if not os.path.exists(xtname):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
446 shutil.copyfile(self.xmlfile,xtname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
447 tarpath = "%s.gz" % self.toolname
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
448 tar = tarfile.open(tarpath, "w:gz")
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
449 tar.add(tdir,arcname=self.toolname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
450 tar.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
451 shutil.copyfile(tarpath,self.opts.new_tool)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
452 shutil.rmtree(tdir)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
453 ## TODO: replace with optional direct upload to local toolshed?
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
454 return retval
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
455
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
456
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
457 def compressPDF(self,inpdf=None,thumbformat='png'):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
458 """need absolute path to pdf
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
459 note that GS gets confoozled if no $TMP or $TEMP
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
460 so we set it
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
461 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
462 assert os.path.isfile(inpdf), "## Input %s supplied to %s compressPDF not found" % (inpdf,self.myName)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
463 hlog = os.path.join(self.opts.output_dir,"compress_%s.txt" % os.path.basename(inpdf))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
464 sto = open(hlog,'a')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
465 our_env = os.environ.copy()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
466 our_tmp = our_env.get('TMP',None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
467 if not our_tmp:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
468 our_tmp = our_env.get('TEMP',None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
469 if not (our_tmp and os.path.exists(our_tmp)):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
470 newtmp = os.path.join(self.opts.output_dir,'tmp')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
471 try:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
472 os.mkdir(newtmp)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
473 except:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
474 sto.write('## WARNING - cannot make %s - it may exist or permissions need fixing\n' % newtmp)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
475 our_env['TEMP'] = newtmp
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
476 if not self.temp_warned:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
477 sto.write('## WARNING - no $TMP or $TEMP!!! Please fix - using %s temporarily\n' % newtmp)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
478 self.temp_warned = True
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
479 outpdf = '%s_compressed' % inpdf
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
480 cl = ["gs", "-sDEVICE=pdfwrite", "-dNOPAUSE", "-dUseCIEColor", "-dBATCH","-dPDFSETTINGS=/printer", "-sOutputFile=%s" % outpdf,inpdf]
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
481 x = subprocess.Popen(cl,stdout=sto,stderr=sto,cwd=self.opts.output_dir,env=our_env)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
482 retval1 = x.wait()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
483 sto.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
484 if retval1 == 0:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
485 os.unlink(inpdf)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
486 shutil.move(outpdf,inpdf)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
487 os.unlink(hlog)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
488 hlog = os.path.join(self.opts.output_dir,"thumbnail_%s.txt" % os.path.basename(inpdf))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
489 sto = open(hlog,'w')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
490 outpng = '%s.%s' % (os.path.splitext(inpdf)[0],thumbformat)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
491 if self.useGM:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
492 cl2 = ['gm', 'convert', inpdf, outpng]
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
493 else: # assume imagemagick
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
494 cl2 = ['convert', inpdf, outpng]
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
495 x = subprocess.Popen(cl2,stdout=sto,stderr=sto,cwd=self.opts.output_dir,env=our_env)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
496 retval2 = x.wait()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
497 sto.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
498 if retval2 == 0:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
499 os.unlink(hlog)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
500 retval = retval1 or retval2
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
501 return retval
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
502
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
503
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
504 def getfSize(self,fpath,outpath):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
505 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
506 format a nice file size string
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
507 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
508 size = ''
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
509 fp = os.path.join(outpath,fpath)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
510 if os.path.isfile(fp):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
511 size = '0 B'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
512 n = float(os.path.getsize(fp))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
513 if n > 2**20:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
514 size = '%1.1f MB' % (n/2**20)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
515 elif n > 2**10:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
516 size = '%1.1f KB' % (n/2**10)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
517 elif n > 0:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
518 size = '%d B' % (int(n))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
519 return size
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
520
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
521 def makeHtml(self):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
522 """ Create an HTML file content to list all the artifacts found in the output_dir
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
523 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
524
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
525 galhtmlprefix = """<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
526 <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
527 <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
528 <meta name="generator" content="Galaxy %s tool output - see http://g2.trac.bx.psu.edu/" />
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
529 <title></title>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
530 <link rel="stylesheet" href="/static/style/base.css" type="text/css" />
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
531 </head>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
532 <body>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
533 <div class="toolFormBody">
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
534 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
535 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/>"""
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
536 galhtmlpostfix = """</div></body></html>\n"""
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
537
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
538 flist = os.listdir(self.opts.output_dir)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
539 flist = [x for x in flist if x <> 'Rplots.pdf']
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
540 flist.sort()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
541 html = []
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
542 html.append(galhtmlprefix % progname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
543 html.append('<div class="infomessage">Galaxy Tool "%s" run at %s</div><br/>' % (self.toolname,timenow()))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
544 fhtml = []
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
545 if len(flist) > 0:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
546 logfiles = [x for x in flist if x.lower().endswith('.log')] # log file names determine sections
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
547 logfiles.sort()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
548 logfiles = [x for x in logfiles if os.path.abspath(x) <> os.path.abspath(self.tlog)]
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
549 logfiles.append(os.path.abspath(self.tlog)) # make it the last one
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
550 pdflist = []
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
551 npdf = len([x for x in flist if os.path.splitext(x)[-1].lower() == '.pdf'])
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
552 for rownum,fname in enumerate(flist):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
553 dname,e = os.path.splitext(fname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
554 sfsize = self.getfSize(fname,self.opts.output_dir)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
555 if e.lower() == '.pdf' : # compress and make a thumbnail
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
556 thumb = '%s.%s' % (dname,self.thumbformat)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
557 pdff = os.path.join(self.opts.output_dir,fname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
558 retval = self.compressPDF(inpdf=pdff,thumbformat=self.thumbformat)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
559 if retval == 0:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
560 pdflist.append((fname,thumb))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
561 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
562 pdflist.append((fname,fname))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
563 if (rownum+1) % 2 == 0:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
564 fhtml.append('<tr class="odd_row"><td><a href="%s">%s</a></td><td>%s</td></tr>' % (fname,fname,sfsize))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
565 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
566 fhtml.append('<tr><td><a href="%s">%s</a></td><td>%s</td></tr>' % (fname,fname,sfsize))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
567 for logfname in logfiles: # expect at least tlog - if more
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
568 if os.path.abspath(logfname) == os.path.abspath(self.tlog): # handled later
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
569 sectionname = 'All tool run'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
570 if (len(logfiles) > 1):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
571 sectionname = 'Other'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
572 ourpdfs = pdflist
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
573 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
574 realname = os.path.basename(logfname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
575 sectionname = os.path.splitext(realname)[0].split('_')[0] # break in case _ added to log
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
576 ourpdfs = [x for x in pdflist if os.path.basename(x[0]).split('_')[0] == sectionname]
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
577 pdflist = [x for x in pdflist if os.path.basename(x[0]).split('_')[0] <> sectionname] # remove
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
578 nacross = 1
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
579 npdf = len(ourpdfs)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
580
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
581 if npdf > 0:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
582 nacross = math.sqrt(npdf) ## int(round(math.log(npdf,2)))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
583 if int(nacross)**2 != npdf:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
584 nacross += 1
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
585 nacross = int(nacross)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
586 width = min(400,int(1200/nacross))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
587 html.append('<div class="toolFormTitle">%s images and outputs</div>' % sectionname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
588 html.append('(Click on a thumbnail image to download the corresponding original PDF image)<br/>')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
589 ntogo = nacross # counter for table row padding with empty cells
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
590 html.append('<div><table class="simple" cellpadding="2" cellspacing="2">\n<tr>')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
591 for i,paths in enumerate(ourpdfs):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
592 fname,thumb = paths
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
593 s= """<td><a href="%s"><img src="%s" title="Click to download a PDF of %s" hspace="5" width="%d"
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
594 alt="Image called %s"/></a></td>\n""" % (fname,thumb,fname,width,fname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
595 if ((i+1) % nacross == 0):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
596 s += '</tr>\n'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
597 ntogo = 0
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
598 if i < (npdf - 1): # more to come
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
599 s += '<tr>'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
600 ntogo = nacross
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
601 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
602 ntogo -= 1
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
603 html.append(s)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
604 if html[-1].strip().endswith('</tr>'):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
605 html.append('</table></div>\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
606 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
607 if ntogo > 0: # pad
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
608 html.append('<td>&nbsp;</td>'*ntogo)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
609 html.append('</tr></table></div>\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
610 logt = open(logfname,'r').readlines()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
611 logtext = [x for x in logt if x.strip() > '']
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
612 html.append('<div class="toolFormTitle">%s log output</div>' % sectionname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
613 if len(logtext) > 1:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
614 html.append('\n<pre>\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
615 html += logtext
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
616 html.append('\n</pre>\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
617 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
618 html.append('%s is empty<br/>' % logfname)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
619 if len(fhtml) > 0:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
620 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')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
621 fhtml.append('</table></div><br/>')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
622 html.append('<div class="toolFormTitle">All output files available for downloading</div>\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
623 html += fhtml # add all non-pdf files to the end of the display
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
624 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
625 html.append('<div class="warningmessagelarge">### Error - %s returned no files - please confirm that parameters are sane</div>' % self.opts.interpreter)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
626 html.append(galhtmlpostfix)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
627 htmlf = file(self.opts.output_html,'w')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
628 htmlf.write('\n'.join(html))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
629 htmlf.write('\n')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
630 htmlf.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
631 self.html = html
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
632
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
633
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
634 def run(self):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
635 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
636 scripts must be small enough not to fill the pipe!
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
637 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
638 if self.treatbashSpecial and self.opts.interpreter in ['bash','sh']:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
639 retval = self.runBash()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
640 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
641 if self.opts.output_dir:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
642 ste = open(self.elog,'w')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
643 sto = open(self.tlog,'w')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
644 sto.write('## Toolfactory generated command line = %s\n' % ' '.join(self.cl))
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
645 sto.flush()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
646 p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=ste,stdin=subprocess.PIPE,cwd=self.opts.output_dir)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
647 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
648 p = subprocess.Popen(self.cl,shell=False,stdin=subprocess.PIPE)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
649 p.stdin.write(self.script)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
650 p.stdin.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
651 retval = p.wait()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
652 if self.opts.output_dir:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
653 sto.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
654 ste.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
655 err = open(self.elog,'r').readlines()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
656 if retval <> 0 and err: # problem
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
657 print >> sys.stderr,err
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
658 if self.opts.make_HTML:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
659 self.makeHtml()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
660 return retval
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
661
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
662 def runBash(self):
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
663 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
664 cannot use - for bash so use self.sfile
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
665 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
666 if self.opts.output_dir:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
667 s = '## Toolfactory generated command line = %s\n' % ' '.join(self.cl)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
668 sto = open(self.tlog,'w')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
669 sto.write(s)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
670 sto.flush()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
671 p = subprocess.Popen(self.cl,shell=False,stdout=sto,stderr=sto,cwd=self.opts.output_dir)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
672 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
673 p = subprocess.Popen(self.cl,shell=False)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
674 retval = p.wait()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
675 if self.opts.output_dir:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
676 sto.close()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
677 if self.opts.make_HTML:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
678 self.makeHtml()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
679 return retval
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
680
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
681
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
682 def main():
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
683 u = """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
684 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
685 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath" --tool_name "foo" --interpreter "Rscript"
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
686 </command>
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
687 """
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
688 op = optparse.OptionParser()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
689 a = op.add_option
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
690 a('--script_path',default=None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
691 a('--tool_name',default=None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
692 a('--interpreter',default=None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
693 a('--output_dir',default='./')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
694 a('--output_html',default=None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
695 a('--input_tab',default="None")
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
696 a('--output_tab',default="None")
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
697 a('--user_email',default='Unknown')
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
698 a('--bad_user',default=None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
699 a('--make_Tool',default=None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
700 a('--make_HTML',default=None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
701 a('--help_text',default=None)
30
fb3fa6a2874d Citations added (thanks John!) and a few more output formats for Alistair Chilcott
fubar
parents: 29
diff changeset
702 a('--citations',default=None)
29
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
703 a('--tool_desc',default=None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
704 a('--new_tool',default=None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
705 a('--tool_version',default=None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
706 a('--include_dependencies',default=None)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
707 opts, args = op.parse_args()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
708 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)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
709 assert opts.tool_name,'## Tool Factory expects a tool name - eg --tool_name=DESeq'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
710 assert opts.interpreter,'## Tool Factory wrapper expects an interpreter - eg --interpreter=Rscript'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
711 assert os.path.isfile(opts.script_path),'## Tool Factory wrapper expects a script path - eg --script_path=foo.R'
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
712 if opts.output_dir:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
713 try:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
714 os.makedirs(opts.output_dir)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
715 except:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
716 pass
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
717 r = ScriptRunner(opts)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
718 if opts.make_Tool:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
719 retcode = r.makeTooltar()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
720 else:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
721 retcode = r.run()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
722 os.unlink(r.sfile)
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
723 if retcode:
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
724 sys.exit(retcode) # indicate failure to job runner
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
725
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
726
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
727 if __name__ == "__main__":
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
728 main()
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
729
bff4c9bfabc7 Fixes for escaping all xml characters in help and code - thanks to Marius van den Beek for pointing these out
fubar
parents:
diff changeset
730