Skip to content

Commit cd619d7

Browse files
committed
two enivronment management
1 parent 438be09 commit cd619d7

3 files changed

Lines changed: 39 additions & 13 deletions

File tree

R/basilisk.R

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,18 @@
11
# Bioconductor-compliant management of Python environments
22
#
3-
# This script defines a basilisk environment for immlynx.
3+
# This script defines basilisk environments for immLynx.
44
#
5-
# The environment is defined using the BasiliskEnvironment function, which
6-
# specifies the name of the environment, the package name, and the list of
7-
# required Python packages.
5+
# Two separate environments are used so that installation failures in
6+
# problematic packages (soNNia and clusTCR) do not prevent the rest of
7+
# the Python tooling from working.
88
#
9-
# The defined environment is then used in the wrapper functions to execute
10-
# Python code using basiliskRun.
9+
# immLynxEnv -- stable dependencies used by the majority of the
10+
# package: OLGA, tcrdist3, metaclonotypist,
11+
# transformers/torch (ESM-2 embeddings), etc.
12+
#
13+
# immLynxExtraEnv -- packages that have historically had installation
14+
# issues: soNNia and clusTCR. Used only by
15+
# calculate.sonia() and calculate.clustcr().
1116
#
1217
# Note: Version checking is disabled because clusTCR is installed directly
1318
# from its GitHub repository via a git+https:// URL in the `pip` vector,
@@ -17,6 +22,9 @@
1722

1823
basilisk::setBasiliskCheckVersions(FALSE)
1924

25+
# ---------------------------------------------------------------------------
26+
# Core environment -- stable packages
27+
# ---------------------------------------------------------------------------
2028
immLynxEnv <- basilisk::BasiliskEnvironment(
2129
envname = "immLynxEnv",
2230
pkgname = "immLynx",
@@ -29,17 +37,35 @@ immLynxEnv <- basilisk::BasiliskEnvironment(
2937
"scikit-learn=1.1.3",
3038
"statsmodels=0.13.2",
3139
"seaborn=0.12.1",
32-
"markov-clustering=0.0.6.dev0",
3340
"faiss-cpu=1.7.4"
3441
),
3542
pip = c(
3643
"tcrdist3==0.2.2",
3744
"olga==1.2.4",
38-
"sonnia==0.2.5",
3945
"metaclonotypist==0.2.0",
4046
"pyrepseq==1.5.1",
4147
"torch==2.1.2",
42-
"transformers==4.36.2",
48+
"transformers==4.36.2"
49+
)
50+
)
51+
52+
# ---------------------------------------------------------------------------
53+
# Extra environment -- soNNia + clusTCR (may fail to install)
54+
# ---------------------------------------------------------------------------
55+
immLynxExtraEnv <- basilisk::BasiliskEnvironment(
56+
envname = "immLynxExtraEnv",
57+
pkgname = "immLynx",
58+
packages = c(
59+
"python=3.9",
60+
"numpy=1.23.4",
61+
"scipy=1.8.0",
62+
"pandas=1.4.4",
63+
"scikit-learn=1.1.3",
64+
"markov-clustering=0.0.6.dev0"
65+
),
66+
pip = c(
67+
"olga==1.2.4",
68+
"sonnia==0.2.5",
4369
"git+https://github.com/svalkiers/clusTCR.git@1.0.3"
4470
)
4571
)

R/calculate_helpers.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ calculate.clustcr <- function(sequences,
8989
eps = 0.5,
9090
min_samples = 2) {
9191

92-
proc <- basilisk::basiliskStart(immLynxEnv)
92+
proc <- basilisk::basiliskStart(immLynxExtraEnv)
9393
on.exit(basilisk::basiliskStop(proc))
9494

9595
cluster_df <- basilisk::basiliskRun(proc, function(sequences,
@@ -258,7 +258,7 @@ calculate.sonia <- function(data_folder,
258258
n_epochs = 100,
259259
save_folder = "sonia_output") {
260260

261-
proc <- basilisk::basiliskStart(immLynxEnv)
261+
proc <- basilisk::basiliskStart(immLynxExtraEnv)
262262
on.exit(basilisk::basiliskStop(proc))
263263

264264
# Read and prepare data as lists of lists: [[cdr3, v_gene, j_gene], ...]

tests/testthat/helper-immLynx.R

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@ olga_available <- function() {
130130
clustcr_available <- function() {
131131
if (is.null(.module_cache$clustcr)) {
132132
.module_cache$clustcr <- tryCatch({
133-
proc <- basilisk::basiliskStart(immLynx:::immLynxEnv)
133+
proc <- basilisk::basiliskStart(immLynx:::immLynxExtraEnv)
134134
on.exit(basilisk::basiliskStop(proc))
135135
basilisk::basiliskRun(proc, function() {
136136
reticulate::import("clustcr")
@@ -145,7 +145,7 @@ clustcr_available <- function() {
145145
sonnia_available <- function() {
146146
if (is.null(.module_cache$sonnia)) {
147147
.module_cache$sonnia <- tryCatch({
148-
proc <- basilisk::basiliskStart(immLynx:::immLynxEnv)
148+
proc <- basilisk::basiliskStart(immLynx:::immLynxExtraEnv)
149149
on.exit(basilisk::basiliskStop(proc))
150150
basilisk::basiliskRun(proc, function() {
151151
reticulate::import("sonnia.sonnia")

0 commit comments

Comments
 (0)