saezlab / decoupler-py

Python package to perform enrichment analysis from omics data.
https://decoupler-py.readthedocs.io/
GNU General Public License v3.0
153 stars 23 forks source link

Marsilea error in dc.plot_associations() #144

Closed dnjst closed 1 month ago

dnjst commented 1 month ago

Describe the bug

Hi, I'm following the tutorial for my own data and I get an error at the dc.plot_associations() step:

TypeError: ColormapRegistry.get_cmap() missing 1 required positional argument: 'cmap'

Is there anything that might have changed in recent marsilea to cause this?


File /lib/python3.11/site-packages/decoupler/plotting.py:1633, in plot_associations(data, uns_key, associations, cols, obs_annotation_cols, obsm_key, use_X, layer, stat_col, titles, sign_thr, n_factors, cmap_stats, cmap_scores, cmap_cats, figsize, dpi, return_fig, save)
   1631 for cat_col in obs_annotation_cols:
   1632     cats = list(data.obs[cat_col].values)
-> 1633     cat_colors = mp.Colors(cats, cmap=cmap_cats, label=cat_col)
   1634     h2.add_right(cat_colors, pad=0.1, size=0.2)
   1636 h2.add_bottom(mp.Labels(acts.columns))

File /lib/python3.11/site-packages/marsilea/plotter/mesh.py:341, in Colors.__init__(self, data, palette, cmap, mask, linewidth, linecolor, label, label_loc, label_props, legend_kws, **kwargs)
    339 cats = np.unique(data)
    340 if cmap is not None:
--> 341     cmap = get_colormap(cmap)
    342     colors = cmap(np.linspace(0, 1, len(cats)))
    343 else:

File /lib/python3.11/site-packages/marsilea/utils.py:73, in get_colormap(cmap)
     71 def get_colormap(cmap):
     72     try:
---> 73         return mpl.cm.ColormapRegistry.get_cmap(cmap)
     74     except AttributeError:
     75         try:

TypeError: ColormapRegistry.get_cmap() missing 1 required positional argument: 'cmap'

To Reproduce

dc.plot_associations(
    pdata,
    uns_key='pca_anova',  # Summary statistics from the anova tests
    obsm_key='X_pca',  # where the PCs are stored
    stat_col='p_adj',  # Which summary statistic to plot
    obs_annotation_cols = ['Stage', 'CellType'], # which sample annotations to plot
    titles=['Principle component scores', 'Adjusted p-values from ANOVA'],
    figsize=(7, 5),
    n_factors=10,
)

System python 3.11 matplotlib 3.9.1 marsilea 0.4.2

PauBadiaM commented 1 month ago

Hi @dnjst,

This is caused due to the recent API changes of matplotlib and marsilea (see https://github.com/saezlab/decoupler-py/issues/127 , https://github.com/Marsilea-viz/marsilea/issues/35 and https://github.com/Marsilea-viz/marsilea/issues/36). Until they are stable, you can revert back to matplotlib < 3.8.4 and marsilea == 0.4.0, this should work.