Waschina / MicrobiomeGS2

2 stars 0 forks source link

Issue: Error in checkForRemoteErrors: could not find function "SYBIL_SETTINGS" #3

Closed wtscott31 closed 4 weeks ago

wtscott31 commented 1 month ago

Hi,

I have been attempting to run a script for performing analysis on a community genome-scale model created with gapseq and join_mult_models function. Despite multiple attempts and troubleshooting, I keep encountering the following error:

Error in checkForRemoteErrors(val) : one node produced an error: one node produced an error: could not find function "SYBIL_SETTINGS" This error occurs even though I have sybil installed and the SYBIL_SETTINGS function properly exported. Below is the script I am using:

# Set working directory
setwd("[My HOME]")
rm(list = ls())

# Load necessary libraries
library(MicrobiomeGS2)
library(sybil)
library(parallel)  # Ensure parallel library is loaded

# Source the settings.R file
source("./settings.R")

# Initialize sybil settings
SYBIL_SETTINGS("SOLVER", "cplexAPI")

# Source the fba_tools.R file
source("./fba_tools.R")

# Load the community model and modj
community_model <- readRDS("community_model.RDS")
modj <- readRDS("modj.RDS")

# Verify that modj is of type 'modelorg'
if (class(modj) == "modelorg") {
  print("Using 'modj' for further analysis.")

  # Initialize cluster
  cl <- makeCluster(detectCores())

  # Export necessary functions and variables to the worker nodes
  clusterEvalQ(cl, {
    library(sybil)
    library(MicrobiomeGS2)
    library(parallel)

    # Define the SYBIL_SETTINGS function
    SYBIL_SETTINGS <- function(setting, value) {
      assign(setting, value, envir = .GlobalEnv)
    }

    # Initialize sybil settings within the worker nodes
    .SYBILenv <- new.env(parent = emptyenv())
    assign(".SYBILenv", .SYBILenv, envir = .GlobalEnv)
    SYBIL_SETTINGS("SOLVER", "cplexAPI")

    # Source the fba_tools.R file
    source("./fba_tools.R")
  })

  # Export the 'modj' object and other necessary elements to the worker nodes
  clusterExport(cl, c("modj", "SYBIL_SETTINGS", "get_growth", "get_produced_metabolites", "get_utilized_metabolites", "get_flux_distribution", "get_metabolite_production_capacity", "get_exchanges", "predict_auxotrophies"))

  # Define the analysis functions
  analyze_growth <- function(modj) {
    growth <- get_growth(modj, multi.thread = FALSE)
    cat("Growth Rate:", growth, "\n")
  }

  analyze_produced_metabolites <- function(modj) {
    produced_metabolites <- get_produced_metabolites(modj)
    print(produced_metabolites)
  }

  analyze_utilized_metabolites <- function(modj) {
    utilized_metabolites <- get_utilized_metabolites(modj)
    print(utilized_metabolites)
  }

  analyze_flux_distribution <- function(modj) {
    flux_distribution <- get_flux_distribution(modj)
    print(flux_distribution)
  }

  analyze_metabolite_production_capacity <- function(modj) {
    metabolite_production_capacity <- get_metabolite_production_capacity(modj)
    print(metabolite_production_capacity)
  }

  analyze_exchanges <- function(modj) {
    exchanges <- get_exchanges(modj)
    print(exchanges)
  }

  analyze_auxotrophies <- function(modj) {
    auxotrophies <- predict_auxotrophies(modj, solver = "cplex")
    print(auxotrophies)
  }

  # Run each analysis function separately in parallel
  parLapply(cl, list(modj), analyze_growth)
  parLapply(cl, list(modj), analyze_produced_metabolites)
  parLapply(cl, list(modj), analyze_utilized_metabolites)
  parLapply(cl, list(modj), analyze_flux_distribution)
  parLapply(cl, list(modj), analyze_metabolite_production_capacity)
  parLapply(cl, list(modj), analyze_exchanges)
  parLapply(cl, list(modj), analyze_auxotrophies)

  # Stop the cluster
  stopCluster(cl)

} else {
  cat("'modj' is not of type 'modelorg'.\n")
}

Steps Taken to Troubleshoot

Ensured sybil and MicrobiomeGS2 libraries are installed. Verified the correct sourcing of settings.R and fba_tools.R. Explicitly defined SYBIL_SETTINGS function within clusterEvalQ. Initialized .SYBILenv environment within the worker nodes. Exported SYBIL_SETTINGS and other necessary functions using clusterExport. Despite these steps, the issue persists. Any guidance on resolving this error would be greatly appreciated.

Additional Information

Operating System: macOS R version: [R version 4.2.2 (2022-10-31)] sybil version: [2.2.0 and 2.2.1 (I tried with both)] MicrobiomeGS2 version: [v0.1.1]

Thank you for your assistance!

Waschina commented 1 month ago

Hi @wtscott31

I can't really say what's the issue with your example, but here are a few things to consider:

wtscott31 commented 4 weeks ago

Hi @Waschina ,

Thank you for your suggestions! Your advice to avoid using parallel processing solved the problem I was encountering. I appreciate your help!

It's unfortunate to hear that MicrobiomeGS2 will be archived, as it seems like a potentially helpful tool for working with gapseq genome-scale reconstructions in the R environment. Do you expect new versions of sybil to be released in the future, or is there any plan for an updated constraint-based model environment that includes many of its features?

Thanks again for your assistance!

Best regards, wtscott31

Waschina commented 4 weeks ago

Yes, we are currently working ib a new R-package that also contains community simulation functions similar to those in MicrobiomeGS2. The package is called "cobrar" and a development version is already available here: https://github.com/Waschina/cobrar