STOmics / Stereopy

A toolkit of spatial transcriptomic analysis.
MIT License
184 stars 64 forks source link

multi sample test error #163

Closed m-fayer closed 11 months ago

m-fayer commented 1 year ago

Hi, I am trying the latest multi sample function.

When running command from stereo.core.ms_pipeline import slice_generator

it showed error:

---------------------------------------------------------------------------
ModuleNotFoundError                       Traceback (most recent call last)
Cell In[2], line 1
----> 1 from stereo.core.ms_pipeline import slice_generator

ModuleNotFoundError: No module named 'stereo.core.ms_pipeline'

From the output of command help(st.core) , there is no content "ms_pipeline", but there is "st_pipeline":

Help on package stereo.core in stereo:

NAME
    stereo.core

DESCRIPTION
    @author: Ping Qiu  qiuping1@genomics.cn
    @last modified by: Ping Qiu
    @file:__init__.py.py
    @time:2021/03/17

PACKAGE CONTENTS
    cell
    constants
    data
    gene
    ms_data
    result
    st_pipeline
    stereo_exp_data
    tool_base

But from stereo.core.st_pipeline import slice_generator also gave error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[4], line 1
----> 1 from stereo.core.st_pipeline import slice_generator

ImportError: cannot import name 'slice_generator' from 'stereo.core.st_pipeline' (C:\Users\xxx\AppData\Local\miniconda3\envs\stm\lib\site-packages\stereo\core\st_pipeline.py)

I installed using PyPi way in the instructions. Using command "conda list", I noticed stereopy version is 0.12.1, not the 0.13.0b1 shown in the page. So it looks the error is because I failed to install the latest version? How can I fix it? I tried the Development way in installation instructions but failed. Thanks.

UglyRay7 commented 1 year ago

Please try installing the latest version by specifying the targeted version number.

pip install stereopy==0.13.0b1

m-fayer commented 1 year ago

This command gave output with some errors below:

...
Successfully built stereopy
Installing collected packages: tornado, requests, lxml, fastcluster, distinctipy, joypy, stereopy
  Attempting uninstall: tornado
    Found existing installation: tornado 6.3.3
    Uninstalling tornado-6.3.3:
      Successfully uninstalled tornado-6.3.3
  Attempting uninstall: requests
    Found existing installation: requests 2.31.0
    Uninstalling requests-2.31.0:
      Successfully uninstalled requests-2.31.0
  Attempting uninstall: stereopy
    Found existing installation: stereopy 0.12.1
    Uninstalling stereopy-0.12.1:
      Successfully uninstalled stereopy-0.12.1
ERROR: pip's dependency resolver does not currently take into account all the packages that are installed. This behaviour is the source of the following dependency conflicts.
jupyter-client 8.3.0 requires tornado>=6.2, but you have tornado 6.1 which is incompatible.
jupyter-server 2.7.2 requires tornado>=6.2.0, but you have tornado 6.1 which is incompatible.
jupyterlab 4.0.5 requires tornado>=6.2.0, but you have tornado 6.1 which is incompatible.
jupyterlab-server 2.24.0 requires requests>=2.28, but you have requests 2.26.0 which is incompatible.
notebook 7.0.2 requires tornado>=6.2.0, but you have tornado 6.1 which is incompatible.
Successfully installed distinctipy-1.2.2 fastcluster-1.2.6 joypy-0.2.6 lxml-4.9.3 requests-2.26.0 stereopy-0.13.0b1 tornado-6.1

But the import command worked. Thanks!

m-fayer commented 11 months ago

Hi, after the installation, I tried some commands in the tutorial. For the "data_dir=" line, I used the downloaded demo data: data_dir = 'Demo_3D_Drosophila/3D_AnnData_0.8.0' . The files inside are:

-a----         1/06/2023   4:26 PM       30096216 0.h5ad
-a----         1/06/2023   4:25 PM       33928248 1.h5ad
-a----         1/06/2023   4:24 PM       62371088 10.h5ad
-a----         1/06/2023   4:24 PM       75232060 11.h5ad
-a----         1/06/2023   4:25 PM       58477648 12.h5ad
-a----         1/06/2023   4:24 PM       63967060 13.h5ad
-a----         1/06/2023   4:24 PM       74081548 14.h5ad
-a----         4/07/2023   4:47 PM       66953940 15.h5ad
-a----         1/06/2023   4:25 PM       36824980 2.h5ad
-a----         1/06/2023   4:25 PM       44668232 3.h5ad
-a----         1/06/2023   4:25 PM       45767372 4.h5ad
-a----         1/06/2023   4:25 PM       49402992 5.h5ad
-a----         1/06/2023   4:26 PM       55391352 6.h5ad
-a----         1/06/2023   4:25 PM       76786828 7.h5ad
-a----         1/06/2023   4:25 PM       77017488 8.h5ad
-a----         1/06/2023   4:25 PM       75554284 9.h5ad

