theislab / scgen

Single cell perturbation prediction
https://scgen.readthedocs.io
GNU General Public License v3.0
260 stars 52 forks source link

Error in "pred, delta" part. KeyError: 'condition' #34

Closed levinhein closed 3 years ago

levinhein commented 3 years ago

Hello. I encountered an error as shown below. May I ask if this error mean that I cannot run an h5ad data if the condition in my actual data is not categorized as "condition"? My experiment condition label on data is "response", and not "condition". Or this error means different?

SCRIPT:

pred, delta = scg.predict(adata=train_new, adata_to_predict=NR_CD4T,
                          conditions={"ctrl": "NR", "stim": "R"}, cell_type_key="celltype", condition_key="response")

ERROR:

---------------------------------------------------------------------------
KeyError                                  Traceback (most recent call last)
~/anaconda3/envs/scgen_test/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2890             try:
-> 2891                 return self._engine.get_loc(casted_key)
   2892             except KeyError as err:

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/index.pyx in pandas._libs.index.IndexEngine.get_loc()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

pandas/_libs/hashtable_class_helper.pxi in pandas._libs.hashtable.PyObjectHashTable.get_item()

KeyError: 'condition'

The above exception was the direct cause of the following exception:

KeyError                                  Traceback (most recent call last)
<ipython-input-12-f1fd2259e7a8> in <module>
      1 pred, delta = scg.predict(adata=train_new, adata_to_predict=NR_CD4T,
----> 2                           conditions={"ctrl": "NR", "stim": "R"}, cell_type_key="celltype", condition_key="response")

~/anaconda3/envs/scgen_test/lib/python3.7/site-packages/scgen/models/_vae_keras.py in predict(self, adata, conditions, cell_type_key, condition_key, adata_to_predict, celltype_to_predict, obs_key)
    320         """
    321         if obs_key == "all":
--> 322             ctrl_x = adata[adata.obs["condition"] == conditions["ctrl"], :]
    323             stim_x = adata[adata.obs["condition"] == conditions["stim"], :]
    324             ctrl_x = balancer(ctrl_x, cell_type_key=cell_type_key, condition_key=condition_key)

~/anaconda3/envs/scgen_test/lib/python3.7/site-packages/pandas/core/frame.py in __getitem__(self, key)
   2900             if self.columns.nlevels > 1:
   2901                 return self._getitem_multilevel(key)
-> 2902             indexer = self.columns.get_loc(key)
   2903             if is_integer(indexer):
   2904                 indexer = [indexer]

~/anaconda3/envs/scgen_test/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
   2891                 return self._engine.get_loc(casted_key)
   2892             except KeyError as err:
-> 2893                 raise KeyError(key) from err
   2894 
   2895         if tolerance is not None:

KeyError: 'condition'
levinhein commented 3 years ago

I don't know if this might help or if it affected this "pred, delta" part. But during the Prediction part, there was a FutureWarning prompt.

SCRIPT: NR_CD4T = train[((train.obs["celltype"] == "Exhausted CD4 T Cells") & (train.obs["response"] == "NR"))] PROMPT:

/home/levinbioinformatics/anaconda3/envs/scgen_test/lib/python3.7/site-packages/anndata/_core/anndata.py:1094: FutureWarning: is_categorical is deprecated and will be removed in a future version.  Use is_categorical_dtype instead
  if not is_categorical(df_full[k]):

SCREENSHOT: image

levinhein commented 3 years ago

Hello. May I ask if you have any idea about this? Thank you!

M0hammadL commented 3 years ago

Hi

We have released a new PyTorch version of the code. Please use this version.

Best Mo