saezlab / liana

LIANA: a LIgand-receptor ANalysis frAmework
https://saezlab.github.io/liana/
GNU General Public License v3.0
183 stars 31 forks source link

AttributeError: 'PreBuiltTensor' object has no attribute 'elbow_metric_raw' #171

Open tangxj98 opened 3 months ago

tangxj98 commented 3 months ago

Dear authors,

The liana_tensor_c2c took 4.5 hours to run but failed with the error: 'PreBuiltTensor' object has no attribute 'elbow_metric_raw' . But the code of liana_tensor_c2c showed that elbow_metric_raw should be something that is defined right here in this step. Why would this happen?

sce <- liana_tensor_c2c(sce = sce, score_col = 'LRscore', rank = NULL, # set to NULL to estimate for you data! how='outer', # defines how the tensor is built conda_env = "liana_env", # used to pass an existing conda env with cell2cell use_available = FALSE # detect & load cell2cell if available ) [1] 0 Loading liana_env Conda Environment Building the tensor using LRscore... Estimating ranks... 100%|█████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████████| 25/25 [4:37:40<00:00, 666.43s/it] The rank at the elbow is: 3 Error in py_get_attr(x, name) : AttributeError: 'PreBuiltTensor' object has no attribute 'elbow_metric_raw' Run reticulate::py_last_error() for details. reticulate::py_last_error()

── Python Exception Message ───────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── AttributeError: 'PreBuiltTensor' object has no attribute 'elbow_metric_raw'

── R Traceback ────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────────── ▆

  1. └─liana::liana_tensor_c2c(...)
  2. ├─tensor$elbow_metric_raw
  3. └─reticulate:::$.python.builtin.object(tensor, "elbow_metric_raw")
  4. └─reticulate:::py_get_attr_or_item(x, name, TRUE)
  5. └─reticulate::py_get_attr(x, name) See reticulate::py_last_error()$r_trace$full_call for more details.
tangxj98 commented 3 months ago

I think there is a bug in the code for rank estimation. I tried with the above estimate rank 3, and the function reported no errors. It seems that the estimated rank, elbow_metric_raw, is not assigned to the tensor, but an undefined/unused orphan variable py$temp. Please check the code liana_tensor_c2c.

   tensor <- c2c$tensor$dataframes_to_tensor(context_df_dict = context_df_dict,                                                                                     
        sender_col = sender_col, receiver_col = receiver_col,
        ligand_col = ligand_col, receptor_col = receptor_col,
        score_col = score_col, how = how, lr_fill = lr_fill,
        cell_fill = cell_fill, lr_sep = lr_sep, context_order = context_order,
        order_labels = list("contexts", "interactions", "senders",
            "receivers"), sort_elements = sort_elements, device = device)
    if (build_only)
        return(tensor)
    elbow_metric_raw <- NULL

    if (is.null(rank)) {
        liana_message(str_glue("Estimating ranks..."), verbose = verbose,
            output = "message")
        py$temp <- tensor$elbow_rank_selection(upper_rank = as.integer(upper_rank),
            runs = as.integer(runs), init = init, automatic_elbow = TRUE,
            random_state = as.integer(seed))
        elbow_metric_raw <- tensor$elbow_metric_raw
        rank <- as.integer(tensor$rank)
    }