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