annotate run_lastz_tarball.py @ 1:ad3554614aad draft

planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit fc8b75c4bed19a7d2eb854ac0476f26c81698c15
author richard-burhans
date Tue, 30 Apr 2024 21:48:00 +0000
parents 103538753e81
children 007990f98551
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
0
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
1 #!/usr/bin/env python
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
2
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
3 import argparse
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
4 import concurrent.futures
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
5 import json
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
6 import multiprocessing
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
7 import os
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
8 import queue
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
9 import re
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
10 import shutil
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
11 import sys
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
12 import subprocess
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
13 import tarfile
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
14 import tempfile
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
15 import typing
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
16 import time
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
17
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
18
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
19 lastz_output_format_regex = re.compile(
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
20 r"^(?:axt\+?|blastn|cigar|differences|general-?.+|lav|lav\+text|maf[-+]?|none|paf(?::wfmash)?|rdotplot|sam-?|softsam-?|text)$",
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
21 re.IGNORECASE,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
22 )
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
23
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
24
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
25 # Specifies the output format: lav, lav+text, axt, axt+, maf, maf+, maf-, sam, softsam, sam-, softsam-, cigar, BLASTN, PAF, PAF:wfmash, differences, rdotplot, text, general[:<fields>], or general-[:<fields>].
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
26 # ‑‑format=none can be used when no alignment output is desired.
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
27
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
28
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
29 def run_command(
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
30 instance: int,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
31 input_queue: "queue.Queue[typing.Dict[str, typing.Any]]",
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
32 output_queue: "queue.Queue[float]",
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
33 debug: bool = False,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
34 ) -> None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
35 os.chdir("galaxy/files")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
36
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
37 while True:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
38 command_dict = input_queue.get()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
39
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
40 if not command_dict:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
41 return
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
42
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
43 args = ["lastz"]
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
44 args.extend(command_dict["args"])
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
45
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
46 stdin = command_dict["stdin"]
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
47 if stdin is not None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
48 stdin = open(stdin, "r")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
49
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
50 stdout = command_dict["stdout"]
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
51 if stdout is not None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
52 stdout = open(stdout, "w")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
53
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
54 stderr = command_dict["stderr"]
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
55 if stderr is not None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
56 stderr = open(stderr, "w")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
57
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
58 begin = time.perf_counter()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
59 p = subprocess.run(args, stdin=stdin, stdout=stdout, stderr=stderr)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
60
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
61 for var in [stdin, stdout, stderr]:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
62 if var is not None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
63 var.close()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
64
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
65 if p.returncode != 0:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
66 sys.exit(f"command failed: {' '.join(args)}")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
67 else:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
68 stderr = command_dict["stderr"]
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
69 if stderr is not None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
70 try:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
71 statinfo = os.stat(stderr, follow_symlinks=False)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
72 except:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
73 statinfo = None
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
74
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
75 if statinfo is None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
76 sys.exit(f"unable to stat stderr file: {' '.join(args)}")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
77
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
78 if statinfo.st_size != 0:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
79 sys.exit(f"stderr file is not empty: {' '.join(args)}")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
80
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
81 elapsed = time.perf_counter() - begin
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
82 output_queue.put(elapsed)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
83
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
84 if debug:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
85 print(f"runtime {elapsed}", file=sys.stderr, flush=True)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
86
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
87
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
88 class BatchTar:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
89 def __init__(self, pathname: str, debug: bool = False) -> None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
90 self.pathname = pathname
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
91 self.debug = debug
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
92 self.tarfile = None
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
93 self.commands: typing.List[typing.Dict[str, typing.Any]] = []
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
94 self._extract()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
95 self._load_commands()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
96
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
97 def batch_commands(self) -> typing.Iterator[typing.Dict[str, typing.Any]]:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
98 for command in self.commands:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
99 yield command
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
100
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
101 def _load_commands(self) -> None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
102 try:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
103 f = open("galaxy/commands.json")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
104 except FileNotFoundError:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
105 sys.exit(
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
106 f"ERROR: input tarball missing galaxy/commands.json: {self.pathname}"
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
107 )
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
108
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
109 begin = time.perf_counter()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
110 for json_line in f:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
111 json_line = json_line.rstrip("\n")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
112 try:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
113 command_dict = json.loads(json_line)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
114 except json.JSONDecodeError:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
115 sys.exit(
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
116 f"ERROR: bad json line in galaxy/commands.json: {self.pathname}"
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
117 )
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
118
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
119 self._load_command(command_dict)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
120
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
121 f.close()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
122 elapsed = time.perf_counter() - begin
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
123
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
124 if self.debug:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
125 print(
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
126 f"loaded {len(self.commands)} commands in {elapsed} seconds ",
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
127 file=sys.stderr,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
128 flush=True,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
129 )
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
130
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
131 def _load_command(self, command_dict: typing.Dict[str, typing.Any]) -> None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
132 # check command_dict structure
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
133 field_types: typing.Dict[str, typing.List[typing.Any]] = {
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
134 "executable": [str],
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
135 "args": [list],
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
136 "stdin": [str, "None"],
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
137 "stdout": [str, "None"],
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
138 "stderr": [str, "None"],
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
139 }
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
140
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
141 bad_format = False
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
142 for field_name in field_types.keys():
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
143 # missing field
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
144 if field_name not in command_dict:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
145 bad_format = True
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
146 break
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
147
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
148 # incorrect field type
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
149 good_type = False
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
150 for field_type in field_types[field_name]:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
151 if isinstance(field_type, str) and field_type == "None":
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
152 if command_dict[field_name] is None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
153 good_type = True
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
154 break
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
155 elif isinstance(command_dict[field_name], field_type):
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
156 good_type = True
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
157 break
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
158
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
159 if good_type is False:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
160 bad_format = True
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
161
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
162 if not bad_format:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
163 # all args must be strings
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
164 for arg in command_dict["args"]:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
165 if not isinstance(arg, str):
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
166 bad_format = True
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
167 break
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
168
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
169 if bad_format:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
170 sys.exit(
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
171 f"ERROR: unexpected json format in line in galaxy/commands.json: {self.pathname}"
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
172 )
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
173
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
174 self.commands.append(command_dict)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
175
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
176 def _extract(self) -> None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
177 try:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
178 self.tarball = tarfile.open(
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
179 name=self.pathname, mode="r:*", format=tarfile.GNU_FORMAT
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
180 )
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
181 except FileNotFoundError:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
182 sys.exit(f"ERROR: unable to find input tarball: {self.pathname}")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
183 except tarfile.ReadError:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
184 sys.exit(f"ERROR: error reading input tarball: {self.pathname}")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
185
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
186 begin = time.perf_counter()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
187 self.tarball.extractall(filter="data")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
188 self.tarball.close()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
189 elapsed = time.perf_counter() - begin
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
190
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
191 if self.debug:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
192 print(
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
193 f"Extracted tarball in {elapsed} seconds", file=sys.stderr, flush=True
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
194 )
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
195
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
196
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
197 class TarRunner:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
198 def __init__(
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
199 self,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
200 input_pathname: str,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
201 output_pathname: str,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
202 parallel: int,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
203 debug: bool = False,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
204 ) -> None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
205 self.input_pathname = input_pathname
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
206 self.output_pathname = output_pathname
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
207 self.parallel = parallel
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
208 self.debug = debug
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
209 self.batch_tar = BatchTar(self.input_pathname, debug=self.debug)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
210 self.output_file_format: typing.Dict[str, str] = {}
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
211 self.output_files: typing.Dict[str, typing.List[str]] = {}
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
212 self._set_output()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
213 self._set_target_query()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
214
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
215 def _set_output(self) -> None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
216 for command_dict in self.batch_tar.batch_commands():
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
217 output_file = None
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
218 output_format = None
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
219
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
220 for arg in command_dict["args"]:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
221 if arg.startswith("--format="):
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
222 output_format = arg[9:]
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
223 elif arg.startswith("--output="):
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
224 output_file = arg[9:]
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
225
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
226 if output_file is None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
227 f = tempfile.NamedTemporaryFile(dir="galaxy/files", delete=False)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
228 output_file = os.path.basename(f.name)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
229 f.close()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
230 command_dict["args"].append(f"--output={output_file}")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
231
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
232 if output_format is None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
233 output_format = "lav"
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
234 command_dict["args"].append(f"--format={output_format}")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
235
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
236 if not lastz_output_format_regex.match(output_format):
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
237 sys.exit(f"ERROR: invalid output format: {output_format}")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
238
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
239 self.output_file_format[output_file] = output_format
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
240
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
241 for output_file, output_format in self.output_file_format.items():
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
242 self.output_files.setdefault(output_format, [])
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
243 self.output_files[output_format].append(output_file)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
244
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
245 def _set_target_query(self) -> None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
246 for command_dict in self.batch_tar.batch_commands():
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
247 new_args: typing.List[str] = []
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
248
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
249 for arg in command_dict["args"]:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
250 if arg.startswith("--target="):
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
251 new_args.insert(0, arg[9:])
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
252 elif arg.startswith("--query="):
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
253 new_args.insert(1, arg[8:])
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
254 else:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
255 new_args.append(arg)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
256
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
257 command_dict["args"] = new_args
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
258
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
259 def run(self) -> None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
260 run_times = []
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
261 begin = time.perf_counter()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
262
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
263 with multiprocessing.Manager() as manager:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
264 input_queue: queue.Queue[typing.Dict[str, typing.Any]] = manager.Queue()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
265 output_queue: queue.Queue[float] = manager.Queue()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
266
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
267 for command_dict in self.batch_tar.batch_commands():
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
268 input_queue.put(command_dict)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
269
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
270 # use the empty dict as a sentinel
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
271 for _ in range(self.parallel):
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
272 input_queue.put({})
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
273
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
274 with concurrent.futures.ProcessPoolExecutor(
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
275 max_workers=self.parallel
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
276 ) as executor:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
277 futures = [
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
278 executor.submit(
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
279 run_command,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
280 instance,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
281 input_queue,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
282 output_queue,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
283 debug=self.debug,
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
284 )
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
285 for instance in range(self.parallel)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
286 ]
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
287
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
288 for f in concurrent.futures.as_completed(futures):
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
289 if not f.done() or f.cancelled() or f.exception() is not None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
290 sys.exit("lastz command failed")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
291
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
292 while not output_queue.empty():
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
293 run_time = output_queue.get()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
294 run_times.append(run_time)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
295
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
296 elapsed = time.perf_counter() - begin
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
297
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
298 if self.debug:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
299 print(f"elapsed {elapsed}", file=sys.stderr, flush=True)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
300
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
301 self._cleanup()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
302
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
303 def _cleanup(self) -> None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
304 num_output_files = len(self.output_files.keys())
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
305
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
306 for file_type, file_list in self.output_files.items():
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
307 with open(f"output.{file_type}", "w") as ofh:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
308 for filename in file_list:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
309 with open(f"galaxy/files/{filename}") as ifh:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
310 for line in ifh:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
311 ofh.write(line)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
312
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
313 if num_output_files == 1:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
314 file_type = list(self.output_files.keys())[0]
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
315 src_filename = f"output.{file_type}"
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
316 shutil.copy2(src_filename, self.output_pathname)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
317
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
318
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
319 def main() -> None:
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
320 if not hasattr(tarfile, "data_filter"):
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
321 sys.exit("ERROR: extracting may be unsafe; consider updating Python")
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
322
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
323 parser = argparse.ArgumentParser()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
324 parser.add_argument("--input", type=str, required=True)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
325 parser.add_argument("--output", type=str, required=True)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
326 parser.add_argument("--parallel", type=int, default=1, required=False)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
327 parser.add_argument("--debug", action="store_true", required=False)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
328
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
329 args = parser.parse_args()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
330 runner = TarRunner(args.input, args.output, args.parallel, args.debug)
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
331 runner.run()
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
332
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
333
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
334 if __name__ == "__main__":
103538753e81 planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff changeset
335 main()