qwerty239qwe / scTenifoldpy

A python package implements scTenifoldnet and scTenifoldknk
https://sctenifoldpy.readthedocs.io/en/latest/
MIT License
8 stars 3 forks source link

knk.build() #15

Open seekning opened 1 month ago

seekning commented 1 month ago

thank you so much for bringing this wonderful tool to us ,but i meet this problem when runing the code follow:

knk = st.scTenifoldKnk(data=df, ko_genes=["NG-17"], # the gene you wants to knock out qc_kws={"min_lib_size": 10}) knk.build()

Removed 0 cells with lib size < 10 Removed 0 outlier cells from original data Found mitochondrial genes: ['MT-1', 'MT-10', 'MT-2', 'MT-3', 'MT-4', 'MT-5', 'MT-6', 'MT-7', 'MT-8', 'MT-9'] Removed 53 samples from original data (mt genes ratio > 0.1) Removed 0 genes expressed in less than 0.05 of data Removed 89 genes with expression values: average < 0.05 or sum < 25 finish QC: WT process qc finished in 0.15192227065563202 secs. make_networks processing time: 17.005548248067498 process nc finished in 17.005826794542372 secs. Using tensorly (11, 11, 10) tensor_decomp processing time: 0.08996262773871422 process td finished in 0.09127406310290098 secs.


KeyError Traceback (most recent call last) Cell In[12], line 1 ----> 1 knk.build()

File ~/miniconda3/envs/scTenifoldKnk/lib/python3.9/site-packages/scTenifold/core/_base.py:500, in scTenifoldKnk.build(self) 498 self.run_step("nc") 499 self.run_step("td") --> 500 self.run_step("ko") 501 self.run_step("ma") 502 self.run_step("dr")

File ~/miniconda3/envs/scTenifoldKnk/lib/python3.9/site-packages/scTenifold/core/_base.py:475, in scTenifoldKnk.run_step(self, step_name, kwargs) 473 ko_genes = self.ko_genes 474 kwargs = (self.ko_kws if kwargs == {} else kwargs) --> 475 self._get_ko_tensor(ko_genes, kwargs) 476 elif step_name == "ma": 477 self.manifold = manifold_alignment(self.tensor_dict["WT"], 478 self.tensor_dict["KO"], 479 **(self.ma_kws if kwargs == {} else kwargs))

File ~/miniconda3/envs/scTenifoldKnk/lib/python3.9/site-packages/scTenifold/core/_base.py:414, in scTenifoldKnk._get_ko_tensor(self, ko_genes, **kwargs) 412 if self.ko_method == "default": 413 self.tensor_dict["KO"] = self.tensor_dict["WT"].copy() --> 414 self.tensor_dict["KO"].loc[ko_genes, :] = 0 415 elif self.ko_method == "propagation": 416 print(self.QC_dict["WT"].index)

File ~/miniconda3/envs/scTenifoldKnk/lib/python3.9/site-packages/pandas/core/indexing.py:688, in _LocationIndexer.setitem(self, key, value) 686 else: 687 key = com.apply_if_callable(key, self.obj) --> 688 indexer = self._get_setitem_indexer(key) 689 self._has_valid_setitem_indexer(key) 691 iloc = self if self.name == "iloc" else self.obj.iloc

File ~/miniconda3/envs/scTenifoldKnk/lib/python3.9/site-packages/pandas/core/indexing.py:630, in _LocationIndexer._get_setitem_indexer(self, key) 628 if isinstance(key, tuple): 629 with suppress(IndexingError): --> 630 return self._convert_tuple(key, is_setter=True) 632 if isinstance(key, range): 633 return list(key)

File ~/miniconda3/envs/scTenifoldKnk/lib/python3.9/site-packages/pandas/core/indexing.py:754, in _LocationIndexer._convert_tuple(self, key, is_setter) 752 self._validate_key_length(key) 753 for i, k in enumerate(key): --> 754 idx = self._convert_to_indexer(k, axis=i, is_setter=is_setter) 755 keyidx.append(idx) 757 return tuple(keyidx)

File ~/miniconda3/envs/scTenifoldKnk/lib/python3.9/site-packages/pandas/core/indexing.py:1212, in _LocIndexer._convert_to_indexer(self, key, axis, is_setter) 1209 return inds 1210 else: 1211 # When setting, missing keys are not allowed, even with .loc: -> 1212 return self._get_listlike_indexer(key, axis, raise_missing=True)[1] 1213 else: 1214 try:

File ~/miniconda3/envs/scTenifoldKnk/lib/python3.9/site-packages/pandas/core/indexing.py:1266, in _LocIndexer._get_listlike_indexer(self, key, axis, raise_missing) 1263 else: 1264 keyarr, indexer, new_indexer = ax._reindex_non_unique(keyarr) -> 1266 self._validate_read_indexer(keyarr, indexer, axis, raise_missing=raise_missing) 1267 return keyarr, indexer

File ~/miniconda3/envs/scTenifoldKnk/lib/python3.9/site-packages/pandas/core/indexing.py:1308, in _LocIndexer._validate_read_indexer(self, key, indexer, axis, raise_missing) 1306 if missing == len(indexer): 1307 axis_name = self.obj._get_axis_name(axis) -> 1308 raise KeyError(f"None of [{key}] are in the [{axis_name}]") 1310 ax = self.obj._get_axis(axis) 1312 # We (temporarily) allow for some missing keys with .loc, except in 1313 # some cases (e.g. setting) in which "raise_missing" will be False

KeyError: "None of [Index(['NG-17'], dtype='object')] are in the [index]" ![Uploading 屏幕截图 2024-09-27 113854.png…]()

i wil be grateful that you could help me point out where the error is ,hope for your reply

qwerty239qwe commented 1 month ago

Thanks so much for the kind words and for bringing this up!

The error is happening because the gene "NG-17" isn’t found in the gene index of your dataset. Can you double-check that the gene is actually in your data? You might also want to check how the genes are named in your dataset to make sure they match up.

If "NG-17" is definitely there and the issue keeps happening, feel free to share a small example, and I’ll help troubleshoot!

Sorry for the delayed response—if the issue is still around, I’ll take a closer look after this Thursday.

Best, Yu-Te

seekning commented 1 month ago

oh thank u,i hava slove that problem, i am a luck dog hahaha,and the question about that "qqplot" is also my question ,would you mind helping me sloving it? thank you so much for having this nice tool