Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Unable to load Seurat library after activating anndata2ri #138

Closed
jchen80 opened this issue Oct 15, 2023 · 2 comments
Closed

Unable to load Seurat library after activating anndata2ri #138

jchen80 opened this issue Oct 15, 2023 · 2 comments
Labels
question Further information is requested

Comments

@jchen80
Copy link

jchen80 commented Oct 15, 2023

Hi,

I'm trying to run the tutorial in Jupyter notebook. I ran into the situation where I can successfully install and load Seurat within jupyter after running %load_ext rpy2.ipython. However, if I first run anndata2ri.activate() before loading the extension, then I get the following error when I attempt to load in the Seurat library.

%%R 
library(Seurat)
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
File ~/miniconda3/envs/bio/lib/python3.10/site-packages/rpy2/rinterface_lib/conversion.py:179, in _get_cdata(obj)
    178 try:
--> 179     cdata = obj.__sexp__._cdata
    180 except AttributeError:

AttributeError: 'numpy.str_' object has no attribute '__sexp__'

During handling of the above exception, another exception occurred:

ValueError                                Traceback (most recent call last)
lab/Ithaka/E1 scRNAseq analysis/integrate.ipynb Cell 4 line 1
----> get_ipython().run_cell_magic('R', '', 'library("Seurat")\n')

File ~/miniconda3/envs/bio/lib/python3.10/site-packages/IPython/core/interactiveshell.py:2493, in InteractiveShell.run_cell_magic(self, magic_name, line, cell)
   2491 with self.builtin_trap:
   2492     args = (magic_arg_s, cell)
-> 2493     result = fn(*args, **kwargs)
   2495 # The code below prevents the output from being displayed
   2496 # when using magics with decorator @output_can_be_silenced
   2497 # when the last Python token in the expression is a ';'.
   2498 if getattr(fn, magic.MAGIC_OUTPUT_CAN_BE_SILENCED, False):

File ~/miniconda3/envs/bio/lib/python3.10/site-packages/rpy2/ipython/rmagic.py:935, in RMagics.R(self, line, cell, local_ns)
...
    182                          'to map it to one: %s' % repr(obj))
    183 else:
    184     cdata = cls(obj)

ValueError: Not an rpy2 R object and unable to map it to one: 'value'

Any idea what might be the issue? Also are there alternative ways of invoking anndata2ri within the Jupyter notebook without needing to globally activate it before loading the extension?

Thanks!

@flying-sheep
Copy link
Collaborator

flying-sheep commented Oct 16, 2023

Also are there alternative ways of invoking anndata2ri within the Jupyter notebook without needing to globally activate it before loading the extension?

yes, see e.g. the first example from the README:

import anndata2ri
from rpy2.robjects import r
from rpy2.robjects.conversion import localconverter

with localconverter(anndata2ri.converter):
    adata = r('as(some_data, "SingleCellExperiment")')

you can also use the -c parameter for the R cell magic:

%% R -c anndata2ri.converter
do_stuff <- in_r

Finally, once I get around to it, I will implement a more convenient way to do this, see #109

@flying-sheep flying-sheep added the question Further information is requested label Oct 16, 2023
@flying-sheep
Copy link
Collaborator

I closed the issue, since not using activate is the future, so #109 covers this

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants