From: Michael R. Crusoe <crusoe@debian.org>
Subject: Make basilisk an optional dependency
--- r-bioc-mofa2.orig/DESCRIPTION
+++ r-bioc-mofa2/DESCRIPTION
@@ -24,11 +24,11 @@
 Imports: rhdf5, dplyr, tidyr, reshape2, pheatmap, ggplot2, methods,
         RColorBrewer, cowplot, ggrepel, reticulate, HDF5Array,
         grDevices, stats, magrittr, forcats, utils, corrplot,
-        DelayedArray, Rtsne, uwot, basilisk, stringi
+        DelayedArray, Rtsne, uwot, stringi
 Suggests: knitr, testthat, Seurat, SeuratObject, ggpubr, foreach,
         psych, MultiAssayExperiment, SummarizedExperiment,
         SingleCellExperiment, ggrastr, mvtnorm, GGally, rmarkdown,
-        data.table, tidyverse, BiocStyle, Matrix, markdown
+        data.table, tidyverse, BiocStyle, Matrix, markdown, basilisk
 biocViews: DimensionReduction, Bayesian, Visualization
 URL: https://biofam.github.io/MOFA2/index.html
 BugReports: https://github.com/bioFAM/MOFA2
--- r-bioc-mofa2.orig/configure
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-${R_HOME}/bin/Rscript -e "basilisk::configureBasiliskEnv()"
--- r-bioc-mofa2.orig/R/basilisk.R
+++ r-bioc-mofa2/R/basilisk.R
@@ -5,17 +5,4 @@
 #   "dtw-python==1.1.10"
 # )
 
-.mofapy2_dependencies <- c(
-    "python=3.10.5",
-    "numpy=1.23.1",
-    "scipy=1.8.1",
-    "pandas=1.4.3",
-    "h5py=3.6.0",
-    "scikit-learn=1.1.1",
-    "dtw-python=1.2.2"
-)
 
-.mofapy2_version <- "0.7.0"
-
-#' @importFrom basilisk BasiliskEnvironment
-mofa_env <- BasiliskEnvironment("mofa_env", pkgname="MOFA2", packages=.mofapy2_dependencies, pip = paste0("mofapy2==",.mofapy2_version))
\ No newline at end of file
--- r-bioc-mofa2.orig/R/run_mofa.R
+++ r-bioc-mofa2/R/run_mofa.R
@@ -20,7 +20,6 @@
 #' or the right conda environment with \code{reticulate::use_condaenv(..., force=TRUE)}.
 #' @return a trained \code{\link{MOFA}} object
 #' @import reticulate
-#' @import basilisk
 #' @export
 #' @examples
 #' # Load data (in data.frame format)
@@ -34,7 +33,7 @@
 #' MOFAmodel <- prepare_mofa(MOFAmodel)
 #' 
 #' # Run the MOFA model
