dylkot / pyWNN

Weighted Nearest Neighbors Analysis implemented in Python (pyWNN)
MIT License
10 stars 2 forks source link

IndexError: question #1

Closed sjfleming closed 2 years ago

sjfleming commented 2 years ago

Hi @dylkot , thanks for making this repo, it's a great idea! And great for somebody like me who is trying to avoid R.

I am probably doing something that's user error, but I wanted to ask in case you know what I'm doing wrong.

I have an AnnData object that has two keys of interest in the obsm slot: 'L1000_pca' and 'CP_pca'. These are each 20-dimensional results of running PCA on two different data modalities.

When I try

from pyWNN import pyWNN

WNNobj = pyWNN(ad_merge_pca, reps=['L1000_pca', 'CP_pca'], 
               npcs=[9, 9], 
               n_neighbors=3, 
               seed=14,
               distances=None)
ad_merge_wnn = WNNobj.compute_wnn(ad_merge_pca)

I see the following error

---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
/tmp/ipykernel_115/1229758374.py in <module>
      3                n_neighbors=3,
      4                seed=14,
----> 5                distances=None)#['distances'])
      6 ad_merge_wnn = WNNobj.compute_wnn(ad_merge_pca)

~/pcl-af-v2f-L1000/edit/pyWNN.py in __init__(self, adata, reps, n_neighbors, npcs, seed, distances)
    164             nn_adj_wdiag = nn_adj.copy()
    165             nn_adj_wdiag.setdiag(1)
--> 166             bw = compute_bw(nn_adj_wdiag, self.adata.obsm[r], n_neighbors=self.n_neighbors)
    167             self.NNidx.append(nn)
    168             self.NNdist.append(dist_to_nn)

~/pcl-af-v2f-L1000/edit/pyWNN.py in compute_bw(knn_adj, embedding, n_neighbors)
     38             sys.exit('Fewer than 20 cells with Jacard sim > 0')
     39         else:
---> 40             curval = valssort[n_neighbors]
     41             for num in range(n_neighbors, numinset):
     42                 if valssort[num]!=curval:

IndexError: index 3 is out of bounds for axis 0 with size 3

Example is below:

image image

sjfleming commented 2 years ago

Checking out https://muon.readthedocs.io/en/latest/index.html at the suggestion of @dylkot