Mercurial > repos > richard-burhans > batched_lastz
annotate run_lastz_tarball.py @ 16:79182c2a8c80 draft default tip
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
| author | richard-burhans |
|---|---|
| date | Tue, 09 Sep 2025 17:51:23 +0000 |
| parents | f6090d2a5722 |
| children |
| 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 |
|
15
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
5 import contextlib |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
6 import gzip |
|
0
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 json |
|
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 multiprocessing |
|
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 os |
|
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 queue |
|
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 re |
|
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 shutil |
|
6
34d51e66256c
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 2ab3532f7a45153eb0f945ac22c37cdcaea8c1e1
richard-burhans
parents:
2
diff
changeset
|
13 import subprocess |
|
0
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 sys |
|
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 tarfile |
|
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 tempfile |
|
6
34d51e66256c
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 2ab3532f7a45153eb0f945ac22c37cdcaea8c1e1
richard-burhans
parents:
2
diff
changeset
|
17 import time |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
18 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
|
19 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
20 |
|
15
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
21 @contextlib.contextmanager |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
22 def open_file(filename: str): |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
23 if filename.endswith(".gz"): |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
24 with gzip.open(filename, "wt", compresslevel=6) as f: |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
25 yield f |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
26 else: |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
27 with open(filename, "w") as f: |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
28 yield f |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
29 |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
30 |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
31 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
|
32 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
|
33 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
|
34 ) |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
35 |
|
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 # 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
|
38 # ‑‑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
|
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 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
41 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
|
42 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
|
43 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
|
44 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
|
45 debug: bool = False, |
|
11
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
46 ) -> str | None: |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
47 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
|
48 |
|
10
d10e7502aba8
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit effd27b9070dc4564d3cea38869d3bf043201683
richard-burhans
parents:
8
diff
changeset
|
49 # These are not considered errors even though |
|
d10e7502aba8
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit effd27b9070dc4564d3cea38869d3bf043201683
richard-burhans
parents:
8
diff
changeset
|
50 # we will end up with a segmented alignment |
|
d10e7502aba8
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit effd27b9070dc4564d3cea38869d3bf043201683
richard-burhans
parents:
8
diff
changeset
|
51 truncation_regex = re.compile( |
|
d10e7502aba8
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit effd27b9070dc4564d3cea38869d3bf043201683
richard-burhans
parents:
8
diff
changeset
|
52 r"truncating alignment (ending|starting) at \(\d+,\d+\); anchor at \(\d+,\d+\)$" |
|
d10e7502aba8
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit effd27b9070dc4564d3cea38869d3bf043201683
richard-burhans
parents:
8
diff
changeset
|
53 ) |
|
d10e7502aba8
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit effd27b9070dc4564d3cea38869d3bf043201683
richard-burhans
parents:
8
diff
changeset
|
54 truncation_msg = "truncation can be reduced by using --allocate:traceback to increase traceback memory" |
|
d10e7502aba8
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit effd27b9070dc4564d3cea38869d3bf043201683
richard-burhans
parents:
8
diff
changeset
|
55 |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
56 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
|
57 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
|
58 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
59 if not command_dict: |
|
11
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
60 return None |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
61 |
|
8
3a67d287d19f
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit a5a11ffe6ec0c36c5997499a50d58c38c36d54ec
richard-burhans
parents:
7
diff
changeset
|
62 args = ["lastz", "--allocate:traceback=1.99G"] |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
63 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
|
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 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
|
66 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
|
67 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
|
68 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
73 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
|
74 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
|
75 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
|
76 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
77 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
|
78 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
|
79 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
80 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
|
81 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
|
82 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
|
83 |
|
11
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
84 # if there is a stderr_file, make sure it is |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
85 # empty or only contains truncation messages |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
86 stderr_ok = True |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
87 stderr_file = command_dict["stderr"] |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
88 |
|
11
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
89 if stderr_file is not None: |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
90 try: |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
91 statinfo = os.stat(stderr_file, follow_symlinks=False) |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
92 if statinfo.st_size != 0: |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
93 with open(stderr_file) as f: |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
94 for stderr_line in f: |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
95 stderr_line = stderr_line.strip() |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
96 if (not truncation_regex.match(stderr_line) and stderr_line != truncation_msg): |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
97 stderr_ok = False |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
98 except Exception: |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
99 stderr_ok = False |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
100 |
|
11
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
101 if p.returncode in [0, 1] and stderr_ok: |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
102 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
|
103 output_queue.put(elapsed) |
|
8
3a67d287d19f
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit a5a11ffe6ec0c36c5997499a50d58c38c36d54ec
richard-burhans
parents:
7
diff
changeset
|
104 else: |
|
11
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
105 return f"command failed (rc={p.returncode}): {' '.join(args)}" |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
106 |
|
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 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
|
109 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
|
110 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
|
111 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
|
112 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
|
113 self.commands: typing.List[typing.Dict[str, typing.Any]] = [] |
|
7
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
114 self.format_name = "tabular" |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
115 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
|
116 self._load_commands() |
|
7
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
117 self._load_format() |
|
0
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 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
|
120 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
|
121 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
|
122 |
|
7
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
123 def final_output_format(self) -> str: |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
124 return self.format_name |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
125 |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
126 def _extract(self) -> None: |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
127 try: |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
128 self.tarball = tarfile.open( |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
129 name=self.pathname, mode="r:*", format=tarfile.GNU_FORMAT |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
130 ) |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
131 except FileNotFoundError: |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
132 sys.exit(f"ERROR: unable to find input tarball: {self.pathname}") |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
133 except tarfile.ReadError: |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
134 sys.exit(f"ERROR: error reading input tarball: {self.pathname}") |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
135 |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
136 begin = time.perf_counter() |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
137 self.tarball.extractall(filter="data") |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
138 self.tarball.close() |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
139 elapsed = time.perf_counter() - begin |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
140 |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
141 if self.debug: |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
142 print( |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
143 f"Extracted tarball in {elapsed} seconds", file=sys.stderr, flush=True |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
144 ) |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
145 |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
146 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
|
147 try: |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
148 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
|
149 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
|
150 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
|
151 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
|
152 ) |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
153 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
154 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
|
155 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
|
156 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
|
157 try: |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
158 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
|
159 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
|
160 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
|
161 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
|
162 ) |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
163 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
164 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
|
165 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
166 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
|
167 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
|
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 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
|
170 print( |
|
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"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
|
172 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
|
173 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
|
174 ) |
|
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 _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
|
177 # 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
|
178 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
|
179 "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
|
180 "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
|
181 "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
|
182 "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
|
183 "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
|
184 } |
|
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 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
|
187 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
|
188 # 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
|
189 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
|
190 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
|
191 break |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
192 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
193 # 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
|
194 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
|
195 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
|
196 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
|
197 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
|
198 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
|
199 break |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
200 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
|
201 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
|
202 break |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
203 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
204 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
|
205 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
|
206 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
207 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
|
208 # 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
|
209 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
|
210 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
|
211 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
|
212 break |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
213 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
214 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
|
215 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
|
216 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
|
217 ) |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
218 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
219 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
|
220 |
|
7
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
221 def _load_format(self) -> None: |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
222 try: |
|
7
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
223 with open("galaxy/format.txt") as f: |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
224 format_name = f.readline() |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
225 format_name = format_name.rstrip("\n") |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
226 except FileNotFoundError: |
|
10
d10e7502aba8
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit effd27b9070dc4564d3cea38869d3bf043201683
richard-burhans
parents:
8
diff
changeset
|
227 sys.exit(f"ERROR: input tarball missing galaxy/format.txt: {self.pathname}") |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
228 |
|
16
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
229 format_map = { |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
230 "axt": "axt", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
231 "axt+": "axt", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
232 "cigar": "cigar", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
233 "differences": "interval", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
234 "lav": "lav", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
235 "lav+text": "lav", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
236 "maf": "maf", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
237 "maf+": "maf", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
238 "maf-": "maf", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
239 "sam": "sam", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
240 "sam-": "sam", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
241 "softsam": "sam", |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
242 "softsam-": "sam" |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
243 } |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
244 |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
245 self.format_name = format_map.get(format_name, "tabular") |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
246 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
247 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
248 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
|
249 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
|
250 self, |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
251 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
|
252 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
|
253 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
|
254 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
|
255 ) -> None: |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
256 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
|
257 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
|
258 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
|
259 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
|
260 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
|
261 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
|
262 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
|
263 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
|
264 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
|
265 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
266 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
|
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 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
|
269 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
|
270 |
|
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 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
|
272 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
|
273 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
|
274 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
|
275 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
|
276 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
277 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
|
278 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
|
279 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
|
280 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
|
281 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
|
282 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
283 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
|
284 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
|
285 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
|
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 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
|
288 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
|
289 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
290 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
|
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 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
|
293 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
|
294 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
|
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 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
|
297 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
|
298 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
|
299 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
300 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
|
301 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
|
302 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
|
303 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
|
304 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
|
305 else: |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
306 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
|
307 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
308 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
|
309 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
310 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
|
311 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
|
312 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
|
313 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
314 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
|
315 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
|
316 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
|
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 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
|
319 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
|
320 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
321 # 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
|
322 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
|
323 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
|
324 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
325 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
|
326 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
|
327 ) 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
|
328 futures = [ |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
329 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
|
330 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
|
331 instance, |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
332 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
|
333 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
|
334 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
|
335 ) |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
336 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
|
337 ] |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
338 |
|
11
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
339 found_falures = False |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
340 |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
341 for f in concurrent.futures.as_completed(futures): |
|
11
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
342 result = f.result() |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
343 if result is not None: |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
344 print(f"lastz: {result}", file=sys.stderr, flush=True) |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
345 |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
346 if not f.done() or f.cancelled() or f.exception() is not None: |
|
11
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
347 found_falures = True |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
348 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
349 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
|
350 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
|
351 run_times.append(run_time) |
|
16
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
352 if self.debug: |
|
79182c2a8c80
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e03d88240ee3894a2bb7bf2f196d9215cb8e0621
richard-burhans
parents:
15
diff
changeset
|
353 print(f"lastz took {run_time}", file=sys.stderr, flush=True) |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
354 |
|
11
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
355 if found_falures: |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
356 sys.exit("lastz command failed") |
|
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
357 |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
358 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
|
359 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
360 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
|
361 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
|
362 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
363 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
|
364 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
365 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
|
366 num_output_files = len(self.output_files.keys()) |
|
7
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
367 if num_output_files != 1: |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
368 sys.exit(f"ERROR: expecting a single output file, found {num_output_files}") |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
369 |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
370 final_output_format = self.batch_tar.final_output_format() |
|
15
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
371 if final_output_format in ["axt", "maf"]: |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
372 final_output_format = f"{final_output_format}.gz" |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
373 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
374 for file_type, file_list in self.output_files.items(): |
|
15
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
375 with open_file(f"output.{final_output_format}") as ofh: |
|
f6090d2a5722
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 439b32f4ac520e4b22770fa2becd363230e198e0
richard-burhans
parents:
11
diff
changeset
|
376 if final_output_format == "maf.gz": |
|
7
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
377 print("##maf version=1", file=ofh) |
|
11
aa5586d83ae3
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit e93d50e4ea6522b591e24c3b0ddbe8f9d322a93a
richard-burhans
parents:
10
diff
changeset
|
378 |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
379 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
|
380 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
|
381 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
|
382 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
|
383 |
|
7
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
384 src_filename = f"output.{final_output_format}" |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
385 shutil.copy2(src_filename, self.output_pathname) |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
386 |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
387 output_metadata = { |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
388 "output": { |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
389 "ext": final_output_format, |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
390 } |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
391 } |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
392 |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
393 with open("galaxy.json", "w") as ofh: |
|
4cd7884635c2
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 869a01abe21b6283d3c83da38fc68761c2e94ba1
richard-burhans
parents:
6
diff
changeset
|
394 json.dump(output_metadata, ofh) |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
395 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
396 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
397 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
|
398 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
|
399 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
|
400 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
401 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
|
402 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
|
403 parser.add_argument("--output", type=str, required=True) |
|
2
007990f98551
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 3bbc9b941798f866a1d8b7af1e3c0444e5130fd9
richard-burhans
parents:
0
diff
changeset
|
404 parser.add_argument("--parallel", type=int, default=2, required=False) |
|
0
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
405 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
|
406 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
407 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
|
408 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
|
409 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
|
410 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
411 |
|
103538753e81
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/batched_lastz commit 7b119b432f721e228a73396d4e8f0d54350b0481
richard-burhans
parents:
diff
changeset
|
412 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
|
413 main() |
