Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issues with Example Notebooks in Sagenet #3

Open
ggui6809 opened this issue Jan 7, 2024 · 3 comments
Open

Issues with Example Notebooks in Sagenet #3

ggui6809 opened this issue Jan 7, 2024 · 3 comments

Comments

@ggui6809
Copy link

ggui6809 commented Jan 7, 2024

Dear Author,

Firstly, I would like to express my appreciation for your excellent work on Sagenet. It's a fantastic tool that has been very helpful. However, I've encountered a couple of issues while working with the example Jupyter notebooks provided in the GitHub repository:

  1. KeyError with map_query Function: In all the example notebooks, I encounter a KeyError: 'dist_map' after executing the map_query function on anndata data. Could you provide any insight or suggestions on how to resolve this?

Code:

import anndata
dist_adata = anndata.AnnData(adata_q.obsm['dist_map'], obs = adata_q.obs)
knn_indices, knn_dists, forest = sc.neighbors.compute_neighbors_umap(dist_adata.X, n_neighbors=50, metric='precomputed')
dist_adata.obsp['distances'], dist_adata.obsp['connectivities'] = sc.neighbors._compute_connectivities_umap(
    knn_indices,
    knn_dists,
    dist_adata.shape[0],
    50, # change to neighbors you plan to use
)
sc.pp.neighbors(dist_adata, metric='precomputed', use_rep='X')
sc.tl.umap(dist_adata)
sc.pl.umap(dist_adata, color='cell_type', palette=celltype_colours, save='eli.pdf')

Output:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<ipython-input-34-f7df6b6fd121> in <cell line: 2>()
      1 import anndata
----> 2 dist_adata = anndata.AnnData(adata_q.obsm['dist_map'], obs = adata_q.obs)
      3 knn_indices, knn_dists, forest = sc.neighbors.compute_neighbors_umap(dist_adata.X, n_neighbors=50, metric='precomputed')
      4 dist_adata.obsp['distances'], dist_adata.obsp['connectivities'] = sc.neighbors._compute_connectivities_umap(
      5     knn_indices,

/usr/local/lib/python3.10/dist-packages/anndata/_core/aligned_mapping.py in __getitem__(self, key)
    190 
    191     def __getitem__(self, key: str) -> V:
--> 192         return self._data[key]
    193 
    194     def __setitem__(self, key: str, value: V):
  1. Error in Loading seqFISH Data: I also faced an issue with the following line of code: adata_r = sg.datasets.seqFISH(). It seems to generate an error indicating that the datasets are not available in the Sagenet package. As a workaround, I tried using:
adata_r = sg.MGA_data.seqFISH1_1()
adata_q1 = copy(adata_r)
adata_q2 = sg.MGA_data.seqFISH2_1()

Is this an appropriate substitution, or would you recommend a different approach?

Any guidance or advice you can provide on these matters would be greatly appreciated. Thank you for your time and for developing such a useful tool.

Best regards,
Guan Gui

@EliHei2
Copy link
Collaborator

EliHei2 commented Jan 10, 2024

Hey @ggui6809 thanks for reaching out.

KeyError with map_query Function: In all the example notebooks, I encounter a KeyError: 'dist_map' after executing the map_query function on anndata data. Could you provide any insight or suggestions on how to resolve this?

could you please print out adata_q? are you running this line after running map_query? Seems that the anndata object adata_q does not have the dist_map. This might be due to the recent updates in the function map_query, if you're running with the default values you should set save_dist=True. I need to add this to the documentation.

Error in Loading seqFISH Data: I also faced an issue with the following line of code: adata_r = sg.datasets.seqFISH(). It seems to generate an error indicating that the datasets are not available in the Sagenet package.

Your workaround is completely valid. I need to update the notebooks according to the new version of the function.

Thanks a lot for pointing these out. I'll update the docs and notebooks accordingly.

Cheers,
Elyas

@ggui6809
Copy link
Author

Hi Elyas,

Thanks for your kind reply. I tried to print out the adata_q for you by running the code again, but it seems there are some new issues when importing the package as below:
Code:

import sagenet as sg
import scanpy as sc
import squidpy as sq
import anndata as ad
import random
random.seed(10)

Error:

/usr/local/lib/python3.10/dist-packages/geopandas/_compat.py:124: UserWarning: The Shapely GEOS version (3.11.2-CAPI-1.17.2) is incompatible with the GEOS version PyGEOS was compiled with (3.10.4-CAPI-1.16.2). Conversions between both will be slow.
  warnings.warn(
/usr/local/lib/python3.10/dist-packages/spatialdata/__init__.py:11: UserWarning: Geopandas was set to use PyGEOS, changing to shapely 2.0 with:

	geopandas.options.use_pygeos = True

If you intended to use PyGEOS, set the option to False.
  _check_geopandas_using_shapely()
---------------------------------------------------------------------------
AttributeError                            Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/pkg_resources/__init__.py](https://localhost:8080/#) in _dep_map(self)
   3107         try:
-> 3108             return self.__dep_map
   3109         except AttributeError:

30 frames
AttributeError: _DistInfoDistribution__dep_map

During handling of the above exception, another exception occurred:

AttributeError                            Traceback (most recent call last)
AttributeError: _pkg_info

During handling of the above exception, another exception occurred:

FileNotFoundError                         Traceback (most recent call last)
[/usr/local/lib/python3.10/dist-packages/pkg_resources/__init__.py](https://localhost:8080/#) in _get(self, path)
   1724 
   1725     def _get(self, path):
-> 1726         with open(path, 'rb') as stream:
   1727             return stream.read()
   1728 

FileNotFoundError: [Errno 2] No such file or directory: '/usr/local/lib/python3.10/dist-packages/numpy-1.23.5.dist-info/METADATA'

And except for pip install the sagenet package, I still need to install the below package that may need to be considered in the sagenet package file.

!pip install squidpy
!pip install gglasso
!pip install torch_geometric

Thanks again for your time and consideration!!

Best regards,
Guan

@ggui6809
Copy link
Author

Hey @EliHei2 ,
Thanks for updating the code; there is some reminder on the example code to avoid the error:

  1. After installing the package from Sagenet, still need to install the package below
!pip install squidpy
!pip install gglasso
!pip install torch_geometric

And need to make sure the package "numpy" version with 1.23.4 before running "import sagenet as sg" otherwise, there will be an error as above.

  1. As per your guidance, it is correct to set the map_query function as below to avoid the error.
sg_obj.map_query(adata_q, save_dist=True)

Thanks again for your help!

Best regards,
Guan

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants