-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathinstall.sh
More file actions
executable file
·260 lines (228 loc) · 7.72 KB
/
install.sh
File metadata and controls
executable file
·260 lines (228 loc) · 7.72 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
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
#!/usr/bin/env bash
set -Eeuo pipefail
# ==========================
# Config
# ==========================
ENV_FILE="env/environment.yml"
SPOT_REPO="https://github.com/jaswindersingh2/SPOT-RNA.git"
SPOT_MODELS_PRIMARY="https://www.dropbox.com/s/dsrcf460nbjqpxa/SPOT-RNA-models.tar.gz"
SPOT_MODELS_FALLBACK="https://app.nihaocloud.com/f/fbf3315a91d542c0bdc2/?dl=1"
RNABENCH_REPO="https://github.com/automl/RnaBench.git"
EXTERNAL_DIR="external_algorithms"
log() { printf "\033[1;32m[+]\033[0m %s\n" "$*"; }
warn() { printf "\033[1;33m[!]\033[0m %s\n" "$*"; }
die() { printf "\033[1;31m[x]\033[0m %s\n" "$*" >&2; exit 1; }
need_cmd() { command -v "$1" >/dev/null 2>&1 || die "Required command '$1' not found."; }
fetch() {
local url="$1" out="$2"
if command -v wget >/dev/null 2>&1; then
wget -q --show-progress --progress=bar:force:noscroll --tries=3 -O "$out" "$url"
elif command -v curl >/dev/null 2>&1; then
curl -L --fail --retry 3 --retry-delay 2 -o "$out" "$url"
else
die "Neither wget nor curl is available; please install one."
fi
}
# Try very hard to discover and initialize conda/mamba
try_source_any_conda_hook() {
# Fast path: conda provides a hook that works even if not initialized
if command -v conda >/dev/null 2>&1; then
# Attempt to source its hook for 'conda run' stability
local hook
if hook="$(conda shell.bash hook 2>/dev/null)"; then eval "$hook" && return 0; fi
fi
# Common install roots
local roots=(
"$HOME/miniconda3" "$HOME/anaconda3" "$HOME/mambaforge" "$HOME/miniforge3"
"/opt/conda" "/usr/local/conda" "/usr/local/miniconda" "/usr/local/miniconda3"
)
for r in "${roots[@]}"; do
[[ -f "$r/etc/profile.d/conda.sh" ]] && { # shellcheck disable=SC1090
source "$r/etc/profile.d/conda.sh" && return 0
}
[[ -f "$r/etc/profile.d/mamba.sh" ]] && { # shellcheck disable=SC1090
source "$r/etc/profile.d/mamba.sh" && return 0
}
done
# Deep scan for conda.sh/mamba.sh under $HOME and common prefixes
shopt -s nullglob globstar
local candidates=(
"$HOME"/**/etc/profile.d/conda.sh
"$HOME"/**/etc/profile.d/mamba.sh
/opt/**/etc/profile.d/conda.sh
/opt/**/etc/profile.d/mamba.sh
/usr/local/**/etc/profile.d/conda.sh
/usr/local/**/etc/profile.d/mamba.sh
)
for f in "${candidates[@]}"; do
# shellcheck disable=SC1090
source "$f" && return 0
done
shopt -u globstar
return 1
}
# Install micromamba into ~/.local/bin if nothing found
bootstrap_micromamba() {
log "No conda/mamba found — bootstrapping micromamba to ~/.local/bin ..."
need_cmd mkdir
need_cmd tar
need_cmd uname
local os arch url tmpdir bin
os="$(uname -s | tr '[:upper:]' '[:lower:]')"
arch="$(uname -m)"
case "$arch" in
x86_64|amd64) arch="64";;
aarch64|arm64) arch="aarch64";;
*) die "Unsupported CPU architecture: $arch";;
esac
case "$os" in
linux) url="https://micro.mamba.pm/api/micromamba/linux-$arch/latest";;
darwin) url="https://micro.mamba.pm/api/micromamba/osx-$arch/latest";;
*) die "Unsupported OS: $os";;
esac
tmpdir="$(mktemp -d)"
bin="$HOME/.local/bin"
mkdir -p "$bin"
fetch "$url" "$tmpdir/micromamba.tar.bz2"
tar -xjf "$tmpdir/micromamba.tar.bz2" -C "$tmpdir" --strip-components=1 bin/micromamba
install -m 0755 "$tmpdir/micromamba" "$bin/micromamba"
rm -rf "$tmpdir"
export PATH="$bin:$PATH"
command -v micromamba >/dev/null 2>&1 || die "micromamba bootstrap failed."
log "micromamba installed at $bin/micromamba"
}
pick_env_mgr() {
# Prefer mamba > micromamba > conda
if command -v mamba >/dev/null 2>&1; then
echo "mamba"; return
fi
if command -v micromamba >/dev/null 2>&1; then
echo "micromamba"; return
fi
if command -v conda >/dev/null 2>&1; then
echo "conda"; return
fi
# Try sourcing hooks to reveal hidden installs
if try_source_any_conda_hook; then
if command -v mamba >/dev/null 2>&1; then echo "mamba"; return; fi
if command -v conda >/dev/null 2>&1; then echo "conda"; return; fi
fi
# Final fallback: bootstrap micromamba
bootstrap_micromamba
echo "micromamba"
}
env_run() {
local mgr="$1" env="$2"; shift 2
case "$mgr" in
micromamba|mamba|conda) "$mgr" run -n "$env" "$@";;
*) die "Unknown env manager: $mgr";;
esac
}
create_or_update_env() {
local mgr="$1" env="$2" file="$3"
# Does env exist?
local exists=""
set +e
if [[ "$mgr" == "micromamba" ]]; then
exists="$("$mgr" env list 2>/dev/null | awk '{print $1}' | grep -Fx "$env")"
else
exists="$("$mgr" env list 2>/dev/null | awk '{print $1}' | grep -Fx "$env")"
fi
set -e
if [[ -n "$exists" ]]; then
log "Environment '$env' exists — updating from $file …"
if [[ "$mgr" == "micromamba" ]]; then
# micromamba 'install -f' acts as update; --prune removes orphans
"$mgr" install -y -n "$env" -f "$file" --prune
else
"$mgr" env update -n "$env" -f "$file" --prune
fi
else
log "Creating environment '$env' from $file …"
if [[ "$mgr" == "micromamba" ]]; then
"$mgr" create -y -n "$env" -f "$file"
else
"$mgr" env create -n "$env" -f "$file"
fi
fi
}
# ==========================
# Pre-flight
# ==========================
need_cmd git
need_cmd tar
[[ -f "$ENV_FILE" ]] || die "Environment file '$ENV_FILE' not found. Run from repo root or update ENV_FILE."
# Resolve project root (repo top if inside a git checkout)
PROJECT_ROOT="$(pwd)"
set +e
GIT_TOP="$(git rev-parse --show-toplevel 2>/dev/null)"
set -e
[[ -n "${GIT_TOP:-}" ]] && PROJECT_ROOT="$GIT_TOP"
log "Project root: $PROJECT_ROOT"
# Pick/create a manager (auto-discovery + bootstrap if needed)
ENV_MGR="$(pick_env_mgr)"
log "Using environment manager: $ENV_MGR"
# Get env name from YAML (fallback to rnabench-env)
if command -v yq >/dev/null 2>&1; then
ENV_NAME="$(yq -r '.name // empty' "$ENV_FILE" || true)"
else
ENV_NAME="$(awk '/^[[:space:]]*name:[[:space:]]*/ {print $2; exit}' "$ENV_FILE" || true)"
fi
[[ -n "${ENV_NAME:-}" ]] || ENV_NAME="rnabench-env"
log "Environment name: $ENV_NAME"
# Create/update env
create_or_update_env "$ENV_MGR" "$ENV_NAME" "$ENV_FILE"
# pip install -e . inside env
log "Installing current repo into '$ENV_NAME' (editable)…"
env_run "$ENV_MGR" "$ENV_NAME" python -m pip install --upgrade pip
env_run "$ENV_MGR" "$ENV_NAME" python -m pip install --no-cache-dir -e "$PROJECT_ROOT"
# External algorithms
mkdir -p "$PROJECT_ROOT/$EXTERNAL_DIR"
cd "$PROJECT_ROOT/$EXTERNAL_DIR"
# --- SPOT-RNA ---
log "Installing SPOT-RNA…"
if [[ -d SPOT-RNA/.git ]]; then
log "SPOT-RNA already cloned — pulling latest…"
(cd SPOT-RNA && git fetch --all --tags --prune && git pull --ff-only)
else
git clone "$SPOT_REPO" SPOT-RNA
fi
# Models (skip if already unpacked)
if [[ ! -d SPOT-RNA/models ]]; then
log "Fetching SPOT-RNA models…"
cd SPOT-RNA
TMP_TAR="SPOT-RNA-models.tar.gz"
set +e
if ! fetch "$SPOT_MODELS_PRIMARY" "$TMP_TAR"; then
warn "Primary URL failed — trying fallback…"
if ! fetch "$SPOT_MODELS_FALLBACK" "$TMP_TAR"; then
die "Failed to download SPOT-RNA models from both URLs."
fi
fi
set -e
tar -xvzf "$TMP_TAR"
rm -f "$TMP_TAR"
cd ..
else
log "SPOT-RNA models already present — skipping."
fi
# --- RnaBench ---
log "Cloning RnaBench…"
if [[ -d RnaBench/.git ]]; then
log "RnaBench already cloned — pulling latest…"
(cd RnaBench && git fetch --all --tags --prune && git pull --ff-only)
else
git clone "$RNABENCH_REPO" RnaBench
fi
cd ..
mv external_algorithms/RnaBench/RnaBench .
rm -rf external_algorithms/RnaBench
log "All set!"
echo ""
echo "Use the environment via:"
echo " $ENV_MGR run -n $ENV_NAME python -c 'import sys; print(sys.executable)'"
if [[ "$ENV_MGR" == "micromamba" ]]; then
echo "Or activate: micromamba activate $ENV_NAME"
else
echo "Or activate: conda activate $ENV_NAME"
fi