liana-py
liana-py copied to clipboard
ZeroDivisionError: float division by zero
Describe the bug
following your tutorial with own data:
li.mt.rank_aggregate.by_sample(
adata,
groupby=groupby,
sample_key=sample_key, # 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
)
I get a zero division error.
To Reproduce
If possible please provide a minimal reproducible example.
For example, a downsampled version of the your anndata
object.
Screenshots File ~/miniconda3/lib/python3.9/site-packages/liana/method/sc/_liana_pipe.py:300, in _get_lr(adata, resource, groupby_pairs, relevant_cols, mat_mean, mat_max, de_method, base, verbose) 298 dedict[label]['zscores'] = temp.layers['scaled'].mean(axis=0) 299 if logfc_flag: --> 300 dedict[label]['logfc'] = _calc_log2fc(adata, label) 301 if isinstance(mat_max, np.float32): # cellchat flag 302 dedict[label]['trimean'] = _trimean(temp.X / mat_max)
File ~/miniconda3/lib/python3.9/site-packages/liana/method/sc/_liana_pipe.py:342, in _calc_log2fc(adata, label) 340 # subject and rest means 341 subj_means = subject.layers['normcounts'].mean(0).A.flatten() --> 342 rest_means = rest.layers['normcounts'].mean(0).A.flatten() 344 # log2 + 1 transform 345 subj_log2means = np.log2(subj_means + 1)
File ~/miniconda3/lib/python3.9/site-packages/scipy/sparse/_base.py:1191, in spmatrix.mean(self, axis, dtype, out) 1189 # axis = 0 or 1 now 1190 if axis == 0: -> 1191 return (inter_self * (1.0 / self.shape[0])).sum( 1192 axis=0, dtype=res_dtype, out=out) 1193 else: 1194 return (inter_self * (1.0 / self.shape[1])).sum( 1195 axis=1, dtype=res_dtype, out=out)
ZeroDivisionError: float division by zero
variables used: sample_key = 'sample' (sample key) condition_key = 'cell_type' (2 cats: malignant/healthy) groupby = 'day' (7 cats: 7 days)