DingWB / PyComplexHeatmap

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

optimizing and sorting dendrogram #59

Open muzier9 opened 6 months ago

muzier9 commented 6 months ago

In the complexheatmap of R, there is a parameter called cluster_columns or clustersrows allows for the transfer of reordered Dendrogram data (such as using Dendsort packedge in R), which changes the order of the dendrogram in the heatmap and allows it to be displayed. I think this is a very useful function. In pycomplexheatmap, it seems that the order of rows or columns can be passed in, but the dendrogram cannot be displayed anymore. I think it may be possible to add a parameter cluster columns or clusters_ rows to pycomplexheatmap as well, an optimized link matrix can be passed in, which can change the order and corresponding clustering tree in the heatmap.

DingWB commented 6 months ago

I didn't understand, what if the given order is not consistent with the calculated dendrogram order? Could you please make it more clear?

muzier9 commented 5 months ago

Happy New Year. Of course, what I mean is that by default, clustering analysis will be performed on rows and columns, and a dendrogram will be drawn. If a parameter (linkage matrix) is passed in to the column, the column will not be clustered, and the incoming linkage matrix will be used to draw the tree diagram and sort the heat map.

DingWB commented 5 months ago

Thank you for explaining that. I know what you mean now. I have such kind of API implemented in my code, but I have never tested it. Could you please help me test it? I just made an push, you can update this package by installing it from github: pip uninstall -y PyComplexHeatmap && pip install git+https://github.com/DingWB/PyComplexHeatmap, to add custom linkage, please add parameter row_dendrogram_kws=dict(linkage=your_linkage) or col_dendrogram_kws=dict(linkage=your_linkage) to ClusterMapPlotter.

Please let me know whether it works or not.

muzier9 commented 5 months ago

I just used it and found that the column works, but the row does not.Meanwhile, the column names of the heatmap cannot be displayed, while the row names are displayed normally.

DingWB commented 5 months ago

That is strange, could you please paste your code here?

muzier9 commented 5 months ago

I tried again and found that passing a linkage matrix to the row is also useful. But I used the following code separately: cm = ClusterMapPlotter(hclust_matrix_filter, show_colnames=True, show_rownames=True, row_dendrogram=True, col_dendrogram=True, row_cluster_method='complete', col_cluster_method='complete', col_dendrogram_kws=dict(linkage=opt_pattern_linkage2) )

cm = ClusterMapPlotter(hclust_matrix_filter.T, show_colnames=True, show_rownames=True, row_dendrogram=True, col_dendrogram=True, row_cluster_method='complete', col_cluster_method='complete', row_dendrogram_kws=dict(linkage=opt_pattern_linkage2) ) Discovered that it only displays row names and does not display column names.

DingWB commented 5 months ago

Hello @muzier9 , Thanks for reporting.

There might be something wrong with your code, if you can paste the completed code here, then I can help you with debugging. Because I tested it myself and everything is OK. Please see the following link on the documentation website: https://dingwb.github.io/PyComplexHeatmap/build/html/notebooks/advanced_usage.html#Custom-linkage

DingWB commented 5 months ago

Pay attention to the transposing (data.T) when you calculate the linkage for columns. @muzier9

DingWB commented 5 months ago

Hello, did it work for you?

muzier9 commented 5 months ago

I use other data and it works fine. There were some issues with the previous data, thank you for your package.