annotate toolfactory/toolfactory.py @ 1:0183cad9d13b draft

planemo upload
author fubar
date Thu, 22 Feb 2024 10:48:01 +0000
parents
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1 # see https://github.com/fubar2/toolfactory
0183cad9d13b planemo upload
fubar
parents:
diff changeset
2 #
0183cad9d13b planemo upload
fubar
parents:
diff changeset
3 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
0183cad9d13b planemo upload
fubar
parents:
diff changeset
4 #
0183cad9d13b planemo upload
fubar
parents:
diff changeset
5 # all rights reserved
0183cad9d13b planemo upload
fubar
parents:
diff changeset
6 # Licensed under the LGPL
0183cad9d13b planemo upload
fubar
parents:
diff changeset
7 # suggestions for improvement and bug fixes welcome at
0183cad9d13b planemo upload
fubar
parents:
diff changeset
8 # https://github.com/fubar2/toolfactory
0183cad9d13b planemo upload
fubar
parents:
diff changeset
9 #
0183cad9d13b planemo upload
fubar
parents:
diff changeset
10 # February 2023: Refactored to use galaxy-tool-test script in galaxyutil
0183cad9d13b planemo upload
fubar
parents:
diff changeset
11 # planemo not needed if tool is already installed.
0183cad9d13b planemo upload
fubar
parents:
diff changeset
12 # sqlite does not seem to work - switch to postgresql in the installation script
0183cad9d13b planemo upload
fubar
parents:
diff changeset
13 #
0183cad9d13b planemo upload
fubar
parents:
diff changeset
14 # march 2022: Refactored into two tools - generate and test/install
0183cad9d13b planemo upload
fubar
parents:
diff changeset
15 # as part of GTN tutorial development and biocontainer adoption
0183cad9d13b planemo upload
fubar
parents:
diff changeset
16 # The tester runs planemo on a non-tested archive, creates the test outputs
0183cad9d13b planemo upload
fubar
parents:
diff changeset
17 # and returns a new proper tool with test.
0183cad9d13b planemo upload
fubar
parents:
diff changeset
18
0183cad9d13b planemo upload
fubar
parents:
diff changeset
19
0183cad9d13b planemo upload
fubar
parents:
diff changeset
20 import argparse
0183cad9d13b planemo upload
fubar
parents:
diff changeset
21 import copy
0183cad9d13b planemo upload
fubar
parents:
diff changeset
22 import json
0183cad9d13b planemo upload
fubar
parents:
diff changeset
23 import logging
0183cad9d13b planemo upload
fubar
parents:
diff changeset
24 import os
0183cad9d13b planemo upload
fubar
parents:
diff changeset
25 import re
0183cad9d13b planemo upload
fubar
parents:
diff changeset
26 import shlex
0183cad9d13b planemo upload
fubar
parents:
diff changeset
27 import shutil
0183cad9d13b planemo upload
fubar
parents:
diff changeset
28 import subprocess
0183cad9d13b planemo upload
fubar
parents:
diff changeset
29 import sys
0183cad9d13b planemo upload
fubar
parents:
diff changeset
30 import tarfile
0183cad9d13b planemo upload
fubar
parents:
diff changeset
31 import tempfile
0183cad9d13b planemo upload
fubar
parents:
diff changeset
32 import time
0183cad9d13b planemo upload
fubar
parents:
diff changeset
33
0183cad9d13b planemo upload
fubar
parents:
diff changeset
34 from bioblend import galaxy
0183cad9d13b planemo upload
fubar
parents:
diff changeset
35 from bioblend import ConnectionError
0183cad9d13b planemo upload
fubar
parents:
diff changeset
36
0183cad9d13b planemo upload
fubar
parents:
diff changeset
37 import galaxyxml.tool as gxt
0183cad9d13b planemo upload
fubar
parents:
diff changeset
38 import galaxyxml.tool.parameters as gxtp
0183cad9d13b planemo upload
fubar
parents:
diff changeset
39
0183cad9d13b planemo upload
fubar
parents:
diff changeset
40 import lxml.etree as ET
0183cad9d13b planemo upload
fubar
parents:
diff changeset
41
0183cad9d13b planemo upload
fubar
parents:
diff changeset
42 import yaml
0183cad9d13b planemo upload
fubar
parents:
diff changeset
43
0183cad9d13b planemo upload
fubar
parents:
diff changeset
44
0183cad9d13b planemo upload
fubar
parents:
diff changeset
45 logger = logging.getLogger(__name__)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
46
0183cad9d13b planemo upload
fubar
parents:
diff changeset
47
0183cad9d13b planemo upload
fubar
parents:
diff changeset
48 class Tool_Factory:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
49 """Wrapper for an arbitrary script
0183cad9d13b planemo upload
fubar
parents:
diff changeset
50 uses galaxyxml
0183cad9d13b planemo upload
fubar
parents:
diff changeset
51 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
52
0183cad9d13b planemo upload
fubar
parents:
diff changeset
53 def __init__(self, args=None): # noqa
0183cad9d13b planemo upload
fubar
parents:
diff changeset
54 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
55 prepare command line cl for running the tool here
0183cad9d13b planemo upload
fubar
parents:
diff changeset
56 and prepare elements needed for galaxyxml tool generation
0183cad9d13b planemo upload
fubar
parents:
diff changeset
57 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
58 assert args.parampass in [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
59 "0",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
60 "embed",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
61 "argparse",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
62 "positional",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
63 "embednfmod",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
64 ], (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
65 "args.parampass %s not 0,positional, embed, embednfmod or argparse"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
66 % args.parampass
0183cad9d13b planemo upload
fubar
parents:
diff changeset
67 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
68 # sed will update these settings during tfsetup.py first run
0183cad9d13b planemo upload
fubar
parents:
diff changeset
69 self.GALAXY_ADMIN_KEY = "1718977735397126400"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
70 self.GALAXY_URL = "http://localhost:8080"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
71 self.profile = "22.05"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
72 self.not_iuc = True
0183cad9d13b planemo upload
fubar
parents:
diff changeset
73 self.args = args
0183cad9d13b planemo upload
fubar
parents:
diff changeset
74 self.tool_version = self.args.tool_version
0183cad9d13b planemo upload
fubar
parents:
diff changeset
75 self.myversion = "V3.0 February 2023"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
76 self.verbose = True
0183cad9d13b planemo upload
fubar
parents:
diff changeset
77 self.debug = True
0183cad9d13b planemo upload
fubar
parents:
diff changeset
78 self.toolFactoryURL = "https://github.com/fubar2/galaxy_tf_overlay"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
79 self.logger = logging.getLogger(__name__)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
80 self.nfcoremod = False
0183cad9d13b planemo upload
fubar
parents:
diff changeset
81 if args.parampass == "embednfmod":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
82 self.nfcoremod = True
0183cad9d13b planemo upload
fubar
parents:
diff changeset
83 self.script_in_help = False # IUC recommendation
0183cad9d13b planemo upload
fubar
parents:
diff changeset
84 self.tool_name = re.sub("[^a-zA-Z0-9_]+", "", args.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
85 self.tool_id = self.tool_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
86 self.local_tools = os.path.realpath(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
87 os.path.join(args.galaxy_root, "local_tools")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
88 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
89 self.repdir = os.path.realpath(args.tfcollection)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
90 self.testdir = os.path.join(self.repdir, self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
91 self.toold = os.path.join(self.local_tools, self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
92 self.tooltestd = os.path.join(self.toold, "test-data")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
93 if self.nfcoremod:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
94 self.local_tools = os.path.join(args.tfcollection, "tools")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
95 self.repdir = os.path.join(args.tfcollection, "TFouts", self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
96 self.toold = os.path.join(self.local_tools, self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
97 self.tooltestd = os.path.join(self.toold, "test-data")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
98 os.makedirs(self.repdir, exist_ok=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
99 os.makedirs(self.toold, exist_ok=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
100 os.makedirs(self.tooltestd, exist_ok=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
101 os.makedirs(self.local_tools, exist_ok=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
102 self.local_tool_conf = os.path.join(self.local_tools, "local_tool_conf.xml")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
103 self.ourcwd = os.getcwd()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
104 self.collections = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
105 if len(args.collection) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
106 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
107 self.collections = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
108 json.loads(x) for x in args.collection if len(x.strip()) > 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
109 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
110 except Exception:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
111 self.logger.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
112 f"--collections parameter {str(args.collection)} is malformed - should be a dictionary"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
113 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
114 self.infiles = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
115 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
116 self.infiles = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
117 json.loads(x) for x in args.input_files if len(x.strip()) > 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
118 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
119 except Exception:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
120 self.logger.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
121 f"--input_files parameter {str(args.input_files)} is malformed - should be a dictionary"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
122 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
123 self.extra_files = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
124 if len(args.xtra_files) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
125 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
126 self.extra_files = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
127 json.loads(x) for x in args.xtra_files if len(x.strip()) > 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
128 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
129 except Exception:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
130 self.logger.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
131 f"--xtra_files parameter {str(args.xtra_files)} is malformed - should be a dictionary"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
132 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
133 self.outfiles = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
134 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
135 self.outfiles = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
136 json.loads(x) for x in args.output_files if len(x.strip()) > 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
137 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
138 except Exception:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
139 self.logger.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
140 f"--output_files parameter {args.output_files} is malformed - should be a dictionary"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
141 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
142 assert (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
143 len(self.outfiles) + len(self.collections)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
144 ) > 0, "No outfiles or output collections specified. The Galaxy job runner will fail without an output of some sort"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
145 self.addpar = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
146 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
147 self.addpar = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
148 json.loads(x) for x in args.additional_parameters if len(x.strip()) > 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
149 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
150 except Exception:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
151 self.logger.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
152 f"--additional_parameters {args.additional_parameters} is malformed - should be a dictionary"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
153 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
154 self.selpar = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
155 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
156 self.selpar = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
157 json.loads(x) for x in args.selecttext_parameters if len(x.strip()) > 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
158 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
159 except Exception:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
160 self.logger.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
161 f"--selecttext_parameters {args.selecttext_parameters} is malformed - should be a dictionary"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
162 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
163 self.selfagpar = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
164 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
165 self.selflagpar = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
166 json.loads(x) for x in args.selectflag_parameters if len(x.strip()) > 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
167 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
168 except Exception:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
169 self.logger.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
170 f"--selectflag_parameters {args.selecttext_parameters} is malformed - should be a dictionary"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
171 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
172 self.cleanuppar()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
173 self.lastxclredirect = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
174 self.xmlcl = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
175 self.is_positional = self.args.parampass == "positional"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
176 self.is_embedded = self.args.parampass == "embedded"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
177 if self.args.sysexe:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
178 if " " in self.args.sysexe:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
179 self.executeme = shlex.split(self.args.sysexe)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
180 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
181 self.executeme = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
182 self.args.sysexe,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
183 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
184 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
185 if self.args.packages:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
186 self.executeme = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
187 self.args.packages.split(",")[0].split(":")[0].strip(),
0183cad9d13b planemo upload
fubar
parents:
diff changeset
188 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
189 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
190 self.executeme = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
191 aXCL = self.xmlcl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
192 self.newtarpath = args.tested_tool_out
0183cad9d13b planemo upload
fubar
parents:
diff changeset
193 self.tinputs = gxtp.Inputs()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
194 self.toutputs = gxtp.Outputs()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
195 self.testparam = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
196 if self.args.script_path:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
197 self.prepScript()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
198 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
199 self.script = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
200 if self.args.cl_override != None:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
201 scos = open(self.args.cl_override, "r").readlines()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
202 self.cl_override = [x.rstrip() for x in scos]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
203 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
204 self.cl_override = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
205 if self.args.test_override != None:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
206 stos = open(self.args.test_override, "r").readlines()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
207 self.test_override = [x.rstrip() for x in stos]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
208 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
209 self.test_override = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
210 if self.args.cl_prefix != None:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
211 scos = open(self.args.cl_prefix, "r").readlines()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
212 self.cl_prefix = [x.rstrip() for x in scos]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
213 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
214 self.cl_prefix = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
215 if self.args.cl_suffix != None:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
216 stos = open(self.args.cl_suffix, "r").readlines()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
217 self.cl_suffix = [x.rstrip() for x in stos]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
218 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
219 self.cl_suffix = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
220 if self.args.script_path:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
221 for ex in self.executeme:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
222 if ex:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
223 aXCL(ex)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
224 aXCL("'$runme'")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
225 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
226 for ex in self.executeme:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
227 aXCL(ex)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
228 if self.args.parampass == "0":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
229 self.clsimple()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
230 elif self.args.parampass == "positional":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
231 self.prepclpos()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
232 self.clpositional()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
233 elif self.args.parampass == "argparse":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
234 self.prepargp()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
235 self.clargparse()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
236 elif self.args.parampass.startswith("embed"):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
237 self.prepembed()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
238 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
239 logging.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
240 "Parampass value %s not in 0, positional, argparse, embed or embednfmod"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
241 % self.args.parampass
0183cad9d13b planemo upload
fubar
parents:
diff changeset
242 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
243 logging.shutdown()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
244 sys.exit(6)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
245
0183cad9d13b planemo upload
fubar
parents:
diff changeset
246 def clsimple(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
247 """no parameters or repeats - uses < and > for i/o"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
248 aXCL = self.xmlcl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
249 if len(self.infiles) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
250 aXCL("<")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
251 aXCL("'$%s'" % self.infiles[0]["infilename"])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
252 if len(self.outfiles) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
253 aXCL(">")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
254 aXCL("'$%s'" % self.outfiles[0]["name"])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
255
0183cad9d13b planemo upload
fubar
parents:
diff changeset
256 def prepembed(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
257 """fix self.script"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
258 scrip = self.script
0183cad9d13b planemo upload
fubar
parents:
diff changeset
259 if self.nfcoremod:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
260 self.script = (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
261 '#set prefix = "%s"\n#set task_process = "%s"\n'
0183cad9d13b planemo upload
fubar
parents:
diff changeset
262 % (self.tool_name, self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
263 + scrip
0183cad9d13b planemo upload
fubar
parents:
diff changeset
264 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
265 self.xmlcl = [] # wipe anything there
0183cad9d13b planemo upload
fubar
parents:
diff changeset
266 aX = self.xmlcl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
267 aX("")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
268 if self.nfcoremod:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
269 aX('#set prefix = "%s"' % self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
270 aX('#set task_process = "%s"' % self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
271 for p in self.collections:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
272 aX("mkdir -p %s &&" % p["name"])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
273 aX("%s '$runme'" % self.args.sysexe)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
274
0183cad9d13b planemo upload
fubar
parents:
diff changeset
275 def prepargp(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
276 xclsuffix = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
277 for i, p in enumerate(self.infiles):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
278 rep = p["required"] in ["optional1", "required1"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
279 req = p["required"] in ["required", "required1"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
280 nam = p["infilename"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
281 flag = p["CL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
282 if p["origCL"].strip().upper() == "STDIN":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
283 xappendme = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
284 nam,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
285 nam,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
286 "< '$%s'" % nam,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
287 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
288 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
289 xappendme = [p["CL"], "'$%s'" % p["CL"], ""]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
290 xclsuffix.append(xappendme)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
291 for i, p in enumerate(self.outfiles):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
292 if p["origCL"].strip().upper() == "STDOUT":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
293 self.lastxclredirect = [">", "'$%s'" % p["name"]]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
294 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
295 xclsuffix.append([p["name"], "'$%s'" % p["name"], ""])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
296 for p in self.addpar:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
297 nam = p["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
298 val = p["value"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
299 flag = p["CL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
300 rep = p.get("repeat", 0) == "1"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
301 if rep:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
302 over = f'#for $rep in $R_{nam}:\n--{nam} "$rep.{nam}"\n#end for'
0183cad9d13b planemo upload
fubar
parents:
diff changeset
303 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
304 over = p.get("override", "")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
305 if p["type"] == "clflag":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
306 over = f'#if ${nam} == "set"\n --{flag}\n#end if'
0183cad9d13b planemo upload
fubar
parents:
diff changeset
307 xclsuffix.append([p["CL"], "'$%s'" % nam, over])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
308 for p in self.selpar:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
309 xclsuffix.append([p["CL"], "'$%s'" % p["name"], p.get("override", "")])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
310 for p in self.selflagpar:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
311 xclsuffix.append(["", "'$%s'" % p["name"], ""])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
312 for p in self.collections:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
313 newname = p["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
314 xclsuffix.append([newname, "'%s'" % newname, ""])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
315 self.xclsuffix = xclsuffix
0183cad9d13b planemo upload
fubar
parents:
diff changeset
316
0183cad9d13b planemo upload
fubar
parents:
diff changeset
317 def prepclpos(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
318 xclsuffix = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
319 for i, p in enumerate(self.infiles):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
320 if p["origCL"].strip().upper() == "STDIN":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
321 xappendme = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
322 "999",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
323 p["infilename"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
324 "< '$%s'" % p["infilename"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
325 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
326 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
327 xappendme = [p["CL"], "'$%s'" % p["infilename"], ""]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
328 xclsuffix.append(xappendme)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
329 for i, p in enumerate(self.outfiles):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
330 if p["origCL"].strip().upper() == "STDOUT":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
331 self.lastxclredirect = [">", "'$%s'" % p["name"]]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
332 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
333 xclsuffix.append([p["CL"], "'$%s'" % p["name"], ""])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
334 for p in self.addpar:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
335 nam = p["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
336 rep = p.get("repeat", "0") == "1" # repeats make NO sense
0183cad9d13b planemo upload
fubar
parents:
diff changeset
337 if rep:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
338 logger.warning(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
339 f"### warning. Repeats for {nam} ignored - not permitted in positional parameter command lines!"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
340 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
341 over = p.get("override", "")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
342 xclsuffix.append([p["CL"], "'$%s'" % nam, over])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
343 for p in self.selpar:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
344 xclsuffix.append([p["CL"], "'$%s'" % p["name"], p.get("override", "")])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
345 for p in self.selflagpar:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
346 xclsuffix.append(["", "'$%s'" % p["name"], ""])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
347 for p in self.collections:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
348 newname = p["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
349 xclsuffix.append([newname, "'$%s'" % newname, ""])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
350 xclsuffix.sort()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
351 self.xclsuffix = xclsuffix
0183cad9d13b planemo upload
fubar
parents:
diff changeset
352
0183cad9d13b planemo upload
fubar
parents:
diff changeset
353 def prepScript(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
354 s = open(self.args.script_path, "r").read()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
355 ss = s.split("\n")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
356 rxcheck = [x for x in ss if x.strip() > ""]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
357 assert len(rxcheck) > 0, "Supplied script is empty. Cannot run"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
358 if self.args.sysexe and self.args.parampass != "embed":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
359 rxcheck.insert(0, "#raw")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
360 rxcheck.append("#end raw")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
361 self.script = "\n".join(rxcheck)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
362 if len(self.executeme) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
363 self.sfile = os.path.join(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
364 self.repdir, "%s.%s.txt" % (self.tool_name, self.executeme[0])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
365 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
366 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
367 self.sfile = os.path.join(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
368 self.repdir, "%s.script.txt" % (self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
369 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
370 tscript = open(self.sfile, "w")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
371 tscript.write(self.script)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
372 tscript.write("\n")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
373 tscript.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
374 self.spacedScript = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
375 f" {x.replace('${','$ {')}" for x in ss if x.strip() > ""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
376 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
377 self.escapedScript = rxcheck
0183cad9d13b planemo upload
fubar
parents:
diff changeset
378
0183cad9d13b planemo upload
fubar
parents:
diff changeset
379 def cleanuppar(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
380 """positional parameters are complicated by their numeric ordinal"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
381 if self.args.parampass == "positional":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
382 for i, p in enumerate(self.infiles):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
383 assert (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
384 p["CL"].isdigit() or p["CL"].strip().upper() == "STDIN"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
385 ), "Positional parameters must be ordinal integers - got %s for %s" % (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
386 p["CL"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
387 p["label"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
388 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
389 for i, p in enumerate(self.outfiles):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
390 assert (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
391 p["CL"].isdigit() or p["CL"].strip().upper() == "STDOUT"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
392 ), "Positional parameters must be ordinal integers - got %s for %s" % (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
393 p["CL"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
394 p["name"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
395 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
396 for i, p in enumerate(self.addpar):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
397 assert p[
0183cad9d13b planemo upload
fubar
parents:
diff changeset
398 "CL"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
399 ].isdigit(), "Positional parameters must be ordinal integers - got %s for %s" % (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
400 p["CL"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
401 p["name"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
402 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
403 for i, p in enumerate(self.infiles):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
404 infp = copy.copy(p)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
405 infp["origCL"] = infp["CL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
406 if self.args.parampass in ["positional", "0"]:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
407 infp["infilename"] = infp["label"].replace(" ", "_")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
408 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
409 infp["infilename"] = infp["CL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
410 self.infiles[i] = infp
0183cad9d13b planemo upload
fubar
parents:
diff changeset
411 for i, p in enumerate(self.outfiles):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
412 outfp = copy.copy(p)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
413 outfp["origCL"] = outfp["CL"] # keep copy
0183cad9d13b planemo upload
fubar
parents:
diff changeset
414 if outfp.get("label", None) == None:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
415 outfp["label"] = ""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
416 self.outfiles[i] = outfp
0183cad9d13b planemo upload
fubar
parents:
diff changeset
417 for i, p in enumerate(self.addpar):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
418 addp = copy.copy(p)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
419 addp["origCL"] = addp["CL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
420 self.addpar[i] = addp
0183cad9d13b planemo upload
fubar
parents:
diff changeset
421 for i, p in enumerate(self.collections):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
422 addp = copy.copy(p)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
423 addp["CL"] = addp["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
424 self.collections[i] = addp
0183cad9d13b planemo upload
fubar
parents:
diff changeset
425
0183cad9d13b planemo upload
fubar
parents:
diff changeset
426 def clpositional(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
427 # inputs in order then params
0183cad9d13b planemo upload
fubar
parents:
diff changeset
428 aXCL = self.xmlcl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
429 for (k, v, koverride) in self.xclsuffix:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
430 aXCL(v)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
431 if self.lastxclredirect:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
432 for cl in self.lastxclredirect:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
433 aXCL(cl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
434
0183cad9d13b planemo upload
fubar
parents:
diff changeset
435 def clargparse(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
436 """argparse style"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
437 aXCL = self.xmlcl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
438 # inputs then params in argparse named form
0183cad9d13b planemo upload
fubar
parents:
diff changeset
439 for (k, v, koverride) in self.xclsuffix:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
440 if koverride > "":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
441 k = koverride
0183cad9d13b planemo upload
fubar
parents:
diff changeset
442 aXCL(k)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
443 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
444 kl = len(k.strip())
0183cad9d13b planemo upload
fubar
parents:
diff changeset
445 if kl == 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
446 k = " "
0183cad9d13b planemo upload
fubar
parents:
diff changeset
447 elif kl == 1:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
448 k = "-%s" % k
0183cad9d13b planemo upload
fubar
parents:
diff changeset
449 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
450 k = "--%s" % k
0183cad9d13b planemo upload
fubar
parents:
diff changeset
451 aXCL(k)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
452 aXCL(v)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
453 if self.lastxclredirect:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
454 for cl in self.lastxclredirect:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
455 aXCL(cl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
456
0183cad9d13b planemo upload
fubar
parents:
diff changeset
457 def getNdash(self, newname):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
458 if self.is_positional:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
459 ndash = 0
0183cad9d13b planemo upload
fubar
parents:
diff changeset
460 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
461 ndash = 2
0183cad9d13b planemo upload
fubar
parents:
diff changeset
462 if len(newname) < 2:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
463 ndash = 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
464 return ndash
0183cad9d13b planemo upload
fubar
parents:
diff changeset
465
0183cad9d13b planemo upload
fubar
parents:
diff changeset
466 def doXMLparam(self): # noqa
0183cad9d13b planemo upload
fubar
parents:
diff changeset
467 """Add all needed elements to tool"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
468 for p in self.outfiles:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
469 newname = p["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
470 newfmt = p["format"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
471 newcl = p["CL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
472 test = p["test"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
473 oldcl = p["origCL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
474 test = test.strip()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
475 filta = p.get("when", [])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
476 lab = p.get("label", "")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
477 if len(lab.strip()) == 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
478 lab = newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
479 ndash = self.getNdash(newcl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
480 aparm = gxtp.OutputData(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
481 name=newname, format=newfmt, num_dashes=ndash, label=lab
0183cad9d13b planemo upload
fubar
parents:
diff changeset
482 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
483 if len(filta) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
484 ofilta = gxtp.ChangeFormat()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
485 for (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
486 whens
0183cad9d13b planemo upload
fubar
parents:
diff changeset
487 ) in filta: # when input=|image_type| value=|large_png| format=|png|
0183cad9d13b planemo upload
fubar
parents:
diff changeset
488 whenss = whens.replace("|", '"').replace("when ", "")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
489 clauses = whenss.split()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
490 for c in clauses:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
491 if c.startswith("value"):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
492 v = c.split("=")[1]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
493 elif c.startswith("format"):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
494 f = c.split("=")[1]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
495 elif c.startswith("input"):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
496 i = c.split("=")[1]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
497 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
498 print(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
499 "bad when - need value=, format= and input=, got", whens
0183cad9d13b planemo upload
fubar
parents:
diff changeset
500 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
501 owhen = gxtp.ChangeFormatWhen(format=f, input=i, value=v)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
502 ofilta.append(owhen)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
503 aparm.append(ofilta)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
504 aparm.positional = self.is_positional
0183cad9d13b planemo upload
fubar
parents:
diff changeset
505 if self.is_positional:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
506 if oldcl.upper() == "STDOUT":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
507 aparm.positional = 9999999
0183cad9d13b planemo upload
fubar
parents:
diff changeset
508 aparm.command_line_override = "> '$%s'" % newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
509 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
510 aparm.positional = int(oldcl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
511 aparm.command_line_override = "'$%s'" % newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
512 self.toutputs.append(aparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
513 ld = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
514 if test.strip() > "":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
515 if test.strip().startswith("diff"):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
516 c = "diff"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
517 ld = 0
0183cad9d13b planemo upload
fubar
parents:
diff changeset
518 if test.split(":")[1].isdigit:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
519 ld = int(test.split(":")[1])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
520 tp = gxtp.TestOutput(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
521 name=newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
522 value="%s_sample" % newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
523 compare=c,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
524 lines_diff=ld,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
525 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
526 elif test.startswith("sim_size"):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
527 c = "sim_size"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
528 tn = test.split(":")[1].strip()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
529 if tn > "":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
530 if "." in tn:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
531 delta = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
532 delta_frac = min(1.0, float(tn))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
533 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
534 delta = int(tn)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
535 delta_frac = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
536 tp = gxtp.TestOutput(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
537 name=newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
538 value="%s_sample" % newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
539 compare=c,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
540 delta=delta,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
541 delta_frac=delta_frac,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
542 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
543 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
544 c = test
0183cad9d13b planemo upload
fubar
parents:
diff changeset
545 tp = gxtp.TestOutput(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
546 name=newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
547 value="%s_sample" % newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
548 compare=c,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
549 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
550 self.testparam.append(tp)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
551 for p in self.infiles:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
552 newname = p["infilename"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
553 newfmt = p["format"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
554 ndash = self.getNdash(newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
555 reps = p.get("required", "") in ["optional1", "required1"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
556 isoptional = p.get("required", "") in ["optional", "optional1"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
557 if not len(p["label"]) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
558 alab = p["CL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
559 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
560 alab = p["label"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
561 aninput = gxtp.DataParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
562 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
563 optional=isoptional,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
564 label=alab,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
565 help=p["help"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
566 format=newfmt,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
567 multiple=reps,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
568 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
569 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
570 aninput.positional = self.is_positional
0183cad9d13b planemo upload
fubar
parents:
diff changeset
571 if self.is_positional:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
572 if p["origCL"].upper() == "STDIN":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
573 aninput.positional = 9999998
0183cad9d13b planemo upload
fubar
parents:
diff changeset
574 aninput.command_line_override = "< '$%s'" % newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
575 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
576 aninput.positional = int(p["origCL"])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
577 aninput.command_line_override = "'$%s'" % newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
578 self.tinputs.append(aninput)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
579 tparm = gxtp.TestParam(newname, value="%s_sample" % newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
580 self.testparam.append(tparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
581 for p in self.addpar:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
582 newname = p["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
583 newval = p.get("value", "")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
584 newlabel = p["label"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
585 newhelp = p.get("help", "")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
586 newtype = p.get("type", "?")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
587 newcl = p["CL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
588 oldcl = p["origCL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
589 reps = p.get("repeat", "0") == "1"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
590 if not len(newlabel) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
591 newlabel = newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
592 ndash = self.getNdash(newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
593 if newtype == "text":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
594 aparm = gxtp.TextParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
595 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
596 label=newlabel,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
597 help=newhelp,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
598 value=newval,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
599 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
600 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
601 elif newtype == "integer":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
602 aparm = gxtp.IntegerParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
603 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
604 label=newlabel,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
605 help=newhelp,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
606 value=int(newval.replace("'", "").replace('"', "")),
0183cad9d13b planemo upload
fubar
parents:
diff changeset
607 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
608 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
609 elif newtype == "float":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
610 aparm = gxtp.FloatParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
611 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
612 label=newlabel,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
613 help=newhelp,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
614 value=float(newval.replace("'", "").replace('"', "")),
0183cad9d13b planemo upload
fubar
parents:
diff changeset
615 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
616 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
617 elif newtype == "boolean":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
618 aparm = gxtp.BooleanParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
619 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
620 label=newlabel,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
621 help=newhelp,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
622 value=newval,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
623 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
624 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
625 elif newtype == "clflag":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
626 initval = newval
0183cad9d13b planemo upload
fubar
parents:
diff changeset
627 aparm = gxtp.SelectParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
628 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
629 label=newlabel,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
630 help=newhelp,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
631 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
632 display="radio",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
633 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
634 anoptt = gxtp.SelectOption(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
635 value="set",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
636 text="Set this flag",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
637 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
638 anoptf = gxtp.SelectOption(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
639 value="notset",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
640 text="Do not set this flag",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
641 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
642 if p["value"] == "set": # make default same as form
0183cad9d13b planemo upload
fubar
parents:
diff changeset
643 aparm.append(anoptt)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
644 aparm.append(anoptf)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
645 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
646 aparm.append(anoptf)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
647 aparm.append(anoptt)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
648 elif newtype == "datacolumn":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
649 aparm = gxtp.TextParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
650 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
651 type="data_column",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
652 data_ref=p["dataref"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
653 multiple=(p["multiple"] == "1"),
0183cad9d13b planemo upload
fubar
parents:
diff changeset
654 label=newlabel,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
655 help=newhelp,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
656 value=newval,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
657 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
658 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
659 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
660 raise ValueError(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
661 'Unrecognised parameter type "%s" for \
0183cad9d13b planemo upload
fubar
parents:
diff changeset
662 additional parameter %s in makeXML'
0183cad9d13b planemo upload
fubar
parents:
diff changeset
663 % (newtype, newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
664 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
665 aparm.positional = self.is_positional
0183cad9d13b planemo upload
fubar
parents:
diff changeset
666 if self.is_positional:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
667 aparm.positional = int(oldcl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
668 if reps:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
669 repe = gxtp.Repeat(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
670 name=f"R_{newname}",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
671 title=f"Any number of {newlabel} repeats are allowed",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
672 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
673 repe.append(aparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
674 self.tinputs.append(repe)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
675 tparm = gxtp.TestRepeat(name=f"R_{newname}")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
676 tparm2 = gxtp.TestParam(newname, value=newval)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
677 tparm.append(tparm2)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
678 self.testparam.append(tparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
679 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
680 self.tinputs.append(aparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
681 tparm = gxtp.TestParam(newname, value=newval)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
682 self.testparam.append(tparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
683 for p in self.selpar:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
684 newname = p["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
685 newval = p.get("value", "")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
686 newlabel = p["label"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
687 newhelp = p["help"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
688 newtype = p["type"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
689 newcl = p["CL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
690 if not len(newlabel) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
691 newlabel = newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
692 ndash = self.getNdash(newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
693 if newtype == "selecttext":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
694 newtext = p["texts"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
695 aparm = gxtp.SelectParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
696 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
697 label=newlabel,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
698 help=newhelp,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
699 num_dashes=ndash,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
700 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
701 for i in range(len(newval)):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
702 anopt = gxtp.SelectOption(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
703 value=newval[i],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
704 text=newtext[i],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
705 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
706 aparm.append(anopt)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
707 aparm.positional = self.is_positional
0183cad9d13b planemo upload
fubar
parents:
diff changeset
708 if self.is_positional:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
709 aparm.positional = int(newcl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
710 self.tinputs.append(aparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
711 tparm = gxtp.TestParam(newname, value=newval[0])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
712 self.testparam.append(tparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
713 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
714 raise ValueError(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
715 'Unrecognised parameter type "%s" for\
0183cad9d13b planemo upload
fubar
parents:
diff changeset
716 selecttext parameter %s in makeXML'
0183cad9d13b planemo upload
fubar
parents:
diff changeset
717 % (newtype, newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
718 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
719 for p in self.selflagpar:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
720 newname = p["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
721 newval = p["value"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
722 newlabel = p["label"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
723 newhelp = p["help"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
724 newtype = p["type"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
725 newtext = p["texts"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
726 newcl = p["CL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
727 if not len(newlabel) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
728 newlabel = newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
729 aparm = gxtp.SelectParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
730 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
731 label=newlabel,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
732 help=newhelp,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
733 num_dashes=0,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
734 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
735 for i in range(len(newval)):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
736 anopt = gxtp.SelectOption(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
737 value=newval[i],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
738 text=newtext[i],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
739 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
740 aparm.append(anopt)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
741 aparm.positional = self.is_positional
0183cad9d13b planemo upload
fubar
parents:
diff changeset
742 if self.is_positional:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
743 aparm.positional = int(newcl)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
744 self.tinputs.append(aparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
745 tparm = gxtp.TestParam(newname, value=newval[0])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
746 self.testparam.append(tparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
747
0183cad9d13b planemo upload
fubar
parents:
diff changeset
748 def doNoXMLparam(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
749 """filter style package - stdin to stdout"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
750 if len(self.infiles) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
751 alab = self.infiles[0]["label"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
752 if len(alab) == 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
753 alab = self.infiles[0]["infilename"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
754 max1s = (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
755 "Maximum one input if parampass is 0 but multiple input files supplied - %s"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
756 % str(self.infiles)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
757 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
758 assert len(self.infiles) == 1, max1s
0183cad9d13b planemo upload
fubar
parents:
diff changeset
759 newname = self.infiles[0]["infilename"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
760 aninput = gxtp.DataParam(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
761 newname,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
762 optional=False,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
763 label=alab,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
764 help=self.infiles[0]["help"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
765 format=self.infiles[0]["format"],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
766 multiple=False,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
767 num_dashes=0,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
768 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
769 aninput.command_line_override = "< $%s" % newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
770 aninput.positional = True
0183cad9d13b planemo upload
fubar
parents:
diff changeset
771 self.tinputs.append(aninput)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
772 tp = gxtp.TestParam(name=newname, value="%s_sample" % newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
773 self.testparam.append(tp)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
774 if len(self.outfiles) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
775 newname = self.outfiles[0]["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
776 newfmt = self.outfiles[0]["format"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
777 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
778 anout.command_line_override = "> $%s" % newname
0183cad9d13b planemo upload
fubar
parents:
diff changeset
779 anout.positional = self.is_positional
0183cad9d13b planemo upload
fubar
parents:
diff changeset
780 self.toutputs.append(anout)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
781 tp = gxtp.TestOutput(name=newname, value="%s_sample" % newname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
782 self.testparam.append(tp)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
783
0183cad9d13b planemo upload
fubar
parents:
diff changeset
784 def makeXML(self): # noqa
0183cad9d13b planemo upload
fubar
parents:
diff changeset
785 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
786 Create a Galaxy xml tool wrapper for the new script
0183cad9d13b planemo upload
fubar
parents:
diff changeset
787 Uses galaxyhtml
0183cad9d13b planemo upload
fubar
parents:
diff changeset
788 Hmmm. How to get the command line into correct order...
0183cad9d13b planemo upload
fubar
parents:
diff changeset
789 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
790 requirements = gxtp.Requirements()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
791 self.condaenv = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
792 if self.args.packages:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
793 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
794 for d in self.args.packages.split(","):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
795 ver = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
796 packg = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
797 d = d.replace("==", ":")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
798 d = d.replace("=", ":")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
799 if ":" in d:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
800 packg, ver = d.split(":")[:2]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
801 ver = ver.strip()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
802 packg = packg.strip()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
803 self.tool_version = ver
0183cad9d13b planemo upload
fubar
parents:
diff changeset
804 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
805 packg = d.strip()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
806 ver = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
807 if ver == "":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
808 ver = None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
809 if packg:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
810 requirements.append(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
811 gxtp.Requirement("package", packg.strip(), ver)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
812 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
813 self.condaenv.append(d)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
814 except Exception:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
815 self.logger.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
816 "### malformed packages string supplied - cannot parse = %s"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
817 % self.args.packages
0183cad9d13b planemo upload
fubar
parents:
diff changeset
818 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
819 sys.exit(2)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
820 elif self.args.container:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
821 requirements.append(gxtp.Requirement("container", self.args.container))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
822 self.newtool = gxt.Tool(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
823 self.tool_name,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
824 self.tool_id,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
825 self.tool_version,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
826 self.args.tool_desc,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
827 "",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
828 profile=self.profile,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
829 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
830 self.newtool.requirements = requirements
0183cad9d13b planemo upload
fubar
parents:
diff changeset
831 iXCL = self.xmlcl.insert
0183cad9d13b planemo upload
fubar
parents:
diff changeset
832 aXCL = self.xmlcl.append
0183cad9d13b planemo upload
fubar
parents:
diff changeset
833 if self.args.cl_prefix: # DIY CL start
0183cad9d13b planemo upload
fubar
parents:
diff changeset
834 self.xmlcl = self.cl_prefix + self.xmlcl
0183cad9d13b planemo upload
fubar
parents:
diff changeset
835 if self.args.cl_suffix: # DIY CL end
0183cad9d13b planemo upload
fubar
parents:
diff changeset
836 self.xmlcl += self.cl_suffix
0183cad9d13b planemo upload
fubar
parents:
diff changeset
837 if self.cl_override:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
838 self.newtool.command_override = self.cl_override # config file
0183cad9d13b planemo upload
fubar
parents:
diff changeset
839 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
840 self.newtool.command_override = self.xmlcl
0183cad9d13b planemo upload
fubar
parents:
diff changeset
841 self.cites = self.parse_citations()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
842 cite = gxtp.Citations()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
843 if self.cites and len(self.cites) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
844 for c in self.cites:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
845 acite = gxtp.Citation(type=c[0], value=c[1])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
846 cite.append(acite)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
847 acite = gxtp.Citation(type="doi", value="10.1093/bioinformatics/bts573")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
848 cite.append(acite)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
849 self.newtool.citations = cite
0183cad9d13b planemo upload
fubar
parents:
diff changeset
850 safertext = ""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
851 if self.args.help_text:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
852 self.helptext = open(self.args.help_text, "r").readlines()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
853 safertext = "\n".join([self.cheetah_escape(x) for x in self.helptext])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
854 if len(safertext.strip()) == 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
855 safertext = (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
856 "Ask the tool author (%s) to rebuild with help text please\n"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
857 % (self.args.user_email)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
858 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
859 if self.script_in_help and self.args.script_path:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
860 if len(safertext) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
861 safertext = safertext + "\n\n------\n" # transition allowed!
0183cad9d13b planemo upload
fubar
parents:
diff changeset
862 scr = [x for x in self.spacedScript if x.strip() > ""]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
863 scr.insert(0, "\n\nScript::\n")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
864 if len(scr) > 300:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
865 scr = (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
866 scr[:100]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
867 + [" >300 lines - stuff deleted", " ......"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
868 + scr[-100:]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
869 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
870 scr.append("\n")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
871 safertext = safertext + "\n".join(scr)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
872 self.newtool.help = " ".join(self.helptext)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
873 for p in self.collections:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
874 newkind = p["kind"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
875 newname = p["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
876 newlabel = p["label"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
877 newdisc = p["discover"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
878 collect = gxtp.OutputCollection(newname, label=newlabel, type=newkind)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
879 disc = gxtp.DiscoverDatasets(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
880 pattern=newdisc, directory=f"{newname}", visible="false"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
881 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
882 collect.append(disc)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
883 self.toutputs.append(collect)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
884 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
885 tparm = gxtp.TestOutputCollection(newname) # broken until PR merged.
0183cad9d13b planemo upload
fubar
parents:
diff changeset
886 self.testparam.append(tparm)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
887 except Exception:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
888 logging.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
889 "WARNING: Galaxyxml version does not have the PR merged yet - tests for collections must be over-ridden until then!"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
890 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
891 self.newtool.version_command = f'echo "{self.tool_version}"'
0183cad9d13b planemo upload
fubar
parents:
diff changeset
892 if self.args.parampass == "0":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
893 self.doNoXMLparam()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
894 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
895 self.doXMLparam()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
896 self.newtool.outputs = self.toutputs
0183cad9d13b planemo upload
fubar
parents:
diff changeset
897 self.newtool.inputs = self.tinputs
0183cad9d13b planemo upload
fubar
parents:
diff changeset
898 if self.args.script_path:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
899 configfiles = gxtp.Configfiles()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
900 configfiles.append(gxtp.Configfile(name="runme", text=self.script))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
901 self.newtool.configfiles = configfiles
0183cad9d13b planemo upload
fubar
parents:
diff changeset
902 tests = gxtp.Tests()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
903 test_a = gxtp.Test()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
904 for tp in self.testparam:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
905 test_a.append(tp)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
906 tests.append(test_a)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
907 self.newtool.tests = tests
0183cad9d13b planemo upload
fubar
parents:
diff changeset
908 self.newtool.add_comment(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
909 "Created by %s at %s using the Galaxy Tool Factory."
0183cad9d13b planemo upload
fubar
parents:
diff changeset
910 % (self.args.user_email, self.timenow())
0183cad9d13b planemo upload
fubar
parents:
diff changeset
911 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
912 self.newtool.add_comment("Source in git at: %s" % (self.toolFactoryURL))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
913 exml = self.newtool.export()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
914 if (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
915 self.test_override
0183cad9d13b planemo upload
fubar
parents:
diff changeset
916 ): # cannot do this inside galaxyxml as it expects lxml objects for tests
0183cad9d13b planemo upload
fubar
parents:
diff changeset
917 part1 = exml.split("<tests>")[0]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
918 part2 = exml.split("</tests>")[1]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
919 fixed = "%s\n%s\n%s" % (part1, "\n".join(self.test_override), part2)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
920 exml = fixed
0183cad9d13b planemo upload
fubar
parents:
diff changeset
921 with open(os.path.join(self.toold, "%s.xml" % self.tool_name), "w") as xf:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
922 xf.write(exml)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
923 xf.write("\n")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
924 with open(os.path.join(self.repdir, "%s_xml.xml" % self.tool_name), "w") as xf:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
925 xf.write(exml)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
926 xf.write("\n")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
927
0183cad9d13b planemo upload
fubar
parents:
diff changeset
928 def writeShedyml(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
929 """for planemo"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
930 yuser = self.args.user_email.split("@")[0]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
931 yfname = os.path.join(self.toold, ".shed.yml")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
932 yamlf = open(yfname, "w")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
933 odict = {
0183cad9d13b planemo upload
fubar
parents:
diff changeset
934 "name": self.tool_name,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
935 "owner": "fubar2",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
936 "type": "unrestricted",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
937 "description": "ToolFactory autogenerated tool",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
938 "synopsis": self.args.tool_desc,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
939 "category": "ToolFactory generated Tools",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
940 }
0183cad9d13b planemo upload
fubar
parents:
diff changeset
941 yaml.dump(odict, yamlf, allow_unicode=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
942 yamlf.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
943
0183cad9d13b planemo upload
fubar
parents:
diff changeset
944 def writeTFyml(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
945 """for posterity"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
946 adict = {}
0183cad9d13b planemo upload
fubar
parents:
diff changeset
947 rargs = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
948 "input_files",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
949 "output_files",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
950 "additional_parameters",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
951 "selecttext_parameters",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
952 "selectflag_parameters",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
953 "xtra_files",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
954 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
955 args = vars(self.args)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
956 for k in args.keys():
0183cad9d13b planemo upload
fubar
parents:
diff changeset
957 if k not in rargs:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
958 adict[k] = args.get(k, None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
959 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
960 if adict.get(k, None):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
961 adict[k].append(adict[k])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
962 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
963 adict[k] = [args.get(k, None)]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
964 adict["script"] = self.script
0183cad9d13b planemo upload
fubar
parents:
diff changeset
965 adict["help"] = self.helptext
0183cad9d13b planemo upload
fubar
parents:
diff changeset
966 yfname = os.path.join(self.repdir, "%s_ToolFactory.yml" % self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
967 yf = open(yfname, "w")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
968 yaml.dump(adict, yf)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
969 yf.close()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
970
0183cad9d13b planemo upload
fubar
parents:
diff changeset
971 def saveTestdata(self, pname, testDataURL):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
972 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
973 may need to be ungzipped and in test folder
0183cad9d13b planemo upload
fubar
parents:
diff changeset
974 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
975 res = 0
0183cad9d13b planemo upload
fubar
parents:
diff changeset
976 localpath = os.path.join(self.tooltestd, "%s_sample" % pname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
977 print("#### save", testDataURL, "for", pname, "to", localpath)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
978 if not os.path.exists(localpath):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
979 cl = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
980 "wget",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
981 "--timeout",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
982 "5",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
983 "--tries",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
984 "2",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
985 "-O",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
986 localpath,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
987 testDataURL,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
988 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
989 if testDataURL.endswith(".gz"): # major kludge as usual...
0183cad9d13b planemo upload
fubar
parents:
diff changeset
990 gzlocalpath = "%s.gz" % localpath
0183cad9d13b planemo upload
fubar
parents:
diff changeset
991 cl = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
992 "wget",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
993 "-q",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
994 "--timeout",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
995 "5",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
996 "--tries",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
997 "2",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
998 "-O",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
999 gzlocalpath,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1000 testDataURL,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1001 "&&",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1002 "rm",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1003 "-f",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1004 localpath,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1005 "&&",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1006 "gunzip",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1007 gzlocalpath,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1008 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1009 p = subprocess.run(" ".join(cl), shell=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1010 if p.returncode:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1011 print("Got", p.returncode, "from executing", " ".join(cl))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1012 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1013 print("Not re-downloading", localpath)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1014 return res
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1015
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1016 def makeTool(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1017 """write xmls and input samples into place"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1018 if self.args.parampass == 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1019 self.doNoXMLparam()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1020 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1021 self.makeXML()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1022 if self.args.script_path and self.not_iuc:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1023 stname = os.path.join(self.toold, os.path.split(self.sfile)[1])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1024 if not os.path.exists(stname):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1025 shutil.copyfile(self.sfile, stname)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1026 logger.info("Copied %s to %s" % (self.sfile, stname))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1027 for p in self.infiles:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1028 paths = p["name"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1029 pname = p["CL"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1030 pathss = paths.split(",")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1031 np = len(pathss)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1032 if p.get("URL", None):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1033 res = self.saveTestdata(pname, p["URL"])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1034 for i, pth in enumerate(pathss):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1035 if os.path.exists(pth):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1036 if np > 1:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1037 dest = os.path.join(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1038 self.tooltestd, "%s_%d_sample" % (p["infilename"], i + 1)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1039 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1040 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1041 dest = os.path.join(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1042 self.tooltestd, "%s_sample" % p["infilename"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1043 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1044 shutil.copyfile(pth, dest)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1045 logger.info("Copied %s to %s" % (pth, dest))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1046 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1047 logger.info(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1048 "Optional input path %s does not exist - not copied" % pth
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1049 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1050 if self.extra_files and len(self.extra_files) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1051 for xtra in self.extra_files:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1052 fpath = xtra["fpath"]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1053 dest = os.path.join(self.toold, xtra["fname"])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1054 shutil.copyfile(fpath, dest)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1055 logger.info("Copied xtra file %s to %s" % (fpath, dest))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1056 shutil.copytree(self.toold, self.testdir, dirs_exist_ok=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1057
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1058 def makeToolTar(self, test_retcode=0):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1059 """move outputs into test-data and prepare the tarball"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1060 excludeme = "tool_test_output"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1061
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1062 def exclude_function(tarinfo):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1063 filename = tarinfo.name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1064 return None if filename.startswith(excludeme) else tarinfo
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1065
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1066 logger.info("makeToolTar starting with tool test retcode=%d\n" % test_retcode)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1067 td = os.listdir(self.toold)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1068 for f in td:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1069 if f.startswith("tool_test_output"):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1070 os.unlink(os.path.join(self.toold, f))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1071 if self.newtarpath:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1072 tf = tarfile.open(self.newtarpath, "w:gz")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1073 tf.add(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1074 name=self.toold,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1075 arcname=self.tool_name,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1076 # filter=exclude_function,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1077 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1078
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1079 def planemo_local_test(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1080 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1081 weird legacyversion error popping up again from package version upgrade in conda_util.py in the venv.
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1082 Seems ok if run as a shell script using the Galaxy installed planemo august 1st 2023
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1083 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1084 shutil.copytree(self.toold, self.testdir, dirs_exist_ok=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1085 x = "%s.xml" % self.tool_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1086 xout = os.path.abspath(os.path.join(self.testdir, x))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1087 cl = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1088 "planemo",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1089 "test",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1090 "--galaxy_admin_key",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1091 self.GALAXY_ADMIN_KEY,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1092 "--engine",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1093 "external_galaxy",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1094 "--update_test_data",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1095 "--galaxy_url",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1096 self.GALAXY_URL,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1097 xout,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1098 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1099 clx = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1100 "planemo",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1101 "test",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1102 "--galaxy_admin_key",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1103 "[GALAXY_ADMIN_KEY]",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1104 "--engine",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1105 "external_galaxy",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1106 "--update_test_data",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1107 "--galaxy_url",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1108 self.GALAXY_URL,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1109 xout,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1110 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1111 logger.info("planemo_local_test executing: %s" % " ".join(clx))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1112 p = subprocess.run(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1113 " ".join(cl),
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1114 timeout=90,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1115 shell=True,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1116 cwd=self.testdir,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1117 capture_output=True,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1118 check=True,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1119 text=True,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1120 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1121 for errline in p.stderr.splitlines():
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1122 logger.info("planemo: %s" % errline)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1123 for errline in p.stdout.splitlines():
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1124 logger.info("planemo: %s" % errline)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1125 shutil.copytree(self.testdir, self.toold)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1126 dest = self.repdir
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1127 src = self.tooltestd
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1128 logger.info("copying to %s to %s test_outs" % (src, dest))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1129 shutil.copytree(src, dest, dirs_exist_ok=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1130 return p.returncode
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1131
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1132 def fast_local_test(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1133 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1134 galaxy-tool-test -u http://localhost:8080 -a 1613612977827175424 -t tacrev -o local --publish-history
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1135 Seems to have a race condition when multiple jobs running. Works well - 15 secs or so if only onejob at a time! so job_conf fixed.
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1136 Failure will eventually get stuck. Might need a timeout in the script
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1137 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1138 scrpt = os.path.join(self.args.toolfactory_dir, "toolfactory_fast_test.sh")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1139 extrapaths = self.tooltestd
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1140 cl = ["/usr/bin/bash", scrpt, self.tool_name, extrapaths, extrapaths]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1141 logger.info("fast_local_test executing %s \n" % (" ".join(cl)))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1142 p = subprocess.run(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1143 " ".join(cl),
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1144 shell=True,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1145 cwd=self.testdir,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1146 capture_output=True,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1147 check=True,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1148 text=True,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1149 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1150 for errline in p.stderr.splitlines():
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1151 logger.info("ephemeris: %s" % errline)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1152 for errline in p.stdout.splitlines():
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1153 logger.info("ephemeris: %s" % errline)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1154 shutil.copytree(self.testdir, self.toold, dirs_exist_ok=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1155 dest = self.repdir
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1156 src = self.tooltestd
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1157 shutil.copytree(src, dest, dirs_exist_ok=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1158 return p.returncode
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1159
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1160 def update_toolconf(self, remove=False):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1161 """tempting to recreate it from the local_tools directory each time
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1162 currently adds new tools if not there.
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1163 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1164
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1165 def sortchildrenby(parent, attr):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1166 parent[:] = sorted(parent, key=lambda child: child.get(attr))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1167
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1168 logger.info("Updating tool conf files for %s\n" % (self.tool_name))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1169 tcpath = self.local_tool_conf
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1170 xmlfile = os.path.join(self.tool_name, "%s.xml" % self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1171 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1172 parser = ET.XMLParser(remove_blank_text=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1173 tree = ET.parse(tcpath, parser)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1174 except ET.XMLSyntaxError:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1175 logger.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1176 "### Tool configuration update access error - %s cannot be parsed as xml by element tree\n"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1177 % tcpath
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1178 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1179 sys.exit(4)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1180 root = tree.getroot()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1181 hasTF = False
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1182 e = root.findall("section")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1183 if len(e) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1184 hasTF = True
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1185 TFsection = e[0]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1186 if not hasTF:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1187 TFsection = ET.Element(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1188 "section", {"id": "localtools", "name": "Local Tools"}
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1189 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1190 root.insert(0, TFsection) # at the top!
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1191 our_tools = TFsection.findall("tool")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1192 conf_tools = [x.attrib["file"] for x in our_tools]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1193 if not remove:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1194 if xmlfile not in conf_tools: # new
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1195 ET.SubElement(TFsection, "tool", {"file": xmlfile})
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1196 sortchildrenby(TFsection, "file")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1197 tree.write(tcpath, pretty_print=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1198 gi = galaxy.GalaxyInstance(url=self.GALAXY_URL, key=self.GALAXY_ADMIN_KEY)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1199 toolready = False
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1200 now = time.time()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1201 nloop = 5
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1202 while nloop >= 0 and not toolready:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1203 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1204 res = gi.tools.show_tool(tool_id=self.tool_name)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1205 toolready = True
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1206 logger.info(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1207 "Tool %s ready after %f seconds - %s\n"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1208 % (self.tool_name, time.time() - now, res)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1209 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1210 except ConnectionError:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1211 nloop -= 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1212 time.sleep(2)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1213 logger.info("Connection error - waiting 2 seconds.\n")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1214 if nloop < 1:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1215 logger.error(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1216 "Tool %s still not ready after %f seconds - please check the form and the generated xml for errors? \n"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1217 % (self.tool_name, time.time() - now)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1218 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1219 return 2
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1220 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1221 return 0
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1222 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1223 if xmlfile in conf_tools: # remove
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1224 for rem in our_tools:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1225 if rem.attrib["file"] == xmlfile:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1226 rem.getparent().remove(rem)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1227 self.logger.info(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1228 "###=============== removed tool %s from %s"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1229 % (xmlfile, tcpath)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1230 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1231 sortchildrenby(TFsection, "file")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1232 tree.write(tcpath, pretty_print=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1233
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1234 def install_deps(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1235 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1236 use script to install new tool dependencies
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1237 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1238 cll = [
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1239 "sh",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1240 "%s/install_tf_deps.sh" % self.args.toolfactory_dir,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1241 self.tool_name,
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1242 ]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1243 self.logger.info("Running %s\n" % " ".join(cll))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1244 try:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1245 p = subprocess.run(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1246 " ".join(cll), shell=True, capture_output=True, check=True, text=True
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1247 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1248 for errline in p.stderr.splitlines():
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1249 self.logger.info(errline)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1250 return p.returncode
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1251 except:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1252 return 1
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1253
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1254 def timenow(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1255 """return current time as a string"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1256 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time()))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1257
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1258 def cheetah_escape(self, text):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1259 """Produce entities within text."""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1260 cheetah_escape_table = {"$": "\\$", "#": "\\#"}
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1261 return "".join([cheetah_escape_table.get(c, c) for c in text])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1262
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1263 def parse_citations(self):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1264 """"""
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1265 if self.args.citations:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1266 ct = open(self.args.citations, "r").read()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1267 citations = [c.strip() for c in ct.split("**ENTRY**") if c.strip()]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1268 citation_tuples = []
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1269 for citation in citations:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1270 if citation.startswith("doi"):
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1271 citation_tuples.append(("doi", citation[len("doi") :].strip()))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1272 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1273 citation_tuples.append(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1274 ("bibtex", citation[len("bibtex") :].strip())
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1275 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1276 return citation_tuples
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1277 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1278 return None
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1279
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1280
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1281 def main():
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1282 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1283 This is a Galaxy wrapper.
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1284 It expects to be called by a special purpose tool.xml
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1285
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1286 """
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1287 parser = argparse.ArgumentParser()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1288 a = parser.add_argument
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1289 a("--nftest", action="store_true", default=False)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1290 a("--script_path", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1291 a("--sysexe", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1292 a("--packages", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1293 a("--tool_name", default="newtool")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1294 a("--input_files", default=[], action="append")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1295 a("--output_files", default=[], action="append")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1296 a("--user_email", default="Unknown")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1297 a("--bad_user", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1298 a("--help_text", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1299 a("--tool_desc", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1300 a("--toolfactory_dir", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1301 a("--tool_version", default="0.01")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1302 a("--citations", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1303 a("--cl_suffix", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1304 a("--cl_prefix", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1305 a("--cl_override", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1306 a("--test_override", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1307 a("--additional_parameters", action="append", default=[])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1308 a("--selecttext_parameters", action="append", default=[])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1309 a("--selectflag_parameters", action="append", default=[])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1310 a("--edit_additional_parameters", action="store_true", default=False)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1311 a("--parampass", default="positional")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1312 a("--tfcollection", default="toolgen")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1313 a("--galaxy_root", default="/galaxy-central")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1314 a("--collection", action="append", default=[])
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1315 a("--include_tests", default=False, action="store_true")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1316 a("--install_flag", action="store_true", default=False)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1317 a("--admin_only", default=True, action="store_true")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1318 a("--tested_tool_out", default=None)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1319 a("--container", default=None, required=False)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1320 a("--tool_conf_path", default="config/tool_conf.xml") # relative to $__root_dir__
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1321 a(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1322 "--xtra_files",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1323 default=[],
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1324 action="append",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1325 ) # history data items to add to the tool base directory
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1326 tfcl = sys.argv[1:]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1327 args = parser.parse_args()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1328 if args.admin_only:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1329 assert not args.bad_user, (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1330 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the galaxy.yml Galaxy configuration file'
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1331 % (args.bad_user, args.bad_user)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1332 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1333 assert (
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1334 args.tool_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1335 ), "## This ToolFactory cannot build a tool without a tool name. Please supply one."
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1336 os.makedirs(args.tfcollection, exist_ok=True)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1337 logfilename = os.path.join(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1338 args.tfcollection, "ToolFactory_make_%s_log.txt" % args.tool_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1339 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1340 logger.setLevel(logging.INFO)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1341 fh = logging.FileHandler(logfilename, mode="w")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1342 fformatter = logging.Formatter("%(asctime)s - %(levelname)s - %(message)s")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1343 fh.setFormatter(fformatter)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1344 logger.addHandler(fh)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1345 tf = Tool_Factory(args)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1346 tf.makeTool()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1347 tf.writeShedyml()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1348 # tf.writeTFyml()tf.writeTFyml()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1349 tf.update_toolconf()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1350 time.sleep(5)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1351 if tf.condaenv and len(tf.condaenv) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1352 res = tf.install_deps()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1353 if res > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1354 logger.debug("Toolfactory installed deps failed")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1355 logging.shutdown()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1356 sys.exit(6)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1357 time.sleep(2)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1358 testret = tf.fast_local_test() # planemo_local_test()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1359 if False and int(testret) > 0:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1360 logger.error("ToolFactory tool build and test failed. :(")
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1361 logger.info(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1362 "This is usually because the supplied script or dependency did not run correctly with the test inputs and parameter settings"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1363 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1364 logger.info("when tested with galaxy_tool_test. Error code:%d" % int(testret))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1365 logger.info(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1366 "The 'i' (information) option shows how the ToolFactory was called, stderr and stdout, and what the command line was."
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1367 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1368 logger.info(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1369 "Expand (click on) any of the broken (red) history output titles to see that 'i' button and click it"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1370 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1371 logger.info(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1372 "Make sure it is the same as your working test command line and double check that data files are coming from and going to where they should"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1373 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1374 logger.info(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1375 "In the output collection, the tool xml <command> element must be the equivalent of your working command line for the test to work"
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1376 )
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1377 logging.shutdown()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1378 sys.exit(5)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1379 else:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1380 tf.makeToolTar(testret)
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1381 jcl = sys.argv[1:]
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1382 with open(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1383 os.path.join(
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1384 args.tfcollection, "ToolFactory_%s_commandline.json" % args.tool_name
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1385 ),
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1386 "w",
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1387 ) as fout:
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1388 fout.write(" ".join(jcl))
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1389 logging.shutdown()
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1390
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1391
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1392 if __name__ == "__main__":
0183cad9d13b planemo upload
fubar
parents:
diff changeset
1393 main()