Everything looks good, until I reached the lines:

# add all samples into MSData
for sample in data_list:
    ms_data += st.io.read_h5ad(file_path=sample, bin_type='bins', bin_size=1)

Some errors came out:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
File ~\AppData\Local\miniconda3\envs\stm\lib\site-packages\anndata\_io\utils.py:156, in report_read_key_on_error.<locals>.func_wrapper(elem, *args, **kwargs)
    155 try:
--> 156     return func(elem, *args, **kwargs)
    157 except Exception as e:

File ~\AppData\Local\miniconda3\envs\stm\lib\site-packages\anndata\_io\h5ad.py:532, in read_group(group)
    531 if encoding_type:
--> 532     EncodingVersions[encoding_type].check(
    533         group.name, group.attrs["encoding-version"]
    534     )
    535 if encoding_type in {None, "raw"}:

File ~\AppData\Local\miniconda3\envs\stm\lib\enum.py:387, in EnumMeta.__getitem__(cls, name)
    386 def __getitem__(cls, name):
--> 387     return cls._member_map_[name]

KeyError: 'dict'

During handling of the above exception, another exception occurred:

AnnDataReadError                          Traceback (most recent call last)
Cell In[9], line 2
      1 for sample in data_list:
----> 2     ms_data += st.io.read_h5ad(file_path=sample, bin_type='bins', bin_size=1)

File ~\AppData\Local\miniconda3\envs\stm\lib\site-packages\stereo\io\reader.py:634, in read_h5ad(file_path, anndata, flavor, bin_type, bin_size, **kwargs)
    632     if file_path is not None and anndata is not None:
    633         raise Exception("'file_path' and 'anndata' only can input one of them")
--> 634     return AnnBasedStereoExpData(h5ad_file_path=file_path, based_ann_data=anndata, bin_type=bin_type, bin_size=bin_size, **kwargs)
    635 else:
    636     raise ValueError("Invalid value for 'flavor'")

File ~\AppData\Local\miniconda3\envs\stm\lib\site-packages\stereo\core\stereo_exp_data.py:601, in AnnBasedStereoExpData.__init__(self, h5ad_file_path, based_ann_data, bin_type, bin_size, *args, **kwargs)
    599     self._ann_data = based_ann_data
    600 else:
--> 601     self._ann_data = anndata.read_h5ad(h5ad_file_path)
    602 self._genes = AnnBasedGene(self._ann_data, self._genes.gene_name)
    603 self._cells = AnnBasedCell(self._ann_data, self._cells.cell_name)

File ~\AppData\Local\miniconda3\envs\stm\lib\site-packages\anndata\_io\h5ad.py:426, in read_h5ad(filename, backed, as_sparse, as_sparse_fmt, chunk_size)
    424         d[k] = read_dataframe(f[k])
    425     else:  # Base case
--> 426         d[k] = read_attribute(f[k])
    428 d["raw"] = _read_raw(f, as_sparse, rdasp)
    430 X_dset = f.get("X", None)

File ~\AppData\Local\miniconda3\envs\stm\lib\functools.py:875, in singledispatch.<locals>.wrapper(*args, **kw)
    871 if not args:
    872     raise TypeError(f'{funcname} requires at least '
    873                     '1 positional argument')
--> 875 return dispatch(args[0].__class__)(*args, **kw)

File ~\AppData\Local\miniconda3\envs\stm\lib\site-packages\anndata\_io\utils.py:162, in report_read_key_on_error.<locals>.func_wrapper(elem, *args, **kwargs)
    160 else:
    161     parent = _get_parent(elem)
--> 162     raise AnnDataReadError(
    163         f"Above error raised while reading key {elem.name!r} of "
    164         f"type {type(elem)} from {parent}."
    165     )

AnnDataReadError: Above error raised while reading key '/layers' of type <class 'h5py._hl.group.Group'> from /.

How can I fix it? Thanks.

tanliwei-coder commented 11 months ago

@m-fayer

Hi!! Download the demo data: Demo_3D_Drosophila/3D_AnnData_0.7.5 to use, because the version of anndata depended by stereopy is 0.7.5 which is not compatible with anndata 0.8.0 and higher.

m-fayer commented 11 months ago

It worked. Thank you so much.