Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
tangxj98 opened this issue Aug 22, 2024 · 1 comment

Comments

@tangxj98
Copy link

tangxj98 commented Aug 22, 2024

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
Copy link
Author

tangxj98 commented Aug 27, 2024

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)
    }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant