saezlab / liana-py

LIANA+: an all-in-one framework for cell-cell communication
http://liana-py.readthedocs.io/
GNU General Public License v3.0
134 stars 15 forks source link

Error with li.mt.rank_aggregate.by_sample #87

Closed Marwansha closed 3 months ago

Marwansha commented 4 months ago

Hello, first of all thanks for the hard and good work with Liana,

I have encountered this issue while doing li.mt.rank_aggregate.by_sample.

i am using a subset of my adata obect just to test it, while using li.mt.rank_aggregate works fine

ad 
AnnData object with n_obs × n_vars = 1000 × 36623
li.mt.rank_aggregate.by_sample(
    ad,
    groupby="final",
    sample_key="cond", # sample key by which we which to loop
    use_raw=False,
    verbose=True, # use 'full' to show all verbose information
    n_perms=100, # reduce permutations for speed
    return_all_lrs=True, # return all LR values
    )
Now running: NS:   0%|          | 0/2 [00:06<?, ?it/s]
---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
/local/scratch/tmp/ipykernel_1649404/55790829.py in ?()
----> 1 li.mt.rank_aggregate.by_sample(
      2     ad,
      3     groupby="final",
      4     sample_key="cond", # sample key by which we which to loop

~/venvs/scvi/lib/python3.11/site-packages/liana/method/sc/_Method.py in ?(self, adata, sample_key, key_added, inplace, verbose, **kwargs)
    147                 temp = temp.to_memory().copy() # NOTE does to_memory copy?
    148             else:
    149                 temp = temp.copy()
    150 
--> 151             sample_res = self.__call__(temp, inplace=False, verbose=full_verbose, **kwargs)
    152 
    153             adata.uns[key_added][sample] = sample_res
    154 

~/venvs/scvi/lib/python3.11/site-packages/liana/method/sc/_rank_aggregate.py in ?(self, adata, groupby, resource_name, expr_prop, min_cells, groupby_pairs, base, aggregate_method, consensus_opts, return_all_lrs, key_added, use_raw, layer, de_method, n_perms, seed, n_jobs, resource, interactions, mdata_kwargs, inplace, verbose)
    123             ad = mdata_to_anndata(adata, **mdata_kwargs, verbose=verbose)
    124         else:
    125             ad = adata
    126 
--> 127         liana_res = liana_pipe(adata=ad,
    128                                groupby=groupby,
    129                                resource_name=resource_name,
    130                                resource=resource,

~/venvs/scvi/lib/python3.11/site-packages/liana/method/sc/_liana_pipe.py in ?(adata, groupby, resource_name, resource, interactions, groupby_pairs, expr_prop, min_cells, base, de_method, n_perms, seed, verbose, use_raw, n_jobs, layer, supp_columns, return_all_lrs, _score, _methods, _consensus_opts, _aggregate_method)
    189                 if verbose:
    190                     print(f"Running {method.method_name}")
    191 
    192                 lrs[method.method_name] = \
--> 193                     _run_method(lr_res=lr_res.copy(),
    194                                 adata=adata,
    195                                 expr_prop=expr_prop,
    196                                 _score=method,

~/venvs/scvi/lib/python3.11/site-packages/liana/method/sc/_liana_pipe.py in ?(lr_res, adata, expr_prop, _score, _key_cols, _complex_cols, _add_cols, n_perms, seed, return_all_lrs, n_jobs, verbose, _aggregate_flag)
    363                 verbose: bool,
    364                 _aggregate_flag: bool = False  # Indicates whether we're generating the consensus
    365                 ) -> pd.DataFrame:
    366     # re-assemble complexes - specific for each method
--> 367     lr_res = filter_reassemble_complexes(lr_res=lr_res,
    368                                          _key_cols=_key_cols,
    369                                          expr_prop=expr_prop,
    370                                          return_all_lrs=return_all_lrs,

~/venvs/scvi/lib/python3.11/site-packages/liana/resource/_reassemble_complexes.py in ?(lr_res, _key_cols, complex_cols, expr_prop, return_all_lrs, complex_policy)
     37     """
     38     # Filter by expr_prop (inner join only complexes where all subunits are expressed)
     39     expressed = (lr_res[_key_cols + ['ligand_props', 'receptor_props']]
     40                  .set_index(_key_cols)
---> 41                  .stack()
     42                  .groupby(_key_cols)
     43                  .agg(prop_min=complex_policy)
     44                  .reset_index()

~/venvs/scvi/lib/python3.11/site-packages/pandas/core/frame.py in ?(self, level, dropna, sort, future_stack)

TypeError: stack() got an unexpected keyword argument 'sort'

here is the session info

anndata 0.10.3 decoupler 1.5.0 liana 1.0.4 matplotlib 3.8.1 mofax NA muon 0.1.5 numpy 1.26.1 pandas 2.1.1 plotnine 0.12.4 scanpy 1.9.6 seaborn 0.12.2 session_info 1.0.0

Click to view modules imported as dependencies

IPython 8.17.2 jupyter_client 8.6.0 jupyter_core 5.5.0

Python 3.11.4 (main, Jul 5 2023, 13:45:01) [GCC 11.2.0] Linux-4.18.0-477.43.1.el8_8.x86_64-x86_64-with-glibc2.28

Session information updated at 2024-02-14 13:12

dbdimitrov commented 4 months ago

Hi @Marwansha,|

Strange.. Is it possible to provide the subset, so that I can test it myself?

It's likely that this is an edge case where maybe there are too few cell per sample, or something along those lines. But either way, it would be good for me to throw an informative error if this is the case.

dbdimitrov commented 4 months ago

you can email a link to daniel(ат)dimitrov.uni-heidelberg.de