-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsetup_environments.sh
More file actions
executable file
·201 lines (165 loc) · 6.74 KB
/
setup_environments.sh
File metadata and controls
executable file
·201 lines (165 loc) · 6.74 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
#!/bin/bash
# Setup script for creating tool-specific mamba environments for benchmarking.
#
# This script creates isolated environments for each benchmarking tool to avoid
# dependency conflicts and ensure reproducible results.
set -e # Exit on any error
echo "Setting up tool-specific environments for benchmarking..."
# Auto-detect mamba/micromamba executable (portable across users and systems)
detect_mamba_executable() {
# Try various common mamba executables in order of preference
local mamba_candidates=(
"mamba" # Standard mamba
"micromamba" # Micromamba
"conda" # Fallback to conda
)
for candidate in "${mamba_candidates[@]}"; do
if command -v "$candidate" &> /dev/null; then
echo "$candidate"
return 0
fi
done
echo "Error: No mamba/conda executable found in PATH" >&2
echo "Please install mamba, micromamba, or conda and ensure it's in your PATH" >&2
return 1
}
# Auto-detect mamba root prefix (portable)
detect_mamba_root() {
local mamba_cmd="$1"
# Get the full path to the mamba executable
local mamba_full_path
mamba_full_path=$(command -v "$mamba_cmd")
# Try to get root prefix from mamba itself (try multiple methods)
local root_prefix
# Method 1: mamba info --base
root_prefix=$("$mamba_full_path" info --base 2>/dev/null | grep -o '/[^[:space:]]*' | head -1 || true)
if [ -n "$root_prefix" ] && [ -d "$root_prefix" ]; then
echo "$root_prefix"
return 0
fi
# Method 2: mamba info (parse output)
root_prefix=$("$mamba_full_path" info 2>/dev/null | grep "base environment" | sed 's/.*base environment[[:space:]]*:[[:space:]]*\([^[:space:]]*\).*/\1/' | head -1 || true)
if [ -n "$root_prefix" ] && [ -d "$root_prefix" ]; then
echo "$root_prefix"
return 0
fi
# Method 3: Try environment variable
if [ -n "$MAMBA_ROOT_PREFIX" ] && [ -d "$MAMBA_ROOT_PREFIX" ]; then
echo "$MAMBA_ROOT_PREFIX"
return 0
fi
# Fallback: use common locations
local common_roots=(
"$HOME/mamba"
"$HOME/micromamba"
"$HOME/.conda"
"$HOME/conda"
)
for root in "${common_roots[@]}"; do
if [ -d "$root" ]; then
echo "$root"
return 0
fi
done
echo "Error: Could not detect mamba root directory" >&2
return 1
}
# Source the portable mamba detection script
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
source "$SCRIPT_DIR/detect_mamba_env.sh"
if [ -z "$MAMBA_EXE" ] || [ -z "$MAMBA_ROOT_PREFIX" ]; then
echo "Error: Could not detect mamba configuration"
exit 1
fi
echo "Using mamba executable: $MAMBA_EXE"
echo "Using mamba root: $MAMBA_ROOT_PREFIX"
# Set MAMBA_CMD for backward compatibility
MAMBA_CMD="$MAMBA_EXE"
# Function to create environment if it doesn't exist
create_env_if_missing() {
local env_name=$1
local packages=$2
local channels=$3
if "$MAMBA_CMD" env list | grep -q "^$env_name "; then
echo "Environment $env_name already exists, skipping..."
else
echo "Creating environment: $env_name"
echo "Packages: $packages"
echo "Channels: $channels"
echo "Running micromamba create command..."
if [ -n "$channels" ]; then
"$MAMBA_CMD" create -n "$env_name" $channels $packages -y -v
else
"$MAMBA_CMD" create -n "$env_name" $packages -y -v
fi
echo "✓ Created $env_name"
fi
}
# 1. Scanpy environment
echo "=== Setting up scanpy environment ==="
create_env_if_missing "scanpy-env" \
"python=3.10 scanpy pandas numpy scipy matplotlib seaborn anndata pyyaml" \
"-c conda-forge -c bioconda"
# 2. MELD environment
echo "=== Setting up MELD environment ==="
create_env_if_missing "meld-env" \
"python=3.10 pandas numpy scipy matplotlib seaborn anndata scanpy pyyaml" \
"-c conda-forge -c bioconda"
# Install MELD via pip (not available in conda)
echo "Installing MELD via pip..."
echo "This may take a few minutes..."
"$MAMBA_CMD" run -n meld-env pip install meld -v
echo "✓ MELD installed"
# 3. scvi-tools environment (for mrVI)
echo "=== Setting up scvi-tools environment ==="
create_env_if_missing "scvi-env" \
"python=3.10 pandas numpy scipy matplotlib seaborn anndata scanpy pytorch pyyaml" \
"-c conda-forge -c bioconda -c pytorch"
# Install scvi-tools via pip
echo "Installing scvi-tools via pip..."
echo "This may take several minutes (large package)..."
"$MAMBA_CMD" run -n scvi-env pip install scvi-tools -v
echo "✓ scvi-tools installed"
# Install mrvi package for multi-resolution variational inference
echo "Installing mrvi package..."
"$MAMBA_CMD" run -n scvi-env pip install mrvi -v
echo "✓ mrvi installed"
# 4. R environments
echo "=== Setting up R environments ==="
# miloR environment
create_env_if_missing "milo-env" \
"r-base=4.3 r-devtools r-biocmanager r-reticulate r-matrix r-igraph r-dplyr r-yaml python=3.10 anndata pyyaml pkg-config freetype fontconfig bioconductor-milor r-systemfonts" \
"-c conda-forge -c bioconda"
# miloR packages will be installed via renv
# Seurat environment
create_env_if_missing "seurat-env" \
"r-base=4.3 r-seurat r-reticulate r-matrix r-mass python=3.10 anndata numpy pandas scipy pyyaml zlib xz liblzma-devel pkg-config freetype-devel-cos7-x86_64 fontconfig-devel-cos7-x86_64" \
"bioconductor-hdf5array bioconductor-rhdf5" \
"-c conda-forge -c bioconda"
# DESeq2 environment
create_env_if_missing "deseq2-env" \
"r-base=4.3 r-devtools r-biocmanager r-reticulate r-mass python=3.10 anndata pyyaml bioconductor-deseq2 zlib xz liblzma-devel pkg-config freetype-devel-cos7-x86_64 fontconfig-devel-cos7-x86_64" \
"bioconductor-hdf5array bioconductor-rhdf5" \
"-c conda-forge -c bioconda"
echo "✓ DESeq2 installed via conda"
# LEMUR environment
create_env_if_missing "lemur-env" \
"r-base=4.3 r-devtools r-biocmanager r-reticulate r-matrix r-mass python=3.10 anndata pyyaml zlib xz liblzma-devel pkg-config freetype-devel-cos7-x86_64 fontconfig-devel-cos7-x86_64" \
"bioconductor-hdf5array bioconductor-rhdf5" \
"-c conda-forge -c bioconda"
# LEMUR packages will be installed via renv
echo ""
echo "=== Environment Setup Complete ==="
echo ""
echo "Available environments:"
"$MAMBA_CMD" env list | grep -E "(scanpy-env|meld-env|scvi-env|milo-env|seurat-env|deseq2-env|lemur-env)"
echo ""
echo "To test an environment:"
echo " micromamba activate scanpy-env"
echo " python -c 'import scanpy; print(scanpy.__version__)'"
echo ""
echo "To test R environments:"
echo " micromamba activate milo-env"
echo " R -e 'library(miloR); packageVersion(\"miloR\")'"
echo ""
echo "Environment setup complete! You can now run tool benchmarking."