saezlab / liana

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

liana_tensor_c2c error: negative dimensions are not allowed #165

Open csennis opened 3 months ago

csennis commented 3 months ago

Hello,

Thank you for such a wonderful tool! I am trying to run tensor decomposition on my data to compare communication networks in treated vs. untreated samples, but I get the following error I can't seem to work around. I am following the liana_tensor_c2c vignette (https://saezlab.github.io/liana/articles/liana_cc2tensor.html) and am able to successfully run liana_bysample. I saw Issue #149 in which you suggest it could be due to negative values, but I don't see any in my data$logcounts or data$counts slot.

Please note that I have done most of my work in Seurat, and converted my object to a SingleCellExperiment object for this workflow. Within Seurat, I performed SCT (https://satijalab.org/seurat/articles/sctransform_vignette.html) instead of log normalization - I am wondering if this is causing the error?

Please find my code below - I created a conda environment called cell2cell_env in which I have pip installed tensor cell2cell.

Thank you in advance for your help/guidance here!

Code: sce <- liana_tensor_c2c(sce = sce, score_col = 'LRscore', sender_col = "source", # Just added this receiver_col = "target", # Just added this ligand_col = "ligand", # Just added this receptor_col = "receptor", # Just added this rank = 'None', # set to None to estimate for you data! how='outer', # defines how the tensor is built conda_env = "cell2cell_env", # used to pass an existing conda env with cell2cell use_available = TRUE # detect & load cell2cell if available )

Error: Error in py_call_impl(callable, call_args$unnamed, call_args$named) : ValueError: negative dimensions are not allowed Run reticulate::py_last_error() for details. In addition: Warning message: In liana_tensor_c2c(sce = pdo_sce, score_col = "LRscore", sender_col = "source", : NAs introduced by coercion

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

  1. └─liana::liana_tensor_c2c(...)
  2. └─tensor$compute_tensor_factorization(...)
  3. └─reticulate:::py_call_impl(callable, call_args$unnamed, call_args$named)
dbdimitrov commented 2 months ago

Hi @csennis,

Thanks for using liana and apologies for the delayed response.

Hmmm, if I remember correctly about SCT transform as long as you use the counts rather than the residuals, it should be okay, since they are drawn from NB/Poisson and are hence non-negative. Maybe make sure that you pass the correct assay to liana so that you indeed use the non-negative counts.

You could also check the liana results, for some unexpected values, e.g. NaNs, as likely there is some issue there (some dimension form the tensor is probably being dropped because of invalid values).

Finally, I recommend following the updated version of tutorial, along with more in-depth tutorials: https://ccc-protocols.readthedocs.io/en/latest/notebooks/ccc_R/QuickStart_pbmc.html