saezlab / ccc_protocols

LIANA x Tensor-cell2cell Protocols
https://ccc-protocols.readthedocs.io
MIT License
1 stars 3 forks source link

c2c.analysis.run_tensor_cell2cell_pipeline() Error #15

Open SimonE1220 opened 5 months ago

SimonE1220 commented 5 months ago

Dear all, thank you for the nice package. However, unfortunatley i have an issue with the tensor2 = c2c.analysis.run_tensor_cell2cell_pipeline(..) function I tried now many times to run it but it always get this error:

rank = int(_compute_elbow(loss)) else: rank = manual_elbow TypeError: int() argument must be a string, a bytes-like object or a real number, not 'NoneType'

After finishing the Elbow analysis.

I am new here, so sorry if sometihing is missing in this question. Would be great if you could help me.

Python Version: 3.11.7

earmingol commented 5 months ago

Hi @SimonE1220 !

Multiple issues could be associated with this:

  1. Your tensor is too sparse so the decomposition perform for computing the elbow analysis does not return a useful curve
  2. You have nan values that are not properly masked in your tensor, so the loss curve for the elbow analysis is 'empty'.
  3. The python version you are using generates conflicts (I recommend using 3.10).
  4. Your environment is generating some incompatibilities, I suggest using this https://github.com/saezlab/ccc_protocols/tree/main/env_setup for creating your environment.

It would be useful if you share your full code here, or some screenshots about your data/tensor objects.

SimonE1220 commented 5 months ago

Thank you very much. The error altough appears if I set the upper rank to 25. Here I just used 2 in order to reduce computational time to check for the error. Thats the code: Unbenannt

earmingol commented 5 months ago

Can you provide more details, as for examples the ones in this screenshot?

Thanks!

Screenshot 2024-04-04 at 14 55 28

SimonE1220 commented 5 months ago

torch.Size([2, 1136, 6, 6]) missing_fraction: 0.7027581930160522 sparsity_fraction: 0.06341695785522461 excluded_value_fraction: 0.7027582228183746

earmingol commented 5 months ago

can you check what version of tensorly you are using?

import tensorly
tensorly.__version__

My guess, this could be due to tensorly version, or because you have only two contexts/samples in your tensor. Can you try passing a rank in your pipeline function? Maybe something like rank=6 and check whether you get a decomposition.

An alternative is that you export your tensor and metadata using these commands,

# Export Tensor after decomposition
c2c.io.export_variable_with_pickle(tensor2, output_folder + 'Tensor.pkl')

# Export Tensor Metadata
c2c.io.export_variable_with_pickle(meta_tensor, output_folder + 'Tensor-Metadata.pkl')

Then put them in your google drive, and load them in this Google Colab notebook to check whether it's an issue with your environment or not: https://colab.research.google.com/drive/1sbNuer5CsPU2hFzyea0AjD_3kgSPOWoC?usp=sharing

earmingol commented 5 months ago

Another option is to try reducing the expr_prop when running liana, this could help to reduce the sparsity. For example you can use this:

li.mt.rank_aggregate.by_sample(adata,
                               sample_key='sample_new',
                               groupby='celltype',
                               resource_name = 'consensus',
                               expr_prop=0.05, 
                               min_cells = 5,
                               n_perms = 100,
                               use_raw = False,
                               verbose = True,
                               inplace = True
                              )
SimonE1220 commented 5 months ago

Hey, now it worked ! I am very happy. Thanks a lot. Did even work without the expr_prop option.