morris-lab/CellOracle

Problem intiating CellOralce object due to colorbar

Opened this issue · 0 comments

Hello, thanks for sharing this package with us all. I am looking forward to applying it to my data.

I am having a problem initiating a CellOracle object using oracle.import_anndata_as_raw_count(). I have my adata containing raw counts for 2000 variable genes x 11254 cells. I have cell annotation in adata.obs as "celltype" and my embedding as "X_wnn.umap" imported from Seurat.

When running the following:

oracle.import_anndata_as_raw_count(adata=adata,
                                   cluster_column_name="celltype",
                                   embedding_name="X_wnn.umap")

I get an error I can't resolve:


TypeError Traceback (most recent call last)
Cell In[26], line 5
2 adata.X = adata.raw.X.copy()
4 # Instantiate Oracle object.
----> 5 oracle.import_anndata_as_raw_count(adata=adata,
6 cluster_column_name="celltype",
7 embedding_name="X_wnn.umap")

File ~/anaconda3/envs/celloracle_env/lib/python3.8/site-packages/celloracle/trajectory/oracle_core.py:392, in Oracle.import_anndata_as_raw_count(self, adata, cluster_column_name, embedding_name, transform)
389 self.adata.layers["normalized_count"] = self.adata.X.copy()
391 # update color information
--> 392 _check_color_information_and_create_if_not_found(adata=self.adata,
393 cluster_column_name=cluster_column_name,
394 embedding_name=embedding_name)
395 col_dict = _get_clustercolor_from_anndata(adata=self.adata,
396 cluster_name=self.cluster_column_name,
397 return_as="dict")
398 self.colorandum = np.array([col_dict[i] for i in self.adata.obs[self.cluster_column_name]])

File ~/anaconda3/envs/celloracle_env/lib/python3.8/site-packages/celloracle/trajectory/oracle_utility.py:29, in _check_color_information_and_create_if_not_found(adata, cluster_column_name, embedding_name)
27 message = f"Color information for the {cluster_column_name} is not found in the anndata. CellOracle is plotting the clustering data, {cluster_column_name}, to create color data."
28 warnings.warn(message, UserWarning)
---> 29 sc.pl.embedding(adata, basis=embedding_name, color=cluster_column_name)

File ~/anaconda3/envs/celloracle_env/lib/python3.8/site-packages/scanpy/plotting/_tools/scatterplots.py:452, in embedding(adata, basis, color, gene_symbols, use_raw, sort_order, edges, edges_width, edges_color, neighbors_key, arrows, arrows_kwds, groups, components, dimensions, layer, projection, scale_factor, color_map, cmap, palette, na_color, na_in_legend, size, frameon, legend_fontsize, legend_fontweight, legend_loc, legend_fontoutline, colorbar_loc, vmax, vmin, vcenter, norm, add_outline, outline_width, outline_color, ncols, hspace, wspace, title, show, save, ax, return_fig, **kwargs)
438 _add_categorical_legend(
439 ax,
440 color_source_vector,
(...)
449 multi_panel=bool(grid),
450 )
451 elif colorbar_loc is not None:
--> 452 pl.colorbar(
453 cax, ax=ax, pad=0.01, fraction=0.08, aspect=30, location=colorbar_loc
454 )
456 if return_fig is True:
457 return fig

File ~/anaconda3/envs/celloracle_env/lib/python3.8/site-packages/matplotlib/pyplot.py:2087, in colorbar(mappable, cax, ax, **kw)
2085 if ax is None:
2086 ax = gca()
-> 2087 ret = gcf().colorbar(mappable, cax=cax, ax=ax, **kw)
2088 return ret

File ~/anaconda3/envs/celloracle_env/lib/python3.8/site-packages/matplotlib/figure.py:2215, in Figure.colorbar(self, mappable, cax, ax, use_gridspec, **kw)
2212 NON_COLORBAR_KEYS = ['fraction', 'pad', 'shrink', 'aspect', 'anchor',
2213 'panchor']
2214 cb_kw = {k: v for k, v in kw.items() if k not in NON_COLORBAR_KEYS}
-> 2215 cb = cbar.colorbar_factory(cax, mappable, **cb_kw)
2217 self.sca(current_ax)
2218 self.stale = True

File ~/anaconda3/envs/celloracle_env/lib/python3.8/site-packages/matplotlib/colorbar.py:1640, in colorbar_factory(cax, mappable, **kwargs)
1638 cb = ColorbarPatch(cax, mappable, **kwargs)
1639 else:
-> 1640 cb = Colorbar(cax, mappable, **kwargs)
1642 cid = mappable.callbacksSM.connect('changed', cb.on_mappable_changed)
1643 mappable.colorbar = cb

File ~/anaconda3/envs/celloracle_env/lib/python3.8/site-packages/matplotlib/colorbar.py:1183, in Colorbar.init(self, ax, mappable, **kw)
1180 if isinstance(mappable, martist.Artist):
1181 kw['alpha'] = mappable.get_alpha()
-> 1183 ColorbarBase.init(self, ax, **kw)

TypeError: init() got an unexpected keyword argument 'location'

My understanding is it is throwing an error while trying to generate colour information by plotting my data. I found a similar issue with scanpy here: scverse/scanpy#2318

Some users suggest trying an earlier version of matplotlib which I tried (3.1.3) but didn't fix the issue. I have also run
c.pl.embedding(adata,basis="X_wnn.umap",color=["celltype"], colorbar_loc=None) to try and set the colour before running CellOracle but this also doesn't work.

Please does anyone have any suggestions as to how I might resolve this? Thank you.