annotate toolfactory/rgToolFactory2.py @ 55:dcf59d4e4515 draft

Uploaded
author fubar
date Mon, 31 Aug 2020 00:20:27 -0400
parents 4b71b252eacb
children 68fbdbe35f08
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1 #!/usr/bin/env python
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
2 # rgToolFactory.py
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
3 # see https://github.com/fubar2/toolfactory
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
4 #
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
5 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
6 #
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
7 # all rights reserved
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
8 # Licensed under the LGPL
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
9 # suggestions for improvement and bug fixes welcome at
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
10 # https://github.com/fubar2/toolfactory
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
11 #
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
12 # July 2020: BCC was fun and I feel like rip van winkle after 5 years.
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
13 # Decided to
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
14 # 1. Fix the toolfactory so it works - done for simplest case
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
15 # 2. Fix planemo so the toolfactory function works
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
16 # 3. Rewrite bits using galaxyxml functions where that makes sense - done
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
17 #
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
18 # removed all the old complications including making the new tool use this same script
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
19 # galaxyxml now generates the tool xml https://github.com/hexylena/galaxyxml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
20 # No support for automatic HTML file creation from arbitrary outputs
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
21 # essential problem is to create two command lines - one for the tool xml and a different
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
22 # one to run the executable with the supplied test data and settings
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
23 # Be simpler to write the tool, then run it with planemo and soak up the test outputs.
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
24
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
25
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
26 import argparse
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
27 import logging
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
28 import os
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
29 import re
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
30 import shutil
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
31 import subprocess
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
32 import sys
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
33 import tarfile
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
34 import tempfile
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
35 import time
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
36
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
37 import galaxyxml.tool as gxt
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
38 import galaxyxml.tool.parameters as gxtp
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
39
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
40 import lxml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
41
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
42 import yaml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
43
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
44 myversion = "V2.1 July 2020"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
45 verbose = True
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
46 debug = True
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
47 toolFactoryURL = "https://github.com/fubar2/toolfactory"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
48 ourdelim = "~~~"
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
49 ALOT = 10000000 # srsly. command or test overrides use read() so just in case
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
50 STDIOXML = """<stdio>
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
51 <exit_code range="100:" level="debug" description="shite happens" />
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
52 </stdio>"""
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
53
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
54 # --input_files="$input_files~~~$CL~~~$input_formats~~~$input_label
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
55 # ~~~$input_help"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
56 IPATHPOS = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
57 ICLPOS = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
58 IFMTPOS = 2
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
59 ILABPOS = 3
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
60 IHELPOS = 4
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
61 IOCLPOS = 5
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
62
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
63 # --output_files "$otab.history_name~~~$otab.history_format~~~$otab.CL~~~otab.history_test
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
64 ONAMEPOS = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
65 OFMTPOS = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
66 OCLPOS = 2
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
67 OTESTPOS = 3
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
68 OOCLPOS = 4
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
69
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
70
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
71 # --additional_parameters="$i.param_name~~~$i.param_value~~~
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
72 # $i.param_label~~~$i.param_help~~~$i.param_type~~~$i.CL~~~i$.param_CLoverride"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
73 ANAMEPOS = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
74 AVALPOS = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
75 ALABPOS = 2
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
76 AHELPPOS = 3
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
77 ATYPEPOS = 4
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
78 ACLPOS = 5
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
79 AOVERPOS = 6
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
80 AOCLPOS = 7
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
81
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
82
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
83 foo = len(lxml.__version__)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
84 # fug you, flake8. Say my name!
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
85 FAKEEXE = "~~~REMOVE~~~ME~~~"
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
86 # need this until a PR/version bump to fix galaxyxml prepending the exe even
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
87 # with override.
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
88
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
89
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
90 def timenow():
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
91 """return current time as a string
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
92 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
93 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time()))
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
94
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
95
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
96 def quote_non_numeric(s):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
97 """return a prequoted string for non-numerics
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
98 useful for perl and Rscript parameter passing?
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
99 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
100 try:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
101 _ = float(s)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
102 return s
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
103 except ValueError:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
104 return '"%s"' % s
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
105
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
106
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
107 html_escape_table = {"&": "&amp;", ">": "&gt;", "<": "&lt;", "$": r"\$"}
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
108
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
109
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
110 def html_escape(text):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
111 """Produce entities within text."""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
112 return "".join(html_escape_table.get(c, c) for c in text)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
113
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
114
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
115 def html_unescape(text):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
116 """Revert entities within text. Multiple character targets so use replace"""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
117 t = text.replace("&amp;", "&")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
118 t = t.replace("&gt;", ">")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
119 t = t.replace("&lt;", "<")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
120 t = t.replace("\\$", "$")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
121 return t
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
122
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
123
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
124 def parse_citations(citations_text):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
125 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
126 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
127 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
128 citation_tuples = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
129 for citation in citations:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
130 if citation.startswith("doi"):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
131 citation_tuples.append(("doi", citation[len("doi") :].strip()))
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
132 else:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
133 citation_tuples.append(("bibtex", citation[len("bibtex") :].strip()))
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
134 return citation_tuples
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
135
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
136
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
137 class ScriptRunner:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
138 """Wrapper for an arbitrary script
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
139 uses galaxyxml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
140
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
141 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
142
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
143 def __init__(self, args=None):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
144 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
145 prepare command line cl for running the tool here
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
146 and prepare elements needed for galaxyxml tool generation
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
147 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
148 self.infiles = [x.split(ourdelim) for x in args.input_files]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
149 self.outfiles = [x.split(ourdelim) for x in args.output_files]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
150 self.addpar = [x.split(ourdelim) for x in args.additional_parameters]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
151 self.args = args
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
152 self.cleanuppar()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
153 self.lastclredirect = None
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
154 self.lastxclredirect = None
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
155 self.cl = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
156 self.xmlcl = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
157 self.is_positional = self.args.parampass == "positional"
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
158 if self.args.packages:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
159 self.executeme = self.args.packages.split(",")[0].split(":")[0]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
160 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
161 self.executeme = self.args.sysexe
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
162 assert (
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
163 self.executeme is not None
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
164 ), "No system or managed executable passed in. Cannot build"
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
165 aCL = self.cl.append
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
166 aXCL = self.xmlcl.append
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
167 assert args.parampass in [
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
168 "0",
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
169 "argparse",
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
170 "positional",
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
171 ], 'args.parampass must be "0","positional" or "argparse"'
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
172 self.tool_name = re.sub("[^a-zA-Z0-9_]+", "", args.tool_name)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
173 self.tool_id = self.tool_name
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
174 self.newtool = gxt.Tool(
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
175 self.args.tool_name,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
176 self.tool_id,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
177 self.args.tool_version,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
178 self.args.tool_desc,
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
179 FAKEEXE,
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
180 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
181 self.tooloutdir = "tfout"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
182 self.repdir = "TF_run_report_tempdir"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
183 self.testdir = os.path.join(self.tooloutdir, "test-data")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
184 if not os.path.exists(self.tooloutdir):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
185 os.mkdir(self.tooloutdir)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
186 if not os.path.exists(self.testdir):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
187 os.mkdir(self.testdir) # make tests directory
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
188 if not os.path.exists(self.repdir):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
189 os.mkdir(self.repdir)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
190 self.tinputs = gxtp.Inputs()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
191 self.toutputs = gxtp.Outputs()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
192 self.testparam = []
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
193 if self.args.script_path:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
194 self.prepScript()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
195 if self.args.command_override:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
196 scos = open(self.args.command_override, "r").readlines()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
197 self.command_override = [x.rstrip() for x in scos]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
198 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
199 self.command_override = None
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
200 if self.args.test_override:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
201 stos = open(self.args.test_override, "r").readlines()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
202 self.test_override = [x.rstrip() for x in stos]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
203 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
204 self.test_override = None
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
205 if self.args.cl_prefix: # DIY CL start
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
206 clp = self.args.cl_prefix.split(" ")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
207 for c in clp:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
208 aCL(c)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
209 aXCL(c)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
210 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
211 if self.args.runmode == "Executable":
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
212 if self.args.script_path:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
213 aCL(self.executeme)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
214 aCL(self.sfile)
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
215 aXCL(self.executeme)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
216 aXCL("$runme")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
217 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
218 aCL(self.executeme) # this little CL will just run
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
219 aXCL(self.executeme)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
220 else:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
221 if self.args.script_path:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
222 aCL(self.executeme)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
223 aCL(self.sfile)
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
224 aXCL(self.executeme)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
225 aXCL("$runme")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
226 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
227 aCL(self.executeme) # this little CL will just run
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
228 aXCL(self.executeme)
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
229 self.elog = os.path.join(self.repdir, "%s_error_log.txt" % self.tool_name)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
230 self.tlog = os.path.join(self.repdir, "%s_runner_log.txt" % self.tool_name)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
231
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
232 if self.args.parampass == "0":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
233 self.clsimple()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
234 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
235 clsuffix = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
236 xclsuffix = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
237 for i, p in enumerate(self.infiles):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
238 if p[IOCLPOS] == "STDIN":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
239 appendme = [
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
240 p[IOCLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
241 p[ICLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
242 p[IPATHPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
243 "< %s" % p[IPATHPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
244 ]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
245 xappendme = [
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
246 p[IOCLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
247 p[ICLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
248 p[IPATHPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
249 "< $%s" % p[ICLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
250 ]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
251 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
252 appendme = [p[IOCLPOS], p[ICLPOS], p[IPATHPOS], ""]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
253 xappendme = [p[IOCLPOS], p[ICLPOS], "$%s" % p[ICLPOS], ""]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
254 clsuffix.append(appendme)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
255 xclsuffix.append(xappendme)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
256 for i, p in enumerate(self.outfiles):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
257 if p[OOCLPOS] == "STDOUT":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
258 self.lastclredirect = [">", p[ONAMEPOS]]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
259 self.lastxclredirect = [">", "$%s" % p[OCLPOS]]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
260 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
261 clsuffix.append([p[OOCLPOS], p[OCLPOS], p[ONAMEPOS], ""])
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
262 xclsuffix.append([p[OOCLPOS], p[OCLPOS], "$%s" % p[ONAMEPOS], ""])
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
263 for p in self.addpar:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
264 clsuffix.append([p[AOCLPOS], p[ACLPOS], p[AVALPOS], p[AOVERPOS]])
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
265 xclsuffix.append(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
266 [p[AOCLPOS], p[ACLPOS], '"$%s"' % p[ANAMEPOS], p[AOVERPOS]]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
267 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
268 clsuffix.sort()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
269 xclsuffix.sort()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
270 self.xclsuffix = xclsuffix
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
271 self.clsuffix = clsuffix
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
272 if self.args.parampass == "positional":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
273 self.clpositional()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
274 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
275 self.clargparse()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
276
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
277 def prepScript(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
278 rx = open(self.args.script_path, "r").readlines()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
279 rx = [x.rstrip() for x in rx]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
280 rxcheck = [x.strip() for x in rx if x.strip() > ""]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
281 assert len(rxcheck) > 0, "Supplied script is empty. Cannot run"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
282 self.script = "\n".join(rx)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
283 fhandle, self.sfile = tempfile.mkstemp(
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
284 prefix=self.tool_name, suffix="_%s" % (self.executeme)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
285 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
286 tscript = open(self.sfile, "w")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
287 tscript.write(self.script)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
288 tscript.close()
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
289 self.indentedScript = " %s" % "\n".join([" %s" % html_escape(x) for x in rx])
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
290 self.escapedScript = "%s" % "\n".join([" %s" % html_escape(x) for x in rx])
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
291 art = "%s.%s" % (self.tool_name, self.executeme)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
292 artifact = open(art, "wb")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
293 artifact.write(bytes(self.script, "utf8"))
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
294 artifact.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
295
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
296 def cleanuppar(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
297 """ positional parameters are complicated by their numeric ordinal"""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
298 for i, p in enumerate(self.infiles):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
299 if self.args.parampass == "positional":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
300 assert p[ICLPOS].isdigit(), (
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
301 "Positional parameters must be ordinal integers - got %s for %s"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
302 % (p[ICLPOS], p[ILABPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
303 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
304 p.append(p[ICLPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
305 if p[ICLPOS].isdigit() or self.args.parampass == "0":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
306 scl = "input%d" % (i + 1)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
307 p[ICLPOS] = scl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
308 self.infiles[i] = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
309 for i, p in enumerate(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
310 self.outfiles
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
311 ): # trying to automagically gather using extensions
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
312 if self.args.parampass == "positional" and p[OCLPOS] != "STDOUT":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
313 assert p[OCLPOS].isdigit(), (
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
314 "Positional parameters must be ordinal integers - got %s for %s"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
315 % (p[OCLPOS], p[ONAMEPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
316 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
317 p.append(p[OCLPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
318 if p[OCLPOS].isdigit() or p[OCLPOS] == "STDOUT":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
319 scl = p[ONAMEPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
320 p[OCLPOS] = scl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
321 self.outfiles[i] = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
322 for i, p in enumerate(self.addpar):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
323 if self.args.parampass == "positional":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
324 assert p[ACLPOS].isdigit(), (
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
325 "Positional parameters must be ordinal integers - got %s for %s"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
326 % (p[ACLPOS], p[ANAMEPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
327 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
328 p.append(p[ACLPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
329 if p[ACLPOS].isdigit():
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
330 scl = "input%s" % p[ACLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
331 p[ACLPOS] = scl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
332 self.addpar[i] = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
333
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
334 def clsimple(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
335 """ no parameters - uses < and > for i/o
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
336 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
337 aCL = self.cl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
338 aCL("<")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
339 aCL(self.infiles[0][IPATHPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
340 aCL(">")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
341 aCL(self.outfiles[0][OCLPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
342 aXCL = self.xmlcl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
343 aXCL("<")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
344 aXCL("$%s" % self.infiles[0][ICLPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
345 aXCL(">")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
346 aXCL("$%s" % self.outfiles[0][ONAMEPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
347
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
348 def clpositional(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
349 # inputs in order then params
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
350 aCL = self.cl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
351 for (o_v, k, v, koverride) in self.clsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
352 if " " in v:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
353 aCL("%s" % v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
354 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
355 aCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
356 aXCL = self.xmlcl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
357 for (o_v, k, v, koverride) in self.xclsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
358 aXCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
359 if self.lastxclredirect:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
360 aXCL(self.lastxclredirect[0])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
361 aXCL(self.lastxclredirect[1])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
362
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
363 def clargparse(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
364 """ argparse style
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
365 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
366 aCL = self.cl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
367 aXCL = self.xmlcl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
368 # inputs then params in argparse named form
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
369 for (o_v, k, v, koverride) in self.xclsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
370 if koverride > "":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
371 k = koverride
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
372 elif len(k.strip()) == 1:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
373 k = "-%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
374 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
375 k = "--%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
376 aXCL(k)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
377 aXCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
378 for (o_v, k, v, koverride) in self.clsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
379 if koverride > "":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
380 k = koverride
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
381 elif len(k.strip()) == 1:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
382 k = "-%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
383 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
384 k = "--%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
385 aCL(k)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
386 aCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
387
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
388 def getNdash(self, newname):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
389 if self.is_positional:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
390 ndash = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
391 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
392 ndash = 2
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
393 if len(newname) < 2:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
394 ndash = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
395 return ndash
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
396
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
397 def doXMLparam(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
398 """flake8 made me do this..."""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
399 for p in self.outfiles:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
400 newname, newfmt, newcl, test, oldcl = p
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
401 ndash = self.getNdash(newcl)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
402 aparm = gxtp.OutputData(newcl, format=newfmt, num_dashes=ndash)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
403 aparm.positional = self.is_positional
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
404 if self.is_positional:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
405 if oldcl == "STDOUT":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
406 aparm.positional = 9999999
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
407 aparm.command_line_override = "> $%s" % newcl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
408 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
409 aparm.positional = int(oldcl)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
410 aparm.command_line_override = "$%s" % newcl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
411 self.toutputs.append(aparm)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
412 usetest = None
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
413 ld = None
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
414 if test > "":
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
415 if test.startswith("diff"):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
416 usetest = "diff"
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
417 if test.split(":")[1].isdigit:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
418 ld = int(test.split(":")[1])
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
419 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
420 usetest = test
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
421 tp = gxtp.TestOutput(
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
422 name=newcl,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
423 value="%s_sample" % newcl,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
424 format=newfmt,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
425 compare=usetest,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
426 lines_diff=ld,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
427 delta=None,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
428 )
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
429 self.testparam.append(tp)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
430 for p in self.infiles:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
431 newname = p[ICLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
432 newfmt = p[IFMTPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
433 ndash = self.getNdash(newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
434 if not len(p[ILABPOS]) > 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
435 alab = p[ICLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
436 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
437 alab = p[ILABPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
438 aninput = gxtp.DataParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
439 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
440 optional=False,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
441 label=alab,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
442 help=p[IHELPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
443 format=newfmt,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
444 multiple=False,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
445 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
446 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
447 aninput.positional = self.is_positional
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
448 self.tinputs.append(aninput)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
449 tparm = gxtp.TestParam(name=newname, value="%s_sample" % newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
450 self.testparam.append(tparm)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
451 for p in self.addpar:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
452 newname, newval, newlabel, newhelp, newtype, newcl, override, oldcl = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
453 if not len(newlabel) > 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
454 newlabel = newname
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
455 ndash = self.getNdash(newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
456 if newtype == "text":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
457 aparm = gxtp.TextParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
458 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
459 label=newlabel,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
460 help=newhelp,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
461 value=newval,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
462 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
463 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
464 elif newtype == "integer":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
465 aparm = gxtp.IntegerParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
466 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
467 label=newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
468 help=newhelp,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
469 value=newval,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
470 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
471 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
472 elif newtype == "float":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
473 aparm = gxtp.FloatParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
474 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
475 label=newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
476 help=newhelp,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
477 value=newval,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
478 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
479 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
480 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
481 raise ValueError(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
482 'Unrecognised parameter type "%s" for\
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
483 additional parameter %s in makeXML'
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
484 % (newtype, newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
485 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
486 aparm.positional = self.is_positional
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
487 if self.is_positional:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
488 aninput.positional = int(oldcl)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
489 self.tinputs.append(aparm)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
490 self.tparm = gxtp.TestParam(newname, value=newval)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
491 self.testparam.append(tparm)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
492
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
493 def doNoXMLparam(self):
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
494 """filter style package - stdin to stdout"""
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
495 alab = self.infiles[0][ILABPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
496 if len(alab) == 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
497 alab = self.infiles[0][ICLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
498 max1s = (
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
499 "Maximum one input if parampass is 0 but multiple input files supplied - %s"
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
500 % str(self.infiles)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
501 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
502 assert len(self.infiles) == 1, max1s
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
503 newname = self.infiles[0][ICLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
504 aninput = gxtp.DataParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
505 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
506 optional=False,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
507 label=alab,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
508 help=self.infiles[0][IHELPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
509 format=self.infiles[0][IFMTPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
510 multiple=False,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
511 num_dashes=0,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
512 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
513 aninput.command_line_override = "< $%s" % newname
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
514 aninput.positional = self.is_positional
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
515 self.tinputs.append(aninput)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
516 tp = gxtp.TestParam(name=newname, value="%s_sample" % newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
517 self.testparam.append(tp)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
518 newname = self.outfiles[0][OCLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
519 newfmt = self.outfiles[0][OFMTPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
520 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
521 anout.command_line_override = "> $%s" % newname
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
522 anout.positional = self.is_positional
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
523 self.toutputs.append(anout)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
524 tp = gxtp.TestOutput(name=newname, value="%s_sample" % newname, format=newfmt)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
525 self.testparam.append(tp)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
526
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
527 def makeXML(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
528 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
529 Create a Galaxy xml tool wrapper for the new script
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
530 Uses galaxyhtml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
531 Hmmm. How to get the command line into correct order...
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
532 """
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
533 if self.command_override:
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
534 self.newtool.command_line_override = self.command_override # config file
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
535 else:
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
536 self.newtool.command_line_override = self.xmlcl
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
537 if self.args.help_text:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
538 helptext = open(self.args.help_text, "r").readlines()
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
539 safertext = [html_escape(x) for x in helptext]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
540 if self.args.script_path:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
541 scrpt = self.script.split('\n')
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
542 scrpt.append("```\n")
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
543 if len(scrpt) > 300:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
544 safertext = safertext + scrpt[:100] + ['>500 lines - stuff deleted','......'] + scrpt[-100:]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
545 else:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
546 safertext = safertext + scrpt
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
547 safertext.append("\n```")
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
548 self.newtool.help = "".join([x for x in safertext])
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
549 else:
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
550 self.newtool.help = (
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
551 "Please ask the tool author (%s) for help \
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
552 as none was supplied at tool generation\n"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
553 % (self.args.user_email)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
554 )
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
555 self.newtool.version_command = None # do not want
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
556 requirements = gxtp.Requirements()
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
557 if self.args.packages:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
558 for d in self.args.packages.split(","):
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
559 if ":" in d:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
560 packg, ver = d.split(":")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
561 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
562 packg = d
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
563 ver = ""
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
564 requirements.append(
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
565 gxtp.Requirement("package", packg.strip(), ver.strip())
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
566 )
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
567 self.newtool.requirements = requirements
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
568 if self.args.parampass == "0":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
569 self.doNoXMLparam()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
570 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
571 self.doXMLparam()
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
572 self.newtool.outputs = self.toutputs
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
573 self.newtool.inputs = self.tinputs
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
574 if self.args.script_path:
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
575 configfiles = gxtp.Configfiles()
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
576 configfiles.append(gxtp.Configfile(name="runme", text=self.script))
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
577 self.newtool.configfiles = configfiles
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
578 tests = gxtp.Tests()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
579 test_a = gxtp.Test()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
580 for tp in self.testparam:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
581 test_a.append(tp)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
582 tests.append(test_a)
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
583 self.newtool.tests = tests
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
584 self.newtool.add_comment(
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
585 "Created by %s at %s using the Galaxy Tool Factory."
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
586 % (self.args.user_email, timenow())
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
587 )
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
588 self.newtool.add_comment("Source in git at: %s" % (toolFactoryURL))
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
589 self.newtool.add_comment(
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
590 "Cite: Creating re-usable tools from scripts doi: \
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
591 10.1093/bioinformatics/bts573"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
592 )
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
593 exml0 = self.newtool.export()
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
594 exml = exml0.replace(FAKEEXE, "") # temporary work around until PR accepted
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
595 if (
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
596 self.test_override
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
597 ): # cannot do this inside galaxyxml as it expects lxml objects for tests
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
598 part1 = exml.split("<tests>")[0]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
599 part2 = exml.split("</tests>")[1]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
600 fixed = "%s\n%s\n%s" % (part1, self.test_override, part2)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
601 exml = fixed
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
602 xf = open("%s.xml" % self.tool_name, "w")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
603 xf.write(exml)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
604 xf.write("\n")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
605 xf.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
606 # ready for the tarball
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
607
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
608 def run(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
609 """
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
610 generate test outputs by running a command line
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
611 won't work if command or test override in play - planemo is the
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
612 easiest way to generate test outputs for that case so is
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
613 automagically selected
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
614 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
615 s = "run cl=%s" % str(self.cl)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
616 logging.debug(s)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
617 scl = " ".join(self.cl)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
618 err = None
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
619 if self.args.parampass != "0":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
620 ste = open(self.elog, "wb")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
621 if self.lastclredirect:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
622 sto = open(self.lastclredirect[1], "wb") # is name of an output file
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
623 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
624 sto = open(self.tlog, "wb")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
625 sto.write(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
626 bytes(
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
627 "## Executing Toolfactory generated command line = %s\n" % scl,
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
628 "utf8",
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
629 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
630 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
631 sto.flush()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
632 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
633 sto.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
634 ste.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
635 tmp_stderr = open(self.elog, "rb")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
636 err = ""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
637 buffsize = 1048576
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
638 try:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
639 while True:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
640 err += str(tmp_stderr.read(buffsize))
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
641 if not err or len(err) % buffsize != 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
642 break
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
643 except OverflowError:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
644 pass
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
645 tmp_stderr.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
646 retval = p.returncode
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
647 else: # work around special case - stdin and write to stdout
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
648 sti = open(self.infiles[0][IPATHPOS], "rb")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
649 sto = open(self.outfiles[0][ONAMEPOS], "wb")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
650 # must use shell to redirect
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
651 p = subprocess.run(self.cl, shell=False, stdout=sto, stdin=sti)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
652 retval = p.returncode
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
653 sto.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
654 sti.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
655 if os.path.isfile(self.tlog) and os.stat(self.tlog).st_size == 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
656 os.unlink(self.tlog)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
657 if os.path.isfile(self.elog) and os.stat(self.elog).st_size == 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
658 os.unlink(self.elog)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
659 if retval != 0 and err: # problem
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
660 sys.stderr.write(err)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
661 logging.debug("run done")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
662 return retval
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
663
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
664 def planemo_shedload(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
665 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
666 planemo shed_create --shed_target testtoolshed
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
667 planemo shed_update --check_diff --shed_target testtoolshed
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
668 """
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
669 if os.path.exists(self.tlog):
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
670 tout = open(self.tlog, "a")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
671 else:
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
672 tout = open(self.tlog, "w")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
673 cll = ["planemo", "shed_create", "--shed_target", "local"]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
674 try:
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
675 p = subprocess.run(
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
676 cll, shell=True, cwd=self.tooloutdir, stdout=tout, stderr=tout
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
677 )
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
678 except:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
679 pass
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
680 if p.returncode != 0:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
681 print("Repository %s exists" % self.args.tool_name)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
682 else:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
683 print("initiated %s" % self.args.tool_name)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
684 cll = [
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
685 "planemo",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
686 "shed_upload",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
687 "--shed_target",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
688 "local",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
689 "--owner",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
690 "fubar",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
691 "--name",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
692 self.args.tool_name,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
693 "--shed_key",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
694 self.args.toolshed_api_key,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
695 "--tar",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
696 self.newtarpath,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
697 ]
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
698 p = subprocess.run(cll, shell=True)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
699 print("Ran", " ".join(cll), "got", p.returncode)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
700 tout.close()
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
701 return p.returncode
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
702
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
703 def planemo_test(self, genoutputs=True):
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
704 """planemo is a requirement so is available for testing
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
705 and for generating test outputs if command or test overrides are supplied
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
706 test outputs are sent to repdir for display
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
707 """
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
708 xreal = "%s.xml" % self.tool_name
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
709 if os.path.exists(self.tlog):
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
710 tout = open(self.tlog, "a")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
711 else:
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
712 tout = open(self.tlog, "w")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
713 if genoutputs:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
714 cll = [
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
715 "planemo",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
716 "test",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
717 "--galaxy_root",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
718 self.args.galaxy_root,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
719 "--update_test_data",
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
720 "--galaxy_python_version",
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
721 "3.6",
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
722 xreal,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
723 ]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
724 else:
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
725 cll = ["planemo", "test", "--galaxy_python_version",
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
726 "3.6", "--galaxy_root",
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
727 self.args.galaxy_root,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
728 xreal,]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
729 p = subprocess.run(
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
730 cll, shell=True, cwd=self.tooloutdir, stderr=tout, stdout=tout
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
731 )
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
732 if genoutputs:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
733 with os.scandir(self.testdir) as outs:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
734 for entry in outs:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
735 if entry.is_file():
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
736 dest = os.path.join(self.repdir, entry.name)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
737 src = os.path.join(self.testdir, entry.name)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
738 shutil.copyfile(src, dest)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
739 tout.write(
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
740 "Copied output %s to %s after planemo test\n" % (src, dest)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
741 )
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
742 tout.close()
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
743 return p.returncode
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
744
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
745 def eph_galaxy_load(self):
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
746 """load the new tool from the local toolshed after planemo uploads it
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
747 """
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
748 if os.path.exists(self.tlog):
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
749 tout = open(self.tlog, "a")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
750 else:
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
751 tout = open(self.tlog, "w")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
752 cll = [
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
753 "shed-tools",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
754 "install",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
755 "-g",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
756 self.args.galaxy_url,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
757 "--latest",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
758 "-a",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
759 self.args.galaxy_api_key,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
760 "--name",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
761 self.args.tool_name,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
762 "--owner",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
763 "fubar",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
764 "--toolshed",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
765 self.args.toolshed_url,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
766 "--section_label",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
767 "Generated Tools",
51
4b71b252eacb Uploaded
fubar
parents: 50
diff changeset
768
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
769 ]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
770 print("running\n", " ".join(cll))
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
771 p = subprocess.run(cll, shell=False, stderr=tout, stdout=tout)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
772 if p.returncode != 0:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
773 print(
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
774 "Repository %s installation returned %d"
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
775 % (self.args.tool_name, p.returncode)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
776 )
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
777 else:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
778 print("installed %s" % self.args.tool_name)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
779 tout.close()
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
780 return p.returncode
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
781
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
782 def writeShedyml(self):
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
783 """for planemo
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
784 """
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
785 yuser = self.args.user_email.split("@")[0]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
786 yfname = os.path.join(self.tooloutdir, ".shed.yml")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
787 yamlf = open(yfname, "w")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
788 odict = {
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
789 "name": self.tool_name,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
790 "owner": yuser,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
791 "type": "unrestricted",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
792 "description": self.args.tool_desc,
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
793 "synopsis": self.args.tool_desc,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
794 "category": "TF Generated Tools",
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
795 }
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
796 yaml.dump(odict, yamlf, allow_unicode=True)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
797 yamlf.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
798
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
799 def makeTool(self):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
800 """write xmls and input samples into place
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
801 """
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
802 self.makeXML()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
803 if self.args.script_path:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
804 stname = os.path.join(self.tooloutdir, "%s" % (self.sfile))
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
805 if not os.path.exists(stname):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
806 shutil.copyfile(self.sfile, stname)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
807 xreal = "%s.xml" % self.tool_name
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
808 xout = os.path.join(self.tooloutdir, xreal)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
809 shutil.copyfile(xreal, xout)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
810 for p in self.infiles:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
811 pth = p[IPATHPOS]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
812 dest = os.path.join(self.testdir, "%s_sample" % p[ICLPOS])
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
813 shutil.copyfile(pth, dest)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
814 dest = os.path.join(self.repdir, "%s.%s" % (p[ICLPOS], p[IFMTPOS]))
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
815 shutil.copyfile(pth, dest)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
816
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
817 def makeToolTar(self):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
818 """ move outputs into test-data and prepare the tarball
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
819 """
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
820 for p in self.outfiles:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
821 src = p[ONAMEPOS]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
822 if os.path.isfile(src):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
823 dest = os.path.join(self.testdir, "%s_sample" % src)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
824 shutil.copyfile(src, dest)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
825 dest = os.path.join(self.repdir, "%s.%s" % (src, p[OFMTPOS]))
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
826 shutil.copyfile(src, dest)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
827 else:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
828 print(
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
829 "### problem - output file %s not found in tooloutdir %s"
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
830 % (src, self.tooloutdir)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
831 )
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
832 self.newtarpath = "toolfactory_%s.tgz" % self.tool_name
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
833 tf = tarfile.open(self.newtarpath, "w:gz")
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
834 tf.add(name=self.tooloutdir, arcname=self.tool_name)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
835 tf.close()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
836 shutil.copyfile(self.newtarpath, self.args.new_tool)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
837
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
838 def moveRunOutputs(self):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
839 """need to move planemo or run outputs into toolfactory collection
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
840 """
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
841 with os.scandir(self.tooloutdir) as outs:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
842 for entry in outs:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
843 if not entry.is_file() or entry.name.startswith("."):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
844 continue
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
845 if "." in entry.name:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
846 nayme, ext = os.path.splitext(entry.name)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
847 else:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
848 ext = ".txt"
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
849 ofn = "%s%s" % (entry.name.replace(".", "_"), ext)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
850 dest = os.path.join(self.repdir, ofn)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
851 src = os.path.join(self.tooloutdir, entry.name)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
852 shutil.copyfile(src, dest)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
853
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
854
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
855 def main():
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
856 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
857 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
858 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath"
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
859 --tool_name "foo" --interpreter "Rscript"
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
860 </command>
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
861 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
862 parser = argparse.ArgumentParser()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
863 a = parser.add_argument
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
864 a("--script_path", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
865 a("--history_test", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
866 a("--cl_prefix", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
867 a("--sysexe", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
868 a("--packages", default=None)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
869 a("--tool_name", default=None)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
870 a("--input_files", default=[], action="append")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
871 a("--output_files", default=[], action="append")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
872 a("--user_email", default="Unknown")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
873 a("--bad_user", default=None)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
874 a("--make_Tool", default="runonly")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
875 a("--help_text", default=None)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
876 a("--tool_desc", default=None)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
877 a("--tool_version", default=None)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
878 a("--citations", default=None)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
879 a("--command_override", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
880 a("--test_override", default=None)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
881 a("--additional_parameters", action="append", default=[])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
882 a("--edit_additional_parameters", action="store_true", default=False)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
883 a("--parampass", default="positional")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
884 a("--tfout", default="./tfout")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
885 a("--new_tool", default="new_tool")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
886 a("--runmode", default=None)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
887 a("--galaxy_url", default="http://localhost:8080")
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
888 a("--galaxy_api_key", default="fakekey")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
889 a("--toolshed_url", default="http://localhost:9009")
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
890 a("--toolshed_api_key", default="fakekey")
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
891 a("--galaxy_root", default="/galaxy-central")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
892
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
893 args = parser.parse_args()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
894 assert not args.bad_user, (
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
895 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file'
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
896 % (args.bad_user, args.bad_user)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
897 )
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
898 assert args.tool_name, "## Tool Factory expects a tool name - eg --tool_name=DESeq"
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
899 assert (
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
900 args.sysexe or args.packages
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
901 ), "## Tool Factory wrapper expects an interpreter or an executable package"
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
902 args.input_files = [x.replace('"', "").replace("'", "") for x in args.input_files]
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
903 # remove quotes we need to deal with spaces in CL params
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
904 for i, x in enumerate(args.additional_parameters):
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
905 args.additional_parameters[i] = args.additional_parameters[i].replace('"', "")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
906 r = ScriptRunner(args)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
907 r.writeShedyml()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
908 r.makeTool()
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
909 if args.command_override or args.test_override:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
910 retcode = r.planemo_test(genoutputs=True) # this fails :( - see PR
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
911 r.moveRunOutputs()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
912 r.makeToolTar()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
913 retcode = r.planemo_test(genoutputs=False)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
914 r.moveRunOutputs()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
915 if args.make_Tool == "gentestinstall":
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
916 r.planemo_shedload()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
917 r.eph_galaxy_load()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
918 else:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
919 retcode = r.run()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
920 if retcode:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
921 sys.stderr.write(
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
922 "## Run failed with return code %d. Cannot build yet. Please fix and retry"
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
923 % retcode
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
924 )
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
925 sys.exit(1)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
926 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
927 r.moveRunOutputs()
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
928 r.makeToolTar()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
929 if args.make_Tool in ["gentestinstall", "gentest"]:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
930 r.planemo_test(genoutputs=False)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
931 r.moveRunOutputs()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
932 if args.make_Tool == "gentestinstall":
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
933 r.planemo_shedload()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
934 r.eph_galaxy_load()
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
935
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
936
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
937 if __name__ == "__main__":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
938 main()