DingWB / PyComplexHeatmap

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

Kmeans clustering when using ClusterMapPlotter function #24

Open Xinfeng-Yao opened 1 year ago

Xinfeng-Yao commented 1 year ago

Will the Pycomplexheatmap support Kmeans clustering when using ClusterMapPlotter function. I just mean that first use Kmeans to form different goups, then run hierarchical clustering within each group, finally hierarchically cluster different groups. The R package complexheatmap support the process. Thanks!

DingWB commented 1 year ago

This is a good suggestion. But unfortunately, it is not supported now. I will add it to PyComplexHeatmap soon. As for now, you can perform K-means clustering using sklearn and then reorder the rows and columns according to the clusterings from K-means. Finally, when you call ClusterMapPlotter, turn off the row_cluster and col_cluster and set parameters row_split and col_split (optional).

ftamiro commented 1 year ago

I am interested in this as well, in the R package I used cluster_columns= cluster_within_group(), it is great not only for grouping by kmeans or any other clustering annotation but also for clinical metadata such as maturation stage of the tumor, etc. Looking forward to seeing this implemented in PyComplexHeatmap.

DingWB commented 1 year ago

I am not quite sure what you mean, could you please make it more specific?

ftamiro commented 1 year ago

Sure, here is an image where I used R ComplexHeatmap as an example in RNA-seq plus clinical metadata from a cancer dataset.

image

Here I used inside the main Heatmap() function, the cluster_columns= cluster_within_group(mat, groups), see the last bloc of features. In this analysis, 'groups' are the molecular groups assigned to patients from the original study, not something I calculated. This option allows me to consider these blocks and cluster them with hierarchical clustering. In other instances, I can use precalculated kmeans or any other clustering or feature I want to obtain a similar result.

I am building a cancer explorer web app and this option is crucial for my visualization

DingWB commented 1 year ago

I see. I will work on it when I have time. For now, you can perform clustering yourself and pass the clustered order to PyComplexHeatmap as row_split_order or col_split_order.

DingWB commented 1 year ago

Would you like to contribute to this package by implementing this function? @ftamiro

ftamiro commented 1 year ago

I am already trying to replicate this function in Python. This could require more skills than what I have now, but if I manage to get something useful, I would like to contribute

DingWB commented 1 year ago

Please let me know if you have any questions during the development.

DingWB commented 1 year ago

Hello Francesco, I have already implemented the cluster_between_groups (https://dingwb.github.io/PyComplexHeatmap/build/html/notebooks/advanced_usage.html#Cluster-between-groups) and moved this discussion to https://github.com/DingWB/PyComplexHeatmap/discussions/53