Mercurial > repos > richard-burhans > segalign
comparison package_output.py @ 16:4966e095e3c3 draft
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 6cf972d7f1c9ecb097994494a27d00906c6c3e4d
author | richard-burhans |
---|---|
date | Tue, 30 Jul 2024 17:19:56 +0000 |
parents | 168b0a92edd3 |
children | cefa7625d6cb |
comparison
equal
deleted
inserted
replaced
15:99ee8d6f6815 | 16:4966e095e3c3 |
---|---|
16 self, | 16 self, |
17 pathname: str = "data_package.tgz", | 17 pathname: str = "data_package.tgz", |
18 top_dir: str = "galaxy", | 18 top_dir: str = "galaxy", |
19 data_dir: str = "files", | 19 data_dir: str = "files", |
20 config_file: str = "commands.json", | 20 config_file: str = "commands.json", |
21 format_file: str = "format.txt" | |
21 ) -> None: | 22 ) -> None: |
22 self.pathname: str = os.path.realpath(pathname) | 23 self.pathname: str = os.path.realpath(pathname) |
23 self.data_root: str = os.path.join(top_dir, data_dir) | 24 self.data_root: str = os.path.join(top_dir, data_dir) |
24 self.config_path: str = os.path.join(top_dir, config_file) | 25 self.config_path: str = os.path.join(top_dir, config_file) |
25 self.config_file: str = config_file | 26 self.config_file: str = config_file |
27 self.format_path: str = os.path.join(top_dir, format_file) | |
28 self.format_file: str = format_file | |
26 self.tarfile: typing.Optional[tarfile.TarFile] = None | 29 self.tarfile: typing.Optional[tarfile.TarFile] = None |
27 self.name_cache: typing.Dict[typing.Any, typing.Any] = {} | 30 self.name_cache: typing.Dict[typing.Any, typing.Any] = {} |
28 self.working_dir: str = os.path.realpath(os.getcwd()) | 31 self.working_dir: str = os.path.realpath(os.getcwd()) |
29 | 32 |
30 def _initialize(self) -> None: | 33 def _initialize(self) -> None: |
74 sys.exit(f"missing source file {source_path}") | 77 sys.exit(f"missing source file {source_path}") |
75 | 78 |
76 self.name_cache[dest_path] = 1 | 79 self.name_cache[dest_path] = 1 |
77 # print(f"added: {dest_path}", flush=True) | 80 # print(f"added: {dest_path}", flush=True) |
78 | 81 |
82 def add_format(self, pathname: str) -> None: | |
83 if self.tarfile is None: | |
84 self._initialize() | |
85 | |
86 source_path = os.path.realpath(pathname) | |
87 | |
88 if self.tarfile is not None: | |
89 self.tarfile.add(source_path, arcname=self.format_path, recursive=False) | |
90 | |
79 def close(self) -> None: | 91 def close(self) -> None: |
80 if self.tarfile is not None: | 92 if self.tarfile is not None: |
81 self.tarfile.close() | 93 self.tarfile.close() |
82 self.tarfile = None | 94 self.tarfile = None |
83 | 95 |
85 class bashCommandLineFile: | 97 class bashCommandLineFile: |
86 def __init__( | 98 def __init__( |
87 self, | 99 self, |
88 pathname: str, | 100 pathname: str, |
89 config: configparser.ConfigParser, | 101 config: configparser.ConfigParser, |
102 args: argparse.Namespace, | |
90 package_file: PackageFile, | 103 package_file: PackageFile, |
91 ) -> None: | 104 ) -> None: |
92 self.pathname: str = pathname | 105 self.pathname: str = pathname |
93 self.config = config | 106 self.config = config |
107 self.args = args | |
94 self.package_file = package_file | 108 self.package_file = package_file |
95 self.executable: typing.Optional[str] = None | 109 self.executable: typing.Optional[str] = None |
96 self._parse_lines() | 110 self._parse_lines() |
111 self._write_format() | |
97 | 112 |
98 def _parse_lines(self) -> None: | 113 def _parse_lines(self) -> None: |
99 with open("commands.json", "w") as ofh: | 114 with open("commands.json", "w") as ofh: |
100 with open(self.pathname) as f: | 115 with open(self.pathname) as f: |
101 line: str | 116 line: str |
233 value = rest.pop(0) | 248 value = rest.pop(0) |
234 command_dict["args"].append(f"--query={value}") | 249 command_dict["args"].append(f"--query={value}") |
235 | 250 |
236 return command_dict | 251 return command_dict |
237 | 252 |
253 def _write_format(self) -> None: | |
254 if self.args.format_selector == "bam": | |
255 format_name = "bam" | |
256 elif self.args.format_selector == "maf": | |
257 format_name = "maf" | |
258 elif self.args.format_selector == "differences": | |
259 format_name = "interval" | |
260 else: | |
261 format_name = "tabular" | |
262 | |
263 with open("format.txt", "w") as ofh: | |
264 print(f"{format_name}", file=ofh) | |
265 | |
266 self.package_file.add_format("format.txt") | |
267 | |
238 | 268 |
239 class nodevisitor(bashlex.ast.nodevisitor): # type: ignore[misc] | 269 class nodevisitor(bashlex.ast.nodevisitor): # type: ignore[misc] |
240 def __init__(self, positions: typing.List[typing.Tuple[int, int]]) -> None: | 270 def __init__(self, positions: typing.List[typing.Tuple[int, int]]) -> None: |
241 self.positions = positions | 271 self.positions = positions |
242 self.stdin = None | 272 self.stdin = None |
270 | 300 |
271 | 301 |
272 def main() -> None: | 302 def main() -> None: |
273 parser = argparse.ArgumentParser() | 303 parser = argparse.ArgumentParser() |
274 parser.add_argument("--tool_directory", type=str, required=True, help="tool directory") | 304 parser.add_argument("--tool_directory", type=str, required=True, help="tool directory") |
305 parser.add_argument("--format_selector", type=str, required=True, help="format selector") | |
275 args = parser.parse_args() | 306 args = parser.parse_args() |
276 | 307 |
277 lastz_command_config_file: str = os.path.join(args.tool_directory, "lastz-cmd.ini") | 308 lastz_command_config_file: str = os.path.join(args.tool_directory, "lastz-cmd.ini") |
278 | 309 |
279 config: configparser.ConfigParser = configparser.ConfigParser() | 310 config: configparser.ConfigParser = configparser.ConfigParser() |
280 config.read(lastz_command_config_file) | 311 config.read(lastz_command_config_file) |
281 | 312 |
282 package_file = PackageFile() | 313 package_file = PackageFile() |
283 lastz_command_file = "lastz-commands.txt" | 314 lastz_command_file = "lastz-commands.txt" |
284 bashCommandLineFile(lastz_command_file, config, package_file) | 315 bashCommandLineFile(lastz_command_file, config, args, package_file) |
285 package_file.close() | 316 package_file.close() |
286 | 317 |
287 | 318 |
288 if __name__ == "__main__": | 319 if __name__ == "__main__": |
289 main() | 320 main() |