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

PMBC3k tutorial - issue loading saved object from .h5ad file #2497

Closed
2 of 3 tasks
tea-kostic opened this issue May 30, 2023 · 1 comment · Fixed by #2546
Closed
2 of 3 tasks

PMBC3k tutorial - issue loading saved object from .h5ad file #2497

tea-kostic opened this issue May 30, 2023 · 1 comment · Fixed by #2546

Comments

@tea-kostic
Copy link

tea-kostic commented May 30, 2023

  • I have checked that this issue has not already been reported.
  • I have confirmed this bug exists on the latest version of scanpy.
  • (optional) I have confirmed this bug exists on the master branch of scanpy.

I am following all the steps from the PBMC3k tutorial (https://scanpy.readthedocs.io/en/latest/tutorials/pbmc3k.html).
I ran the wilcoxon method for finding marker genes and saved the object to a .h5ad file, after which I reloaded the object from the file and the log1p dict appears to be empty for some reason. I checked the object before saving it to the file and it had the 'base' key whereas after loading it back it was missing, causing the error below.

Minimal code sample (that we can copy&paste without having any data)

adata = sc.read(results_file)
pd.DataFrame(adata.uns['rank_genes_groups']['names']).head(5)
result = adata.uns['rank_genes_groups']
groups = result['names'].dtype.names
pd.DataFrame(
    {group + '_' + key[:1]: result[key][group]
    for group in groups for key in ['names', 'pvals']}).head(5)
sc.tl.rank_genes_groups(adata, 'leiden', groups=['0'], reference='1', method='wilcoxon')
sc.pl.rank_genes_groups(adata, groups=['0'], n_genes=20)
KeyError                                  Traceback (most recent call last)
Input In [57], in <cell line: 1>()
----> 1 sc.tl.rank_genes_groups(adata, 'leiden', groups=['0'], reference='1', method='wilcoxon')
      2 sc.pl.rank_genes_groups(adata, groups=['0'], n_genes=20)

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/scanpy/tools/_rank_genes_groups.py:590, in rank_genes_groups(adata, groupby, use_raw, groups, reference, n_genes, rankby_abs, pts, key_added, copy, method, corr_method, tie_correct, layer, **kwds)
    580 adata.uns[key_added] = {}
    581 adata.uns[key_added]['params'] = dict(
    582     groupby=groupby,
    583     reference=reference,
   (...)
    587     corr_method=corr_method,
    588 )
--> 590 test_obj = _RankGenes(adata, groups_order, groupby, reference, use_raw, layer, pts)
    592 if check_nonnegative_integers(test_obj.X) and method != 'logreg':
    593     logg.warning(
    594         "It seems you use rank_genes_groups on the raw count data. "
    595         "Please logarithmize your data before calling rank_genes_groups."
    596     )

File /Library/Frameworks/Python.framework/Versions/3.10/lib/python3.10/site-packages/scanpy/tools/_rank_genes_groups.py:93, in _RankGenes.__init__(self, adata, groups, groupby, reference, use_raw, layer, comp_pts)
     82 def __init__(
     83     self,
     84     adata,
   (...)
     90     comp_pts=False,
     91 ):
---> 93     if 'log1p' in adata.uns_keys() and adata.uns['log1p']['base'] is not None:
     94         self.expm1_func = lambda x: np.expm1(x * np.log(adata.uns['log1p']['base']))
     95     else:

KeyError: 'base'

Versions

-----
anndata     0.9.1
scanpy      1.9.3
-----
PIL                 9.2.0
appnope             0.1.3
asttokens           NA
backcall            0.2.0
beta_ufunc          NA
binom_ufunc         NA
cffi                1.15.0
cycler              0.10.0
cython_runtime      NA
dateutil            2.8.2
debugpy             1.6.0
decorator           5.1.1
defusedxml          0.7.1
entrypoints         0.4
executing           0.8.3
h5py                3.7.0
hypergeom_ufunc     NA
igraph              0.9.11
ipykernel           6.13.0
ipython_genutils    0.2.0
ipywidgets          8.0.2
jedi                0.18.1
joblib              1.2.0
kiwisolver          1.4.4
leidenalg           0.8.10
llvmlite            0.39.1
louvain             0.7.1
matplotlib          3.6.0
matplotlib_inline   NA
mpl_toolkits        NA
natsort             8.2.0
nbinom_ufunc        NA
ncf_ufunc           NA
numba               0.56.2
numpy               1.23.0
packaging           21.3
pandas              1.4.3
parso               0.8.3
patsy               0.5.2
pexpect             4.8.0
pickleshare         0.7.5
pkg_resources       NA
prompt_toolkit      3.0.29
psutil              5.9.0
ptyprocess          0.7.0
pure_eval           0.2.2
pycparser           2.21
pydev_ipython       NA
pydevconsole        NA
pydevd              2.8.0
pydevd_file_utils   NA
pydevd_plugins      NA
pydevd_tracing      NA
pygments            2.11.2
pynndescent         0.5.7
pyparsing           3.0.8
pytz                2022.1
ruamel              NA
scipy               1.9.1
seaborn             0.12.0
session_info        1.0.0
six                 1.16.0
sklearn             1.1.2
stack_data          0.2.0
statsmodels         0.13.2
texttable           1.6.4
threadpoolctl       3.1.0
tornado             6.1
tqdm                4.64.1
traitlets           5.1.1
typing_extensions   NA
umap                0.5.3
wcwidth             0.2.5
yaml                5.3.1
zmq                 22.3.0
-----
IPython             8.2.0
jupyter_client      7.2.2
jupyter_core        4.9.2
notebook            6.4.10
-----
Python 3.10.2 (v3.10.2:a58ebcc701, Jan 13 2022, 14:50:16) [Clang 13.0.0 (clang-1300.0.29.30)]
macOS-13.3.1-x86_64-i386-64bit
-----
Session information updated at 2023-05-30 21:48

Any help would be appreciated! Thanks!

@flying-sheep
Copy link
Member

Duplicate of scverse/anndata#673

@flying-sheep flying-sheep marked this as a duplicate of scverse/anndata#673 Jun 7, 2023
@flying-sheep flying-sheep closed this as not planned Won't fix, can't repro, duplicate, stale Jun 7, 2023
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

Successfully merging a pull request may close this issue.

2 participants