STOmics / Stereopy

A toolkit of spatial transcriptomic analysis.
MIT License
180 stars 59 forks source link

KeyError: "Unable to synchronously open object (object 'cellBin' doesn't exist)" #215

Closed yang050036 closed 7 months ago

yang050036 commented 8 months ago

Hi, I have got an error when I used st.io.update_gef: KeyError: "Unable to synchronously open object (object 'cellBin' doesn't exist)" Any help for me?

Zhenbin24 commented 8 months ago

Hello, can you post your script here? I will take a look at the specific content of the script and troubleshoot the problem later.

yang050036 commented 8 months ago

I wished to save the cluster result to gef file for generate_loom. st.io.update_gef(data=data, gef_file="result-LBB-2/7.RNA_velo/LBB-2_cluster.gef.bkk", cluser_res_key='leiden_0.5')


TypeError Traceback (most recent call last) Cell In[79], line 1 ----> 1 st.io.update_gef(data=data, gef_file="result-LBB-2/7.RNA_velo/LBB-2_cluster.gef.bkk", cluser_res_key='leiden_0.5')

TypeError: update_gef() got an unexpected keyword argument 'cluser_res_key'

In [80]: st.io.update_gef(data=data, gef_file="result-LBB-2/7.RNA_velo/LBB-2_cluster.gef.bkk", clutser_res_key='leiden_0.5')

TypeError Traceback (most recent call last) Cell In[80], line 1 ----> 1 st.io.update_gef(data=data, gef_file="result-LBB-2/7.RNA_velo/LBB-2_cluster.gef.bkk", clutser_res_key='leiden_0.5')

TypeError: update_gef() got an unexpected keyword argument 'clutser_res_key'

In [81]: st.io.update_gef(data=data, gef_file="result-LBB-2/7.RNA_velo/LBB-2_cluster.gef.bkk", cluster_res_key='leiden_0.5')

KeyError Traceback (most recent call last) Cell In[81], line 1 ----> 1 st.io.update_gef(data=data, gef_file="result-LBB-2/7.RNA_velo/LBB-2_cluster.gef.bkk", cluster_res_key='leiden_0.5')

File /annoroad/data1/bioinfo/PMO/yupengyang/Software/install/miniconda3/envs/STO/lib/python3.8/site-packages/stereo/io/writer.py:397, in update_gef(data, gef_file, cluster_res_key) 394 is_numeric = False 396 with h5py.File(gef_file, 'r+') as h5f: --> 397 cell_names = np.bitwise_or(np.left_shift(h5f['cellBin']['cell']['x'].astype('uint64'), 32), h5f['cellBin']['cell']['y'].astype('uint64')).astype('U') 398 celltid = np.zeros(h5f['cellBin']['cell'].shape, dtype='uint16') 400 for n, cell_name in enumerate(cell_names):

File h5py/_objects.pyx:54, in h5py._objects.with_phil.wrapper()

File h5py/_objects.pyx:55, in h5py._objects.with_phil.wrapper()

File /annoroad/data1/bioinfo/PMO/yupengyang/Software/install/miniconda3/envs/STO/lib/python3.8/site-packages/h5py/_hl/group.py:357, in Group.getitem(self, name) 355 raise ValueError("Invalid HDF5 object reference") 356 elif isinstance(name, (bytes, str)): --> 357 oid = h5o.open(self.id, self._e(name), lapl=self._lapl) 358 else: 359 raise TypeError("Accessing a group is done with bytes or str, " 360 "not {}".format(type(name)))

File h5py/_objects.pyx:54, in h5py._objects.with_phil.wrapper()

File h5py/_objects.pyx:55, in h5py._objects.with_phil.wrapper()

File h5py/h5o.pyx:190, in h5py.h5o.open()

KeyError: "Unable to open object (object 'cellBin' doesn't exist)"

And, I sovled this problem with other way. Convert the stereo object to anndata h5ad file, and add the cluster to dyn anndata from the converted h5ad.

stereopy==0.14.0b1

Zhenbin24 commented 8 months ago

Hello, the parameters you filled in are incorrect. st.io.update_gef(data=data, gef_file="result-LBB-2/7.RNA_velo/LBB-2_cluster.gef.bkk", cluser_res_key='leiden_0.5') -> st.io.update_gef(data=data, gef_file="result-LBB-2/7.RNA_velo/LBB-2_cluster.gef.bkk", cluster_res_key='leiden_0.5')

Zhenbin24 commented 8 months ago

Hello, the gef_file you use must have the cellBin attribute. You can refer to the example below. image

`import stereo as st import warnings warnings.filterwarnings('ignore')

read the GEF file

data_path = './SS200000135TL_D1.cellbin.gef' data = st.io.read_gef(file_path=data_path, bin_type='cell_bins')

preprocessing

data.tl.cal_qc() data.tl.raw_checkpoint() data.tl.sctransform(res_key='sctransform', inplace=True)

clustering

data.tl.pca(use_highly_genes=False, n_pcs=30, res_key='pca') data.tl.neighbors(pca_res_key='pca', n_pcs=30, res_key='neighbors') data.tl.umap(pca_res_key='pca', neighbors_res_key='neighbors', res_key='umap') data.tl.leiden(neighbors_res_key='neighbors', res_key='leiden')

add the imformation of clustering groups stored in cluster_res_key to input GEF file.

st.io.update_gef( data=data, gef_file=data_path, cluster_res_key='leiden', )`

demo_file: http://116.6.21.110:8090/share/dd965cba-7c1f-40b2-a275-0150890e005f

image

yang050036 commented 8 months ago

I paid attention to the 'cellbin', but I am not get the cellbin.gef now. Would you update the function for gef file?

Zhenbin24 commented 8 months ago

No, it’s just that the file used in the above example is wrong. We will fix this problem in the next version

tanliwei-coder commented 7 months ago

I paid attention to the 'cellbin', but I am not get the cellbin.gef now. Would you update the function for gef file?

@yang050036

Function update_gef only can be used to update a cluster result into the corresponding cellbin.gef file, because Cluster is a function used to classify the cells, but in gef file(not cellbin.gef file), there is no infomation about cells, we cannot give the cell types to conrresponding cells.