Hi,
I’m trying to run decoupler for a pesudobulk analysis of my data. However, when I’m trying to run the following code:
pdata = dc.pp.pseudobulk(adata, sample_col="sample", groups_col="annotation", layer='rawcounts', mode="sum", skip_checks=True)
I get an error:
TypeError Traceback (most recent call last)
Cell In[6], line 4
----> 4 pdata = dc.pp.pseudobulk(adata, sample_col="sample", groups_col="annotation", layer='rawcounts', mode="sum", skip_checks=True)
File /projects/env/lib/python3.10/site-packages/decoupler/pp/anndata.py:378, in pseudobulk(adata, sample_col, groups_col, layer, raw, empty, mode, skip_checks, bsize, verbose)
376 _validate_X(X=X, mode=mode, skip_checks=skip_checks)
377 # Format inputs
--> 378 obs, groups_col, smples, groups, n_rows = _sample_group_by(
379 sample=sample_col,
380 group=groups_col,
381 obs=obs,
382 verbose=verbose,
383 )
384 n_cols = var.index.size
385 new_obs = pd.DataFrame(columns=obs.columns)
File /projects/env/lib/python3.10/site-packages/decoupler/pp/anndata.py:202, in _sample_group_by(sample, group, obs, verbose)
200 # Get unique samples and groups
201 smples = np.unique(obs[sample].values)
--> 202 groups = np.unique(obs[group].values)
203 # Get number of obs
204 n_rows = len(smples) * len(groups)
File /projects/env/lib/python3.10/site-packages/numpy/lib/arraysetops.py:274, in unique(ar, return_index, return_inverse, return_counts, axis, equal_nan)
272 ar = np.asanyarray(ar)
273 if axis is None:
--> 274 ret = _unique1d(ar, return_index, return_inverse, return_counts,
275 equal_nan=equal_nan)
276 return _unpack_tuple(ret)
278 # axis was specified and not None
File /projects/env/lib/python3.10/site-packages/numpy/lib/arraysetops.py:336, in _unique1d(ar, return_index, return_inverse, return_counts, equal_nan)
334 aux = ar[perm]
335 else:
--> 336 ar.sort()
337 aux = ar
338 mask = np.empty(aux.shape, dtype=np.bool_)
TypeError: '<' not supported between instances of 'float' and 'str'
I heard that SoupX can store the counts as floats. I used SoupX at the beginning of my pipeline. What I’m using as input is raw counts from a layer stored before normalization and log-transformation. I suppose I’m not the only one using both SoupX as well as this tool (if this in fact is the reason why I have floats), so if there are anyone who knows what to do here and could share it with me, I would appreciate it a lot!
Just to show how the layer was stored before normalization and transformation:
adata.layers['rawcounts'] = adata.X.copy()
sc.pp.normalize_total(adata, target_sum=1e4)
sc.pp.log1p(adata)
adata.layers["lognormcounts"] = adata.X.copy()
The error I got before I added skip_checks=True:
AssertionError: Provided data contains float (decimal) values.
Check the parameters raw and layers to determine if you are selecting the correct matrix.
If decimal values are to be expected, override this error by setting skip_checks=True
Hope someone can help me with this. Thank you!