Mercurial > repos > richard-burhans > segalign
annotate runner.py @ 9:08e987868f0f draft
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 062a761a340e095ea7ef7ed7cd1d3d55b1fdc5c4
author | richard-burhans |
---|---|
date | Wed, 10 Jul 2024 17:06:45 +0000 |
parents | 150de8a3954a |
children | ae2cd39594eb |
rev | line source |
---|---|
8
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
1 #!/usr/bin/env python |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
2 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
3 import argparse |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
4 import collections |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
5 import concurrent.futures |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
6 import multiprocessing |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
7 import os |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
8 import queue |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
9 import re |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
10 import resource |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
11 import statistics |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
12 import subprocess |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
13 import sys |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
14 import time |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
15 import typing |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
16 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
17 SENTINEL_VALUE: typing.Final = "SENTINEL" |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
18 # CA_SENTEL_VALUE: typing.Final = ChunkAddress(0, 0, 0, 0, 0, SENTINEL_VALUE) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
19 RUSAGE_ATTRS: typing.Final = ["ru_utime", "ru_stime", "ru_maxrss", "ru_minflt", "ru_majflt", "ru_inblock", "ru_oublock", "ru_nvcsw", "ru_nivcsw"] |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
20 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
21 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
22 class LastzCommands: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
23 def __init__(self) -> None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
24 self.commands: dict[str, LastzCommand] = {} |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
25 self.segalign_segments: SegAlignSegments = SegAlignSegments() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
26 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
27 def add(self, line: str) -> None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
28 if line not in self.commands: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
29 self.commands[line] = LastzCommand(line) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
30 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
31 command = self.commands[line] |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
32 self.segalign_segments.add(command.segments_filename) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
33 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
34 def segments(self) -> typing.Iterator["SegAlignSegment"]: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
35 for segment in self.segalign_segments: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
36 yield segment |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
37 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
38 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
39 class LastzCommand: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
40 lastz_command_regex = re.compile(r"lastz (.+?)?ref\.2bit\[nameparse=darkspace\]\[multiple\]\[subset=ref_block(\d+)\.name\] (.+?)?query\.2bit\[nameparse=darkspace\]\[subset=query_block(\d+)\.name] --format=(\S+) --ydrop=(\d+) --gappedthresh=(\d+) --strand=(minus|plus)(?: --ambiguous=(\S+))?(?: --(notrivial))?(?: --scoring=(\S+))? --segments=tmp(\d+)\.block(\d+)\.r(\d+)\.(minus|plus)(?:\.split(\d+))?\.segments --output=tmp(\d+)\.block(\d+)\.r(\d+)\.(minus|plus)(?:\.split(\d+))?\.(\S+) 2> tmp(\d+)\.block(\d+)\.r(\d+)\.(minus|plus)(?:\.split(\d+))?\.err") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
41 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
42 def __init__(self, line: str) -> None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
43 self.line = line |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
44 self.args: list[str] = [] |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
45 self.target_filename: str = '' |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
46 self.query_filename: str = '' |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
47 self.data_folder: str = '' |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
48 self.ref_block: int = 0 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
49 self.query_block: int = 0 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
50 self.output_format: str = '' |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
51 self.ydrop: int = 0 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
52 self.gappedthresh: int = 0 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
53 self.strand: int | None = None |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
54 self.ambiguous: bool = False |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
55 self.nontrivial: bool = False |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
56 self.scoring: str | None = None |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
57 self.segments_filename: str = '' |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
58 self.output_filename: str = '' |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
59 self.error_filename: str = '' |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
60 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
61 self._parse_command() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
62 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
63 def _parse_command(self) -> None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
64 match = self.lastz_command_regex.match(self.line) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
65 if not match: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
66 sys.exit(f"Unkown lastz command format: {self.line}") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
67 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
68 self.data_folder = match.group(1) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
69 self.ref_block = int(match.group(2)) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
70 self.query_block = int(match.group(4)) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
71 self.output_format = match.group(5) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
72 self.ydrop = int(match.group(6)) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
73 self.gappedthresh = int(match.group(7)) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
74 strand = match.group(8) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
75 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
76 if strand == 'plus': |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
77 self.strand = 0 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
78 elif strand == 'minus': |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
79 self.strand = 1 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
80 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
81 self.target_filename = f"{self.data_folder}ref.2bit[nameparse=darkspace][multiple][subset=ref_block{self.ref_block}.name]" |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
82 self.query_filename = f"{self.data_folder}query.2bit[nameparse=darkspace][subset=query_block{self.query_block}.name]" |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
83 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
84 self.args = [ |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
85 "lastz", |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
86 self.target_filename, |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
87 self.query_filename, |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
88 f"--format={self.output_format}", |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
89 f"--ydrop={self.ydrop}", |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
90 f"--gappedthresh={self.gappedthresh}", |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
91 f"--strand={strand}" |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
92 ] |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
93 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
94 ambiguous = match.group(9) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
95 if ambiguous is not None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
96 self.ambiguous = True |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
97 self.args.append(f"--ambiguous={ambiguous}") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
98 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
99 nontrivial = match.group(10) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
100 if nontrivial is not None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
101 self.nontrivial = True |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
102 self.args.append("--nontrivial") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
103 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
104 scoring = match.group(11) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
105 if scoring is not None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
106 self.scoring = scoring |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
107 self.args.append(f"--scoring={scoring}") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
108 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
109 tmp_no = int(match.group(12)) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
110 block_no = int(match.group(13)) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
111 r_no = int(match.group(14)) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
112 split = match.group(16) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
113 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
114 base_filename = f"tmp{tmp_no}.block{block_no}.r{r_no}.{strand}" |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
115 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
116 if split is not None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
117 base_filename = f"{base_filename}.split{split}" |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
118 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
119 self.segments_filename = f"{base_filename}.segments" |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
120 self.args.append(f"--segments={self.segments_filename}") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
121 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
122 self.output_filename = f"{base_filename}.{self.output_format}" |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
123 self.args.append(f"--output={self.output_filename}") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
124 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
125 self.error_filename = f"{base_filename}.err" |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
126 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
127 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
128 class SegAlignSegments: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
129 def __init__(self) -> None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
130 self.segments: dict[str, SegAlignSegment] = {} |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
131 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
132 def add(self, filename: str) -> None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
133 if filename not in self.segments: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
134 self.segments[filename] = SegAlignSegment(filename) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
135 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
136 def __iter__(self) -> "SegAlignSegments": |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
137 return self |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
138 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
139 def __next__(self) -> typing.Generator["SegAlignSegment", None, None]: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
140 for segment in sorted(self.segments.values()): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
141 yield segment |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
142 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
143 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
144 class SegAlignSegment: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
145 def __init__(self, filename: str): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
146 self.filename = filename |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
147 self.tmp: int = 0 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
148 self.block: int = 0 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
149 self.r: int = 0 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
150 self.strand: int = 0 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
151 self.split: int | None = None |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
152 self.fmt: str = "" |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
153 self._parse_filename() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
154 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
155 def _parse_filename(self) -> None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
156 match = re.match(r"tmp(\d+)\.block(\d+)\.r(\d+)\.(minus|plus)(?:\.split(\d+))?\.segments$", self.filename) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
157 if not match: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
158 sys.exit(f"Unkown segment filename format: {self.filename}") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
159 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
160 self.tmp = int(match.group(1)) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
161 self.block = int(match.group(2)) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
162 self.r = int(match.group(3)) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
163 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
164 strand = match.group(4) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
165 if strand == 'plus': |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
166 self.strand = 0 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
167 if strand == 'minus': |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
168 self.strand = 1 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
169 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
170 split = match.group(5) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
171 if split is None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
172 self.split = None |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
173 else: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
174 self.split = int(split) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
175 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
176 def __lt__(self, other: "SegAlignSegment") -> bool: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
177 for attr in ['strand', 'tmp', 'block', 'r', 'split']: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
178 self_value = getattr(self, attr) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
179 other_value = getattr(other, attr) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
180 if self_value < other_value: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
181 return True |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
182 elif self_value > other_value: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
183 return False |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
184 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
185 return False |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
186 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
187 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
188 def main() -> None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
189 args, segalign_args = parse_args() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
190 lastz_commands = LastzCommands() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
191 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
192 if args.diagonal_partition: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
193 num_diagonal_partitioners = args.num_cpu |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
194 else: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
195 num_diagonal_partitioners = 0 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
196 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
197 with multiprocessing.Manager() as manager: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
198 segalign_q: queue.Queue[str] = manager.Queue() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
199 skip_segalign = run_segalign(args, num_diagonal_partitioners, segalign_args, segalign_q, lastz_commands) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
200 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
201 if num_diagonal_partitioners > 0: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
202 diagonal_partition_q = segalign_q |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
203 segalign_q = manager.Queue() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
204 run_diagonal_partitioners(args, num_diagonal_partitioners, diagonal_partition_q, segalign_q) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
205 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
206 segalign_q.put(SENTINEL_VALUE) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
207 output_q = segalign_q |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
208 segalign_q = manager.Queue() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
209 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
210 output_filename = "lastz-commands.txt" |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
211 if args.output_type == "commands": |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
212 output_filename = args.output_file |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
213 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
214 with open(output_filename, "w") as f: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
215 while True: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
216 line = output_q.get() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
217 if line == SENTINEL_VALUE: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
218 output_q.task_done() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
219 break |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
220 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
221 # messy, fix this |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
222 if skip_segalign: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
223 lastz_commands.add(line) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
224 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
225 if args.output_type != "commands": |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
226 segalign_q.put(line) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
227 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
228 print(line, file=f) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
229 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
230 if args.output_type == "output": |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
231 run_lastz(args, segalign_q, lastz_commands) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
232 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
233 with open(args.output_file, 'w') as of: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
234 print("##maf version=1", file=of) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
235 for lastz_command in lastz_commands.commands.values(): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
236 with open(lastz_command.output_filename) as f: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
237 for line in f: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
238 of.write(line) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
239 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
240 if args.output_type == "tarball": |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
241 pass |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
242 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
243 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
244 def run_lastz(args: argparse.Namespace, input_q: queue.Queue[str], lastz_commands: LastzCommands) -> None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
245 num_lastz_workers = args.num_cpu |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
246 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
247 for _ in range(num_lastz_workers): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
248 input_q.put(SENTINEL_VALUE) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
249 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
250 if args.debug: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
251 r_beg = resource.getrusage(resource.RUSAGE_CHILDREN) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
252 beg: int = time.monotonic_ns() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
253 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
254 try: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
255 with concurrent.futures.ProcessPoolExecutor(max_workers=num_lastz_workers) as executor: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
256 for i in range(num_lastz_workers): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
257 executor.submit(lastz_worker, input_q, i, lastz_commands) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
258 except Exception as e: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
259 sys.exit(f"Error: lastz failed: {e}") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
260 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
261 if args.debug: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
262 ns: int = time.monotonic_ns() - beg |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
263 r_end = resource.getrusage(resource.RUSAGE_CHILDREN) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
264 print(f"lastz clock time: {ns} ns", file=sys.stderr, flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
265 for rusage_attr in RUSAGE_ATTRS: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
266 value = getattr(r_end, rusage_attr) - getattr(r_beg, rusage_attr) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
267 print(f" lastz {rusage_attr}: {value}", file=sys.stderr, flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
268 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
269 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
270 def lastz_worker(input_q: queue.Queue[str], instance: int, lastz_commands: LastzCommands) -> None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
271 while True: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
272 line = input_q.get() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
273 if line == SENTINEL_VALUE: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
274 input_q.task_done() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
275 break |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
276 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
277 if line not in lastz_commands.commands: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
278 sys.exit(f"Error: lastz worker {instance} unexpected command format: {line}") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
279 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
280 command = lastz_commands.commands[line] |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
281 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
282 if not os.path.exists(command.output_filename): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
283 process = subprocess.run(command.args, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
284 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
285 for line in process.stdout.splitlines(): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
286 print(line, file=sys.stdout, flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
287 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
288 if len(process.stderr) != 0: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
289 for line in process.stderr.splitlines(): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
290 print(line, file=sys.stderr, flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
291 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
292 if process.returncode != 0: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
293 sys.exit(f"Error: lastz {instance} exited with returncode {process.returncode}") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
294 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
295 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
296 def run_diagonal_partitioners(args: argparse.Namespace, num_workers: int, input_q: queue.Queue[str], output_q: queue.Queue[str]) -> None: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
297 chunk_size = estimate_chunk_size(args) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
298 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
299 if args.debug: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
300 print(f"estimated chunk size: {chunk_size}", file=sys.stderr, flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
301 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
302 with concurrent.futures.ProcessPoolExecutor(max_workers=num_workers) as executor: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
303 for i in range(num_workers): |
9
08e987868f0f
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 062a761a340e095ea7ef7ed7cd1d3d55b1fdc5c4
richard-burhans
parents:
8
diff
changeset
|
304 executor.submit(diagonal_partition_worker(args, input_q, output_q, chunk_size, i)) |
8
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
305 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
306 |
9
08e987868f0f
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 062a761a340e095ea7ef7ed7cd1d3d55b1fdc5c4
richard-burhans
parents:
8
diff
changeset
|
307 def diagonal_partition_worker(args: argparse.Namespace, input_q: queue.Queue[str], output_q: queue.Queue[str], chunk_size: int, instance: int) -> None: |
8
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
308 while True: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
309 line = input_q.get() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
310 if line == SENTINEL_VALUE: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
311 input_q.task_done() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
312 break |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
313 |
9
08e987868f0f
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 062a761a340e095ea7ef7ed7cd1d3d55b1fdc5c4
richard-burhans
parents:
8
diff
changeset
|
314 run_args = ["python", f"{args.tool_directory}/diagonal_partition.py", str(chunk_size)] |
8
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
315 for word in line.split(): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
316 run_args.append(word) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
317 process = subprocess.run(run_args, stdin=subprocess.DEVNULL, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
318 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
319 for line in process.stdout.splitlines(): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
320 output_q.put(line) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
321 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
322 for line in process.stderr.splitlines(): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
323 print(line, file=sys.stderr, flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
324 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
325 if process.returncode != 0: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
326 sys.exit(f"Error: diagonal partitioner {instance} exited with returncode {process.returncode}") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
327 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
328 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
329 def estimate_chunk_size(args: argparse.Namespace) -> int: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
330 chunk_size = -1 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
331 line_size = -1 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
332 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
333 if args.debug: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
334 r_beg = resource.getrusage(resource.RUSAGE_SELF) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
335 beg: int = time.monotonic_ns() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
336 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
337 # get size of each segment assuming DELETE_AFTER_CHUNKING == True |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
338 # takes into account already split segments |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
339 fdict: typing.DefaultDict[str, int] = collections.defaultdict(int) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
340 for entry in os.scandir("."): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
341 if entry.name.endswith(".segments"): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
342 try: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
343 file_size = entry.stat().st_size |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
344 except FileNotFoundError: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
345 continue |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
346 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
347 if line_size == -1: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
348 try: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
349 with open(entry.name) as f: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
350 line_size = len(f.readline()) # add 1 for newline |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
351 except FileNotFoundError: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
352 continue |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
353 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
354 fdict[entry.name.split(".split", 1)[0]] += file_size |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
355 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
356 # if noot enough segment files for estimation, continue |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
357 if len(fdict) > 2: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
358 chunk_size = int(statistics.quantiles(fdict.values())[-1] // line_size) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
359 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
360 if args.debug: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
361 ns: int = time.monotonic_ns() - beg |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
362 r_end = resource.getrusage(resource.RUSAGE_SELF) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
363 print(f"estimate chunk size clock time: {ns} ns", file=sys.stderr, flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
364 for rusage_attr in RUSAGE_ATTRS: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
365 value = getattr(r_end, rusage_attr) - getattr(r_beg, rusage_attr) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
366 print(f" estimate chunk size {rusage_attr}: {value}", file=sys.stderr, flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
367 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
368 return chunk_size |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
369 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
370 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
371 def run_segalign(args: argparse.Namespace, num_sentinel: int, segalign_args: list[str], segalign_q: queue.Queue[str], commands: LastzCommands) -> bool: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
372 skip_segalign: bool = False |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
373 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
374 # use the currently existing output file if it exists |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
375 if args.debug: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
376 skip_segalign = load_segalign_output("lastz-commands.txt", segalign_q) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
377 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
378 if not skip_segalign: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
379 run_args = ["segalign"] |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
380 run_args.extend(segalign_args) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
381 run_args.append("--num_threads") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
382 run_args.append(str(args.num_cpu)) |
9
08e987868f0f
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 062a761a340e095ea7ef7ed7cd1d3d55b1fdc5c4
richard-burhans
parents:
8
diff
changeset
|
383 run_args.append("work/") |
8
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
384 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
385 if args.debug: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
386 beg: int = time.monotonic_ns() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
387 r_beg = resource.getrusage(resource.RUSAGE_CHILDREN) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
388 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
389 process = subprocess.run(run_args, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
390 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
391 for line in process.stdout.splitlines(): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
392 commands.add(line) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
393 segalign_q.put(line) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
394 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
395 if len(process.stderr) != 0: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
396 for line in process.stderr.splitlines(): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
397 print(line, file=sys.stderr, flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
398 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
399 if process.returncode != 0: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
400 sys.exit(f"Error: segalign exited with returncode {process.returncode}") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
401 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
402 if args.debug: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
403 ns: int = time.monotonic_ns() - beg |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
404 r_end = resource.getrusage(resource.RUSAGE_CHILDREN) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
405 print(f"segalign clock time: {ns} ns", file=sys.stderr, flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
406 for rusage_attr in RUSAGE_ATTRS: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
407 value = getattr(r_end, rusage_attr) - getattr(r_beg, rusage_attr) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
408 print(f" segalign {rusage_attr}: {value}", flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
409 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
410 for _ in range(num_sentinel): |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
411 segalign_q.put(SENTINEL_VALUE) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
412 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
413 return skip_segalign |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
414 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
415 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
416 def load_segalign_output(filename: str, segalign_q: queue.Queue[str]) -> bool: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
417 load_success = False |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
418 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
419 r_beg = resource.getrusage(resource.RUSAGE_SELF) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
420 beg: int = time.monotonic_ns() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
421 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
422 try: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
423 with open(filename) as f: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
424 for line in f: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
425 line = line.rstrip("\n") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
426 segalign_q.put(line) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
427 load_success = True |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
428 except FileNotFoundError: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
429 pass |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
430 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
431 if load_success: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
432 ns: int = time.monotonic_ns() - beg |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
433 r_end = resource.getrusage(resource.RUSAGE_SELF) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
434 print(f"load output clock time: {ns} ns", file=sys.stderr, flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
435 for rusage_attr in RUSAGE_ATTRS: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
436 value = getattr(r_end, rusage_attr) - getattr(r_beg, rusage_attr) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
437 print(f" load output {rusage_attr}: {value}", flush=True) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
438 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
439 return load_success |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
440 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
441 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
442 def parse_args() -> tuple[argparse.Namespace, list[str]]: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
443 parser = argparse.ArgumentParser(allow_abbrev=False) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
444 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
445 parser.add_argument("--output-type", nargs="?", const="commands", default="commands", type=str, choices=["commands", "output", "tarball"], help="output type (default: %(default)s)") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
446 parser.add_argument("--output-file", type=str, required=True, help="output pathname") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
447 parser.add_argument("--diagonal-partition", action="store_true", help="run diagonal partition optimization") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
448 parser.add_argument("--nogapped", action="store_true", help="don't perform gapped extension stage") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
449 parser.add_argument("--markend", action="store_true", help="write a marker line just before completion") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
450 parser.add_argument("--num-gpu", default=-1, type=int, help="number of GPUs to use (default: %(default)s [use all GPUs])") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
451 parser.add_argument("--num-cpu", default=-1, type=int, help="number of CPUs to use (default: %(default)s [use all CPUs])") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
452 parser.add_argument("--debug", action="store_true", help="print debug messages") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
453 parser.add_argument("--tool_directory", type=str, required=True, help="tool directory") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
454 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
455 if not sys.argv[1:]: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
456 parser.print_help() |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
457 sys.exit(0) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
458 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
459 args, segalign_args = parser.parse_known_args(sys.argv[1:]) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
460 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
461 cpus_available = len(os.sched_getaffinity(0)) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
462 if args.num_cpu == -1: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
463 args.num_cpu = cpus_available |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
464 elif args.num_cpu > cpus_available: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
465 sys.exit(f"Error: additional {args.num_cpu - cpus_available} CPUs") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
466 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
467 if args.nogapped: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
468 segalign_args.append("--nogapped") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
469 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
470 if args.markend: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
471 segalign_args.append("--markend") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
472 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
473 if args.num_gpu != -1: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
474 segalign_args.extend(["--num_gpu", f"{args.num_gpu}"]) |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
475 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
476 if args.debug: |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
477 segalign_args.append("--debug") |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
478 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
479 return args, segalign_args |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
480 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
481 |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
482 if __name__ == "__main__": |
150de8a3954a
planemo upload for repository https://github.com/richard-burhans/galaxytools/tree/main/tools/segalign commit 11132ef8b4103731b6f5860ea736bf332a06e303
richard-burhans
parents:
diff
changeset
|
483 main() |