theislab / scib

Benchmarking analysis of data integration tools
MIT License
294 stars 63 forks source link

Conversion 'py2rpy' not defined for objects of type '<class 'numpy.ndarray' #266

Closed Hrovatin closed 3 years ago

Hrovatin commented 3 years ago

After installing latest master of scIB I get this error:

Traceback (most recent call last):
  File "/storage/groups/ml01/code/karin.hrovatin//qtr_intercode_reproducibility-/scripts/integration_benchmarks/run_metrics.py", line 113, in <module>
    kBET_per_label=sm.kBET(adata=latent_adata, batch_key=args.batch, 
  File "/storage/groups/ml01/code/karin.hrovatin/scib/scIB/metrics/kbet.py", line 161, in kBET
    score = kBET_single(
  File "/storage/groups/ml01/code/karin.hrovatin/scib/scIB/metrics/kbet.py", line 38, in kBET_single
    ro.globalenv['data_mtrx'] = matrix
  File "/home/icb/karin.hrovatin/miniconda3/envs/scib2/lib/python3.8/site-packages/rpy2/robjects/environments.py", line 34, in __setitem__
    robj = conversion.converter.py2rpy(value)
  File "/home/icb/karin.hrovatin/miniconda3/envs/scib2/lib/python3.8/functools.py", line 874, in wrapper
    return dispatch(args[0].__class__)(*args, **kw)
  File "/home/icb/karin.hrovatin/miniconda3/envs/scib2/lib/python3.8/site-packages/rpy2/robjects/conversion.py", line 188, in _py2rpy
    raise NotImplementedError(
NotImplementedError: Conversion 'py2rpy' not defined for objects of type '<class 'numpy.ndarray'>'

I have tried importing numpy arrays into r as done in the function in the same env on the same server node, but there it had worked. I have also tried adding activate numpy before every activate anndata call in scIB code (as suggested here https://github.com/theislab/anndata2ri/issues/50 ), but it did not work either.

gokceneraslan commented 3 years ago

Minimal example to reproduce:

#import numpy as np
import scanpy as sc
import scIB

#import anndata2ri
#anndata2ri.activate()

#import rpy2.robjects as ro
#ro.globalenv['x'] = np.ones((10, 10))

ad = sc.datasets.pbmc68k_reduced()
something_proper = scIB.metrics.kBET(ad, 'louvain', 'phase')
gokceneraslan commented 3 years ago

@LuckyMD Can you close this one too, it should be fixed in the master branch.

gokceneraslan commented 3 years ago

You guys might consider adding the snippet above as a unit test for kBET though, apparently the existing test didn't catch this one.

mumichae commented 3 years ago

Good point and thanks for the minimal example. We don't yet have proper kbet testing, as that requires an R installation, but once that is fixed, we'll update

LuckyMD commented 3 years ago

Thanks @gokceneraslan! @mumichae is now tracking this in #270

gokceneraslan commented 3 years ago

Thanks!