Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

optimizing and sorting dendrogram #59

Open
muzier9 opened this issue Dec 27, 2023 · 10 comments
Open

optimizing and sorting dendrogram #59

muzier9 opened this issue Dec 27, 2023 · 10 comments

Comments

@muzier9
Copy link

muzier9 commented Dec 27, 2023

In the complexheatmap of R, there is a parameter called cluster_columns or clusters_rows 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
Copy link
Owner

DingWB commented Jan 1, 2024

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
Copy link
Author

muzier9 commented Jan 30, 2024

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
Copy link
Owner

DingWB commented Jan 30, 2024

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
Copy link
Author

muzier9 commented Jan 30, 2024

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
Copy link
Owner

DingWB commented Jan 30, 2024

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

@muzier9
Copy link
Author

muzier9 commented Jan 31, 2024

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
Copy link
Owner

DingWB commented Jan 31, 2024

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
Copy link
Owner

DingWB commented Jan 31, 2024

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

@DingWB
Copy link
Owner

DingWB commented Feb 3, 2024

Hello, did it work for you?

@muzier9
Copy link
Author

muzier9 commented Feb 4, 2024

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants