DingWB / PyComplexHeatmap

PyComplexHeatmap: A Python package to plot complex heatmap (clustermap)
https://dingwb.github.io/PyComplexHeatmap/
MIT License
247 stars 28 forks source link

No attribute 'N' for get_colormap #79

Open Bo-UT opened 3 days ago

Bo-UT commented 3 days ago

Hi,

I upgraded pycomplexheatmap from 1.6.8 to 1.7.4. I got an error while running

col_ha = pch.HeatmapAnnotation(sample = pch.anno_simple(subset_adata.obs['sample'],legend=True, cmap='cmap50'),
                               dx = pch.anno_simple(subset_adata.obs['dx'],legend=True,colors={'yes':'black','no':'silver'}))
  File "/path/to/miniconda3/envs/single-cell/lib/python3.10/site-packages/PyComplexHeatmap/annotations.py", line 171, in _check_cmap
    get_colormap(self.cmap).N == 256
AttributeError: 'NoneType' object has no attribute 'N'

Thanks

Bo-UT commented 3 days ago

Hi,

I downgraded to 1.6.8, and it works, but I got another memory error:

File "/path/to/miniconda3/envs/single-cell/lib/python3.10/site-packages/scipy/spatial/distance.py", line 1687, in __call__
    dm = _prepare_out_argument(out, np.float64, (out_size,))
  File "/path/to/miniconda3/envs/single-cell/lib/python3.10/site-packages/scipy/spatial/distance.py", line 2668, in _prepare_out_argument
    return np.empty(expected_shape, dtype=dtype)
numpy.core._exceptions._ArrayMemoryError: Unable to allocate 1.43 TiB for an array with shape (195975874830,) and data type float64

I am trying to plot about 650k cells.

df = pd.DataFrame(adata.X.toarray(),index=adata.obs.index)
pch.ClusterMapPlotter(df, # columns are cells
                      top_annotation = col_ha,
                      cmap="bwr", vmax=2)

Thank you.

DingWB commented 3 days ago

What's the version of matpltolib? Can you run any example on the documentation website successfully? @Bo-UT

DingWB commented 3 days ago

Did you install all those dependencies? https://github.com/DingWB/PyComplexHeatmap/blob/c9e1b222e4d926132a621317e81d503c6326b91a/pyproject.toml#L12

Bo-UT commented 3 days ago

Hi,

Thanks for your prompt response. Yes, all dependencies have been installed. The matplotlib is 3.7.5. Pycomplexheatmap worked after I downgraded it to 1.6.8, but it seems not working for 1.7.4 (there is no N attribute found in dir(plt.colormaps.get('cmap50'))).

DingWB commented 3 days ago

I guess I know where the issue is. You mix the old version and the new version. Because I renamed cmap50 to random50 in the new version. Please uninstall and then install again:

pip uninstall -y PyComplexHeatmap
pip install git+https://github.com/DingWB/PyComplexHeatmap

Please let me know whether it works or not.

Bo-UT commented 3 days ago

yes, random50 works for pycomplexheatmap 1.7.4. Do you have an insight about the memory issue? There about 650k cells. numpy.core._exceptions._ArrayMemoryError: Unable to allocate 1.43 TiB for an array with shape (195975874830,) and data type float64 Thanks

DingWB commented 3 days ago

There is nothing I can do if you don't have enough memory on your computer. I suggest you randomly sample some rows or columns from this big matrix.

Bo-UT commented 2 days ago

Thank you. Worthing trying downsampling.