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

composite Clustermap enforces same dimensions for both clustermaps #41

Closed
demian1 opened this issue Jul 14, 2023 · 5 comments
Closed

composite Clustermap enforces same dimensions for both clustermaps #41

demian1 opened this issue Jul 14, 2023 · 5 comments

Comments

@demian1
Copy link
Contributor

demian1 commented Jul 14, 2023

When trying to plot two clustermaps that share one axis, PyComplexHeatmap.clustermap.composite() enforces both column and indexes to be the same as the main cluster map.

This is enforced in the following code:

for i, cm in enumerate(cmlist):
        if i == main:
            continue
        gs1 = gs[i, 0] if axis == 0 else gs[0, i]
        cm.plot(ax=axes[i], subplot_spec=gs1, row_order=cm_1.row_order, col_order=cm_1.col_order)
        for L in cm.legend_list:
            if L[1] not in legend_names:
                legend_names.append(L[1])
                legend_list.append(L)
        w = ax.figure.get_window_extent().width * cm.label_max_width / cm.ax.figure.get_window_extent().width
        if w > label_max_width:
            label_max_width = w

The parameters row_order and col_order in cm.plot should be given dynamically depending on whether axis = 0 or axis = 1

@DingWB
Copy link
Owner

DingWB commented Jul 14, 2023

Yeah, you are right. Sorry for the mistake. I have already fixed it in the latest GitHub push. Please install it using pip install git+https://github.com/DingWB/PyComplexHeatmap
Please kindly test it and give me feedback if there are any bugs.

@demian1
Copy link
Contributor Author

demian1 commented Jul 16, 2023

Thanks for the quick fix!

I would also recommend the option to pass height_ratios and width_ratios to the function. Something like:

if axis == 1:  # horizontally
        wspace = col_gap * mm2inch * ax.figure.dpi / (ax.get_window_extent().width / n)
        nrows = 1
        ncols = n
        width_ratios = [cm.data2d.shape[1] for cm in cmlist] if width_ratios is None else width_ratios
        height_ratios = None
else:  # vertically
        hspace = row_gap * mm2inch * ax.figure.dpi / (ax.get_window_extent().height / n)
        nrows = n
        ncols = 1
        width_ratios = None
        height_ratios = [cm.data2d.shape[0] for cm in cmlist] if height_ratios is None else height_ratios

@demian1
Copy link
Contributor Author

demian1 commented Jul 16, 2023

I've been playing around with the function on my own data, and it works great so far!

Of course the clustermaps do not align anymore if one provides different number of row or column annotations

@DingWB
Copy link
Owner

DingWB commented Jul 16, 2023

That's a good idea. Could you please make a pull request?

@demian1
Copy link
Contributor Author

demian1 commented Jul 19, 2023

Just did

@DingWB DingWB closed this as completed Jul 21, 2023
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