jleechung/banksy-zenodo

Error: Function "BanksyObject" Not Found

Closed this issue · 3 comments

I encountered an error while running the script process_hypothalamus_merfish.R which uses the BanksyObject function. The error message is:

Error in BanksyObject(own.expr = expr.list, cell.locs = locs.list) : 
  could not find function "BanksyObject"

I searched through the GitHub repository and could not find this function. Below is the relevant section of my code:

if (USE_PROVIDED_BANKSY_OBJ){
  bank <- readRDS(file = paste0(data.dir, 'banksyObj_provided.rds'))
  
} else {
  # # Load data
  all_mfish = fread('data/merfish_all_cells.csv') # see the readme file in the data dir
  all_mfish <- all_mfish[,-c('Fos')]# remove Fos gene per Moffitt manuscript
  all_mfish = cbind(cell_ids = paste0('cell_', 1:nrow(all_mfish)), all_mfish)
  m.list = lapply(list_of_animal_IDs, function(x) all_mfish[all_mfish$Animal_ID==x,])
  expr.list <- lapply(m.list, function(x){
    expr = t(as.matrix(x[,-c(1:10)]))
    colnames(expr) <- x$cell_ids
    expr})
  locs.list <- lapply(m.list, function(x){
    df = as.data.frame(cbind(sdimx = x$Centroid_X, sdimy = x$Centroid_Y,
                             sdimz = 1000*x$Bregma))
    rownames(df) <- x$cell_ids
    df})
  names(expr.list) <- names(locs.list) <- paste0('Animal_', list_of_animal_IDs)
  
  # ------ start clustering block ---------
  bank <- BanksyObject(own.expr = expr.list, cell.locs = locs.list)
  all_mfish_by_animal_list = lapply(list_of_animal_IDs, function(x) all_mfish[Animal_ID %in% x,
                                                                              c('cell_ids',
                                                                                'Animal_ID',
                                                                                'Animal_sex',
                                                                                'Behavior',
                                                                                'Bregma',
                                                                                'Centroid_X',
                                                                                'Centroid_Y',
                                                                                'Cell_class',
                                                                                'Neuron_cluster_ID')])
  bank@meta.data = cbind(bank@meta.data, do.call(rbind, all_mfish_by_animal_list))
  
  # bank <- ComputeBanksy(bank, k_geom = k_geom)
  ram_compute_banksy = peakRAM(bank <- ComputeBanksy(bank, k_geom = k_geom))
  
  # bank <- ScaleBanksy(bank)
  ram_scale_banksy = peakRAM(
    bank <- ScaleBanksy(bank)
  )
  
  lambdas<-c(0, lambda)
  
  # bank <- Banksy:::RunBanksyPCA(bank, lambda = lambdas, npcs = npcs)
  ram_pca_banksy = peakRAM(
    bank <- Banksy:::RunBanksyPCA(bank, lambda = lambdas, npcs = npcs)
  )
  
  # bank <- Banksy:::RunBanksyUMAP(bank, lambda = lambdas, npcs = npcs, nneighbors = k_expr)
  
  ram_umap_banksy = peakRAM(
    bank <- Banksy:::RunBanksyUMAP(bank, lambda = lambdas, npcs = npcs, nneighbors = k_expr)
  )
  
  clust_major_numeric = as.numeric(factor(bank@meta.data$Cell_class))
  clust_major_names = as.character(factor(bank@meta.data$Cell_class))
  bank@meta.data = cbind(bank@meta.data, clust_major_num = clust_major_numeric)
  set.seed(42)
  ptm <- proc.time()
  # bank <- ClusterBanksy(bank, lambda = lambdas, pca = TRUE, npcs = npcs,
  #                       method = 'leiden', k.neighbors = k_expr, resolution = res)
  ram_cluster_banksy = peakRAM(
    bank <- ClusterBanksy(bank, lambda = lambdas, pca = TRUE, npcs = npcs,
                          method = 'leiden', num.cores = 8,
                          k.neighbors = k_expr, resolution = res)
  )
  time_taken = proc.time() - ptm
  print(time_taken)
  saveRDS(bank, file = paste0(data.dir, 'banksyObj_naive_', number_of_animals, '.rds'))
  # bank <- readRDS(file = paste0(data.dir, 'banksyObj_naive_run.rds'))
  # ------ end clustering block ---------
}

I suspect that the package version might be incorrect or I might be missing some additional setup steps. Could you please help me identify whether I have the wrong package version, or if there's something else I'm missing?

Thank you!

Hi! All the analyses in these scripts were done using an older version of BANKSY. Try using this line to install banksy:
remotes::install_github("prabhakarlab/Banksy@main") # to install 0.1.5.

You can share your session info with us, that might be helpful in case the problem is something else..

After changing to version 0.1.5, the script runs smoothly. Thank you!

Excellent!