annotate toolfactory/rgToolFactory2.py @ 101:557d5f06f213 draft

Uploaded
author fubar
date Thu, 26 Nov 2020 06:17:12 +0000
parents c749364c2283
children c632db66f8c0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
84
5304cda01f60 Uploaded
fubar
parents: 83
diff changeset
1 # replace with shebang for biocontainer
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
2 # see https://github.com/fubar2/toolfactory
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
3 #
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
4 # copyright ross lazarus (ross stop lazarus at gmail stop com) May 2012
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
5 #
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
6 # all rights reserved
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
7 # Licensed under the LGPL
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
8 # suggestions for improvement and bug fixes welcome at
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
9 # https://github.com/fubar2/toolfactory
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
10 #
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
11 # July 2020: BCC was fun and I feel like rip van winkle after 5 years.
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
12 # Decided to
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
13 # 1. Fix the toolfactory so it works - done for simplest case
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
14 # 2. Fix planemo so the toolfactory function works
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
15 # 3. Rewrite bits using galaxyxml functions where that makes sense - done
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
16 #
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
17 # removed all the old complications including making the new tool use this same script
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
18 # galaxyxml now generates the tool xml https://github.com/hexylena/galaxyxml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
19 # No support for automatic HTML file creation from arbitrary outputs
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
20 # essential problem is to create two command lines - one for the tool xml and a different
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
21 # one to run the executable with the supplied test data and settings
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
22 # Be simpler to write the tool, then run it with planemo and soak up the test outputs.
95
6d122fd54cd0 Uploaded
fubar
parents: 91
diff changeset
23 # well well. sh run_tests.sh --id rgtf2 --report_file tool_tests_tool_conf.html functional.test_toolbox
6d122fd54cd0 Uploaded
fubar
parents: 91
diff changeset
24 # does the needful. Use GALAXY_TEST_SAVE /foo to save outputs - only the tar.gz - not the rest sadly
6d122fd54cd0 Uploaded
fubar
parents: 91
diff changeset
25 # GALAXY_TEST_NO_CLEANUP GALAXY_TEST_TMP_DIR=wherever
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
26 # planemo test --engine docker_galaxy --test_data ./test-data/ --docker_extra_volume ./test-data rgToolFactory2.xml
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
27
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
28 import argparse
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
29 import copy
76
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
30 import datetime
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
31 import json
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
32 import logging
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
33 import os
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
34 import re
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
35 import shutil
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
36 import subprocess
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
37 import sys
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
38 import tarfile
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
39 import tempfile
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
40 import time
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
41
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
42
100
c749364c2283 Uploaded
fubar
parents: 99
diff changeset
43 from bioblend import ConnectionError
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
44 from bioblend import toolshed
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
45
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
46 import docker
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
47
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
48 import galaxyxml.tool as gxt
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
49 import galaxyxml.tool.parameters as gxtp
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
50
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
51 import lxml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
52
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
53 import yaml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
54
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
55 myversion = "V2.1 July 2020"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
56 verbose = True
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
57 debug = True
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
58 toolFactoryURL = "https://github.com/fubar2/toolfactory"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
59 ourdelim = "~~~"
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
60 ALOT = 10000000 # srsly. command or test overrides use read() so just in case
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
61 STDIOXML = """<stdio>
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
62 <exit_code range="100:" level="debug" description="shite happens" />
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
63 </stdio>"""
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
64
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
65 # --input_files="$input_files~~~$CL~~~$input_formats~~~$input_label
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
66 # ~~~$input_help"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
67 IPATHPOS = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
68 ICLPOS = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
69 IFMTPOS = 2
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
70 ILABPOS = 3
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
71 IHELPOS = 4
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
72 IOCLPOS = 5
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
73
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
74 # --output_files "$otab.history_name~~~$otab.history_format~~~$otab.CL~~~otab.history_test
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
75 ONAMEPOS = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
76 OFMTPOS = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
77 OCLPOS = 2
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
78 OTESTPOS = 3
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
79 OOCLPOS = 4
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
80
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
81
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
82 # --additional_parameters="$i.param_name~~~$i.param_value~~~
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
83 # $i.param_label~~~$i.param_help~~~$i.param_type~~~$i.CL~~~i$.param_CLoverride"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
84 ANAMEPOS = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
85 AVALPOS = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
86 ALABPOS = 2
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
87 AHELPPOS = 3
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
88 ATYPEPOS = 4
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
89 ACLPOS = 5
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
90 AOVERPOS = 6
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
91 AOCLPOS = 7
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
92
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
93
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
94 foo = len(lxml.__version__)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
95 # fug you, flake8. Say my name!
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
96 FAKEEXE = "~~~REMOVE~~~ME~~~"
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
97 # need this until a PR/version bump to fix galaxyxml prepending the exe even
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
98 # with override.
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
99
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
100
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
101 def timenow():
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
102 """return current time as a string"""
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
103 return time.strftime("%d/%m/%Y %H:%M:%S", time.localtime(time.time()))
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
104
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
105
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
106 def quote_non_numeric(s):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
107 """return a prequoted string for non-numerics
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
108 useful for perl and Rscript parameter passing?
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
109 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
110 try:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
111 _ = float(s)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
112 return s
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
113 except ValueError:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
114 return '"%s"' % s
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
115
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
116
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
117 html_escape_table = {"&": "&amp;", ">": "&gt;", "<": "&lt;", "$": r"\$"}
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
118
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
119
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
120 def html_escape(text):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
121 """Produce entities within text."""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
122 return "".join(html_escape_table.get(c, c) for c in text)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
123
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
124
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
125 def html_unescape(text):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
126 """Revert entities within text. Multiple character targets so use replace"""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
127 t = text.replace("&amp;", "&")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
128 t = t.replace("&gt;", ">")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
129 t = t.replace("&lt;", "<")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
130 t = t.replace("\\$", "$")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
131 return t
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
132
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
133
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
134 def parse_citations(citations_text):
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
135 """"""
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
136 citations = [c for c in citations_text.split("**ENTRY**") if c.strip()]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
137 citation_tuples = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
138 for citation in citations:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
139 if citation.startswith("doi"):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
140 citation_tuples.append(("doi", citation[len("doi") :].strip()))
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
141 else:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
142 citation_tuples.append(("bibtex", citation[len("bibtex") :].strip()))
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
143 return citation_tuples
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
144
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
145
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
146 class ScriptRunner:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
147 """Wrapper for an arbitrary script
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
148 uses galaxyxml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
149
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
150 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
151
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
152 def __init__(self, args=None):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
153 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
154 prepare command line cl for running the tool here
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
155 and prepare elements needed for galaxyxml tool generation
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
156 """
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
157 self.ourcwd = os.getcwd()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
158 self.ourenv = copy.deepcopy(os.environ)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
159 self.infiles = [x.split(ourdelim) for x in args.input_files]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
160 self.outfiles = [x.split(ourdelim) for x in args.output_files]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
161 self.addpar = [x.split(ourdelim) for x in args.additional_parameters]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
162 self.args = args
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
163 self.cleanuppar()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
164 self.lastclredirect = None
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
165 self.lastxclredirect = None
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
166 self.cl = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
167 self.xmlcl = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
168 self.is_positional = self.args.parampass == "positional"
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
169 if self.args.sysexe:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
170 self.executeme = self.args.sysexe
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
171 else:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
172 if self.args.packages:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
173 self.executeme = self.args.packages.split(",")[0].split(":")[0]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
174 else:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
175 self.executeme = None
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
176 aCL = self.cl.append
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
177 aXCL = self.xmlcl.append
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
178 assert args.parampass in [
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
179 "0",
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
180 "argparse",
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
181 "positional",
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
182 ], 'args.parampass must be "0","positional" or "argparse"'
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
183 self.tool_name = re.sub("[^a-zA-Z0-9_]+", "", args.tool_name)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
184 self.tool_id = self.tool_name
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
185 self.newtool = gxt.Tool(
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
186 self.tool_name,
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
187 self.tool_id,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
188 self.args.tool_version,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
189 self.args.tool_desc,
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
190 FAKEEXE,
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
191 )
76
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
192 self.newtarpath = "toolfactory_%s.tgz" % self.tool_name
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
193 self.tooloutdir = "./tfout"
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
194 self.repdir = "./TF_run_report_tempdir"
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
195 self.testdir = os.path.join(self.tooloutdir, "test-data")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
196 if not os.path.exists(self.tooloutdir):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
197 os.mkdir(self.tooloutdir)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
198 if not os.path.exists(self.testdir):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
199 os.mkdir(self.testdir) # make tests directory
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
200 if not os.path.exists(self.repdir):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
201 os.mkdir(self.repdir)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
202 self.tinputs = gxtp.Inputs()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
203 self.toutputs = gxtp.Outputs()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
204 self.testparam = []
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
205 if self.args.script_path:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
206 self.prepScript()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
207 if self.args.command_override:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
208 scos = open(self.args.command_override, "r").readlines()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
209 self.command_override = [x.rstrip() for x in scos]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
210 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
211 self.command_override = None
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
212 if self.args.test_override:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
213 stos = open(self.args.test_override, "r").readlines()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
214 self.test_override = [x.rstrip() for x in stos]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
215 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
216 self.test_override = None
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
217 if self.args.cl_prefix: # DIY CL start
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
218 clp = self.args.cl_prefix.split(" ")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
219 for c in clp:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
220 aCL(c)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
221 aXCL(c)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
222 else:
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
223 if self.args.script_path:
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
224 aCL(self.executeme)
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
225 aCL(self.sfile)
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
226 aXCL(self.executeme)
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
227 aXCL("$runme")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
228 else:
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
229 aCL(self.executeme) # this little CL will just run
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
230 aXCL(self.executeme)
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
231 self.elog = os.path.join(self.repdir, "%s_error_log.txt" % self.tool_name)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
232 self.tlog = os.path.join(self.repdir, "%s_runner_log.txt" % self.tool_name)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
233
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
234 if self.args.parampass == "0":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
235 self.clsimple()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
236 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
237 clsuffix = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
238 xclsuffix = []
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
239 for i, p in enumerate(self.infiles):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
240 if p[IOCLPOS] == "STDIN":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
241 appendme = [
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
242 p[IOCLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
243 p[ICLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
244 p[IPATHPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
245 "< %s" % p[IPATHPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
246 ]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
247 xappendme = [
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
248 p[IOCLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
249 p[ICLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
250 p[IPATHPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
251 "< $%s" % p[ICLPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
252 ]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
253 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
254 appendme = [p[IOCLPOS], p[ICLPOS], p[IPATHPOS], ""]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
255 xappendme = [p[IOCLPOS], p[ICLPOS], "$%s" % p[ICLPOS], ""]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
256 clsuffix.append(appendme)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
257 xclsuffix.append(xappendme)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
258 for i, p in enumerate(self.outfiles):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
259 if p[OOCLPOS] == "STDOUT":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
260 self.lastclredirect = [">", p[ONAMEPOS]]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
261 self.lastxclredirect = [">", "$%s" % p[OCLPOS]]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
262 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
263 clsuffix.append([p[OOCLPOS], p[OCLPOS], p[ONAMEPOS], ""])
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
264 xclsuffix.append([p[OOCLPOS], p[OCLPOS], "$%s" % p[ONAMEPOS], ""])
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
265 for p in self.addpar:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
266 clsuffix.append([p[AOCLPOS], p[ACLPOS], p[AVALPOS], p[AOVERPOS]])
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
267 xclsuffix.append(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
268 [p[AOCLPOS], p[ACLPOS], '"$%s"' % p[ANAMEPOS], p[AOVERPOS]]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
269 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
270 clsuffix.sort()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
271 xclsuffix.sort()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
272 self.xclsuffix = xclsuffix
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
273 self.clsuffix = clsuffix
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
274 if self.args.parampass == "positional":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
275 self.clpositional()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
276 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
277 self.clargparse()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
278
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
279 def prepScript(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
280 rx = open(self.args.script_path, "r").readlines()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
281 rx = [x.rstrip() for x in rx]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
282 rxcheck = [x.strip() for x in rx if x.strip() > ""]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
283 assert len(rxcheck) > 0, "Supplied script is empty. Cannot run"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
284 self.script = "\n".join(rx)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
285 fhandle, self.sfile = tempfile.mkstemp(
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
286 prefix=self.tool_name, suffix="_%s" % (self.executeme)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
287 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
288 tscript = open(self.sfile, "w")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
289 tscript.write(self.script)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
290 tscript.close()
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
291 self.indentedScript = " %s" % "\n".join([" %s" % html_escape(x) for x in rx])
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
292 self.escapedScript = "%s" % "\n".join([" %s" % html_escape(x) for x in rx])
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
293 art = "%s.%s" % (self.tool_name, self.executeme)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
294 artifact = open(art, "wb")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
295 artifact.write(bytes(self.script, "utf8"))
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
296 artifact.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
297
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
298 def cleanuppar(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
299 """ positional parameters are complicated by their numeric ordinal"""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
300 for i, p in enumerate(self.infiles):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
301 if self.args.parampass == "positional":
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
302 assert p[
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
303 ICLPOS
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
304 ].isdigit(), "Positional parameters must be ordinal integers - got %s for %s" % (
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
305 p[ICLPOS],
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
306 p[ILABPOS],
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
307 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
308 p.append(p[ICLPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
309 if p[ICLPOS].isdigit() or self.args.parampass == "0":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
310 scl = "input%d" % (i + 1)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
311 p[ICLPOS] = scl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
312 self.infiles[i] = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
313 for i, p in enumerate(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
314 self.outfiles
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
315 ): # trying to automagically gather using extensions
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
316 if self.args.parampass == "positional" and p[OCLPOS] != "STDOUT":
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
317 assert p[
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
318 OCLPOS
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
319 ].isdigit(), "Positional parameters must be ordinal integers - got %s for %s" % (
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
320 p[OCLPOS],
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
321 p[ONAMEPOS],
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
322 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
323 p.append(p[OCLPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
324 if p[OCLPOS].isdigit() or p[OCLPOS] == "STDOUT":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
325 scl = p[ONAMEPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
326 p[OCLPOS] = scl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
327 self.outfiles[i] = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
328 for i, p in enumerate(self.addpar):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
329 if self.args.parampass == "positional":
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
330 assert p[
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
331 ACLPOS
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
332 ].isdigit(), "Positional parameters must be ordinal integers - got %s for %s" % (
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
333 p[ACLPOS],
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
334 p[ANAMEPOS],
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
335 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
336 p.append(p[ACLPOS])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
337 if p[ACLPOS].isdigit():
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
338 scl = "input%s" % p[ACLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
339 p[ACLPOS] = scl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
340 self.addpar[i] = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
341
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
342 def clsimple(self):
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
343 """no parameters - uses < and > for i/o"""
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
344 aCL = self.cl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
345 aXCL = self.xmlcl.append
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
346
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
347 if len(self.infiles) > 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
348 aCL("<")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
349 aCL(self.infiles[0][IPATHPOS])
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
350 aXCL("<")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
351 aXCL("$%s" % self.infiles[0][ICLPOS])
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
352 if len(self.outfiles) > 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
353 aCL(">")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
354 aCL(self.outfiles[0][OCLPOS])
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
355 aXCL(">")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
356 aXCL("$%s" % self.outfiles[0][ONAMEPOS])
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
357
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
358 def clpositional(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
359 # inputs in order then params
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
360 aCL = self.cl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
361 for (o_v, k, v, koverride) in self.clsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
362 if " " in v:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
363 aCL("%s" % v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
364 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
365 aCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
366 aXCL = self.xmlcl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
367 for (o_v, k, v, koverride) in self.xclsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
368 aXCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
369 if self.lastxclredirect:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
370 aXCL(self.lastxclredirect[0])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
371 aXCL(self.lastxclredirect[1])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
372
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
373 def clargparse(self):
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
374 """argparse style"""
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
375 aCL = self.cl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
376 aXCL = self.xmlcl.append
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
377 # inputs then params in argparse named form
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
378 for (o_v, k, v, koverride) in self.xclsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
379 if koverride > "":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
380 k = koverride
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
381 elif len(k.strip()) == 1:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
382 k = "-%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
383 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
384 k = "--%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
385 aXCL(k)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
386 aXCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
387 for (o_v, k, v, koverride) in self.clsuffix:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
388 if koverride > "":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
389 k = koverride
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
390 elif len(k.strip()) == 1:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
391 k = "-%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
392 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
393 k = "--%s" % k
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
394 aCL(k)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
395 aCL(v)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
396
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
397 def getNdash(self, newname):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
398 if self.is_positional:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
399 ndash = 0
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
400 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
401 ndash = 2
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
402 if len(newname) < 2:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
403 ndash = 1
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
404 return ndash
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
405
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
406 def doXMLparam(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
407 """flake8 made me do this..."""
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
408 for p in self.outfiles:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
409 newname, newfmt, newcl, test, oldcl = p
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
410 ndash = self.getNdash(newcl)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
411 aparm = gxtp.OutputData(newcl, format=newfmt, num_dashes=ndash)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
412 aparm.positional = self.is_positional
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
413 if self.is_positional:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
414 if oldcl == "STDOUT":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
415 aparm.positional = 9999999
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
416 aparm.command_line_override = "> $%s" % newcl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
417 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
418 aparm.positional = int(oldcl)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
419 aparm.command_line_override = "$%s" % newcl
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
420 self.toutputs.append(aparm)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
421 usetest = None
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
422 ld = None
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
423 if test > "":
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
424 if test.startswith("diff"):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
425 usetest = "diff"
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
426 if test.split(":")[1].isdigit:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
427 ld = int(test.split(":")[1])
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
428 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
429 usetest = test
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
430 tp = gxtp.TestOutput(
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
431 name=newcl,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
432 value="%s_sample" % newcl,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
433 format=newfmt,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
434 compare=usetest,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
435 lines_diff=ld,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
436 delta=None,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
437 )
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
438 self.testparam.append(tp)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
439 for p in self.infiles:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
440 newname = p[ICLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
441 newfmt = p[IFMTPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
442 ndash = self.getNdash(newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
443 if not len(p[ILABPOS]) > 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
444 alab = p[ICLPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
445 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
446 alab = p[ILABPOS]
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
447 aninput = gxtp.DataParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
448 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
449 optional=False,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
450 label=alab,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
451 help=p[IHELPOS],
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
452 format=newfmt,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
453 multiple=False,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
454 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
455 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
456 aninput.positional = self.is_positional
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
457 self.tinputs.append(aninput)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
458 tparm = gxtp.TestParam(name=newname, value="%s_sample" % newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
459 self.testparam.append(tparm)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
460 for p in self.addpar:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
461 newname, newval, newlabel, newhelp, newtype, newcl, override, oldcl = p
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
462 if not len(newlabel) > 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
463 newlabel = newname
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
464 ndash = self.getNdash(newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
465 if newtype == "text":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
466 aparm = gxtp.TextParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
467 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
468 label=newlabel,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
469 help=newhelp,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
470 value=newval,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
471 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
472 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
473 elif newtype == "integer":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
474 aparm = gxtp.IntegerParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
475 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
476 label=newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
477 help=newhelp,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
478 value=newval,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
479 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
480 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
481 elif newtype == "float":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
482 aparm = gxtp.FloatParam(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
483 newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
484 label=newname,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
485 help=newhelp,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
486 value=newval,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
487 num_dashes=ndash,
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
488 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
489 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
490 raise ValueError(
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
491 'Unrecognised parameter type "%s" for\
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
492 additional parameter %s in makeXML'
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
493 % (newtype, newname)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
494 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
495 aparm.positional = self.is_positional
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
496 if self.is_positional:
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
497 aparm.positional = int(oldcl)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
498 self.tinputs.append(aparm)
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
499 tparm = gxtp.TestParam(newname, value=newval)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
500 self.testparam.append(tparm)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
501
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
502 def doNoXMLparam(self):
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
503 """filter style package - stdin to stdout"""
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
504 if len(self.infiles) > 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
505 alab = self.infiles[0][ILABPOS]
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
506 if len(alab) == 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
507 alab = self.infiles[0][ICLPOS]
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
508 max1s = (
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
509 "Maximum one input if parampass is 0 but multiple input files supplied - %s"
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
510 % str(self.infiles)
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
511 )
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
512 assert len(self.infiles) == 1, max1s
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
513 newname = self.infiles[0][ICLPOS]
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
514 aninput = gxtp.DataParam(
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
515 newname,
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
516 optional=False,
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
517 label=alab,
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
518 help=self.infiles[0][IHELPOS],
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
519 format=self.infiles[0][IFMTPOS],
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
520 multiple=False,
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
521 num_dashes=0,
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
522 )
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
523 aninput.command_line_override = "< $%s" % newname
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
524 aninput.positional = self.is_positional
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
525 self.tinputs.append(aninput)
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
526 tp = gxtp.TestParam(name=newname, value="%s_sample" % newname)
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
527 self.testparam.append(tp)
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
528 if len(self.outfiles) > 0:
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
529 newname = self.outfiles[0][OCLPOS]
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
530 newfmt = self.outfiles[0][OFMTPOS]
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
531 anout = gxtp.OutputData(newname, format=newfmt, num_dashes=0)
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
532 anout.command_line_override = "> $%s" % newname
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
533 anout.positional = self.is_positional
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
534 self.toutputs.append(anout)
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
535 tp = gxtp.TestOutput(
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
536 name=newname, value="%s_sample" % newname, format=newfmt
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
537 )
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
538 self.testparam.append(tp)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
539
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
540 def makeXML(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
541 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
542 Create a Galaxy xml tool wrapper for the new script
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
543 Uses galaxyhtml
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
544 Hmmm. How to get the command line into correct order...
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
545 """
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
546 if self.command_override:
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
547 self.newtool.command_override = self.command_override # config file
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
548 else:
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
549 self.newtool.command_override = self.xmlcl
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
550 if self.args.help_text:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
551 helptext = open(self.args.help_text, "r").readlines()
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
552 safertext = [html_escape(x) for x in helptext]
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
553 if False and self.args.script_path:
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
554 scrp = self.script.split("\n")
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
555 scrpt = [" %s" % x for x in scrp] # try to stop templating
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
556 scrpt.insert(0, "```\n")
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
557 if len(scrpt) > 300:
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
558 safertext = (
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
559 safertext + scrpt[:100] + \
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
560 [">500 lines - stuff deleted", "......"] + scrpt[-100:]
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
561 )
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
562 else:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
563 safertext = safertext + scrpt
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
564 safertext.append("\n```")
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
565 self.newtool.help = "\n".join([x for x in safertext])
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
566 else:
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
567 self.newtool.help = (
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
568 "Please ask the tool author (%s) for help \
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
569 as none was supplied at tool generation\n"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
570 % (self.args.user_email)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
571 )
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
572 self.newtool.version_command = None # do not want
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
573 requirements = gxtp.Requirements()
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
574 if self.args.packages:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
575 for d in self.args.packages.split(","):
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
576 if ":" in d:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
577 packg, ver = d.split(":")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
578 else:
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
579 packg = d
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
580 ver = ""
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
581 requirements.append(
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
582 gxtp.Requirement("package", packg.strip(), ver.strip())
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
583 )
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
584 self.newtool.requirements = requirements
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
585 if self.args.parampass == "0":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
586 self.doNoXMLparam()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
587 else:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
588 self.doXMLparam()
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
589 self.newtool.outputs = self.toutputs
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
590 self.newtool.inputs = self.tinputs
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
591 if self.args.script_path:
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
592 configfiles = gxtp.Configfiles()
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
593 configfiles.append(gxtp.Configfile(name="runme", text=self.script))
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
594 self.newtool.configfiles = configfiles
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
595 tests = gxtp.Tests()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
596 test_a = gxtp.Test()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
597 for tp in self.testparam:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
598 test_a.append(tp)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
599 tests.append(test_a)
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
600 self.newtool.tests = tests
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
601 self.newtool.add_comment(
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
602 "Created by %s at %s using the Galaxy Tool Factory."
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
603 % (self.args.user_email, timenow())
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
604 )
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
605 self.newtool.add_comment("Source in git at: %s" % (toolFactoryURL))
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
606 self.newtool.add_comment(
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
607 "Cite: Creating re-usable tools from scripts doi: \
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
608 10.1093/bioinformatics/bts573"
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
609 )
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
610 exml0 = self.newtool.export()
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
611 exml = exml0.replace(FAKEEXE, "") # temporary work around until PR accepted
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
612 if (
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
613 self.test_override
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
614 ): # cannot do this inside galaxyxml as it expects lxml objects for tests
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
615 part1 = exml.split("<tests>")[0]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
616 part2 = exml.split("</tests>")[1]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
617 fixed = "%s\n%s\n%s" % (part1, self.test_override, part2)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
618 exml = fixed
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
619 exml = exml.replace('range="1:"', 'range="1000:"')
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
620 xf = open("%s.xml" % self.tool_name, "w")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
621 xf.write(exml)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
622 xf.write("\n")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
623 xf.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
624 # ready for the tarball
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
625
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
626 def run(self):
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
627 """
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
628 generate test outputs by running a command line
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
629 won't work if command or test override in play - planemo is the
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
630 easiest way to generate test outputs for that case so is
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
631 automagically selected
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
632 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
633 scl = " ".join(self.cl)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
634 err = None
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
635 if self.args.parampass != "0":
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
636 if os.path.exists(self.elog):
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
637 ste = open(self.elog, "a")
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
638 else:
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
639 ste = open(self.elog, "w")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
640 if self.lastclredirect:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
641 sto = open(self.lastclredirect[1], "wb") # is name of an output file
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
642 else:
56
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
643 if os.path.exists(self.tlog):
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
644 sto = open(self.tlog, "a")
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
645 else:
68fbdbe35f08 Uploaded
fubar
parents: 51
diff changeset
646 sto = open(self.tlog, "w")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
647 sto.write(
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
648 "## Executing Toolfactory generated command line = %s\n" % scl
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
649 )
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
650 sto.flush()
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
651 subp = subprocess.run(self.cl, env=self.ourenv, shell=False, stdout=sto, stderr=ste)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
652 sto.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
653 ste.close()
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
654 retval = subp.returncode
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
655 else: # work around special case - stdin and write to stdout
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
656 if len(self.infiles) > 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
657 sti = open(self.infiles[0][IPATHPOS], "rb")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
658 else:
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
659 sti = sys.stdin
62
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
660 if len(self.outfiles) > 0:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
661 sto = open(self.outfiles[0][ONAMEPOS], "wb")
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
662 else:
881bd8c81ac9 Uploaded
fubar
parents: 57
diff changeset
663 sto = sys.stdout
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
664 subp = subprocess.run(self.cl, env=self.ourenv, shell=False, stdout=sto, stdin=sti)
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
665 sto.write("## Executing Toolfactory generated command line = %s\n" % scl)
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
666 retval = subp.returncode
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
667 sto.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
668 sti.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
669 if os.path.isfile(self.tlog) and os.stat(self.tlog).st_size == 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
670 os.unlink(self.tlog)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
671 if os.path.isfile(self.elog) and os.stat(self.elog).st_size == 0:
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
672 os.unlink(self.elog)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
673 if retval != 0 and err: # problem
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
674 sys.stderr.write(err)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
675 logging.debug("run done")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
676 return retval
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
677
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
678
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
679 def copy_to_container(self, src, dest, container):
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
680 """ Recreate the src directory tree at dest - full path included
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
681 """
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
682 idir = os.getcwd()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
683 workdir = os.path.dirname(src)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
684 os.chdir(workdir)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
685 _, tfname = tempfile.mkstemp(suffix=".tar")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
686 tar = tarfile.open(tfname, mode='w')
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
687 srcb = os.path.basename(src)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
688 tar.add(srcb)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
689 tar.close()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
690 data = open(tfname, 'rb').read()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
691 container.put_archive(dest, data)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
692 os.unlink(tfname)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
693 os.chdir(idir)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
694
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
695
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
696 def copy_from_container(self, src, dest, container):
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
697 """ recreate the src directory tree at dest using docker sdk
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
698 """
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
699 os.makedirs(dest,exist_ok=True)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
700 _, tfname = tempfile.mkstemp(suffix=".tar")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
701 tf = open(tfname,'wb')
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
702 bits, stat = container.get_archive(src)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
703 for chunk in bits:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
704 tf.write(chunk)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
705 tf.close()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
706 tar = tarfile.open(tfname,'r')
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
707 tar.extractall(dest)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
708 tar.close()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
709 os.unlink(tfname)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
710
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
711
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
712
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
713 def planemo_biodocker_test(self):
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
714 """planemo currently leaks dependencies if used in the same container and gets unhappy after a
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
715 first successful run. https://github.com/galaxyproject/planemo/issues/1078#issuecomment-731476930
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
716
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
717 Docker biocontainer has planemo with caches filled to save repeated downloads
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
718
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
719
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
720 """
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
721 if os.path.exists(self.tlog):
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
722 tout = open(self.tlog, "a")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
723 else:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
724 tout = open(self.tlog, "w")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
725 planemoimage = "quay.io/fubar2/planemo-biocontainer"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
726 xreal = "%s.xml" % self.tool_name
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
727 destdir = "/tmp/tfout"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
728 repname = f"{self.tool_name}_planemo_test_report.html"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
729 imrep = os.path.join(destdir,repname)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
730 ptestrep_path = os.path.join(self.repdir,repname)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
731 tool_name = self.tool_name
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
732 client = docker.from_env()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
733 container = client.containers.run(planemoimage,'sleep 10000m', detach=True)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
734 rlog = container.exec_run(f"mkdir -p {destdir}")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
735 slogl = str(rlog).split('\\n')
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
736 slog = '\n'.join(slogl)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
737 tout.write(f"## got rlog {slog} from mkdir {destdir}")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
738 ptestpath = os.path.join(destdir,xreal)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
739 self.copy_to_container(self.tooloutdir,'/tmp',container)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
740 rlog = container.exec_run(f"ls -la {destdir}")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
741 ptestcl = f"planemo test --update_test_data --galaxy_root /home/biodocker/galaxy-central {ptestpath}"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
742 try:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
743 rlog = container.exec_run(ptestcl)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
744 except:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
745 e = sys.exc_info()[0]
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
746 tout.write(f"#### error: {e} from {ptestcl}")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
747 # fails - used to generate test outputs
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
748 ptestcl = f"planemo test --test_output {imrep} --galaxy_root /home/biodocker/galaxy-central {ptestpath}"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
749 try:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
750 rlog = container.exec_run(ptestcl)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
751 except:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
752 pass
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
753 slogl = str(rlog).split('\\n')
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
754 slog = '\n'.join(slogl)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
755 tout.write(f"## got rlog {slog} from mkdir {destdir}")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
756 testouts = tempfile.mkdtemp(suffix=None, prefix="tftemp",dir=".")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
757 self.copy_from_container(destdir,testouts,container)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
758 try:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
759 shutil.rmtree(os.path.join(testouts,self.tooloutdir,'test-data','test-data'))
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
760 except:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
761 e = sys.exc_info()[0]
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
762 tout.write(f"#### error: {e} from {ptestcl}")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
763 shutil.copytree(os.path.join(testouts,self.tooloutdir), self.tooloutdir, dirs_exist_ok=True)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
764 tout.close()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
765 container.stop()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
766 container.remove()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
767 shutil.rmtree(testouts)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
768
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
769
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
770 def planemo_biodocker_vol_test(self):
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
771 """planemo currently leaks dependencies if used in the same container and gets unhappy after a
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
772 first successful run. https://github.com/galaxyproject/planemo/issues/1078#issuecomment-731476930
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
773
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
774 Docker biocontainer has planemo with caches filled to save repeated downloads
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
775 Cannot get volumes to work right in this version
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
776
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
777 """
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
778 if os.path.exists(self.tlog):
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
779 tout = open(self.tlog, "a")
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
780 else:
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
781 tout = open(self.tlog, "w")
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
782 planemoimage = "quay.io/fubar2/planemo-biocontainer"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
783 xreal = "%s.xml" % self.tool_name
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
784 repname = f"{self.tool_name}_planemo_test_report.html"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
785 ptestrep_path = os.path.join(self.repdir,repname)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
786 tool_name = self.tool_name
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
787 workdir = "export"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
788 aworkdir = os.path.abspath(workdir)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
789 os.makedirs(workdir, exist_ok=True)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
790 os.chmod(workdir,0o777)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
791 imworkdir = "/export"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
792 # must be mounted as a volume
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
793 tooldir = os.path.join(workdir,self.tool_name)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
794 testdir = os.path.join(tooldir,'test-data')
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
795 imtooldir = os.path.join(imworkdir,self.tool_name)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
796 imtestdir = os.path.join(imtooldir,'test-data')
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
797 for d in [tooldir,testdir]:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
798 if not os.path.exists(d):
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
799 os.mkdir(d)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
800 with os.scandir(self.testdir) as outs:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
801 for entry in outs:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
802 if not entry.is_file():
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
803 continue
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
804 src = os.path.join(self.testdir, entry.name)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
805 dest = os.path.join(testdir, entry.name)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
806 shutil.copyfile(src, dest)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
807 shutil.copyfile(xreal,os.path.join(tooldir,xreal))
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
808 client = docker.from_env()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
809 # mnt = docker.types.Mount(source='workdir', target=imworkdir) # mounts=[mnt],)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
810 atestcl = "ls -lt /export"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
811 container = client.containers.run(planemoimage,atestcl,
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
812 volumes={aworkdir:{'bind':'/export','mode':'rw'}}, )
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
813 tout.write(f"## Ran {atestcl} and got {container}")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
814 ptestpath = os.path.join(imtooldir,xreal)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
815 ptestcll = f"planemo test --job_output_files {imtooldir} --update_test_data --test_data {imtestdir} --galaxy_root /home/biodocker/galaxy-central {ptestpath}"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
816 try:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
817 container = client.containers.run(planemoimage,ptestcl,
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
818 volumes={aworkdir:{'bind':'/export','mode':'rw'}}, )
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
819 except:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
820 pass
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
821 tout.write(f"## Ran {ptestcl}")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
822 with os.scandir(testdir) as outs:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
823 for entry in outs:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
824 if not entry.is_file():
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
825 continue
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
826 src = os.path.join(testdir, entry.name)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
827 dest = os.path.join(self.testdir, entry.name)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
828 shutil.copyfile(src, dest)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
829 imrep_path = os.path.join(imtooldir,repname)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
830 ptestcl = f"planemo test --job_output_files {imtooldir} --test_output {imrep_path} --test_data {imtestdir} --galaxy_root /home/biodocker/galaxy-central {ptestpath}"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
831 try:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
832 container = client.containers.run(planemoimage,ptestcl,
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
833 volumes={aworkdir:{'bind':'/export','mode':'rw'}}, )
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
834 except:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
835 pass
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
836 tout.write(f"## Ran {ptestcl}")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
837 if os.path.isfile(imrep_path):
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
838 shutil.copyfile(imrep_path,ptestrep_path)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
839 else:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
840 tout.write(f"## planemo_biodocker_test - no test report {imrep_path} found")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
841 tout.close()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
842 #shutil.rmtree(workdir)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
843
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
844
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
845
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
846 def gal_tool_test(self):
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
847 """
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
848 On path should be a handy script writes test outputs even if they don't exist
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
849
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
850 galaxy-tool-test -u http://localhost:8080 -a 3c9afe09f1b7892449d266109639c104 -o /tmp/foo -t hello -j /tmp/foo/hello.json --verbose
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
851
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
852 leaves outputs in -o !
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
853 """
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
854 gttscript = f"""#!{self.args.galaxy_venv}/bin/python3
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
855 # -*- coding: utf-8 -*-
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
856 import re
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
857 import sys
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
858 from galaxy.tool_util.verify.script import main
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
859 if __name__ == '__main__':
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
860 sys.argv[0] = re.sub(r'(-script\.pyw|\.exe)?$', '', sys.argv[0])
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
861 sys.exit(main())
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
862
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
863 """
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
864 galaxy_lib = os.path.join(self.args.galaxy_root,'lib')
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
865 fakeenv = copy.copy(os.environ)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
866 fakeenv ["PATH"] = "/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
867 fakeenv ["PYTHONPATH"] = f"{galaxy_lib}"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
868 if os.path.exists(self.tlog):
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
869 tout = open(self.tlog, "a")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
870 else:
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
871 tout = open(self.tlog, "w")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
872 testouts = tempfile.mkdtemp(suffix=None, prefix="tftemp",dir="/tmp")
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
873 tout.write(f"#### using {testouts} as tempdir\n")
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
874 dummy, tfile = tempfile.mkstemp()
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
875 gtt = 'galaxy-tool-test'
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
876 gttf = open(gtt,'w')
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
877 gttf.write(gttscript)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
878 gttf.write('\n')
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
879 gttf.close()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
880 os.chmod(gtt,0o744)
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
881 cll = [
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
882 os.path.abspath(gtt),
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
883 "-u",
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
884 self.args.galaxy_url,
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
885 "-k",
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
886 self.args.galaxy_api_key,
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
887 "-t",
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
888 self.tool_name,
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
889 "-o",
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
890 testouts,
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
891 ]
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
892 subp = subprocess.run(
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
893 cll, env=fakeenv, cwd=galaxy_lib, shell=True, stderr=tout, stdout=tout
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
894 )
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
895 outfiles = []
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
896 for p in self.outfiles:
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
897 oname = p[ONAMEPOS]
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
898 outfiles.append(oname)
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
899 with os.scandir(testouts) as outs:
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
900 for entry in outs:
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
901 if not entry.is_file():
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
902 continue
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
903 dest = os.path.join(self.tooloutdir, entry.name)
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
904 src = os.path.join(testouts, entry.name)
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
905 shutil.copyfile(src, dest)
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
906 testdest = os.path.join(self.testdir, entry.name)
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
907 src = os.path.join(testouts, entry.name)
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
908 shutil.copyfile(src, testdest)
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
909 dest = os.path.join(self.repdir,f"{entry.name}_sample")
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
910 tout.write(f"## found and moved output {entry.name} to {dest} and {testdest}\n")
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
911 tout.close()
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
912 #shutil.rmtree(testouts)
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
913 return subp.returncode
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
914
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
915 def gal_test(self):
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
916 """
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
917 Uses the built in galaxy tool tester run_test.sh
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
918
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
919 export GALAXY_TEST_SAVE="./foo" && export GALAXY_TEST_NO_CLEANUP="1" \
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
920 && export GALAXY_TEST_TMP_DIR=./foo && sh run_tests.sh --id rgtf2 --report_file tool_tests_tool_conf.html functional.test_toolbox
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
921
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
922 """
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
923 testdir = tempfile.mkdtemp(suffix=None, prefix="tftemp",dir="/tmp")
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
924 tool_test_rep = f"{self.tool_name}_galaxy_test_report_html.html"
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
925 if os.path.exists(self.tlog):
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
926 tout = open(self.tlog, "a")
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
927 else:
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
928 tout = open(self.tlog, "w")
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
929
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
930 fakeenv = copy.copy(os.environ)
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
931 fakeenv["GALAXY_TEST_SAVE"] = testdir
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
932 fakeenv["GALAXY_TEST_NO_CLEANUP"] = "1"
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
933 fakeenv["GALAXY_TEST_TMP_DIR"] = testdir
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
934 galaxy_lib = os.path.join(self.args.galaxy_root,'lib')
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
935
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
936 cll = [
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
937 "sh", f"{self.args.galaxy_root}/run_tests.sh", "--id", self.tool_name,
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
938 "--report_file", os.path.join(testdir,tool_test_rep), "functional.test_toolbox",
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
939 ]
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
940 subp = subprocess.run(
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
941 cll, env = fakeenv ,
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
942 shell=False, cwd=galaxy_lib, stderr=tout, stdout=tout
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
943 )
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
944 src = os.path.join(testdir, tool_test_rep)
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
945 if os.path.isfile(src):
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
946 dest = os.path.join(self.repdir, tool_test_rep)
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
947 shutil.copyfile(src, dest)
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
948 else:
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
949 tout.write(f"### {src} not found\n")
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
950 tout.close()
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
951 return subp.returncode
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
952
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
953
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
954 def shedLoad(self):
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
955 """
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
956 {'deleted': False,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
957 'description': 'Tools for manipulating data',
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
958 'id': '175812cd7caaf439',
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
959 'model_class': 'Category',
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
960 'name': 'Text Manipulation',
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
961 'url': '/api/categories/175812cd7caaf439'}]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
962
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
963
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
964 """
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
965 if os.path.exists(self.tlog):
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
966 sto = open(self.tlog, "a")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
967 else:
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
968 sto = open(self.tlog, "w")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
969
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
970 ts = toolshed.ToolShedInstance(
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
971 url=self.args.toolshed_url, key=self.args.toolshed_api_key, verify=False
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
972 )
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
973 repos = ts.repositories.get_repositories()
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
974 rnames = [x.get("name", "?") for x in repos]
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
975 rids = [x.get("id", "?") for x in repos]
80
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
976 sto.write(f"############names={rnames} rids={rids}\n")
100
c749364c2283 Uploaded
fubar
parents: 99
diff changeset
977 sto.write(f"############names={repos}\n")
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
978 tfcat = "ToolFactory generated tools"
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
979 if self.tool_name not in rnames:
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
980 tscat = ts.categories.get_categories()
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
981 cnames = [x.get("name", "?").strip() for x in tscat]
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
982 cids = [x.get("id", "?") for x in tscat]
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
983 catID = None
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
984 if tfcat.strip() in cnames:
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
985 ci = cnames.index(tfcat)
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
986 catID = cids[ci]
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
987 res = ts.repositories.create_repository(
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
988 name=self.args.tool_name,
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
989 synopsis="Synopsis:%s" % self.args.tool_desc,
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
990 description=self.args.tool_desc,
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
991 type="unrestricted",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
992 remote_repository_url=self.args.toolshed_url,
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
993 homepage_url=None,
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
994 category_ids=catID,
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
995 )
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
996 tid = res.get("id", None)
80
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
997 sto.write(f"##########create res={res}\n")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
998 else:
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
999 i = rnames.index(self.tool_name)
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1000 tid = rids[i]
100
c749364c2283 Uploaded
fubar
parents: 99
diff changeset
1001 try:
c749364c2283 Uploaded
fubar
parents: 99
diff changeset
1002 res = ts.repositories.update_repository(
c749364c2283 Uploaded
fubar
parents: 99
diff changeset
1003 id=tid, tar_ball_path=self.newtarpath, commit_message=None)
c749364c2283 Uploaded
fubar
parents: 99
diff changeset
1004 sto.write(f"#####update res={res}\n")
c749364c2283 Uploaded
fubar
parents: 99
diff changeset
1005 except ConnectionError:
c749364c2283 Uploaded
fubar
parents: 99
diff changeset
1006 sto.write("Probably no change to repository - bioblend shed upload failed\n")
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1007 sto.close()
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1008
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1009 def eph_galaxy_load(self):
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1010 """load the new tool from the local toolshed after planemo uploads it"""
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1011 if os.path.exists(self.tlog):
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1012 tout = open(self.tlog, "a")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1013 else:
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1014 tout = open(self.tlog, "w")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1015 cll = [
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1016 "shed-tools",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1017 "install",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1018 "-g",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1019 self.args.galaxy_url,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1020 "--latest",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1021 "-a",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1022 self.args.galaxy_api_key,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1023 "--name",
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1024 self.tool_name,
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1025 "--owner",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1026 "fubar",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1027 "--toolshed",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1028 self.args.toolshed_url,
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1029 "--section_label",
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1030 "ToolFactory",
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1031 ]
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1032 tout.write("running\n%s\n" % " ".join(cll))
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1033 subp = subprocess.run(cll, env=self.ourenv, cwd=self.ourcwd, shell=False, stderr=tout, stdout=tout)
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1034 tout.write(
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1035 "installed %s - got retcode %d\n" % (self.tool_name, subp.returncode)
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1036 )
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1037 tout.close()
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1038 return subp.returncode
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1039
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1040 def planemo_shedLoad(self):
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1041 """
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1042 planemo shed_create --shed_target testtoolshed
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1043 planemo shed_init --name=<name>
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1044 --owner=<shed_username>
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1045 --description=<short description>
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1046 [--remote_repository_url=<URL to .shed.yml on github>]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1047 [--homepage_url=<Homepage for tool.>]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1048 [--long_description=<long description>]
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1049 [--category=<category name>]*
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1050
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1051
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1052 planemo shed_update --check_diff --shed_target testtoolshed
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1053 """
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1054 if os.path.exists(self.tlog):
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1055 tout = open(self.tlog, "a")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1056 else:
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1057 tout = open(self.tlog, "w")
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1058 ts = toolshed.ToolShedInstance(
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1059 url=self.args.toolshed_url, key=self.args.toolshed_api_key, verify=False
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1060 )
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1061 repos = ts.repositories.get_repositories()
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1062 rnames = [x.get("name", "?") for x in repos]
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1063 rids = [x.get("id", "?") for x in repos]
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1064 #cat = "ToolFactory generated tools"
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1065 if self.tool_name not in rnames:
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1066 cll = [
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1067 "planemo",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1068 "shed_create",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1069 "--shed_target",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1070 "local",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1071 "--owner",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1072 "fubar",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1073 "--name",
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1074 self.tool_name,
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1075 "--shed_key",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1076 self.args.toolshed_api_key,
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1077 ]
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1078 try:
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1079 subp = subprocess.run(
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1080 cll, env=self.ourenv, shell=False, cwd=self.tooloutdir, stdout=tout, stderr=tout
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1081 )
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1082 except:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1083 pass
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1084 if subp.returncode != 0:
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1085 tout.write("Repository %s exists\n" % self.tool_name)
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1086 else:
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1087 tout.write("initiated %s\n" % self.tool_name)
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1088 cll = [
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1089 "planemo",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1090 "shed_upload",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1091 "--shed_target",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1092 "local",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1093 "--owner",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1094 "fubar",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1095 "--name",
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1096 self.tool_name,
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1097 "--shed_key",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1098 self.args.toolshed_api_key,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1099 "--tar",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1100 self.newtarpath,
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1101 ]
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1102 subp = subprocess.run(cll, env=self.ourenv, cwd=self.ourcwd, shell=False, stdout=tout, stderr=tout)
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1103 tout.write("Ran %s got %d\n" % (" ".join(cll),subp.returncode))
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1104 tout.close()
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1105 return subp.returncode
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1106
76
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1107 def eph_test(self, genoutputs=True):
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1108 """problem getting jobid - ephemeris upload is the job before the one we want - but depends on how many inputs
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1109 """
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1110 if os.path.exists(self.tlog):
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1111 tout = open(self.tlog, "a")
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1112 else:
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1113 tout = open(self.tlog, "w")
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1114 cll = [
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1115 "shed-tools",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1116 "test",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1117 "-g",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1118 self.args.galaxy_url,
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1119 "-a",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1120 self.args.galaxy_api_key,
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1121 "--name",
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1122 self.tool_name,
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1123 "--owner",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1124 "fubar",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1125 ]
76
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1126 if genoutputs:
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1127 dummy, tfile = tempfile.mkstemp()
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1128 subp = subprocess.run(
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1129 cll, env=self.ourenv, cwd=self.ourcwd, shell=False, stderr=dummy, stdout=dummy
76
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1130 )
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1131
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1132 with open('tool_test_output.json','rb') as f:
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1133 s = json.loads(f.read())
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1134 print('read %s' % s)
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1135 cl = s['tests'][0]['data']['job']['command_line'].split()
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1136 n = cl.index('--script_path')
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1137 jobdir = cl[n+1]
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1138 jobdir = jobdir.replace('"','')
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1139 jobdir = jobdir.split('/configs')[0]
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1140 print('jobdir=%s' % jobdir)
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1141
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1142 #"/home/ross/galthrow/database/jobs_directory/000/649/configs/tmptfxu51gs\"
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1143 src = os.path.join(jobdir,'working',self.newtarpath)
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1144 if os.path.exists(src):
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1145 dest = os.path.join(self.testdir, self.newtarpath)
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1146 shutil.copyfile(src, dest)
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1147 else:
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1148 tout.write('No toolshed archive found after first ephemeris test - not a good sign')
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1149 ephouts = os.path.join(jobdir,'working','tfout','test-data')
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1150 with os.scandir(ephouts) as outs:
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1151 for entry in outs:
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1152 if not entry.is_file():
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1153 continue
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1154 dest = os.path.join(self.tooloutdir, entry.name)
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1155 src = os.path.join(ephouts, entry.name)
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1156 shutil.copyfile(src, dest)
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1157 else:
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1158 subp = subprocess.run(
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1159 cll, env=self.ourenv, cwd=self.ourcwd, shell=False, stderr=tout, stdout=tout)
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1160 tout.write("eph_test Ran %s got %d" % (" ".join(cll), subp.returncode))
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1161 tout.close()
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1162 return subp.returncode
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1163
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1164 def planemo_test_biocontainer(self, genoutputs=True):
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1165 """planemo is a requirement so is available for testing but testing in a biocontainer
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1166 requires some fiddling to use the hacked galaxy-central .venv
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1167
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1168 Planemo runs:
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1169 python ./scripts/functional_tests.py -v --with-nosehtml --html-report-file
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1170 /export/galaxy-central/database/job_working_directory/000/17/working/TF_run_report_tempdir/tacrev_planemo_test_report.html
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1171 --with-xunit --xunit-file /tmp/tmpt90p7f9h/xunit.xml --with-structureddata
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1172 --structured-data-file
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1173 /export/galaxy-central/database/job_working_directory/000/17/working/tfout/tool_test_output.json functional.test_toolbox
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1174
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1175
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1176 for the planemo-biocontainer,
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1177 planemo test --conda_dependency_resolution --skip_venv --galaxy_root /galthrow/ rgToolFactory2.xml
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1178
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1179 """
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1180 xreal = "%s.xml" % self.tool_name
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1181 tool_test_path = os.path.join(self.repdir,f"{self.tool_name}_planemo_test_report.html")
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1182 if os.path.exists(self.tlog):
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1183 tout = open(self.tlog, "a")
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1184 else:
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1185 tout = open(self.tlog, "w")
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1186 if genoutputs:
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1187 dummy, tfile = tempfile.mkstemp()
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1188 cll = [
95
6d122fd54cd0 Uploaded
fubar
parents: 91
diff changeset
1189 ".", os.path.join(self.args.galaxy_root,'.venv','bin','activate'),"&&",
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1190 "planemo",
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1191 "test",
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1192 "--test_data", self.testdir,
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1193 "--test_output", tool_test_path,
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1194 "--skip_venv",
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1195 "--galaxy_root",
91
7176af503cdd Uploaded
fubar
parents: 87
diff changeset
1196 self.args.galaxy_root,
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1197 "--update_test_data",
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1198 xreal,
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1199 ]
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1200 subp = subprocess.run(
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1201 cll,
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1202 env=self.ourenv,
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1203 shell=False,
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1204 cwd=self.tooloutdir,
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1205 stderr=dummy,
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1206 stdout=dummy,
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1207 )
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1208
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1209 else:
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1210 cll = [
95
6d122fd54cd0 Uploaded
fubar
parents: 91
diff changeset
1211 ".", os.path.join(self.args.galaxy_root,'.venv','bin','activate'),"&&",
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1212 "planemo",
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1213 "test",
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1214 "--test_data", os.path.self.testdir,
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1215 "--test_output", os.path.tool_test_path,
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1216 "--skip_venv",
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1217 "--galaxy_root",
91
7176af503cdd Uploaded
fubar
parents: 87
diff changeset
1218 self.args.galaxy_root,
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1219 xreal,
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1220 ]
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1221 subp = subprocess.run(
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1222 cll, env=self.ourenv, shell=False, cwd=self.tooloutdir, stderr=tout, stdout=tout
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1223 )
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1224 tout.close()
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1225 return subp.returncode
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1226
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1227 def planemo_test(self, genoutputs=True):
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1228 """planemo is a requirement so is available for testing but needs a different call if
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1229 in the biocontainer - see above
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1230 and for generating test outputs if command or test overrides are supplied
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1231 test outputs are sent to repdir for display
81
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1232 planemo test --engine docker_galaxy --galaxy_root /galaxy-central pyrevpos/pyrevpos.xml
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1233
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1234 Planemo runs:
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1235 python ./scripts/functional_tests.py -v --with-nosehtml --html-report-file
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1236 /export/galaxy-central/database/job_working_directory/000/17/working/TF_run_report_tempdir/tacrev_planemo_test_report.html
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1237 --with-xunit --xunit-file /tmp/tmpt90p7f9h/xunit.xml --with-structureddata
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1238 --structured-data-file
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1239 /export/galaxy-central/database/job_working_directory/000/17/working/tfout/tool_test_output.json functional.test_toolbox
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1240
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1241
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1242 for the planemo-biocontainer,
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1243 planemo test --conda_dependency_resolution --skip_venv --galaxy_root /galthrow/ rgToolFactory2.xml
6395be766c2e Uploaded
fubar
parents: 80
diff changeset
1244
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1245 """
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1246 xreal = "%s.xml" % self.tool_name
78
89aca6c67405 Uploaded
fubar
parents: 76
diff changeset
1247 tool_test_path = os.path.join(self.repdir,f"{self.tool_name}_planemo_test_report.html")
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1248 if os.path.exists(self.tlog):
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1249 tout = open(self.tlog, "a")
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1250 else:
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1251 tout = open(self.tlog, "w")
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1252 if genoutputs:
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1253 dummy, tfile = tempfile.mkstemp()
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1254 cll = [
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1255 "planemo",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1256 "test",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1257 "--galaxy_root",
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1258 self.args.galaxy_root,
74
3d4324df911b Uploaded
fubar
parents: 72
diff changeset
1259 "--update_test_data",
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1260 xreal,
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1261 ]
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1262 subp = subprocess.run(
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1263 cll,
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1264 env=self.ourenv,
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1265 shell=False,
96
d54976fc996a Uploaded
fubar
parents: 95
diff changeset
1266 cwd=self.testdir,
80
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1267 stderr=dummy,
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1268 stdout=dummy,
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1269 )
80
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1270
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1271 else:
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1272 cll = [
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1273 "planemo",
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1274 "test",
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1275 "--test_data", self.testdir,
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1276 "--test_output",tool_test_path,
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1277 "--galaxy_root",
74
3d4324df911b Uploaded
fubar
parents: 72
diff changeset
1278 self.args.galaxy_root,
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1279 xreal,
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1280 ]
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1281 subp = subprocess.run(
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1282 cll, env=self.ourenv, shell=False, cwd=self.testdir, stderr=tout, stdout=tout
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1283 )
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1284 tout.close()
98
67628c7dc9f3 Uploaded
fubar
parents: 97
diff changeset
1285 return subp.returncode
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1286
83
48acd0708839 Uploaded
fubar
parents: 81
diff changeset
1287
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1288 def writeShedyml(self):
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1289 """for planemo"""
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1290 yuser = self.args.user_email.split("@")[0]
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1291 yfname = os.path.join(self.tooloutdir, ".shed.yml")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1292 yamlf = open(yfname, "w")
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1293 odict = {
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1294 "name": self.tool_name,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1295 "owner": yuser,
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1296 "type": "unrestricted",
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1297 "description": self.args.tool_desc,
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1298 "synopsis": self.args.tool_desc,
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1299 "category": "TF Generated Tools",
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1300 }
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1301 yaml.dump(odict, yamlf, allow_unicode=True)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1302 yamlf.close()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1303
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1304 def makeTool(self):
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1305 """write xmls and input samples into place"""
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1306 self.makeXML()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1307 if self.args.script_path:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1308 stname = os.path.join(self.tooloutdir, "%s" % (self.sfile))
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1309 if not os.path.exists(stname):
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1310 shutil.copyfile(self.sfile, stname)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1311 xreal = "%s.xml" % self.tool_name
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1312 xout = os.path.join(self.tooloutdir, xreal)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1313 shutil.copyfile(xreal, xout)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1314 for p in self.infiles:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1315 pth = p[IPATHPOS]
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1316 dest = os.path.join(self.testdir, "%s_sample" % p[ICLPOS])
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1317 shutil.copyfile(pth, dest)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1318
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1319 def makeToolTar(self):
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1320 """move outputs into test-data and prepare the tarball"""
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1321 excludeme = "_planemo_test_report.html"
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1322
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1323 def exclude_function(tarinfo):
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1324 filename = tarinfo.name
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1325 return (
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1326 None
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1327 if filename.endswith(excludeme)
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1328 else tarinfo
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1329 )
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1330
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1331 for p in self.outfiles:
96
d54976fc996a Uploaded
fubar
parents: 95
diff changeset
1332 oname = p[ONAMEPOS]
99
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1333 tdest = os.path.join(self.testdir, "%s_sample" % oname)
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1334 if not os.path.isfile(tdest):
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1335 src = os.path.join(self.testdir,oname)
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1336 if os.path.isfile(src):
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1337 shutil.copyfile(src, tdest)
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1338 dest = os.path.join(self.repdir, "%s.sample" % (oname))
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1339 shutil.copyfile(src, dest)
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1340 else:
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1341 print(
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1342 "### problem - output file %s not found in testdir %s"
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1343 % (tdest, self.testdir)
d4d88d393285 Uploaded
fubar
parents: 98
diff changeset
1344 )
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1345 tf = tarfile.open(self.newtarpath, "w:gz")
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1346 tf.add(name=self.tooloutdir, arcname=self.tool_name, filter=exclude_function)
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1347 tf.close()
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1348 shutil.copyfile(self.newtarpath, self.args.new_tool)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1349
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1350 def moveRunOutputs(self):
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1351 """need to move planemo or run outputs into toolfactory collection"""
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1352 with os.scandir(self.tooloutdir) as outs:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1353 for entry in outs:
80
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1354 if not entry.is_file():
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1355 continue
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1356 if "." in entry.name:
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1357 nayme, ext = os.path.splitext(entry.name)
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1358 if ext in ['.yml','.xml','.json','.yaml']:
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1359 ext = f'{ext}.txt'
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1360 else:
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1361 ext = ".txt"
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1362 ofn = "%s%s" % (entry.name.replace(".", "_"), ext)
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1363 dest = os.path.join(self.repdir, ofn)
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1364 src = os.path.join(self.tooloutdir, entry.name)
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1365 shutil.copyfile(src, dest)
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1366 with os.scandir(self.testdir) as outs:
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1367 for entry in outs:
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1368 if (not entry.is_file()) or entry.name.endswith('_sample') or entry.name.endswith("_planemo_test_report.html"):
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1369 continue
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1370 if "." in entry.name:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1371 nayme, ext = os.path.splitext(entry.name)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1372 else:
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1373 ext = ".txt"
80
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1374 newname = f"{entry.name}{ext}"
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1375 dest = os.path.join(self.repdir, newname)
f423a77bc669 Uploaded
fubar
parents: 78
diff changeset
1376 src = os.path.join(self.testdir, entry.name)
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1377 shutil.copyfile(src, dest)
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1378
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1379
76
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1380
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1381 def main():
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1382 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1383 This is a Galaxy wrapper. It expects to be called by a special purpose tool.xml as:
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1384 <command interpreter="python">rgBaseScriptWrapper.py --script_path "$scriptPath"
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1385 --tool_name "foo" --interpreter "Rscript"
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1386 </command>
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1387 """
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1388 parser = argparse.ArgumentParser()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1389 a = parser.add_argument
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1390 a("--script_path", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1391 a("--history_test", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1392 a("--cl_prefix", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1393 a("--sysexe", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1394 a("--packages", default=None)
76
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1395 a("--tool_name", default="newtool")
72
a8764cda9dbf Uploaded
fubar
parents: 69
diff changeset
1396 a("--tool_dir", default=None)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1397 a("--input_files", default=[], action="append")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1398 a("--output_files", default=[], action="append")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1399 a("--user_email", default="Unknown")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1400 a("--bad_user", default=None)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1401 a("--make_Tool", default="runonly")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1402 a("--help_text", default=None)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1403 a("--tool_desc", default=None)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1404 a("--tool_version", default=None)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1405 a("--citations", default=None)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1406 a("--command_override", default=None)
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1407 a("--test_override", default=None)
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1408 a("--additional_parameters", action="append", default=[])
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1409 a("--edit_additional_parameters", action="store_true", default=False)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1410 a("--parampass", default="positional")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1411 a("--tfout", default="./tfout")
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1412 a("--new_tool", default="new_tool")
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1413 a("--galaxy_url", default="http://localhost:8080")
75
25dd9364a32a Uploaded
fubar
parents: 74
diff changeset
1414 a(
76
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1415 "--toolshed_url", default="http://localhost:9009")
46db8143adb7 Uploaded
fubar
parents: 75
diff changeset
1416 # make sure this is identical to tool_sheds_conf.xml localhost != 127.0.0.1 so validation fails
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1417 a("--toolshed_api_key", default="fakekey")
50
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1418 a("--galaxy_api_key", default="fakekey")
bf432f4486c7 Uploaded
fubar
parents: 49
diff changeset
1419 a("--galaxy_root", default="/galaxy-central")
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1420 a("--galaxy_venv", default="/galaxy_venv")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1421 args = parser.parse_args()
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1422 assert not args.bad_user, (
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1423 'UNAUTHORISED: %s is NOT authorized to use this tool until Galaxy admin adds %s to "admin_users" in the Galaxy configuration file'
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1424 % (args.bad_user, args.bad_user)
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1425 )
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1426 assert args.tool_name, "## Tool Factory expects a tool name - eg --tool_name=DESeq"
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1427 assert (
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1428 args.sysexe or args.packages
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1429 ), "## Tool Factory wrapper expects an interpreter or an executable package"
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1430 args.input_files = [x.replace('"', "").replace("'", "") for x in args.input_files]
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1431 # remove quotes we need to deal with spaces in CL params
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1432 for i, x in enumerate(args.additional_parameters):
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1433 args.additional_parameters[i] = args.additional_parameters[i].replace('"', "")
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1434 r = ScriptRunner(args)
49
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1435 r.writeShedyml()
35a912ce0c83 Can now make the bwa example from planemo :)
fubar
parents: 48
diff changeset
1436 r.makeTool()
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1437 if args.make_Tool == "generate":
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1438 retcode = r.run() # for testing toolfactory itself
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1439 r.moveRunOutputs()
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1440 r.makeToolTar()
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1441 else:
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1442 r.planemo_biodocker_test() # test to make outputs and then test
66
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1443 r.moveRunOutputs()
bc1977b1f7b5 Uploaded
fubar
parents: 65
diff changeset
1444 r.makeToolTar()
101
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1445 if args.make_Tool == "gentestinstall":
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1446 r.shedLoad()
557d5f06f213 Uploaded
fubar
parents: 100
diff changeset
1447 r.eph_galaxy_load()
63
b3254219d4fb Uploaded
fubar
parents: 62
diff changeset
1448
48
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1449
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1450 if __name__ == "__main__":
5a7a5b06bce0 Uploaded
fubar
parents:
diff changeset
1451 main()