scib: RRuntimeError: Unable to find an inherited method for function ‘assay’ for signature ‘"dgCMatrix", "character"’

I’m trying to troubleshoot a bug associate with a package I’m working on with @LuckyMD (https://github.com/singlecellopenproblems/SingleCellOpenProblems). I tried using toy data and am getting this error

import anndata
import numpy as np
import scIB.preprocessing

adata = anndata.AnnData(np.random.normal(100,1, size=(3000,1000)))
scIB.preprocessing.normalize(adata)

raises

---------------------------------------------------------------------------
RRuntimeError                             Traceback (most recent call last)
<ipython-input-1-68c695ef7288> in <module>
      4
      5 adata = anndata.AnnData(np.random.normal(100,1, size=(3000,1000)))
----> 6 scIB.preprocessing.normalize(adata)

~/.local/lib/python3.8/site-packages/scIB/preprocessing.py in normalize(adata, min_mean)
    168     ro.globalenv['data_mat'] = adata.X.T
    169     ro.globalenv['input_groups'] = adata_pp.obs['groups']
--> 170     size_factors = ro.r(f'computeSumFactors(data_mat, clusters = input_groups, min.mean = {min_mean})')
    171     del adata_pp
    172

/usr/lib/python3.8/site-packages/rpy2/robjects/__init__.py in __call__(self, string)
    414     def __call__(self, string):
    415         p = rinterface.parse(string)
--> 416         res = self.eval(p)
    417         return conversion.rpy2py(res)
    418

/usr/lib/python3.8/site-packages/rpy2/robjects/functions.py in __call__(self, *args, **kwargs)
    195                 v = kwargs.pop(k)
    196                 kwargs[r_k] = v
--> 197         return (super(SignatureTranslatedFunction, self)
    198                 .__call__(*args, **kwargs))
    199

/usr/lib/python3.8/site-packages/rpy2/robjects/functions.py in __call__(self, *args, **kwargs)
    123             else:
    124                 new_kwargs[k] = conversion.py2rpy(v)
--> 125         res = super(Function, self).__call__(*new_args, **new_kwargs)
    126         res = conversion.rpy2py(res)
    127         return res

/usr/lib/python3.8/site-packages/rpy2/rinterface_lib/conversion.py in _(*args, **kwargs)
     42 def _cdata_res_to_rinterface(function):
     43     def _(*args, **kwargs):
---> 44         cdata = function(*args, **kwargs)
     45         # TODO: test cdata is of the expected CType
     46         return _cdata_to_rinterface(cdata)

/usr/lib/python3.8/site-packages/rpy2/rinterface.py in __call__(self, *args, **kwargs)
    622                     error_occured))
    623             if error_occured[0]:
--> 624                 raise embedded.RRuntimeError(_rinterface._geterrmessage())
    625         return res
    626

RRuntimeError: Error in (function (classes, fdef, mtable)  :
  unable to find an inherited method for function ‘assay’ for signature ‘"dgCMatrix", "character"’

I’m have the following package versions installed

anndata 0.7.4
scanpy 1.4.5.post3
rpy2 3.3.5
anndata2ri 1.0.3
scanorama 1.6
memory_profiler 0.57.0
networkx 2.4
igraph 0.8.2
louvain 0.6.1

About this issue

  • Original URL
  • State: closed
  • Created 4 years ago
  • Comments: 19 (8 by maintainers)

Commits related to this issue

Most upvoted comments

So in version 3.11 scran requires an sce object as input. A pity, but okay… will test whether this is consistent in 3.10 as well on my end and then merge. Thanks @scottgigante !

damn, I thought that’s what I was doing the whole time. So it seems as though they introduced a new function calculateSumFactors() which uses the data matrix input. computeSumFactors() now only takes SingleCellExperiment objects where it did both before. So either, move to sce for everything, or write a bioconductor version check to see if it’s >=3.11.

This works in both:

BiocGenerics::sizeFactors(
  scran::computeSumFactors(
    SingleCellExperiment::SingleCellExperiment(list(
      counts=matrix(runif(10, 100, 100), ncol=10)
    ))
  )
)