annotate toolfactory/rgToolFactory2.py @ 49:35a912ce0c83 draft

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