From: Michael R. Crusoe <crusoe@debian.org>
Subject: Make basilisk an optional dependency
 basilisk is moved from Imports to Suggests.  The basilisk environment is
 no longer defined at package load time; run_mofa() defines it only when
 called with use_basilisk = TRUE, reusing the upstream pins in R/basilisk.R.
 The configure script, which only calls basilisk, is removed.
Forwarded: not-needed
--- a/DESCRIPTION
+++ b/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
--- a/configure
+++ /dev/null
@@ -1,3 +0,0 @@
-#!/bin/sh
-
-${R_HOME}/bin/Rscript -e "basilisk::configureBasiliskEnv()"
--- a/R/basilisk.R
+++ b/R/basilisk.R
@@ -17,6 +17,3 @@
 
 # Pinned version of mofapy2: defines the basilisk env and is what run_mofa() checks the reticulate install against.
 .mofapy2_version <- "0.7.5"
-
-#' @importFrom basilisk BasiliskEnvironment
-mofa_env <- BasiliskEnvironment("mofa_env", pkgname="MOFA2", packages=.mofapy2_dependencies, pip = paste0("mofapy2==",.mofapy2_version))
\ No newline at end of file
--- a/R/run_mofa.R
+++ b/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) }
+#' \dontrun{ MOFAmodel <- run_mofa(MOFAmodel, use_basilisk = FALSE) }
 run_mofa <- function(object, outfile = NULL, save_data = TRUE, use_basilisk = FALSE) {
   
   # Sanity checks
@@ -99,13 +98,19 @@
     
   # 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) {
+    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)
   }
--- a/inst/doc/MEFISTO_temporal.R
+++ b/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)
--- a/inst/doc/MEFISTO_temporal.Rmd
+++ b/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)
 ```
 
 
--- a/inst/doc/getting_started_R.R
+++ b/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()
--- a/inst/doc/getting_started_R.Rmd
+++ b/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:
--- a/man/run_mofa.Rd
+++ b/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) }
 }
--- a/vignettes/MEFISTO_temporal.Rmd
+++ b/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)
 ```
 
 
--- a/vignettes/getting_started_R.Rmd
+++ b/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:
--- a/NAMESPACE
+++ b/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)
