Open
Description
I am getting an error with sc.pl.paga_path. It doesnt plot genes that my data has - i doubled checked my gene, it is in adata.var_names... if i use a gene that is not in adata.var_names, then it can plot... any idea about why the code is wrong?
_, axs = pl.subplots(ncols=3, figsize=(6, 2.5), gridspec_kw={'wspace': 0.05, 'left': 0.12})
pl.subplots_adjust(left=0.05, right=0.98, top=0.82, bottom=0.2)
for ipath, (descr, path) in enumerate(paths):
_, data = sc.pl.paga_path(
adata, path, gene_names,
show_node_names=False,
ax=axs[ipath],
ytick_fontsize=12,
left_margin=0.15,
n_avg=50,
annotations=['distance'],
show_yticks=True if ipath==0 else False,
show_colorbar=False,
color_map='Greys',
groups_key='clusters',
color_maps_annotations={'distance': 'viridis'},
title='{} path'.format(descr),
return_data=True,
show=False)
pl.savefig('./figures/paga_path_paul15.pdf')
pl.show()
Errors:
---------------------------------------------------------------------------
KeyError Traceback (most recent call last)
~/opt/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2645 try:
-> 2646 return self._engine.get_loc(key)
2647 except KeyError:
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: 'Ascl1'
During handling of the above exception, another exception occurred:
KeyError Traceback (most recent call last)
<ipython-input-522-a191d9b34213> in <module>
17 title='{} path'.format(descr),
18 return_data=True,
---> 19 show=False)
20 data.to_csv('./write/paga_path_{}.csv'.format(descr))
21 pl.savefig('./figures/paga_path_paul15.pdf')
~/opt/anaconda3/lib/python3.7/site-packages/scanpy/plotting/_tools/paga.py in paga_path(adata, nodes, keys, use_raw, annotations, color_map, color_maps_annotations, palette_groups, n_avg, groups_key, xlim, title, left_margin, ytick_fontsize, title_fontsize, show_node_names, show_yticks, show_colorbar, legend_fontsize, legend_fontweight, normalize_to_zero_one, as_heatmap, return_data, show, save, ax)
1090 x += list(adata.obs[key].values[idcs])
1091 else:
-> 1092 x += list(adata_X[:, key].X[idcs])
1093 if ikey == 0:
1094 groups += [group for i in range(len(idcs))]
~/opt/anaconda3/lib/python3.7/site-packages/anndata/_core/raw.py in __getitem__(self, index)
99
100 def __getitem__(self, index):
--> 101 oidx, vidx = self._normalize_indices(index)
102
103 # To preserve two dimensional shape
~/opt/anaconda3/lib/python3.7/site-packages/anndata/_core/raw.py in _normalize_indices(self, packed_index)
159 obs, var = unpack_index(packed_index)
160 obs = _normalize_index(obs, self._adata.obs_names)
--> 161 var = _normalize_index(var, self.var_names)
162 return obs, var
163
~/opt/anaconda3/lib/python3.7/site-packages/anndata/_core/index.py in _normalize_index(indexer, index)
72 return indexer
73 elif isinstance(indexer, str):
---> 74 return index.get_loc(indexer) # int
75 elif isinstance(indexer, (Sequence, np.ndarray, pd.Index, spmatrix, np.matrix)):
76 if hasattr(indexer, "shape") and (
~/opt/anaconda3/lib/python3.7/site-packages/pandas/core/indexes/base.py in get_loc(self, key, method, tolerance)
2646 return self._engine.get_loc(key)
2647 except KeyError:
-> 2648 return self._engine.get_loc(self._maybe_cast_indexer(key))
2649 indexer = self.get_indexer([key], method=method, tolerance=tolerance)
2650 if indexer.ndim > 1 or indexer.size > 1:
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: 'Ascl1'