Hi,
I’m having error while running summarize_clonal_expansion function. It works with old metrics (e.g. days) but gets errors with new metrics that I concatenate (e.g. annotation_lvl2_marker_draining_days).
Thank you!
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
File /conda/envs/tcr/lib/python3.10/site-packages/pandas/core/indexes/base.py:3812, in Index.get_loc(self, key)
3811 try:
-> 3812 return self._engine.get_loc(casted_key)
3813 except KeyError as err:
File pandas/_libs/index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()
File pandas/_libs/index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()
File pandas/_libs/hashtable_class_helper.pxi:7088, in pandas._libs.hashtable.PyObjectHashTable.get_item()
File pandas/_libs/hashtable_class_helper.pxi:7096, in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'airr:annotation_lvl2_marker_draining_days'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
File /conda/envs/tcr/lib/python3.10/site-packages/scirpy/util/__init__.py:164, in DataHandler._get_obs_col(self, column)
163 try:
--> 164 return self.mdata.obs[column]
165 except (KeyError, AttributeError):
File /conda/envs/tcr/lib/python3.10/site-packages/pandas/core/frame.py:4107, in DataFrame.__getitem__(self, key)
4106 return self._getitem_multilevel(key)
-> 4107 indexer = self.columns.get_loc(key)
4108 if is_integer(indexer):
File /conda/envs/tcr/lib/python3.10/site-packages/pandas/core/indexes/base.py:3819, in Index.get_loc(self, key)
3818 raise InvalidIndexError(key)
-> 3819 raise KeyError(key) from err
3820 except TypeError:
3821 # If we have a listlike key, _check_indexing_error will raise
3822 # InvalidIndexError. Otherwise we fall through and re-raise
3823 # the TypeError.
KeyError: 'airr:annotation_lvl2_marker_draining_days'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
File /conda/envs/tcr/lib/python3.10/site-packages/pandas/core/indexes/base.py:3812, in Index.get_loc(self, key)
3811 try:
-> 3812 return self._engine.get_loc(casted_key)
3813 except KeyError as err:
File pandas/_libs/index.pyx:167, in pandas._libs.index.IndexEngine.get_loc()
File pandas/_libs/index.pyx:196, in pandas._libs.index.IndexEngine.get_loc()
File pandas/_libs/hashtable_class_helper.pxi:7088, in pandas._libs.hashtable.PyObjectHashTable.get_item()
File pandas/_libs/hashtable_class_helper.pxi:7096, in pandas._libs.hashtable.PyObjectHashTable.get_item()
KeyError: 'airr:annotation_lvl2_marker_draining_days'
The above exception was the direct cause of the following exception:
KeyError Traceback (most recent call last)
Cell In[38], line 1
----> 1 plot_df = ir.tl.summarize_clonal_expansion(
2 mdata_sub, target_col="airr:cc_aa_tcrdist_same_v", groupby="airr:annotation_lvl2_marker_draining_days", breakpoints=(1, 2, 5),
3 normalize=False)
File /conda/envs/tcr/lib/python3.10/site-packages/scirpy/tl/_clonal_expansion.py:169, in summarize_clonal_expansion(adata, groupby, target_col, summarize_by, normalize, airr_mod, **kwargs)
166 tmp_col = target_col + "_clipped_count"
167 tmp_col_weight = target_col + "_weight"
--> 169 obs = params.get_obs([groupby, target_col])
170 obs[tmp_col] = expansion
172 # filter NA values
File /conda/envs/tcr/lib/python3.10/site-packages/scirpy/util/__init__.py:155, in DataHandler.get_obs(self, columns)
153 else:
154 if len(columns):
--> 155 df = pd.concat({c: self._get_obs_col(c) for c in columns}, axis=1)
156 assert df.index.is_unique, "Index not unique"
157 return df.reindex(self.data.obs_names)
File /conda/envs/tcr/lib/python3.10/site-packages/scirpy/util/__init__.py:155, in <dictcomp>(.0)
153 else:
154 if len(columns):
--> 155 df = pd.concat({c: self._get_obs_col(c) for c in columns}, axis=1)
156 assert df.index.is_unique, "Index not unique"
157 return df.reindex(self.data.obs_names)
File /conda/envs/tcr/lib/python3.10/site-packages/scirpy/util/__init__.py:166, in DataHandler._get_obs_col(self, column)
164 return self.mdata.obs[column]
165 except (KeyError, AttributeError):
--> 166 return self.adata.obs[column]
File /conda/envs/tcr/lib/python3.10/site-packages/pandas/core/frame.py:4107, in DataFrame.__getitem__(self, key)
4105 if self.columns.nlevels > 1:
4106 return self._getitem_multilevel(key)
-> 4107 indexer = self.columns.get_loc(key)
4108 if is_integer(indexer):
4109 indexer = [indexer]
File /conda/envs/tcr/lib/python3.10/site-packages/pandas/core/indexes/base.py:3819, in Index.get_loc(self, key)
3814 if isinstance(casted_key, slice) or (
3815 isinstance(casted_key, abc.Iterable)
3816 and any(isinstance(x, slice) for x in casted_key)
3817 ):
3818 raise InvalidIndexError(key)
-> 3819 raise KeyError(key) from err
3820 except TypeError:
3821 # If we have a listlike key, _check_indexing_error will raise
3822 # InvalidIndexError. Otherwise we fall through and re-raise
3823 # the TypeError.
3824 self._check_indexing_error(key)
KeyError: 'airr:annotation_lvl2_marker_draining_days'