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

Issue with model.initialize_archetypes() #41

Open
iamsalil opened this issue May 18, 2023 · 4 comments
Open

Issue with model.initialize_archetypes() #41

iamsalil opened this issue May 18, 2023 · 4 comments

Comments

@iamsalil
Copy link

iamsalil commented May 18, 2023

I have an AnnData object (adata) from which I am trying to create a SEACells model. The AnnData object has 593 rows corresponding to 593 cells.
I'm running into an error at this line of code which I pulled from one of the tutorial notebooks:
`

    # SEACells parameter setup
    n_SEACells = 1 + int(len(adata)/75)
    build_kernel_on = "XPCA"
    n_waypoint_eigs = 10 # Number of eigenvalues to consider when initializing metacells
    
    # Build SEACells model
    model = SEACells.core.SEACells(adata,
              build_kernel_on=build_kernel_on,
              n_SEACells=n_SEACells,
              use_gpu=True,
              n_waypoint_eigs=n_waypoint_eigs,
              convergence_epsilon = 1e-5)
    model.construct_kernel_matrix()
    M = model.kernel_matrix

    # Initialize archetypes
    model.initialize_archetypes()`

The error I'm getting is an IndexError seemed to be caused by Palantir:

Traceback (most recent call last):
File "1_make_metacells.py", line 176, in main
model.initialize_archetypes()
File "/users/salil512/miniconda3/envs/seacells/lib/python3.8/site-packages/SEACells/gpu.py", line 162, in initialize_archetypes
waypoint_ix = self._get_waypoint_centers(k)
File "/users/salil512/miniconda3/envs/seacells/lib/python3.8/site-packages/SEACells/gpu.py", line 286, in _get_waypoint_centers
waypoint_init = palantir.core._max_min_sampling(data=dc_components, num_waypoints=k)
File "/users/salil512/miniconda3/envs/seacells/lib/python3.8/site-packages/palantir/core.py", line 145, in _max_min_sampling
dists[:, 0] = abs(vec - data[ind].values[iter_set])
IndexError: index 0 is out of bounds for axis 1 with size 0

I have the latest version of SEACells and my palantir version is 1.1

Some help debugging this would be appreciated. Thanks.

@iamsalil
Copy link
Author

I determined the cause of the issue. n_waypoint_eigs must be <= n_SEACells + 1. If this does not hold true, then at line 132 of palantir/core.py, no_iterations is set to 0 and the error is thrown (In that function, data.shape[1] = n_waypoint_eigs-1 and num_waypoints = n_SEACells).

In this case, I had 8 SEACells and had set n_waypoint_eigs to 10, following the default number in the example notebooks.

Could you please advise in general about how n_SEACells and n_waypoint_eigs should be set? In a tutorial notebook it says that it should be the number of cells / 75. However, I feel like I read somewhere else (I can't seem to find the source for where I read it) that the number of SEACells should be equal to the number of cells / 100. Also, I didn't really find any direction about best practices for how to set the value of n_waypoint_eigs. What's best practices for this? Does it scale on the size of the dataset?

@zqun1
Copy link

zqun1 commented Jan 27, 2024

I have the same problem when my n_SEACells is 7 (I do not have enough cells) while keeping n_waypoint_eigs=10. Any updates?

@OMIC-coding
Copy link


AttributeError Traceback (most recent call last)
Cell In[9], line 2
1 # Initialize archetypes---------------------------------------------------------------------------
AttributeError Traceback (most recent call last)
Cell In[9], line 2
1 # Initialize archetypes
----> 2 model.initialize_archetypes()

File ~/miniconda3/envs/seacells/lib/python3.8/site-packages/SEACells/core.py:129, in SEACells.initialize_archetypes(self)
126 else:
127 from_greedy = self.k
--> 129 greedy_ix = self._get_greedy_centers(n_mcs=from_greedy + 10)
130 if self.verbose:
131 print(f'Selecting {from_greedy} cells from greedy initialization.')

File ~/miniconda3/envs/seacells/lib/python3.8/site-packages/SEACells/core.py:245, in SEACells._get_greedy_centers(self, n_mcs)
236 """Initialize SEACells using fast greedy adaptive CSSP
237
238 From https://arxiv.org/pdf/1312.6838.pdf
(...)
241 :return: B - (array) n_datapoints x n_SEACells matrix with initial SEACell definitions
242 """
244 K = self.K
--> 245 n = K.shape[0]
247 if n_mcs is None:
248 k = self.k

AttributeError: 'NoneType' object has no attribute 'shape'
----> 2 model.initialize_archetypes()

File ~/miniconda3/envs/seacells/lib/python3.8/site-packages/SEACells/core.py:129, in SEACells.initialize_archetypes(self)
126 else:
127 from_greedy = self.k
--> 129 greedy_ix = self._get_greedy_centers(n_mcs=from_greedy + 10)
130 if self.verbose:
131 print(f'Selecting {from_greedy} cells from greedy initialization.')

File ~/miniconda3/envs/seacells/lib/python3.8/site-packages/SEACells/core.py:245, in SEACells._get_greedy_centers(self, n_mcs)
236 """Initialize SEACells using fast greedy adaptive CSSP
237
238 From https://arxiv.org/pdf/1312.6838.pdf
(...)
241 :return: B - (array) n_datapoints x n_SEACells matrix with initial SEACell definitions
242 """
244 K = self.K
--> 245 n = K.shape[0]
247 if n_mcs is None:
248 k = self.k

AttributeError: 'NoneType' object has no attribute 'shape'

@OMIC-coding
Copy link

Could you help me solve this bug? I am stuck in this step for a long time.

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

3 participants