scverse / scverse/scanpy

Ingest won't integrate datasets of different lengths

Open
#2,085 8 comments 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Python
Stars
2.6k
Forks
779
Avg merge
1d 4h
Merged PRs (30d)
27

Description

  • [x ] I have checked that this issue has not already been reported.
  • [ x] 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 trying to ingest a CITEseq dataset into another clustered dataset. These datasets have different numbers of cells but I ran neighbors(n_neighbors=30) for both prior to running umap. I have confirmed that both datasets have the same variable names and the same number of variable names (38). Both objects look identical when a call adata.var.

I receive the error: "all input arrays must have the same shape".

sc.pp.neighbors(CODEX_sub, n_neighbors=30) 
sc.tl.umap(CODEX_sub)
sc.pp.neighbors(adata_sub, n_neighbors = 30)
sc.tl.umap(adata_sub)
sc.tl.ingest(CODEX_sub, adata_sub, obs='leiden', embedding_method='umap')
ValueError                                Traceback (most recent call last)
<ipython-input-214-01a03312d3df> in <module>
----> 1 sc.tl.ingest(CODEX_sub, adata_sub, obs='leiden', embedding_method='umap')

~\anaconda3\envs\scenv\lib\site-packages\scanpy\tools\_ingest.py in ingest(adata, adata_ref, obs, embedding_method, labeling_method, neighbors_key, inplace, **kwargs)
    124         labeling_method = labeling_method * len(obs)
    125 
--> 126     ing = Ingest(adata_ref, neighbors_key)
    127     ing.fit(adata)
    128 

~\anaconda3\envs\scenv\lib\site-packages\scanpy\tools\_ingest.py in __init__(self, adata, neighbors_key)
    383 
    384         if neighbors_key in adata.uns:
--> 385             self._init_neighbors(adata, neighbors_key)
    386         else:
    387             raise ValueError(

~\anaconda3\envs\scenv\lib\site-packages\scanpy\tools\_ingest.py in _init_neighbors(self, adata, neighbors_key)
    349         else:
    350             self._neigh_random_state = neighbors['params'].get('random_state', 0)
--> 351             self._init_pynndescent(neighbors['distances'])
    352 
    353     def _init_pca(self, adata):

~\anaconda3\envs\scenv\lib\site-packages\scanpy\tools\_ingest.py in _init_pynndescent(self, distances)
    284 
    285         first_col = np.arange(distances.shape[0])[:, None]
--> 286         init_indices = np.hstack((first_col, np.stack(distances.tolil().rows)))
    287 
    288         self._nnd_idx = NNDescent(

<__array_function__ internals> in stack(*args, **kwargs)

~\anaconda3\envs\scenv\lib\site-packages\numpy\core\shape_base.py in stack(arrays, axis, out)
    424     shapes = {arr.shape for arr in arrays}
    425     if len(shapes) != 1:
--> 426         raise ValueError('all input arrays must have the same shape')
    427 
    428     result_ndim = arrays[0].ndim + 1

ValueError: all input arrays must have the same shape

Versions

scanpy==1.7.0 anndata==0.7.6 umap==0.5.1 numpy==1.21.1 scipy==1.7.0 pandas==1.2.5 scikit-learn==0.24.2 statsmodels==0.12.2 python-igraph==0.9.8

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the failure with the shown sc.tl.ingest sequence, then inspect scanpy/tools/_ingest.py, especially Ingest._init_neighbors and _init_pynndescent where the traceback reaches NumPy stack. Compare the reference neighbor data for datasets with different cell counts and verify that the ingest call completes without the shape error.

Written by the indexing model from the issue text.

Assessment

Tech stack
numpy, python
Domain
data, machine-learning
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
38/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.