diff 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
line wrap: on
line diff
--- a/package_output.py	Tue Jul 30 03:31:29 2024 +0000
+++ b/package_output.py	Tue Jul 30 17:19:56 2024 +0000
@@ -18,11 +18,14 @@
         top_dir: str = "galaxy",
         data_dir: str = "files",
         config_file: str = "commands.json",
+        format_file: str = "format.txt"
     ) -> None:
         self.pathname: str = os.path.realpath(pathname)
         self.data_root: str = os.path.join(top_dir, data_dir)
         self.config_path: str = os.path.join(top_dir, config_file)
         self.config_file: str = config_file
+        self.format_path: str = os.path.join(top_dir, format_file)
+        self.format_file: str = format_file
         self.tarfile: typing.Optional[tarfile.TarFile] = None
         self.name_cache: typing.Dict[typing.Any, typing.Any] = {}
         self.working_dir: str = os.path.realpath(os.getcwd())
@@ -76,6 +79,15 @@
                     self.name_cache[dest_path] = 1
                     # print(f"added: {dest_path}", flush=True)
 
+    def add_format(self, pathname: str) -> None:
+        if self.tarfile is None:
+            self._initialize()
+
+        source_path = os.path.realpath(pathname)
+
+        if self.tarfile is not None:
+            self.tarfile.add(source_path, arcname=self.format_path, recursive=False)
+
     def close(self) -> None:
         if self.tarfile is not None:
             self.tarfile.close()
@@ -87,13 +99,16 @@
         self,
         pathname: str,
         config: configparser.ConfigParser,
+        args: argparse.Namespace,
         package_file: PackageFile,
     ) -> None:
         self.pathname: str = pathname
         self.config = config
+        self.args = args
         self.package_file = package_file
         self.executable: typing.Optional[str] = None
         self._parse_lines()
+        self._write_format()
 
     def _parse_lines(self) -> None:
         with open("commands.json", "w") as ofh:
@@ -235,6 +250,21 @@
 
         return command_dict
 
+    def _write_format(self) -> None:
+        if self.args.format_selector == "bam":
+            format_name = "bam"
+        elif self.args.format_selector == "maf":
+            format_name = "maf"
+        elif self.args.format_selector == "differences":
+            format_name = "interval"
+        else:
+            format_name = "tabular"
+
+        with open("format.txt", "w") as ofh:
+            print(f"{format_name}", file=ofh)
+
+        self.package_file.add_format("format.txt")
+
 
 class nodevisitor(bashlex.ast.nodevisitor):  # type: ignore[misc]
     def __init__(self, positions: typing.List[typing.Tuple[int, int]]) -> None:
@@ -272,6 +302,7 @@
 def main() -> None:
     parser = argparse.ArgumentParser()
     parser.add_argument("--tool_directory", type=str, required=True, help="tool directory")
+    parser.add_argument("--format_selector", type=str, required=True, help="format selector")
     args = parser.parse_args()
 
     lastz_command_config_file: str = os.path.join(args.tool_directory, "lastz-cmd.ini")
@@ -281,7 +312,7 @@
 
     package_file = PackageFile()
     lastz_command_file = "lastz-commands.txt"
-    bashCommandLineFile(lastz_command_file, config, package_file)
+    bashCommandLineFile(lastz_command_file, config, args, package_file)
     package_file.close()