SpatialDM icon indicating copy to clipboard operation
SpatialDM copied to clipboard

InvalidIndexError when running sdm.extract_lr(adata, 'human', min_cell=3)

Open Smilenone opened this issue 2 months ago • 0 comments

I encountered an error when running sdm.extract_lr(adata, 'human', min_cell=3), following is the detailed issue:

sdm.weight_matrix(adata, l=1.2, cutoff=0.2, single_cell=False) # weight_matrix by rbf kernel
----> 3 sdm.extract_lr(adata, 'human', min_cell=3)      # find overlapping LRs from CellChatDB
      5 sdm.spatialdm_global(adata, 1000, specified_ind=None, method='both', nproc=1)     # global Moran selection
      6 sdm.sig_pairs(adata, method='permutation', fdr=True, threshold=0.1)     # select significant pairs

File ~\AppData\Roaming\Python\Python39\site-packages\spatialdm\main.py:149, in extract_lr(adata, species, mean, min_cell, datahost)
    147     meanR = gmean(adata[:, receptor[i]].X, axis=1)
    148 else:
--> 149     meanL = adata[:, ligand[i]].X.mean(axis=1)
    150     meanR = adata[:, receptor[i]].X.mean(axis=1)
    151 if (sum(meanL > 0) >= min_cell) * \
    152         (sum(meanR > 0) >= min_cell):

File ~\AppData\Roaming\Python\Python39\site-packages\anndata\_core\anndata.py:1108, in AnnData.__getitem__(self, index)
   1106 def __getitem__(self, index: Index) -> "AnnData":
   1107     """Returns a sliced view of the object."""
-> 1108     oidx, vidx = self._normalize_indices(index)
   1109     return AnnData(self, oidx=oidx, vidx=vidx, asview=True)

File ~\AppData\Roaming\Python\Python39\site-packages\anndata\_core\anndata.py:1089, in AnnData._normalize_indices(self, index)
   1088 def _normalize_indices(self, index: Optional[Index]) -> Tuple[slice, slice]:
-> 1089     return _normalize_indices(index, self.obs_names, self.var_names)

File ~\AppData\Roaming\Python\Python39\site-packages\anndata\_core\index.py:33, in _normalize_indices(index, names0, names1)
     31 ax0, ax1 = unpack_index(index)
     32 ax0 = _normalize_index(ax0, names0)
---> 33 ax1 = _normalize_index(ax1, names1)
     34 return ax0, ax1

File ~\AppData\Roaming\Python\Python39\site-packages\anndata\_core\index.py:95, in _normalize_index(indexer, index)
     93     return positions  # np.ndarray[int]
     94 else:  # indexer should be string array
---> 95     positions = index.get_indexer(indexer)
     96     if np.any(positions < 0):
     97         not_found = indexer[positions < 0]

File ~\AppData\Roaming\Python\Python39\site-packages\pandas\core\indexes\base.py:3904, in Index.get_indexer(self, target, method, limit, tolerance)
   3901 self._check_indexing_method(method, limit, tolerance)
   3903 if not self._index_as_unique:
-> 3904     raise InvalidIndexError(self._requires_unique_msg)
   3906 if len(target) == 0:
   3907     return np.array([], dtype=np.intp)

InvalidIndexError: Reindexing only valid with uniquely valued Index objects

Can you help?

Smilenone avatar Apr 07 '24 19:04 Smilenone