Closed Donovan-Correa closed 1 year ago
Hello - Can you please share the exact error you encountered with the start cell ?
KeyError Traceback (most recent call last) Cell In[7], line 2 1 start_cell = 'CCGACGAGATGGTGAAGC-0-2' ----> 2 pr_res = palantir.core.run_palantir(ms_data, start_cell, num_waypoints=500, terminal_states=None)
File ~\AppData\Local\anaconda3\lib\site-packages\palantir\core.py:69, in run_palantir(ms_data, early_cell, terminal_states, knn, num_waypoints, n_jobs, scale_components, use_early_cell_as_start, max_iterations) 65 # ################################################ 66 # Determine the boundary cell closest to user defined early cell 67 dm_boundaries = pd.Index(set(data.idxmax()).union(data.idxmin())) 68 dists = pairwise_distances( ---> 69 data.loc[dm_boundaries, :], data.loc[early_cell, :].values.reshape(1, -1) 70 ) 71 start_cell = pd.Series(np.ravel(dists), index=dm_boundaries).idxmin() 72 if use_early_cell_as_start:
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexing.py:1067, in _LocationIndexer.getitem(self, key) 1065 if self._is_scalar_access(key): 1066 return self.obj._get_value(*key, takeable=self._takeable) -> 1067 return self._getitem_tuple(key) 1068 else: 1069 # we by definition only have the 0th axis 1070 axis = self.axis or 0
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexing.py:1247, in _LocIndexer._getitem_tuple(self, tup) 1245 with suppress(IndexingError): 1246 tup = self._expand_ellipsis(tup) -> 1247 return self._getitem_lowerdim(tup) 1249 # no multi-index, so validate all of the indexers 1250 tup = self._validate_tuple_indexer(tup)
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexing.py:967, in _LocationIndexer._getitem_lowerdim(self, tup)
963 for i, key in enumerate(tup):
964 if is_label_like(key):
965 # We don't need to check for tuples here because those are
966 # caught by the _is_nested_tuple_indexer check above.
--> 967 section = self._getitem_axis(key, axis=i)
969 # We should never have a scalar section here, because
970 # _getitem_lowerdim is only called after a check for
971 # is_scalar_access, which that would be.
972 if section.ndim == self.ndim:
973 # we're in the middle of slicing through a MultiIndex
974 # revise the key wrt to section
by inserting an _NS
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexing.py:1312, in _LocIndexer._getitem_axis(self, key, axis) 1310 # fall thru to straight lookup 1311 self._validate_key(key, axis) -> 1312 return self._get_label(key, axis=axis)
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexing.py:1260, in _LocIndexer._get_label(self, label, axis) 1258 def _get_label(self, label, axis: int): 1259 # GH#5567 this will fail if the label is not present in the axis. -> 1260 return self.obj.xs(label, axis=axis)
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\generic.py:4056, in NDFrame.xs(self, key, axis, level, drop_level) 4054 new_index = index[loc] 4055 else: -> 4056 loc = index.getloc(key) 4058 if isinstance(loc, np.ndarray): 4059 if loc.dtype == np.bool:
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexes\range.py:395, in RangeIndex.get_loc(self, key, method, tolerance) 393 raise KeyError(key) from err 394 self._check_indexing_error(key) --> 395 raise KeyError(key) 396 return super().get_loc(key, method=method, tolerance=tolerance)
KeyError: 'CCGACGAGATGGTGAAGC-0-2'
Does ms_data
have the observation names set properly? You need to make sure the cell names are passed when computing diffusion maps using run_diffusion_maps
Hi Manu,
that solved it, thanks! But still I got the problem of plotting anything due to the findfont issue. I used the
warnings.filterwarnings(action="ignore", module="matplotlib", message="findfont")
bit but it didn't help. I still get the same error below. Any suggestion?
KeyError Traceback (most recent call last) Cell In[15], line 1 ----> 1 palantir.plot.plot_diffusion_components(umap, dm_res)
File ~\AppData\Local\anaconda3\lib\site-packages\palantir\plot.py:317, in plot_diffusion_components(tsne, dm_res) 313 fig = FigureGrid(dm_res["EigenVectors"].shape[1], 5) 315 for i, ax in enumerate(fig): 316 ax.scatter( --> 317 tsne["x"], 318 tsne["y"], 319 c=dm_res["EigenVectors"].loc[tsne.index, i], 320 cmap=matplotlib.cm.Spectral_r, 321 edgecolors="none", 322 s=3, 323 ) 324 ax.xaxis.set_major_locator(plt.NullLocator()) 325 ax.yaxis.set_major_locator(plt.NullLocator())
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\frame.py:3807, in DataFrame.getitem(self, key) 3805 if self.columns.nlevels > 1: 3806 return self._getitem_multilevel(key) -> 3807 indexer = self.columns.get_loc(key) 3808 if is_integer(indexer): 3809 indexer = [indexer]
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexes\range.py:395, in RangeIndex.get_loc(self, key, method, tolerance) 393 raise KeyError(key) from err 394 self._check_indexing_error(key) --> 395 raise KeyError(key) 396 return super().get_loc(key, method=method, tolerance=tolerance)
KeyError: 'x' findfont: Font family 'Bitstream Vera Sans' not found. findfont: Font family 'Bitstream Vera Sans' not found. findfont: Font family 'Bitstream Vera Sans' not found. findfont: Font family 'Bitstream Vera Sans' not found. findfont: Font family 'Bitstream Vera Sans' not found. findfont: Font family 'Bitstream Vera Sans' not found. findfont: Font family 'Bitstream Vera Sans' not found. findfont: Font family 'Bitstream Vera Sans' not found. findfont: Font family 'Bitstream Vera Sans' not found. findfont: Font family 'Bitstream Vera Sans' not found.
Hi again,
I'm getting now new errors after plotting anything unrelated using
sc.pl.umap()
after that and trying
palantir.plot.plot_diffusion_components(umap, dm_res)
I get the following error:
KeyError Traceback (most recent call last) Cell In[20], line 1 ----> 1 palantir.plot.plot_diffusion_components(umap, dm_res)
File ~\AppData\Local\anaconda3\lib\site-packages\palantir\plot.py:317, in plot_diffusion_components(tsne, dm_res) 313 fig = FigureGrid(dm_res["EigenVectors"].shape[1], 5) 315 for i, ax in enumerate(fig): 316 ax.scatter( --> 317 tsne["x"], 318 tsne["y"], 319 c=dm_res["EigenVectors"].loc[tsne.index, i], 320 cmap=matplotlib.cm.Spectral_r, 321 edgecolors="none", 322 s=3, 323 ) 324 ax.xaxis.set_major_locator(plt.NullLocator()) 325 ax.yaxis.set_major_locator(plt.NullLocator())
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\frame.py:3807, in DataFrame.getitem(self, key) 3805 if self.columns.nlevels > 1: 3806 return self._getitem_multilevel(key) -> 3807 indexer = self.columns.get_loc(key) 3808 if is_integer(indexer): 3809 indexer = [indexer]
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexes\range.py:395, in RangeIndex.get_loc(self, key, method, tolerance) 393 raise KeyError(key) from err 394 self._check_indexing_error(key) --> 395 raise KeyError(key) 396 return super().get_loc(key, method=method, tolerance=tolerance)
KeyError: 'x'
And for
palantir.plot.plot_palantir_results(pr_res, umap)
I get the error:
KeyError Traceback (most recent call last) Cell In[19], line 1 ----> 1 palantir.plot.plot_palantir_results(pr_res, umap)
File ~\AppData\Local\anaconda3\lib\site-packages\palantir\plot.py:347, in plot_palantir_results(pr_res, tsne) 345 ax = plt.subplot(gs[0:2, 1:3]) 346 c = prres.pseudotime[tsne.index] --> 347 ax.scatter(tsne.loc[:, "x"], tsne.loc[:, "y"], s=3, cmap=matplotlib.cm.plasma, c=c) 348 normalize = matplotlib.colors.Normalize(vmin=np.min(c), vmax=np.max(c)) 349 cax, = matplotlib.colorbar.make_axes(ax)
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexing.py:1067, in _LocationIndexer.getitem(self, key) 1065 if self._is_scalar_access(key): 1066 return self.obj._get_value(*key, takeable=self._takeable) -> 1067 return self._getitem_tuple(key) 1068 else: 1069 # we by definition only have the 0th axis 1070 axis = self.axis or 0
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexing.py:1247, in _LocIndexer._getitem_tuple(self, tup) 1245 with suppress(IndexingError): 1246 tup = self._expand_ellipsis(tup) -> 1247 return self._getitem_lowerdim(tup) 1249 # no multi-index, so validate all of the indexers 1250 tup = self._validate_tuple_indexer(tup)
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexing.py:967, in _LocationIndexer._getitem_lowerdim(self, tup)
963 for i, key in enumerate(tup):
964 if is_label_like(key):
965 # We don't need to check for tuples here because those are
966 # caught by the _is_nested_tuple_indexer check above.
--> 967 section = self._getitem_axis(key, axis=i)
969 # We should never have a scalar section here, because
970 # _getitem_lowerdim is only called after a check for
971 # is_scalar_access, which that would be.
972 if section.ndim == self.ndim:
973 # we're in the middle of slicing through a MultiIndex
974 # revise the key wrt to section
by inserting an _NS
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexing.py:1312, in _LocIndexer._getitem_axis(self, key, axis) 1310 # fall thru to straight lookup 1311 self._validate_key(key, axis) -> 1312 return self._get_label(key, axis=axis)
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexing.py:1260, in _LocIndexer._get_label(self, label, axis) 1258 def _get_label(self, label, axis: int): 1259 # GH#5567 this will fail if the label is not present in the axis. -> 1260 return self.obj.xs(label, axis=axis)
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\generic.py:4041, in NDFrame.xs(self, key, axis, level, drop_level) 4039 if axis == 1: 4040 if drop_level: -> 4041 return self[key] 4042 index = self.columns 4043 else:
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\frame.py:3807, in DataFrame.getitem(self, key) 3805 if self.columns.nlevels > 1: 3806 return self._getitem_multilevel(key) -> 3807 indexer = self.columns.get_loc(key) 3808 if is_integer(indexer): 3809 indexer = [indexer]
File ~\AppData\Local\anaconda3\lib\site-packages\pandas\core\indexes\range.py:395, in RangeIndex.get_loc(self, key, method, tolerance) 393 raise KeyError(key) from err 394 self._check_indexing_error(key) --> 395 raise KeyError(key) 396 return super().get_loc(key, method=method, tolerance=tolerance)
KeyError: 'x'
Does it has anything to do that both functions refer to tSNE instead of UMAP in the code?
Hi once more,
I found that in other closed issue it was solved by adding
umap.rename(columns={0:"x",1:"y"},inplace=True)
and it worked. Thanks for the support Manu!
Great - plotting issues are also fixed in d61eff7f2e70d570650fd41bee6c7b426595e581
Hi Manu. I'm having trouble when running
start_cell = 'CCGACGAGATGGTGAAGC-0-2' pr_res = palantir.core.run_palantir(ms_data, start_cell, num_waypoints=500, terminal_states=None)
as it appears as it cannot find the cell ID in adata.obs_names even though it is indeed there:
LIST=adata.obs_names.tolist()
if 'CCGACGAGATGGTGAAGC-0-2' in LIST:
print("Element is in the list")
else:
print("Element is not in the list")
Any idea how to sourt this out?
Also, I'm getting the findfont error which prevents from further plotting after importing palantir
I have tried with both V 1.2 and 1.0.1 but is the same
print (palantir.__version__) 1.0.1