annotate toolfactory/rgToolFactory2.py @ 74:3d4324df911b draft

Uploaded
author fubar
date Sat, 14 Nov 2020 21:52:39 +0000
parents a8764cda9dbf
children 25dd9364a32a
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
69
afa3da660ae3 Uploaded
fubar
parents: 67
diff changeset
1 #!/usr/bin/python3
48
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
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
27 import copy
48
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
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
38 from bioblend import galaxy
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
39 from bioblend import toolshed
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
40
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
41 import galaxyxml.tool as gxt
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
42 import galaxyxml.tool.parameters as gxtp
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
43
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
44 import lxml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
45
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
46 import yaml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
47
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
48 myversion = "V2.1 July 2020"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
49 verbose = True
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
50 debug = True
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
51 toolFactoryURL = "https://github.com/fubar2/toolfactory"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
52 ourdelim = "~~~"
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
53 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
54 STDIOXML = """<stdio>
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
55 <exit_code range="100:" level="debug" description="shite happens" />
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
56 </stdio>"""
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
57
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
58 # --input_files="$input_files~~~$CL~~~$input_formats~~~$input_label
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
59 # ~~~$input_help"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
60 IPATHPOS = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
61 ICLPOS = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
62 IFMTPOS = 2
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
63 ILABPOS = 3
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
64 IHELPOS = 4
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
65 IOCLPOS = 5
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
66
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
67 # --output_files "$otab.history_name~~~$otab.history_format~~~$otab.CL~~~otab.history_test
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
68 ONAMEPOS = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
69 OFMTPOS = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
70 OCLPOS = 2
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
71 OTESTPOS = 3
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
72 OOCLPOS = 4
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
73
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
74
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
75 # --additional_parameters="$i.param_name~~~$i.param_value~~~
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
76 # $i.param_label~~~$i.param_help~~~$i.param_type~~~$i.CL~~~i$.param_CLoverride"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
77 ANAMEPOS = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
78 AVALPOS = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
79 ALABPOS = 2
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
80 AHELPPOS = 3
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
81 ATYPEPOS = 4
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
82 ACLPOS = 5
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
83 AOVERPOS = 6
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
84 AOCLPOS = 7
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
85
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
86
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
87 foo = len(lxml.__version__)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
88 # fug you, flake8. Say my name!
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
89 FAKEEXE = "~~~REMOVE~~~ME~~~"
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
90 # 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
91 # with override.
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
92
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
93
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
94 def timenow():
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
95 """return current time as a string
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
96 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
97 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time()))
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
98
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
99
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
100 def quote_non_numeric(s):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
101 """return a prequoted string for non-numerics
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
102 useful for perl and Rscript parameter passing?
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
103 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
104 try:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
105 _ = float(s)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
106 return s
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
107 except ValueError:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
108 return '"%s"' % s
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
109
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
110
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
111 html_escape_table = {"&": "&amp;", ">": "&gt;", "<": "&lt;", "$": r"\$"}
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
112
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
113
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
114 def html_escape(text):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
115 """Produce entities within text."""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
116 return "".join(html_escape_table.get(c, c) for c in text)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
117
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
118
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
119 def html_unescape(text):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
120 """Revert entities within text. Multiple character targets so use replace"""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
121 t = text.replace("&amp;", "&")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
122 t = t.replace("&gt;", ">")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
123 t = t.replace("&lt;", "<")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
124 t = t.replace("\\$", "$")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
125 return t
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
126
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
127
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
128 def parse_citations(citations_text):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
129 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
130 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
131 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
132 citation_tuples = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
133 for citation in citations:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
134 if citation.startswith("doi"):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
135 citation_tuples.append(("doi", citation[len("doi") :].strip()))
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
136 else:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
137 citation_tuples.append(("bibtex", citation[len("bibtex") :].strip()))
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
138 return citation_tuples
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
139
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
140
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
141 class ScriptRunner:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
142 """Wrapper for an arbitrary script
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
143 uses galaxyxml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
144
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
145 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
146
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
147 def __init__(self, args=None):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
148 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
149 prepare command line cl for running the tool here
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
150 and prepare elements needed for galaxyxml tool generation
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
151 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
152 self.infiles = [x.split(ourdelim) for x in args.input_files]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
153 self.outfiles = [x.split(ourdelim) for x in args.output_files]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
154 self.addpar = [x.split(ourdelim) for x in args.additional_parameters]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
155 self.args = args
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
156 self.cleanuppar()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
157 self.lastclredirect = None
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
158 self.lastxclredirect = None
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
159 self.cl = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
160 self.xmlcl = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
161 self.is_positional = self.args.parampass == "positional"
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
162 if self.args.sysexe:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
163 self.executeme = self.args.sysexe
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
164 else:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
165 if self.args.packages:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
166 self.executeme = self.args.packages.split(",")[0].split(":")[0]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
167 else:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
168 self.executeme = None
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
169 aCL = self.cl.append
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
170 aXCL = self.xmlcl.append
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
171 assert args.parampass in [
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
172 "0",
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
173 "argparse",
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
174 "positional",
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
175 ], 'args.parampass must be "0","positional" or "argparse"'
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
176 self.tool_name = re.sub("[^a-zA-Z0-9_]+", "", args.tool_name)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
177 self.tool_id = self.tool_name
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
178 self.newtool = gxt.Tool(
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
179 self.args.tool_name,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
180 self.tool_id,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
181 self.args.tool_version,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
182 self.args.tool_desc,
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
183 FAKEEXE,
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
184 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
185 self.tooloutdir = "tfout"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
186 self.repdir = "TF_run_report_tempdir"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
187 self.testdir = os.path.join(self.tooloutdir, "test-data")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
188 if not os.path.exists(self.tooloutdir):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
189 os.mkdir(self.tooloutdir)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
190 if not os.path.exists(self.testdir):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
191 os.mkdir(self.testdir) # make tests directory
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
192 if not os.path.exists(self.repdir):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
193 os.mkdir(self.repdir)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
194 self.tinputs = gxtp.Inputs()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
195 self.toutputs = gxtp.Outputs()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
196 self.testparam = []
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
197 if self.args.script_path:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
198 self.prepScript()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
199 if self.args.command_override:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
200 scos = open(self.args.command_override, "r").readlines()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
201 self.command_override = [x.rstrip() for x in scos]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
202 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
203 self.command_override = None
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
204 if self.args.test_override:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
205 stos = open(self.args.test_override, "r").readlines()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
206 self.test_override = [x.rstrip() for x in stos]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
207 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
208 self.test_override = None
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
209 if self.args.cl_prefix: # DIY CL start
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
210 clp = self.args.cl_prefix.split(" ")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
211 for c in clp:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
212 aCL(c)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
213 aXCL(c)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
214 else:
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
215 if self.args.script_path:
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
216 aCL(self.executeme)
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
217 aCL(self.sfile)
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
218 aXCL(self.executeme)
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
219 aXCL("$runme")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
220 else:
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
221 aCL(self.executeme) # this little CL will just run
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
222 aXCL(self.executeme)
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
223 self.elog = os.path.join(self.repdir, "%s_error_log.txt" % self.tool_name)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
224 self.tlog = os.path.join(self.repdir, "%s_runner_log.txt" % self.tool_name)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
225
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
226 if self.args.parampass == "0":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
227 self.clsimple()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
228 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
229 clsuffix = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
230 xclsuffix = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
231 for i, p in enumerate(self.infiles):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
232 if p[IOCLPOS] == "STDIN":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
233 appendme = [
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
234 p[IOCLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
235 p[ICLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
236 p[IPATHPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
237 "< %s" % p[IPATHPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
238 ]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
239 xappendme = [
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[ICLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
244 ]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
245 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
246 appendme = [p[IOCLPOS], p[ICLPOS], p[IPATHPOS], ""]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
247 xappendme = [p[IOCLPOS], p[ICLPOS], "$%s" % p[ICLPOS], ""]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
248 clsuffix.append(appendme)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
249 xclsuffix.append(xappendme)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
250 for i, p in enumerate(self.outfiles):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
251 if p[OOCLPOS] == "STDOUT":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
252 self.lastclredirect = [">", p[ONAMEPOS]]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
253 self.lastxclredirect = [">", "$%s" % p[OCLPOS]]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
254 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
255 clsuffix.append([p[OOCLPOS], p[OCLPOS], p[ONAMEPOS], ""])
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
256 xclsuffix.append([p[OOCLPOS], p[OCLPOS], "$%s" % p[ONAMEPOS], ""])
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
257 for p in self.addpar:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
258 clsuffix.append([p[AOCLPOS], p[ACLPOS], p[AVALPOS], p[AOVERPOS]])
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
259 xclsuffix.append(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
260 [p[AOCLPOS], p[ACLPOS], '"$%s"' % p[ANAMEPOS], p[AOVERPOS]]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
261 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
262 clsuffix.sort()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
263 xclsuffix.sort()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
264 self.xclsuffix = xclsuffix
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
265 self.clsuffix = clsuffix
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
266 if self.args.parampass == "positional":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
267 self.clpositional()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
268 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
269 self.clargparse()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
270
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
271 def prepScript(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
272 rx = open(self.args.script_path, "r").readlines()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
273 rx = [x.rstrip() for x in rx]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
274 rxcheck = [x.strip() for x in rx if x.strip() > ""]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
275 assert len(rxcheck) > 0, "Supplied script is empty. Cannot run"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
276 self.script = "\n".join(rx)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
277 fhandle, self.sfile = tempfile.mkstemp(
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
278 prefix=self.tool_name, suffix="_%s" % (self.executeme)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
279 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
280 tscript = open(self.sfile, "w")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
281 tscript.write(self.script)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
282 tscript.close()
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
283 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
284 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
285 art = "%s.%s" % (self.tool_name, self.executeme)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
286 artifact = open(art, "wb")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
287 artifact.write(bytes(self.script, "utf8"))
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
288 artifact.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
289
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
290 def cleanuppar(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
291 """ positional parameters are complicated by their numeric ordinal"""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
292 for i, p in enumerate(self.infiles):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
293 if self.args.parampass == "positional":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
294 assert p[ICLPOS].isdigit(), (
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
295 "Positional parameters must be ordinal integers - got %s for %s"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
296 % (p[ICLPOS], p[ILABPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
297 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
298 p.append(p[ICLPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
299 if p[ICLPOS].isdigit() or self.args.parampass == "0":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
300 scl = "input%d" % (i + 1)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
301 p[ICLPOS] = scl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
302 self.infiles[i] = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
303 for i, p in enumerate(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
304 self.outfiles
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
305 ): # trying to automagically gather using extensions
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
306 if self.args.parampass == "positional" and p[OCLPOS] != "STDOUT":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
307 assert p[OCLPOS].isdigit(), (
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
308 "Positional parameters must be ordinal integers - got %s for %s"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
309 % (p[OCLPOS], p[ONAMEPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
310 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
311 p.append(p[OCLPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
312 if p[OCLPOS].isdigit() or p[OCLPOS] == "STDOUT":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
313 scl = p[ONAMEPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
314 p[OCLPOS] = scl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
315 self.outfiles[i] = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
316 for i, p in enumerate(self.addpar):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
317 if self.args.parampass == "positional":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
318 assert p[ACLPOS].isdigit(), (
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
319 "Positional parameters must be ordinal integers - got %s for %s"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
320 % (p[ACLPOS], p[ANAMEPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
321 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
322 p.append(p[ACLPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
323 if p[ACLPOS].isdigit():
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
324 scl = "input%s" % p[ACLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
325 p[ACLPOS] = scl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
326 self.addpar[i] = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
327
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
328 def clsimple(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
329 """ no parameters - uses < and > for i/o
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
330 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
331 aCL = self.cl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
332 aXCL = self.xmlcl.append
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
333
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
334 if len(self.infiles) > 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
335 aCL("<")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
336 aCL(self.infiles[0][IPATHPOS])
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
337 aXCL("<")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
338 aXCL("$%s" % self.infiles[0][ICLPOS])
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
339 if len(self.outfiles) > 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
340 aCL(">")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
341 aCL(self.outfiles[0][OCLPOS])
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
342 aXCL(">")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
343 aXCL("$%s" % self.outfiles[0][ONAMEPOS])
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
344
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
345 def clpositional(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
346 # inputs in order then params
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
347 aCL = self.cl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
348 for (o_v, k, v, koverride) in self.clsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
349 if " " in v:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
350 aCL("%s" % v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
351 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
352 aCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
353 aXCL = self.xmlcl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
354 for (o_v, k, v, koverride) in self.xclsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
355 aXCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
356 if self.lastxclredirect:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
357 aXCL(self.lastxclredirect[0])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
358 aXCL(self.lastxclredirect[1])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
359
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
360 def clargparse(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
361 """ argparse style
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
362 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
363 aCL = self.cl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
364 aXCL = self.xmlcl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
365 # inputs then params in argparse named form
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
366 for (o_v, k, v, koverride) in self.xclsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
367 if koverride > "":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
368 k = koverride
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
369 elif len(k.strip()) == 1:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
370 k = "-%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
371 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
372 k = "--%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
373 aXCL(k)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
374 aXCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
375 for (o_v, k, v, koverride) in self.clsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
376 if koverride > "":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
377 k = koverride
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
378 elif len(k.strip()) == 1:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
379 k = "-%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
380 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
381 k = "--%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
382 aCL(k)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
383 aCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
384
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
385 def getNdash(self, newname):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
386 if self.is_positional:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
387 ndash = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
388 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
389 ndash = 2
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
390 if len(newname) < 2:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
391 ndash = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
392 return ndash
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
393
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
394 def doXMLparam(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
395 """flake8 made me do this..."""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
396 for p in self.outfiles:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
397 newname, newfmt, newcl, test, oldcl = p
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
398 ndash = self.getNdash(newcl)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
399 aparm = gxtp.OutputData(newcl, format=newfmt, num_dashes=ndash)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
400 aparm.positional = self.is_positional
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
401 if self.is_positional:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
402 if oldcl == "STDOUT":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
403 aparm.positional = 9999999
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
404 aparm.command_line_override = "> $%s" % newcl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
405 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
406 aparm.positional = int(oldcl)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
407 aparm.command_line_override = "$%s" % newcl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
408 self.toutputs.append(aparm)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
409 usetest = None
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
410 ld = None
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
411 if test > "":
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
412 if test.startswith("diff"):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
413 usetest = "diff"
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
414 if test.split(":")[1].isdigit:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
415 ld = int(test.split(":")[1])
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
416 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
417 usetest = test
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
418 tp = gxtp.TestOutput(
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
419 name=newcl,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
420 value="%s_sample" % newcl,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
421 format=newfmt,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
422 compare=usetest,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
423 lines_diff=ld,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
424 delta=None,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
425 )
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
426 self.testparam.append(tp)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
427 for p in self.infiles:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
428 newname = p[ICLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
429 newfmt = p[IFMTPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
430 ndash = self.getNdash(newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
431 if not len(p[ILABPOS]) > 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
432 alab = p[ICLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
433 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
434 alab = p[ILABPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
435 aninput = gxtp.DataParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
436 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
437 optional=False,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
438 label=alab,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
439 help=p[IHELPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
440 format=newfmt,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
441 multiple=False,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
442 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
443 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
444 aninput.positional = self.is_positional
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
445 self.tinputs.append(aninput)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
446 tparm = gxtp.TestParam(name=newname, value="%s_sample" % newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
447 self.testparam.append(tparm)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
448 for p in self.addpar:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
449 newname, newval, newlabel, newhelp, newtype, newcl, override, oldcl = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
450 if not len(newlabel) > 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
451 newlabel = newname
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
452 ndash = self.getNdash(newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
453 if newtype == "text":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
454 aparm = gxtp.TextParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
455 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
456 label=newlabel,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
457 help=newhelp,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
458 value=newval,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
459 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
460 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
461 elif newtype == "integer":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
462 aparm = gxtp.IntegerParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
463 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
464 label=newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
465 help=newhelp,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
466 value=newval,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
467 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
468 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
469 elif newtype == "float":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
470 aparm = gxtp.FloatParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
471 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
472 label=newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
473 help=newhelp,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
474 value=newval,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
475 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
476 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
477 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
478 raise ValueError(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
479 'Unrecognised parameter type "%s" for\
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
480 additional parameter %s in makeXML'
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
481 % (newtype, newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
482 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
483 aparm.positional = self.is_positional
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
484 if self.is_positional:
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
485 aparm.positional = int(oldcl)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
486 self.tinputs.append(aparm)
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
487 tparm = gxtp.TestParam(newname, value=newval)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
488 self.testparam.append(tparm)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
489
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
490 def doNoXMLparam(self):
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
491 """filter style package - stdin to stdout"""
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
492 if len(self.infiles) > 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
493 alab = self.infiles[0][ILABPOS]
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
494 if len(alab) == 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
495 alab = self.infiles[0][ICLPOS]
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
496 max1s = (
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
497 "Maximum one input if parampass is 0 but multiple input files supplied - %s"
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
498 % str(self.infiles)
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
499 )
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
500 assert len(self.infiles) == 1, max1s
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
501 newname = self.infiles[0][ICLPOS]
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
502 aninput = gxtp.DataParam(
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
503 newname,
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
504 optional=False,
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
505 label=alab,
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
506 help=self.infiles[0][IHELPOS],
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
507 format=self.infiles[0][IFMTPOS],
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
508 multiple=False,
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
509 num_dashes=0,
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
510 )
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
511 aninput.command_line_override = "< $%s" % newname
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
512 aninput.positional = self.is_positional
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
513 self.tinputs.append(aninput)
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
514 tp = gxtp.TestParam(name=newname, value="%s_sample" % newname)
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
515 self.testparam.append(tp)
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
516 if len(self.outfiles) > 0:
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
517 newname = self.outfiles[0][OCLPOS]
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
518 newfmt = self.outfiles[0][OFMTPOS]
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
519 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0)
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
520 anout.command_line_override = "> $%s" % newname
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
521 anout.positional = self.is_positional
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
522 self.toutputs.append(anout)
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
523 tp = gxtp.TestOutput(name=newname, value="%s_sample" % newname, format=newfmt)
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
524 self.testparam.append(tp)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
525
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
526 def makeXML(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
527 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
528 Create a Galaxy xml tool wrapper for the new script
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
529 Uses galaxyhtml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
530 Hmmm. How to get the command line into correct order...
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
531 """
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
532 if self.command_override:
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
533 self.newtool.command_override = self.command_override # config file
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
534 else:
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
535 self.newtool.command_override = self.xmlcl
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
536 if self.args.help_text:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
537 helptext = open(self.args.help_text, "r").readlines()
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
538 safertext = [html_escape(x) for x in helptext]
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
539 if False and self.args.script_path:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
540 scrp = self.script.split('\n')
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
541 scrpt = [' %s' % x for x in scrp] # try to stop templating
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
542 scrpt.insert(0,"```\n")
50
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```")
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
548 self.newtool.help = "\n".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
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
602 exml = exml.replace('range="1:"', 'range="1000:"')
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
603 xf = open("%s.xml" % self.tool_name, "w")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
604 xf.write(exml)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
605 xf.write("\n")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
606 xf.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
607 # ready for the tarball
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
608
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
609 def run(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
610 """
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
611 generate test outputs by running a command line
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
612 won't work if command or test override in play - planemo is the
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
613 easiest way to generate test outputs for that case so is
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
614 automagically selected
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
615 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
616 scl = " ".join(self.cl)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
617 err = None
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
618 if self.args.parampass != "0":
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
619 if os.path.exists(self.elog):
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
620 ste = open(self.elog, "a")
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
621 else:
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
622 ste = open(self.elog, "w")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
623 if self.lastclredirect:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
624 sto = open(self.lastclredirect[1], "wb") # is name of an output file
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
625 else:
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
626 if os.path.exists(self.tlog):
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
627 sto = open(self.tlog, "a")
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
628 else:
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
629 sto = open(self.tlog, "w")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
630 sto.write(
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
631 "## Executing Toolfactory generated command line = %s\n" % scl
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
632 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
633 sto.flush()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
634 p = subprocess.run(self.cl, shell=False, stdout=sto, stderr=ste)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
635 sto.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
636 ste.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
637 retval = p.returncode
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
638 else: # work around special case - stdin and write to stdout
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
639 if len(self.infiles) > 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
640 sti = open(self.infiles[0][IPATHPOS], "rb")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
641 else:
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
642 sti = sys.stdin
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
643 if len(self.outfiles) > 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
644 sto = open(self.outfiles[0][ONAMEPOS], "wb")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
645 else:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
646 sto = sys.stdout
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
647 p = subprocess.run(self.cl, shell=False, stdout=sto, stdin=sti)
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
648 sto.write(
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
649 "## Executing Toolfactory generated command line = %s\n" % scl
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
650 )
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
651 retval = p.returncode
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
652 sto.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
653 sti.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
654 if os.path.isfile(self.tlog) and os.stat(self.tlog).st_size == 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
655 os.unlink(self.tlog)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
656 if os.path.isfile(self.elog) and os.stat(self.elog).st_size == 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
657 os.unlink(self.elog)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
658 if retval != 0 and err: # problem
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
659 sys.stderr.write(err)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
660 logging.debug("run done")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
661 return retval
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
662
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
663
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
664 def shedLoad(self):
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
665 """
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
666 {'deleted': False,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
667 'description': 'Tools for manipulating data',
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
668 'id': '175812cd7caaf439',
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
669 'model_class': 'Category',
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
670 'name': 'Text Manipulation',
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
671 'url': '/api/categories/175812cd7caaf439'}]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
672
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
673
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
674 """
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
675 if os.path.exists(self.tlog):
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
676 sto = open(self.tlog, "a")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
677 else:
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
678 sto = open(self.tlog, "w")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
679
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
680 ts = toolshed.ToolShedInstance(url=self.args.toolshed_url,key=self.args.toolshed_api_key,verify=False)
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
681 repos = ts.repositories.get_repositories()
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
682 rnames = [x.get('name','?') for x in repos]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
683 rids = [x.get('id','?') for x in repos]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
684 sto.write(f'############names={rnames} rids={rids}')
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
685 cat = 'ToolFactory generated tools'
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
686 if self.args.tool_name not in rnames:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
687 tscat = ts.categories.get_categories()
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
688 cnames = [x.get('name','?') for x in tscat]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
689 cids = [x.get('id','?') for x in tscat]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
690 catID = None
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
691 if cat in cnames:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
692 ci = cnames.index(cat)
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
693 catID = cids[ci]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
694 res = ts.repositories.create_repository(name=self.args.tool_name, synopsis='Synopsis:%s' % self.args.tool_desc, description=self.args.tool_desc,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
695 type='unrestricted', remote_repository_url=self.args.toolshed_url,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
696 homepage_url=None, category_ids=catID)
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
697 tid = res.get('id',None)
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
698 sto.write(f'##########create res={res}')
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
699 else:
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
700 i = rnames.index(self.args.tool_name)
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
701 tid = rids[i]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
702 res = ts.repositories.update_repository(id=tid, tar_ball_path=self.newtarpath, commit_message=None)
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
703 sto.write(f'#####update res={res}')
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
704 sto.close()
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
705
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
706
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
707 def eph_galaxy_load(self):
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
708 """load the new tool from the local toolshed after planemo uploads it
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
709 """
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
710 if os.path.exists(self.tlog):
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
711 tout = open(self.tlog, "a")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
712 else:
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
713 tout = open(self.tlog, "w")
49
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 "shed-tools",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
716 "install",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
717 "-g",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
718 self.args.galaxy_url,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
719 "--latest",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
720 "-a",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
721 self.args.galaxy_api_key,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
722 "--name",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
723 self.args.tool_name,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
724 "--owner",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
725 "fubar",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
726 "--toolshed",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
727 self.args.toolshed_url,
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
728 "--section_label",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
729 "ToolFactory",
51
4b71b252eacb Uploaded
fubar
parents: 50
diff changeset
730
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
731 ]
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
732 tout.write("running\n%s\n" % " ".join(cll))
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
733 p = subprocess.run(cll, shell=False, stderr=tout, stdout=tout)
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
734 tout.write("installed %s - got retcode %d\n" % (self.args.tool_name,p.returncode))
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
735 tout.close()
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
736 return p.returncode
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
737
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
738
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
739 def planemo_shedload(self):
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
740 """
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
741 planemo shed_create --shed_target testtoolshed
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
742 planemo shed_init --name=<name>
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
743 --owner=<shed_username>
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
744 --description=<short description>
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
745 [--remote_repository_url=<URL to .shed.yml on github>]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
746 [--homepage_url=<Homepage for tool.>]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
747 [--long_description=<long description>]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
748 [--category=<category name>]*
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
749
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
750
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
751 planemo shed_update --check_diff --shed_target testtoolshed
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
752 """
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
753 if os.path.exists(self.tlog):
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
754 tout = open(self.tlog, "a")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
755 else:
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
756 tout = open(self.tlog, "w")
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
757 ts = toolshed.ToolShedInstance(url=self.args.toolshed_url,key=self.args.toolshed_api_key,verify=False)
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
758 repos = ts.repositories.get_repositories()
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
759 rnames = [x.get('name','?') for x in repos]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
760 rids = [x.get('id','?') for x in repos]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
761 tout.write(f'############names={rnames} rids={rids}')
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
762 cat = 'ToolFactory generated tools'
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
763 if self.args.tool_name not in rnames:
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
764 cll = ["planemo", "shed_create", "--shed_target", "local",
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
765 "--owner","fubar","--name",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
766 self.args.tool_name,"--shed_key",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
767 self.args.toolshed_api_key,]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
768 try:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
769 p = subprocess.run(
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
770 cll, shell=False, cwd=self.tooloutdir, stdout=tout, stderr=tout
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
771 )
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
772 except:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
773 pass
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
774 if p.returncode != 0:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
775 tout.write("Repository %s exists" % self.args.tool_name)
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
776 else:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
777 tout.write("initiated %s" % self.args.tool_name)
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
778 cll = [
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
779 "planemo",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
780 "shed_upload",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
781 "--shed_target",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
782 "local",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
783 "--owner",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
784 "fubar",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
785 "--name",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
786 self.args.tool_name,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
787 "--shed_key",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
788 self.args.toolshed_api_key,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
789 "--tar",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
790 self.newtarpath,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
791 ]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
792 p = subprocess.run(cll, shell=False, stdout=tout, stderr=tout)
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
793 tout.write("Ran %s got %d" % (" ".join(cll), p.returncode))
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
794 tout.close()
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
795 return p.returncode
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
796
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
797
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
798 def eph_test(self):
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
799 """
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
800 """
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
801 if os.path.exists(self.tlog):
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
802 tout = open(self.tlog, "a")
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
803 else:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
804 tout = open(self.tlog, "w")
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
805 cll = [
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
806 "shed-tools",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
807 "test",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
808 "-g",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
809 self.args.galaxy_url,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
810 "-a",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
811 self.args.galaxy_api_key,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
812 "--name",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
813 self.args.tool_name,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
814 "--owner",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
815 "fubar",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
816 ]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
817 p = subprocess.run(
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
818 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
819 )
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
820 tout.write("eph_test Ran %s got %d" % (" ".join(cll), p.returncode))
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
821 tout.close()
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
822 return p.returncode
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
823
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
824 def planemo_test(self, genoutputs=True):
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
825 """planemo is a requirement so is available for testing
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
826 and for generating test outputs if command or test overrides are supplied
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
827 test outputs are sent to repdir for display
67
2cb06a59d84b Uploaded
fubar
parents: 66
diff changeset
828 planemo test --engine docker_galaxy --database_type docker_postgres --galaxy_root /galaxy-central pyrevpos/pyrevpos.xml
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
829 """
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
830 xreal = "%s.xml" % self.tool_name
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
831 if os.path.exists(self.tlog):
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
832 tout = open(self.tlog, "a")
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
833 else:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
834 tout = open(self.tlog, "w")
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
835 if genoutputs:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
836 dummy,tfile = tempfile.mkstemp()
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
837 cll = [
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
838 "planemo",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
839 "test",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
840 "--galaxy_root",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
841 self.args.galaxy_root,
74
3d4324df911b Uploaded
fubar
parents: 72
diff changeset
842 "--update_test_data",
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
843 xreal,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
844 ]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
845 p = subprocess.run(
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
846 cll, shell=False, cwd=self.tooloutdir, stderr=dummy, stdout=dummy,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
847 )
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
848 else:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
849 cll = ["planemo", "test", "--galaxy_root",
74
3d4324df911b Uploaded
fubar
parents: 72
diff changeset
850 self.args.galaxy_root,
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
851 xreal,]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
852 p = subprocess.run(
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
853 cll, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
854 )
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
855 tout.close()
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
856 return p.returncode
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
857
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
858
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
859
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
860 def writeShedyml(self):
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
861 """for planemo
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
862 """
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
863 yuser = self.args.user_email.split("@")[0]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
864 yfname = os.path.join(self.tooloutdir, ".shed.yml")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
865 yamlf = open(yfname, "w")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
866 odict = {
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
867 "name": self.tool_name,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
868 "owner": yuser,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
869 "type": "unrestricted",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
870 "description": self.args.tool_desc,
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
871 "synopsis": self.args.tool_desc,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
872 "category": "TF Generated Tools",
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
873 }
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
874 yaml.dump(odict, yamlf, allow_unicode=True)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
875 yamlf.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
876
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
877 def makeTool(self):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
878 """write xmls and input samples into place
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
879 """
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
880 self.makeXML()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
881 if self.args.script_path:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
882 stname = os.path.join(self.tooloutdir, "%s" % (self.sfile))
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
883 if not os.path.exists(stname):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
884 shutil.copyfile(self.sfile, stname)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
885 xreal = "%s.xml" % self.tool_name
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
886 xout = os.path.join(self.tooloutdir, xreal)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
887 shutil.copyfile(xreal, xout)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
888 for p in self.infiles:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
889 pth = p[IPATHPOS]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
890 dest = os.path.join(self.testdir, "%s_sample" % p[ICLPOS])
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
891 shutil.copyfile(pth, dest)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
892 dest = os.path.join(self.repdir, "%s.%s" % (p[ICLPOS], p[IFMTPOS]))
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
893 shutil.copyfile(pth, dest)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
894
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
895 def makeToolTar(self):
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
896 """ move outputs into test-data and prepare the tarball
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
897 """
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
898 excludeme = "tool_test_output"
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
899 def exclude_function(tarinfo):
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
900 filename = tarinfo.name
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
901 return None if filename.startswith(excludeme) or os.path.splitext(filename)[1].startswith(excludeme) else tarinfo
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
902
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
903 for p in self.outfiles:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
904 src = p[ONAMEPOS]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
905 if os.path.isfile(src):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
906 dest = os.path.join(self.testdir, "%s_sample" % src)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
907 shutil.copyfile(src, dest)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
908 dest = os.path.join(self.repdir, "%s.%s" % (src, p[OFMTPOS]))
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
909 shutil.copyfile(src, dest)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
910 else:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
911 print(
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
912 "### problem - output file %s not found in tooloutdir %s"
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
913 % (src, self.tooloutdir)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
914 )
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
915 self.newtarpath = "toolfactory_%s.tgz" % self.tool_name
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
916 tf = tarfile.open(self.newtarpath, "w:gz")
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
917 tf.add(name=self.tooloutdir, arcname=self.tool_name, filter=exclude_function)
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
918 tf.close()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
919 shutil.copyfile(self.newtarpath, self.args.new_tool)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
920
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
921 def moveRunOutputs(self):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
922 """need to move planemo or run outputs into toolfactory collection
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
923 """
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
924 with os.scandir(self.tooloutdir) as outs:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
925 for entry in outs:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
926 if not entry.is_file() or entry.name.startswith("."):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
927 continue
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
928 if "." in entry.name:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
929 nayme, ext = os.path.splitext(entry.name)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
930 else:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
931 ext = ".txt"
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
932 ofn = "%s%s" % (entry.name.replace(".", "_"), ext)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
933 dest = os.path.join(self.repdir, ofn)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
934 src = os.path.join(self.tooloutdir, entry.name)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
935 shutil.copyfile(src, dest)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
936
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
937
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
938 def main():
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
939 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
940 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
941 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath"
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
942 --tool_name "foo" --interpreter "Rscript"
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
943 </command>
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
944 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
945 parser = argparse.ArgumentParser()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
946 a = parser.add_argument
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
947 a("--script_path", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
948 a("--history_test", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
949 a("--cl_prefix", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
950 a("--sysexe", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
951 a("--packages", default=None)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
952 a("--tool_name", default=None)
72
a8764cda9dbf Uploaded
fubar
parents: 69
diff changeset
953 a("--tool_dir", default=None)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
954 a("--input_files", default=[], action="append")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
955 a("--output_files", default=[], action="append")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
956 a("--user_email", default="Unknown")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
957 a("--bad_user", default=None)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
958 a("--make_Tool", default="runonly")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
959 a("--help_text", default=None)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
960 a("--tool_desc", default=None)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
961 a("--tool_version", default=None)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
962 a("--citations", default=None)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
963 a("--command_override", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
964 a("--test_override", default=None)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
965 a("--additional_parameters", action="append", default=[])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
966 a("--edit_additional_parameters", action="store_true", default=False)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
967 a("--parampass", default="positional")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
968 a("--tfout", default="./tfout")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
969 a("--new_tool", default="new_tool")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
970 a("--galaxy_url", default="http://localhost:8080")
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
971 a("--toolshed_url", default="http://localhost:9009") # make sure this is NOT 127.0.0.1 - it won't work if tool_sheds_conf.xml has localhost
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
972 #a("--galaxy_api_key", default="1e62ddad74fe9bf112859f4e9efea48b")
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
973 #a("--toolshed_api_key", default="9154c91f2a162bf12fda15764f43846c")
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
974
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
975 a("--toolshed_api_key", default="fakekey")
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
976 a("--galaxy_api_key", default="fakekey")
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
977 a("--galaxy_root", default="/galaxy-central")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
978
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
979
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
980 args = parser.parse_args()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
981 assert not args.bad_user, (
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
982 '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
983 % (args.bad_user, args.bad_user)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
984 )
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
985 assert args.tool_name, "## Tool Factory expects a tool name - eg --tool_name=DESeq"
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
986 assert (
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
987 args.sysexe or args.packages
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
988 ), "## 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
989 args.input_files = [x.replace('"', "").replace("'", "") for x in args.input_files]
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
990 # remove quotes we need to deal with spaces in CL params
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
991 for i, x in enumerate(args.additional_parameters):
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
992 args.additional_parameters[i] = args.additional_parameters[i].replace('"', "")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
993 r = ScriptRunner(args)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
994 r.writeShedyml()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
995 r.makeTool()
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
996 if args.make_Tool == "generate":
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
997 retcode = r.run()
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
998 r.moveRunOutputs()
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
999 r.makeToolTar()
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1000 else:
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1001 retcode = r.planemo_test(genoutputs=True) # this fails :( - see PR
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1002 r.moveRunOutputs()
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1003 r.makeToolTar()
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1004 retcode = r.planemo_test(genoutputs=False)
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1005 r.moveRunOutputs()
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1006 if args.make_Tool == "gentestinstall":
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1007 retcode = r.planemo_shedload() #r.shedLoad()
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1008 print(f'planemo_shedload returned {retcode}')
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1009 r.eph_galaxy_load()
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1010
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1011
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1012
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1013 if __name__ == "__main__":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1014 main()