Skip to content

KeyError: "Values ['HLA-DQB1'], from ['HLA-DQB1'], are not valid obs/ var names or indices." #39

@ChenPeizhan

Description

@ChenPeizhan

Dear developers,
Thank you so much for providing such useful method, I met an issue when I run the sdm.spatialdm_local(subset, n_perm=99, method='z-score', specified_ind=None, nproc=1) step:

sdm.spatialdm_local(subset, n_perm=99, method='z-score', specified_ind=None, nproc=1) # local spot selection


KeyError Traceback (most recent call last)
Cell In[167], line 1
----> 1 sdm.spatialdm_local(subset, n_perm=99, method='z-score', specified_ind=None, nproc=1) # local spot selection

File ~/miniconda3/envs/omicversev17/lib/python3.11/site-packages/spatialdm/main.py:237, in spatialdm_local(adata, n_perm, method, specified_ind, nproc, scale_X)
235 ## different approaches
236 with threadpool_limits(limits=nproc, user_api='blas'):
--> 237 spot_selection_matrix(adata, ligand, receptor, ind, n_perm, method, scale_X)

File ~/miniconda3/envs/omicversev17/lib/python3.11/site-packages/spatialdm/utils.py:190, in spot_selection_matrix(adata, ligand, receptor, ind, n_perm, method, scale_X)
188 from scipy.stats.mstats import gmean
189 L1 = [pd.Series(x[0]).dropna().values for x in ligand.values]
--> 190 L_mat0 = [raw_norm[:, L1[l]].X.toarray().astype(np.float64)[:, 0] for l in range(len(L1))]
191 for i, k in enumerate(ligand.index):
192 if len(ligand.loc[k].dropna()) > 1:

File ~/miniconda3/envs/omicversev17/lib/python3.11/site-packages/spatialdm/utils.py:190, in (.0)
188 from scipy.stats.mstats import gmean
189 L1 = [pd.Series(x[0]).dropna().values for x in ligand.values]
--> 190 L_mat0 = [raw_norm[:, L1[l]].X.toarray().astype(np.float64)[:, 0] for l in range(len(L1))]
191 for i, k in enumerate(ligand.index):
192 if len(ligand.loc[k].dropna()) > 1:

File ~/miniconda3/envs/omicversev17/lib/python3.11/site-packages/anndata/_core/anndata.py:1011, in AnnData.getitem(self, index)
1009 def getitem(self, index: Index) -> AnnData:
1010 """Returns a sliced view of the object."""
-> 1011 oidx, vidx = self._normalize_indices(index)
1012 return AnnData(self, oidx=oidx, vidx=vidx, asview=True)

File ~/miniconda3/envs/omicversev17/lib/python3.11/site-packages/anndata/_core/anndata.py:992, in AnnData._normalize_indices(self, index)
991 def _normalize_indices(self, index: Index | None) -> tuple[slice, slice]:
--> 992 return _normalize_indices(index, self.obs_names, self.var_names)

File ~/miniconda3/envs/omicversev17/lib/python3.11/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 ~/miniconda3/envs/omicversev17/lib/python3.11/site-packages/anndata/_core/index.py:111, in _normalize_index(indexer, index)
106 not_found = indexer[positions < 0]
107 msg = (
108 f"Values {list(not_found)}, from {list(indexer)}, "
109 "are not valid obs/ var names or indices."
110 )
--> 111 raise KeyError(msg)
112 return positions # np.ndarray[int]
113 msg = f"Unknown indexer {indexer!r} of type {type(indexer)}"

KeyError: "Values ['HLA-DQB1'], from ['HLA-DQB1'], are not valid obs/ var names or indices."

After I check the var.names in the AnnData, I could find the var_names in it. Can you help me to check this?

Thank you so much.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions