Skip to content

Support BiocSingular’s LowRankMatrix #17

Description

@LuckyMD

Hi!

I ran into a strange error when trying to write a quick script for Seurat -> Anndata conversion. I'm just loading data from a Seurat tutorial and then want to use their convert function to SingleCellExperiment, but anndata2ri is complaining. Here's the code:

%%R
library(Seurat)

# Load PBMC dataset from Seurat tutorial
pbmc.data <- Read10X(data.dir = "./filtered_gene_bc_matrices/hg19/")

# Initialize the Seurat object with the raw (non-normalized data).
pbmc <- CreateSeuratObject(counts = pbmc.data, project = "pbmc3k", min.cells = 3, min.features = 200)
%%R 
#convert the Seurat object to a SingleCellExperiment object
pbmc_sce <- as.SingleCellExperiment(pbmc)

pbmc_sce

In the second cell, anndata2ri complains, although I have not put in any -o flags to output the object to python. The error message is the following:

---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
<ipython-input-12-3fcf8ce65415> in <module>
----> 1 get_ipython().run_cell_magic('R', '', '#convert the Seurat object to a SingleCellExperiment object\npbmc_sce <- as.SingleCellExperiment(pbmc)\n\npbmc_sce\n')

/usr/local/lib/python3.7/site-packages/IPython/core/interactiveshell.py in run_cell_magic(self, magic_name, line, cell)
   2350             with self.builtin_trap:
   2351                 args = (magic_arg_s, cell)
-> 2352                 result = fn(*args, **kwargs)
   2353             return result
   2354 

</usr/local/lib/python3.7/site-packages/decorator.py:decorator-gen-806> in R(self, line, cell, local_ns)

/usr/local/lib/python3.7/site-packages/IPython/core/magic.py in <lambda>(f, *a, **k)
    185     # but it's overkill for just that one bit of state.
    186     def magic_deco(arg):
--> 187         call = lambda f, *a, **k: f(*a, **k)
    188 
    189         if callable(arg):

/usr/local/lib/python3.7/site-packages/rpy2/ipython/rmagic.py in R(self, line, cell, local_ns)
    725                     return_output = False
    726             else:
--> 727                 text_result, result, visible = self.eval(code)
    728                 text_output += text_result
    729                 if visible:

/usr/local/lib/python3.7/site-packages/rpy2/ipython/rmagic.py in eval(self, code)
    257             try:
    258                 # Need the newline in case the last line in code is a comment.
--> 259                 value, visible = ro.r("withVisible({%s\n})" % code)
    260             except (ri.embedded.RRuntimeError, ValueError) as exception:
    261                 # Otherwise next return seems to have copy of error.

/usr/local/lib/python3.7/site-packages/rpy2/robjects/vectors.py in __getitem__(self, i)
    260 
    261         if isinstance(res, Sexp):
--> 262             res = conversion.rpy2py(res)
    263         return res
    264 

/usr/local/Cellar/python/3.7.2_2/Frameworks/Python.framework/Versions/3.7/lib/python3.7/functools.py in wrapper(*args, **kw)
    822                             '1 positional argument')
    823 
--> 824         return dispatch(args[0].__class__)(*args, **kw)
    825 
    826     funcname = getattr(func, '__name__', 'singledispatch function')

/usr/local/lib/python3.7/site-packages/anndata2ri/r2py.py in rpy2py_s4(obj)
     25         return rpy2py_data_frame(obj)
     26     elif "SingleCellExperiment" in r_classes:
---> 27         return rpy2py_single_cell_experiment(obj)
     28     elif supported_r_matrix_classes() & r_classes:
     29         return rmat_to_spmat(obj)

/usr/local/lib/python3.7/site-packages/anndata2ri/r2py.py in rpy2py_single_cell_experiment(obj)
     56             assay_names = [str(a) for a in se.assayNames(obj)]
     57             # The assays can be stored in an env or elsewise so we don’t use obj.slots['assays']
---> 58             assays = [numpy2ri.rpy2py(assay).T for assay in (se.assay(obj, n) for n in assay_names)]
     59             # There’s SingleCellExperiment with no assays
     60             exprs, layers = assays[0], dict(zip(assay_names[1:], assays[1:]))

/usr/local/lib/python3.7/site-packages/anndata2ri/r2py.py in <listcomp>(.0)
     56             assay_names = [str(a) for a in se.assayNames(obj)]
     57             # The assays can be stored in an env or elsewise so we don’t use obj.slots['assays']
---> 58             assays = [numpy2ri.rpy2py(assay).T for assay in (se.assay(obj, n) for n in assay_names)]
     59             # There’s SingleCellExperiment with no assays
     60             exprs, layers = assays[0], dict(zip(assay_names[1:], assays[1:]))

AttributeError: 'RS4' object has no attribute 'T'

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions