jianhuupenn / TESLA

Deciphering tumor ecosystems at super-resolution from spatial transcriptomics with TESLA
MIT License
38 stars 10 forks source link

Error in tesla.tumor_edge_core_separation #5

Closed iS4i4S closed 1 year ago

iS4i4S commented 1 year ago

Hello,

Thanks for this great outil, I have a problem when running the function 'tesla.tumor_edge_core_separation'. All previous step were performed succesfully. The error is:

shrink_rate=0.8 res=10 binary_tumor, binary_core, core_edge_exp=tesla.tumor_edge_core_separation(img=img, binary=binary, resize_factor=resize_factor, pred_refined=pred_refined, target_clusters=target_clusters, sudo_adata=enhanced_exp_adata, res=res, shrink_rate=shrink_rate)

Running Connected Components ... Running Select biggest Tumor region ...

AssertionError Traceback (most recent call last) Cell In[179], line 3 1 shrink_rate=0.8 2 res=10 ----> 3 binary_tumor, binary_core, core_edge_exp=tesla.tumor_edge_core_separation(img=img, 4 binary=binary, 5 resize_factor=resize_factor, 6 pred_refined=pred_refined, 7 target_clusters=target_clusters, 8 sudo_adata=enhanced_exp_adata, 9 res=res, 10 shrink_rate=shrink_rate) 12 ret_img=tesla.plot_tumor_edge_core(img=img, 13 resize_factor=resize_factor, 14 binary=binary, (...) 17 color_edge=[66, 50, 225], 18 color_core=[62, 25, 53]) 20 cv2.imwrite('core_edge.jpg', ret_img)

File ~/.local/share/r-miniconda/envs/SCP_env/lib/python3.8/site-packages/TESLAforST-1.2.4-py3.8.egg/TESLA/tumor_edge_core.py:56, in tumor_edge_core_separation(img, binary, resize_factor, pred_refined, target_clusters, sudo_adata, res, shrink_rate) 54 print("Running Select biggest Tumor region ...") 55 #cc_info[0][0] contains the index of all superpiexls in the biggest tumor region ---> 56 sudo_tumor_sub=sudo_tumor[sudo_tumor.obs.index.isin(cc_info[0][0])] 57 adj_sub=adj.loc[cc_info[0][0], cc_info[0][0]] 58 adj_sub=adj_sub[np.sum(adj_sub, 1)>2]

File ~/.local/share/r-miniconda/envs/SCP_env/lib/python3.8/site-packages/anndata/_core/anndata.py:1113, in AnnData.getitem(self, index) 1111 def getitem(self, index: Index) -> "AnnData": 1112 """Returns a sliced view of the object.""" -> 1113 oidx, vidx = self._normalize_indices(index) 1114 return AnnData(self, oidx=oidx, vidx=vidx, asview=True)

File ~/.local/share/r-miniconda/envs/SCP_env/lib/python3.8/site-packages/anndata/_core/anndata.py:1094, in AnnData._normalize_indices(self, index) 1093 def _normalize_indices(self, index: Optional[Index]) -> Tuple[slice, slice]: -> 1094 return _normalize_indices(index, self.obs_names, self.var_names)

File ~/.local/share/r-miniconda/envs/SCP_env/lib/python3.8/site-packages/anndata/_core/index.py:35, in _normalize_indices(index, names0, names1) 33 index = index[0].values, index[1] 34 ax0, ax1 = unpack_index(index) ---> 35 ax0 = _normalize_index(ax0, names0) 36 ax1 = _normalize_index(ax1, names1) 37 return ax0, ax1

File ~/.local/share/r-miniconda/envs/SCP_env/lib/python3.8/site-packages/anndata/_core/index.py:53, in _normalize_index(indexer, index) 40 def _normalize_index( 41 indexer: Union[ 42 slice, (...) 50 index: pd.Index, 51 ) -> Union[slice, int, np.ndarray]: # ndarray of int 52 if not isinstance(index, pd.RangeIndex): ---> 53 assert ( 54 index.dtype != float and index.dtype != int 55 ), "Don’t call _normalize_index with non-categorical/string names" 57 # the following is insanely slow for sequences, 58 # we replaced it using pandas below 59 def name_idx(i):

AssertionError: Don’t call _normalize_index with non-categorical/string names

Thanks Best

jianhuupenn commented 1 year ago

Thank you for your interest in TESLA. Do you encounter the same error when running on the toy data I provided? You can try

enhanced_exp_adata.obs.index = enhanced_exp_adata.obs.index.astype(str)

before tesla.tumor_edge_core_separation()

iS4i4S commented 1 year ago

@jianhuupenn That did the trick, thanks a lot Best regards