theislab / scarches

Reference mapping for single-cell genomics
https://docs.scarches.org/en/latest/
BSD 3-Clause "New" or "Revised" License
331 stars 51 forks source link

Fail to get latent representation of reference + query dataset #197

Closed Yuki-YqHuang closed 1 year ago

Yuki-YqHuang commented 1 year ago

Hi,

I'm trying to implement the code in your tutorial example "Unsupervised surgery pipeline with SCVI". In step [21] I tried to concatenate source_adata and target_adata, but got the following error:


AttributeError Traceback (most recent call last) Cell In[42], line 1 ----> 1 adata_full = source_adata.concatenate(target_adata) 2 full_latent = sc.AnnData(model.get_latent_representation(adata=adata_full)) 3 full_latent.obs['cell_type'] = adata_full.obs[cell_type_key].tolist()

File /opt/conda/envs/cell2loc_env/lib/python3.11/site-packages/anndata/_core/anndata.py:1808, in AnnData.concatenate(self, join, batch_key, batch_categories, uns_merge, index_unique, fill_value, *adatas) 1799 pat = rf"-({'|'.join(batch_categories)})$" 1800 out.var = merge_dataframes( 1801 [a.var for a in all_adatas], 1802 out.var_names, 1803 partial(merge_outer, batch_keys=batch_categories, merge=merge_same), 1804 ) 1805 out.var = out.var.iloc[ 1806 :, 1807 ( -> 1808 out.var.columns.str.extract(pat, expand=False) 1809 .fillna("") 1810 .argsort(kind="stable") 1811 ), 1812 ] 1814 return out

File /opt/conda/envs/cell2loc_env/lib/python3.11/site-packages/pandas/core/accessor.py:224, in CachedAccessor.get(self, obj, cls) 221 if obj is None: 222 # we're accessing the attribute of the class, i.e., Dataset.geo 223 return self._accessor --> 224 accessor_obj = self._accessor(obj) 225 # Replace the property with the accessor object. Inspired by: 226 # https://www.pydanny.com/cached-property.html 227 # We need to use object.setattr because we overwrite setattr on 228 # NDFrame 229 object.setattr(obj, self._name, accessor_obj)

File /opt/conda/envs/cell2locenv/lib/python3.11/site-packages/pandas/core/strings/accessor.py:181, in StringMethods.init(self, data) 178 def init(self, data) -> None: 179 from pandas.core.arrays.string import StringDtype --> 181 self._inferred_dtype = self._validate(data) 182 self._is_categorical = is_categorical_dtype(data.dtype) 183 self._is_string = isinstance(data.dtype, StringDtype)

File /opt/conda/envs/cell2loc_env/lib/python3.11/site-packages/pandas/core/strings/accessor.py:235, in StringMethods._validate(data) 232 inferred_dtype = lib.infer_dtype(values, skipna=True) 234 if inferred_dtype not in allowed_types: --> 235 raise AttributeError("Can only use .str accessor with string values!") 236 return inferred_dtype

AttributeError: Can only use .str accessor with string values!

Koncopd commented 1 year ago

@Yuki-YqHuang this is certainly an anndata error, please ask here https://github.com/scverse/anndata