question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

sc.pp.neighbors throws KeyError: diffmap_evals due to obsm concatenation

See original GitHub issue

Duplicating from https://github.com/theislab/anndata/pull/284:

@Koncopd @falexwolf

There is an issue with the obsm concatenation. When we run sc.tl.diffmap with different anndata objects, concatenate them and run sc.pp.neighbors on the concatenated new anndata, we get the following exception. The reason is that X_diffmap' is available in obsm but .uns['diffmap_evals'] is not.

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
<timed exec> in <module>

/opt/conda/lib/python3.7/site-packages/scanpy/neighbors/__init__.py in neighbors(adata, n_neighbors, n_pcs, use_rep, knn, random_state, method, metric, metric_kwds, copy)
    104     if adata.isview:  # we shouldn't need this here...
    105         adata._init_as_actual(adata.copy())
--> 106     neighbors = Neighbors(adata)
    107     neighbors.compute_neighbors(
    108         n_neighbors=n_neighbors, knn=knn, n_pcs=n_pcs, use_rep=use_rep,

/opt/conda/lib/python3.7/site-packages/scanpy/neighbors/__init__.py in __init__(self, adata, n_dcs)
    527                 self._number_connected_components = self._connected_components[0]
    528         if 'X_diffmap' in adata.obsm_keys():
--> 529             self._eigen_values = _backwards_compat_get_full_eval(adata)
    530             self._eigen_basis = _backwards_compat_get_full_X_diffmap(adata)
    531             if n_dcs is not None:

/opt/conda/lib/python3.7/site-packages/scanpy/neighbors/__init__.py in _backwards_compat_get_full_eval(adata)
    395         return np.r_[1, adata.uns['diffmap_evals']]
    396     else:
--> 397         return adata.uns['diffmap_evals']
    398 
    399 

KeyError: 'diffmap_evals'

Doesn’t it make more sense to make obsm concatenation False by default, by the way? Should concatenating obsm be the default behaviour?

Issue Analytics

  • State:open
  • Created 4 years ago
  • Comments:9 (6 by maintainers)

github_iconTop GitHub Comments

2reactions
gokceneraslancommented, Feb 5, 2020

I think concatenating obsm makes sense for default behavior.

I’m not entirely sure. Less experienced users might concatenate things and plot a UMAP without running sc.tl.umap on the new concatenated object and see some super weird things. We should never assume that ALL users know how exactly sc.tl.umap, adata.obsm and AnnData.concatenate work. The decisions about the defaults are always more than what we want to see in scanpy for our own convenience.

Would sc.pp.neighbors do anything different if diffmap had been run before? It doesn’t look to me like it would. If this is the case, the bug here is that neighbors is checking expectations unrelated to what it’s doing.

Concatenating obsm without touching uns puts the object in an unstable state somehow from diffmap point of view, since it has obsm X_diffmap but not uns diff_evals 😃 I don’t know why “neighbors” needs diffmap_evals…

0reactions
dangelescommented, Dec 7, 2020

Hi all! I’ve been using scanpy and ran into a similar problem. I was wondering if there’s an easy / appropriate work-around, other than simply deleting obsm[X_diffmap]?

Thank you all for developing scanpy, it’s a really wonderful piece of software.

Read more comments on GitHub >

github_iconTop Results From Across the Web

sc.pp.neighbors throws KeyError: diffmap_evals due to ...
There is an issue with the obsm concatenation. When we run sc.tl.diffmap with different anndata objects, concatenate them and run sc.pp.
Read more >
scanpy.pp.neighbors — Scanpy 1.9.1 documentation
scanpy.pp.neighbors ... Compute a neighborhood graph of observations [McInnes18]. The neighbor search efficiency of this heavily relies on UMAP [McInnes18], ...
Read more >
infercnvpy.pp.neighbors
Arguments passed to scanpy.pp.neighbors() . Returns. Depending on the value of inplace, updates anndata or returns the distance and connectivity matrices.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found