-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmetainformant.sh
More file actions
executable file
·213 lines (175 loc) · 5.56 KB
/
metainformant.sh
File metadata and controls
executable file
·213 lines (175 loc) · 5.56 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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
#!/bin/bash
# METAINFORMANT Orchestrator Script
# Provides interactive menu access and direct script execution
set -euo pipefail
# Get script directory and repo root
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
REPO_ROOT="$SCRIPT_DIR"
# Source common utilities if available
if [ -f "$REPO_ROOT/scripts/package/_common.sh" ]; then
source "$REPO_ROOT/scripts/package/_common.sh"
fi
# Colors for output
GREEN='\033[0;32m'
BLUE='\033[0;34m'
YELLOW='\033[1;33m'
NC='\033[0m' # No Color
# Function to print usage
print_usage() {
cat <<EOF
METAINFORMANT Orchestrator
Usage:
$0 [OPTIONS] [CATEGORY] [SCRIPT] [ARGS...]
Options:
--help, -h Show this help message
--menu, -m Launch interactive menu
--list, -l List available scripts
--category, -c Show scripts in a category
Examples:
$0 # Launch interactive menu (default)
$0 --menu # Launch interactive menu explicitly
$0 --help # Show this help message
$0 --list # List all available scripts
$0 rna # Show RNA scripts menu
$0 rna run_workflow.py --config config.yaml # Execute script directly
Categories:
core, rna, gwas, dna, protein, networks, multiomics, math, ml,
singlecell, quality, simulation, visualization, epigenome, ecology,
ontology, phenotype, life_events, package
EOF
}
# Function to check if uv is available (required)
check_python_env() {
if ! command -v uv >/dev/null 2>&1; then
echo "❌ Error: uv package manager is required"
echo " METAINFORMANT uses uv for all Python package management and execution"
echo " Install uv from: https://github.com/astral.sh/uv"
echo " curl -LsSf https://astral.sh/uv/install.sh | sh"
return 1
fi
# Verify uv can run Python
if ! uv run python --version >/dev/null 2>&1; then
echo "❌ Error: uv cannot run Python"
echo " Try: uv python install 3.11"
return 1
fi
return 0
}
# Function to launch interactive menu
launch_menu() {
check_python_env || return 1
# Launch the dedicated Python menu script
local menu_script="$REPO_ROOT/scripts/menu/run_menu.py"
if [ ! -f "$menu_script" ]; then
echo "❌ Error: Menu launcher script not found: $menu_script"
return 1
fi
# Execute menu script with uv
uv run python "$menu_script"
}
# Function to list available scripts
list_scripts() {
check_python_env || return 1
uv run python -c "
from pathlib import Path
import sys
sys.path.insert(0, str(Path('$REPO_ROOT/src')))
from metainformant.menu import discover_scripts
scripts = discover_scripts(Path('$REPO_ROOT'))
for category, script_list in sorted(scripts.items()):
print(f'\n{category.upper()}:')
for script in script_list:
print(f' {script.name:<40} {script.description}')
"
}
# Function to show category menu
show_category() {
local category="$1"
check_python_env || return 1
uv run python -c "
from pathlib import Path
import sys
sys.path.insert(0, str(Path('$REPO_ROOT/src')))
from metainformant.menu import discover_scripts, generate_menu_from_scripts
from metainformant.menu.display import show_menu
scripts = discover_scripts(Path('$REPO_ROOT'))
menus = generate_menu_from_scripts(scripts)
menu_id = f'menu_{category}'
if menu_id in menus:
menu = menus[menu_id]
show_menu(menu.items, menu.title)
else:
print(f'❌ Category \"{category}\" not found')
sys.exit(1)
"
}
# Function to execute script directly
execute_direct() {
local category="$1"
local script_name="$2"
shift 2
local script_args=("$@")
# Find script
local script_path="$REPO_ROOT/scripts/$category/$script_name"
if [ ! -f "$script_path" ]; then
# Try with .py extension
script_path="$REPO_ROOT/scripts/$category/${script_name}.py"
fi
if [ ! -f "$script_path" ]; then
# Try with .sh extension
script_path="$REPO_ROOT/scripts/$category/${script_name}.sh"
fi
if [ ! -f "$script_path" ]; then
echo "Error: Script not found: $category/$script_name"
echo "Available scripts in $category:"
ls -1 "$REPO_ROOT/scripts/$category/" 2>/dev/null | grep -E '\.(py|sh)$' || echo " (none)"
return 1
fi
# Execute script
if [[ "$script_path" == *.py ]]; then
uv run python "$script_path" "${script_args[@]}"
elif [[ "$script_path" == *.sh ]]; then
bash "$script_path" "${script_args[@]}"
else
echo "❌ Error: Unsupported script type: $script_path"
return 1
fi
}
# Main argument parsing
main() {
# Handle help first (explicit help overrides default behavior)
if [ $# -gt 0 ] && ([ "$1" = "--help" ] || [ "$1" = "-h" ]); then
print_usage
exit 0
fi
# Handle menu launch
if [ $# -gt 0 ] && ([ "$1" = "--menu" ] || [ "$1" = "-m" ]); then
launch_menu
exit $?
fi
# Handle list
if [ $# -gt 0 ] && ([ "$1" = "--list" ] || [ "$1" = "-l" ]); then
list_scripts
exit $?
fi
# Handle category display
if [ $# -gt 0 ] && ([ "$1" = "--category" ] || [ "$1" = "-c" ]); then
if [ $# -lt 2 ]; then
echo "Error: Category name required"
print_usage
exit 1
fi
show_category "$2"
exit $?
fi
# Direct execution: category script [args...]
if [ $# -ge 2 ]; then
execute_direct "$@"
exit $?
fi
# Default: launch menu
launch_menu
exit $?
}
# Run main function
main "$@"