Open nroak opened 1 year ago
Hey!
R does not have unsigned integers. It seems that you have one in your adata object though. Please check adata.obs.dtypes
and adata.var.dtypes
to see if any of them come up as unsigned integer. Then you can either remove this column or convert it. Then the conversion should work again!
Here's the output for these values. Doesn't look like unsigned integer?
adata.var.dtypes
Accession object
Chromosome category
End int64
Start int64
Strand category
mt bool
ribo bool
hb bool
n_cells_by_counts int64
mean_counts float32
log1p_mean_counts float32
pct_dropout_by_counts float64
total_counts float32
log1p_total_counts float32
n_cells int64
dtype: object
adata.obs.dtypes
genotype category
replicate category
batch category
scDblFinder_class int32
n_genes_by_counts int32
log1p_n_genes_by_counts float64
total_counts float32
log1p_total_counts float32
pct_counts_in_top_20_genes float64
total_counts_mt float32
log1p_total_counts_mt float32
pct_counts_mt float32
total_counts_ribo float32
log1p_total_counts_ribo float32
pct_counts_ribo float32
total_counts_hb float32
log1p_total_counts_hb float32
pct_counts_hb float32
outlier bool
size_factors float64
dtype: object
I re-ran the tutorial from the beginning and getting a different error but at the same step:
if issparse(adata.X):
if not adata.X.has_sorted_indices:
adata.X.sort_indices()
ro.globalenv["adata"] = adata
---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
File ~/opt/anaconda3/envs/velocyto/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: 'AnnData' object has no attribute '__sexp__'
During handling of the above exception, another exception occurred:
ValueError Traceback (most recent call last)
Cell In[68], line 4
2 if not adata.X.has_sorted_indices:
3 adata.X.sort_indices()
----> 4 ro.globalenv["adata"] = adata
File ~/opt/anaconda3/envs/velocyto/lib/python3.10/site-packages/rpy2/robjects/environments.py:36, in Environment.__setitem__(self, item, value)
34 def __setitem__(self, item: str, value: typing.Any) -> None:
35 robj = conversion.get_conversion().py2rpy(value)
---> 36 super(Environment, self).__setitem__(item, robj)
File ~/opt/anaconda3/envs/velocyto/lib/python3.10/site-packages/rpy2/rinterface_lib/sexp.py:404, in SexpEnvironment.__setitem__(self, key, value)
400 key_cchar = conversion._str_to_cchar(key)
401 symbol = rmemory.protect(
402 openrlib.rlib.Rf_install(key_cchar)
403 )
--> 404 cdata = rmemory.protect(conversion._get_cdata(value))
405 cdata_copy = rmemory.protect(
406 openrlib.rlib.Rf_duplicate(cdata)
407 )
408 openrlib.rlib.Rf_defineVar(symbol,
409 cdata_copy,
410 self.__sexp__._cdata)
File ~/opt/anaconda3/envs/velocyto/lib/python3.10/site-packages/rpy2/rinterface_lib/conversion.py:181, in _get_cdata(obj)
179 cdata = obj.__sexp__._cdata
180 except AttributeError:
--> 181 raise ValueError('Not an rpy2 R object and unable '
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: AnnData object with n_obs × n_vars = 23018 × 18216
obs: 'genotype', 'replicate', 'batch', 'scDblFinder_class', 'n_genes_by_counts', 'log1p_n_genes_by_counts', 'total_counts', 'log1p_total_counts', 'pct_counts_in_top_20_genes', 'total_counts_mt', 'log1p_total_counts_mt', 'pct_counts_mt', 'total_counts_ribo', 'log1p_total_counts_ribo', 'pct_counts_ribo', 'total_counts_hb', 'log1p_total_counts_hb', 'pct_counts_hb', 'outlier', 'mt_outlier', 'size_factors'
var: 'gene_ids', 'feature_types', 'genome', 'mt', 'ribo', 'hb', 'n_cells_by_counts', 'mean_counts', 'log1p_mean_counts', 'pct_dropout_by_counts', 'total_counts', 'log1p_total_counts', 'n_cells'
layers: 'counts', 'soupX_counts', 'log1pPF_normalization', 'PFlog1pPF_normalization', 'scran_normalization'
scanpy==1.9.1 anndata==0.8.0 umap==0.5.3 numpy==1.23.5 scipy==1.10.0 pandas==1.5.3 scikit-learn==1.2.0 statsmodels==0.13.5 python-igraph==0.10.4 louvain==0.8.0 pynndescent==0.5.8
For the first error, you could also check .obsm
, .obsp
, .varm
, .varp
and .uns
. You also have quite a few layers where unsigned ints may be hiding (not sure)... For the second error, I'm not sure what's going on there. You may be better off reporting this at the anndata2ri repo though as the error is in that step.
I'm encountering error below while saving the AnnData object in the R environment in this step of the tutorial.