-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBioAnalyzer
More file actions
executable file
·119 lines (101 loc) · 4 KB
/
BioAnalyzer
File metadata and controls
executable file
·119 lines (101 loc) · 4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python3
"""
BioAnalyzer Global Command - User-Friendly Entry Point
This script provides a global command interface for BioAnalyzer.
It can be installed system-wide or used as a standalone command.
Usage:
BioAnalyzer help # Show help
BioAnalyzer build # Build containers
BioAnalyzer start # Start application
BioAnalyzer analyze <pmid> # Analyze single paper
BioAnalyzer analyze <pmid1,pmid2> # Analyze multiple papers
BioAnalyzer fields # Show field information
BioAnalyzer status # Check status
BioAnalyzer stop # Stop application
"""
import sys
import os
from pathlib import Path
# Find the BioAnalyzer backend directory
def find_bioanalyzer_backend():
"""Find the BioAnalyzer backend directory."""
# Try different possible locations
possible_paths = [
Path(__file__).parent, # Current directory
Path(__file__).parent / "BioAnalyzer-Backend", # Adjacent directory
Path.home() / "Desktop" / "BioAnalyzer-Backend", # Desktop
Path("/opt/bioanalyzer"), # System installation
Path("/usr/local/bin/bioanalyzer"), # Local installation
]
for path in possible_paths:
cli_path = path / "cli.py"
if cli_path.exists():
return path
return None
def main():
"""Main entry point for BioAnalyzer command."""
# Find the backend directory
backend_dir = find_bioanalyzer_backend()
if not backend_dir:
print("""
❌ Error: BioAnalyzer backend not found!
Please ensure BioAnalyzer-Backend is installed and accessible.
Possible solutions:
1. Run from the BioAnalyzer-Backend directory
2. Install BioAnalyzer system-wide: ./install.sh
3. Set BIOANALYZER_PATH environment variable
For help, visit: https://github.com/your-repo/bioanalyzer-backend
""")
sys.exit(1)
# Add the backend directory to Python path
sys.path.insert(0, str(backend_dir))
# Change to the backend directory
os.chdir(backend_dir)
# Load .env from the backend directory if present so CLI and docker-run
# receive the same environment variables developers place in .env.
try:
env_path = backend_dir / '.env'
if env_path.exists():
try:
from dotenv import load_dotenv
load_dotenv(str(env_path))
print(f"Loaded environment variables from {env_path}")
except Exception:
# Fallback: parse the .env file manually if python-dotenv is not installed
try:
with open(env_path, 'r', encoding='utf-8') as f:
for raw in f:
line = raw.strip()
if not line or line.startswith('#'):
continue
if '=' not in line:
continue
key, val = line.split('=', 1)
key = key.strip()
val = val.strip().strip('"').strip("'")
# Only set the env var if not already present in the environment
if key and val and os.environ.get(key) is None:
os.environ[key] = val
print(f"Loaded environment variables from {env_path} (fallback parser)")
except Exception:
pass
except Exception:
pass
# Import and run the CLI
try:
from cli import main as cli_main
cli_main()
except ImportError as e:
print(f"""
❌ Error importing BioAnalyzer CLI: {e}
Please ensure all dependencies are installed:
pip install -r config/requirements.txt
Or use Docker:
./docker-setup.sh
""")
sys.exit(1)
except Exception as e:
print(f"❌ Error running BioAnalyzer: {e}")
sys.exit(1)
if __name__ == "__main__":
main()