-#' \dontrun{ MOFAmodel <- run_mofa(MOFAmodel, use_basilisk = TRUE) }
+#' MOFAmodel <- run_mofa(MOFAmodel)
 run_mofa <- function(object, outfile = NULL, save_data = TRUE, use_basilisk = FALSE) {
   
   # Sanity checks
@@ -99,13 +98,29 @@
     
   # Connect to mofapy2 using basilisk (optional)
   if (use_basilisk) {
+    if (!requireNamespace("basilisk", quietly = TRUE)) {
+      stop("The r-bioc-basilisk package must be installed when use_basilisk = True.")
+    }
     
     message("Connecting to the mofapy2 package using basilisk. 
     Set 'use_basilisk' to FALSE if you prefer to manually set the python binary using 'reticulate'.")
-    
-    proc <- basiliskStart(mofa_env)
-    on.exit(basiliskStop(proc))
-    tmp <- basiliskRun(proc, function(object, outfile, save_data) {
+
+    .mofapy2_dependencies <- c(
+        "python=3.10.5",
+        "numpy=1.23.1",
+        "scipy=1.8.1",
+        "pandas=1.4.3",
+        "h5py=3.6.0",
+        "scikit-learn=1.1.1",
+        "dtw-python=1.2.2"
+    )
+
+    .mofapy2_version <- "0.7.0"
+
+    mofa_env <- basilisk::BasiliskEnvironment("mofa_env", pkgname="MOFA2", packages=.mofapy2_dependencies, pip = paste0("mofapy2==",.mofapy2_version))
+    proc <- basilisk::basiliskStart(mofa_env)
+    on.exit(basilisk::basiliskStop(proc))
+    tmp <- basilisk::basiliskRun(proc, function(object, outfile, save_data) {
       .run_mofa_reticulate(object, outfile, save_data)
     }, object=object, outfile=outfile, save_data=save_data)
   }
--- r-bioc-mofa2.orig/inst/doc/MEFISTO_temporal.R
+++ r-bioc-mofa2/inst/doc/MEFISTO_temporal.R
@@ -51,7 +51,7 @@
 
 ## ----warning=FALSE, message=FALSE---------------------------------------------
 outfile = file.path(tempdir(),"model.hdf5")
-sm <- run_mofa(sm, outfile, use_basilisk = TRUE)
+sm <- run_mofa(sm, outfile, use_basilisk = FALSE)
 
 ## ----fig.width=5, fig.height=4------------------------------------------------
 plot_variance_explained(sm)
--- r-bioc-mofa2.orig/inst/doc/MEFISTO_temporal.Rmd
+++ r-bioc-mofa2/inst/doc/MEFISTO_temporal.Rmd
@@ -94,7 +94,7 @@
 Now, the MOFA object is ready for training. Using `run_mofa` we can fit the model, which is saved in the file specified as `outfile`. If none is specified the output is saved in a temporary location.
 ```{r, warning=FALSE, message=FALSE}
 outfile = file.path(tempdir(),"model.hdf5")
-sm <- run_mofa(sm, outfile, use_basilisk = TRUE)
+sm <- run_mofa(sm, outfile, use_basilisk = FALSE)
 ```
 
 
--- r-bioc-mofa2.orig/inst/doc/getting_started_R.R
+++ r-bioc-mofa2/inst/doc/getting_started_R.R
@@ -63,7 +63,7 @@
 
 ## -----------------------------------------------------------------------------
 outfile = file.path(tempdir(),"model.hdf5")
-MOFAobject.trained <- run_mofa(MOFAobject, outfile, use_basilisk=TRUE)
+MOFAobject.trained <- run_mofa(MOFAobject, outfile, use_basilisk=FALSE)
 
 ## -----------------------------------------------------------------------------
 sessionInfo()
--- r-bioc-mofa2.orig/inst/doc/getting_started_R.Rmd
+++ r-bioc-mofa2/inst/doc/getting_started_R.Rmd
@@ -211,7 +211,7 @@
 if you have issues. The output is saved in the file specified as `outfile`. If none is specified, the output is saved in a temporary location.
 ```{r}
 outfile = file.path(tempdir(),"model.hdf5")
-MOFAobject.trained <- run_mofa(MOFAobject, outfile, use_basilisk=TRUE)
+MOFAobject.trained <- run_mofa(MOFAobject, outfile, use_basilisk=FALSE)
 ```
 
 If everything is successful, you should observe an output analogous to the following:
--- r-bioc-mofa2.orig/man/run_mofa.Rd
+++ r-bioc-mofa2/man/run_mofa.Rd
@@ -44,5 +44,5 @@
 MOFAmodel <- prepare_mofa(MOFAmodel)
 
 # Run the MOFA model
-\dontrun{ MOFAmodel <- run_mofa(MOFAmodel, use_basilisk = TRUE) }
+\dontrun{ MOFAmodel <- run_mofa(MOFAmodel, use_basilisk = FALSE) }
 }
--- r-bioc-mofa2.orig/vignettes/MEFISTO_temporal.Rmd
+++ r-bioc-mofa2/vignettes/MEFISTO_temporal.Rmd
@@ -94,7 +94,7 @@
 Now, the MOFA object is ready for training. Using `run_mofa` we can fit the model, which is saved in the file specified as `outfile`. If none is specified the output is saved in a temporary location.
 ```{r, warning=FALSE, message=FALSE}
 outfile = file.path(tempdir(),"model.hdf5")
-sm <- run_mofa(sm, outfile, use_basilisk = TRUE)
+sm <- run_mofa(sm, outfile, use_basilisk = FALSE)
 ```
 
 
--- r-bioc-mofa2.orig/vignettes/getting_started_R.Rmd
+++ r-bioc-mofa2/vignettes/getting_started_R.Rmd
@@ -211,7 +211,7 @@
 if you have issues. The output is saved in the file specified as `outfile`. If none is specified, the output is saved in a temporary location.
 ```{r}
 outfile = file.path(tempdir(),"model.hdf5")
-MOFAobject.trained <- run_mofa(MOFAobject, outfile, use_basilisk=TRUE)
+MOFAobject.trained <- run_mofa(MOFAobject, outfile, use_basilisk=FALSE)
 ```
 
 If everything is successful, you should observe an output analogous to the following:
--- r-bioc-mofa2.orig/NAMESPACE
+++ r-bioc-mofa2/NAMESPACE
@@ -109,7 +109,6 @@
 exportMethods(samples_metadata)
 exportMethods(samples_names)
 exportMethods(views_names)
-import(basilisk)
 import(cowplot)
 import(dplyr)
 import(ggplot2)
@@ -123,7 +122,6 @@
 importFrom(HDF5Array,HDF5ArraySeed)
 importFrom(RColorBrewer,brewer.pal)
 importFrom(Rtsne,Rtsne)
-importFrom(basilisk,BasiliskEnvironment)
 importFrom(corrplot,corrplot)
 importFrom(cowplot,plot_grid)
 importFrom(dplyr,bind_rows)
