annotate toolfactory/rgToolFactory2.py @ 119:8ea1133b9d9a draft

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