bbmapy 0.0.2__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
bbmapy/__init__.py ADDED
@@ -0,0 +1,9 @@
1
+ import os
2
+ from bbmapy.scanner import scan_bbtools
3
+
4
+ # Generate commands.py if it doesn't exist
5
+ if not os.path.exists(os.path.join(os.path.dirname(__file__), "commands.py")):
6
+ scan_bbtools()
7
+
8
+ # Import all functions from commands
9
+ from bbmapy.commands import *
bbmapy/_version.py ADDED
@@ -0,0 +1,16 @@
1
+ # file generated by setuptools_scm
2
+ # don't change, don't track in version control
3
+ TYPE_CHECKING = False
4
+ if TYPE_CHECKING:
5
+ from typing import Tuple, Union
6
+ VERSION_TUPLE = Tuple[Union[int, str], ...]
7
+ else:
8
+ VERSION_TUPLE = object
9
+
10
+ version: str
11
+ __version__: str
12
+ __version_tuple__: VERSION_TUPLE
13
+ version_tuple: VERSION_TUPLE
14
+
15
+ __version__ = version = '0.0.2'
16
+ __version_tuple__ = version_tuple = (0, 0, 2)
bbmapy/base.py ADDED
@@ -0,0 +1,78 @@
1
+ import os
2
+ import sys
3
+ import subprocess
4
+ from typing import List, Dict, Union, Tuple
5
+ from rich import print as rprint
6
+
7
+ def find_bbtools_path():
8
+ # Check if we're running from an installed package
9
+ if getattr(sys, 'frozen', False):
10
+ # We're running from a bundle (e.g., PyInstaller)
11
+ base_path = sys._MEIPASS
12
+ else:
13
+ # We're running from a normal Python environment
14
+ base_path = os.path.abspath(os.path.dirname(__file__))
15
+
16
+ # Navigate up to the project root
17
+ while not os.path.exists(os.path.join(base_path, 'vendor')):
18
+ base_path = os.path.dirname(base_path)
19
+ if base_path == os.path.dirname(base_path): # We've reached the root directory
20
+ raise FileNotFoundError("Could not find BBTools directory")
21
+
22
+ bbtools_path = os.path.join(base_path, 'vendor', 'bbmap')
23
+
24
+ if not os.path.exists(bbtools_path):
25
+ raise FileNotFoundError(f"BBTools directory not found at {bbtools_path}")
26
+
27
+ return bbtools_path
28
+
29
+ BBTOOLS_PATH = find_bbtools_path()
30
+ os.environ["PATH"] = f"{BBTOOLS_PATH}/current/:{os.environ["PATH"]}"
31
+
32
+ def _pack_args(kwargs: Dict[str, Union[str, bool, int]]) -> List[str]:
33
+ args = []
34
+
35
+ for key, value in kwargs.items():
36
+ if key in ['Xmx', 'Xms', 'da', 'ea', 'eoom']:
37
+ if isinstance(value, bool) and value:
38
+ args.append(f"-{key}")
39
+ elif value is not None:
40
+ args.append(f"-{key}{value}")
41
+ elif key == "in_file":
42
+ args.append(f"in={value}")
43
+ elif isinstance(value, bool) and value:
44
+ args.append(key)
45
+ elif value is not None:
46
+ args.append(f"{key}={value}")
47
+
48
+ return args
49
+
50
+ def _run_command(tool: str, args: List[str], capture_output: bool = False) -> Union[None, Tuple[str, str]]:
51
+ command = [os.path.join(BBTOOLS_PATH,tool)] + args # ,
52
+ # command = [tool] + args # ,
53
+
54
+
55
+ if capture_output:
56
+ result = subprocess.run(command, capture_output=True, text=True)
57
+ if result.returncode != 0:
58
+ raise RuntimeError(f"Command failed: {' '.join(command)}\nError: {result.stderr}")
59
+ return result.stdout, result.stderr
60
+ else:
61
+ process = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, text=True)
62
+
63
+ while True:
64
+ stdout_line = process.stdout.readline()
65
+ stderr_line = process.stderr.readline()
66
+
67
+ if not stdout_line and not stderr_line and process.poll() is not None:
68
+ break
69
+
70
+ if stdout_line:
71
+ rprint(stdout_line.strip())
72
+ if stderr_line:
73
+ rprint("[bold red]" + stderr_line.strip() + "[/bold red]")
74
+
75
+ if process.returncode != 0:
76
+ raise RuntimeError(f"Command failed: {' '.join(command)}")
77
+
78
+ return None