STOmics / Stereopy

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

Cryptic error message when region passed to read_gef() isn't covered by sample #289

Closed ViHammer closed 1 month ago

ViHammer commented 1 month ago

Running:

st.io.read_gef(file_path=gef_path, 
                             bin_size=bin_size, 
                             region=region)

and setting the region parameter to a region not covered by the <sample_name>.tissue.gef sample causes cryptic error:

[2024-06-01 11:46:22][Stereo][1662278][MainThread][140198435661632][reader][1070][INFO]: read_gef begin ...

---------------------------------------------------------------------------
TypeError                                 Traceback (most recent call last)
Cell In[17], line 1
----> 1 st.io.read_gef(file_path=gef_path, 
      2                              bin_size=bin_size, 
      3                              region=region)

File /.../mambaforge/envs/st/lib/python3.8/site-packages/stereo/utils/read_write_utils.py:37, in ReadWriteUtils.check_file_exists.<locals>.wrapped(*args, **kwargs)
     35     else:
     36         raise FileNotFoundError("Please ensure there is a file")
---> 37 return func(*args, **kwargs)

File /.../mambaforge/envs/st/lib/python3.8/site-packages/stereo/io/reader.py:1191, in read_gef(file_path, bin_type, bin_size, is_sparse, gene_list, region, gene_name_index)
   1187 cell_num = uniq_cell.size
   1188 gene_num = gene_names.size
   1190 data.position = np.array(
-> 1191     list((zip(np.right_shift(uniq_cell, 32), np.bitwise_and(uniq_cell, 0xffffffff))))).astype('uint32')
   1192 data.cells = Cell(cell_name=uniq_cell)
   1194 exp_matrix = csr_matrix((count, (cell_ind, gene_ind)), shape=(cell_num, gene_num), dtype=np.uint32)

TypeError: ufunc 'right_shift' not supported for the input types, and the inputs could not be safely coerced to any supported types according to the casting rule ''safe''

With the correct region coordinates, no errors.

An easier to understand error message would help trouble shooting.

tanliwei-genomics-cn commented 1 month ago

This error was caused by that no data can be extracted by the region you specified, we will improve the error message, thanks your feedback!