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

Provide pre-calculated linkage for the split heatmap #17

Closed
wants to merge 2 commits into from
Closed

Provide pre-calculated linkage for the split heatmap #17

wants to merge 2 commits into from

Conversation

liuzj039
Copy link
Contributor

fix #16 .

Hi @Mr-Milk , I apologize for not being able to complete this task until the weekend. I could not locate a section in the current code to save the order, hence I noted them in the _split_{axis}_group_order attribute of the clusterboard and deform, respectively. I apologise if I have overlooked anything. I hope this code would be helpful.

@liuzj039
Copy link
Contributor Author

liuzj039 commented Dec 10, 2023

And the use case:

ar_data = np.array([[4.4879415 , 4.10098041, 3.51843572, 3.49319912, 3.70876169,
        3.53841469, 3.62779429, 3.53420859, 3.56575433, 3.51107504,
        3.5899394 , 3.49950827, 3.73610133, 3.62148514, 3.65513393,
        3.71927694, 3.67616442, 3.50792047],
       [3.88862879, 4.4879415 , 3.49756349, 3.49206521, 3.590347  ,
        3.55873188, 3.5298659 , 3.51612019, 3.50787277, 3.52093119,
        3.51337105, 3.49481435, 3.58759786, 3.58072501, 3.63776968,
        3.80615456, 3.55941916, 3.5016872 ],
       [3.73580475, 3.60759962, 4.4879415 , 3.67597569, 3.75289876,
        3.57341159, 3.69306971, 3.56486458, 3.62469364, 3.51358253,
        3.6845227 , 3.50503552, 3.77853979, 3.60759962, 3.65033466,
        3.5905056 , 3.72725774, 3.49648851],
       [3.61952045, 3.64583624, 4.06688887, 4.4879415 , 3.54057308,
        3.51425729, 3.56688887, 3.61952045, 3.51425729, 3.61952045,
        3.51425729, 3.4879415 , 3.59320466, 3.72478361, 3.64583624,
        3.56688887, 3.51425729, 3.59320466],
       [3.78371615, 3.69780065, 3.53160347, 3.4907584 , 4.4879415 ,
        3.60202601, 3.5851246 , 3.50484291, 3.62456122, 3.53442037,
        3.59780065, 3.4907584 , 3.85273023, 3.62456122, 3.60343446,
        3.5823077 , 3.81611051, 3.50484291],
       [3.73283946, 4.0134517 , 3.53896191, 3.49304354, 3.90120681,
        4.4879415 , 3.56447211, 3.59508436, 3.56957415, 3.63590068,
        3.54406395, 3.49304354, 3.79406395, 3.7379415 , 3.67671701,
        3.7634517 , 3.68181905, 3.54406395],
       [3.98982829, 3.71813018, 3.57850754, 3.49926225, 3.74831886,
        3.54454527, 4.4879415 , 3.66907358, 3.72945093, 3.5369981 ,
        3.80114905, 3.52567735, 3.7369981 , 3.64643207, 3.58228112,
        3.60492263, 3.85020565, 3.52945093],
       [3.71358253, 3.69819791, 3.53409535, 3.51358253, 3.54947996,
        3.59563381, 3.73409535, 4.4879415 , 3.52896714, 3.70332612,
        3.62640304, 3.58024919, 3.56486458, 3.73409535, 3.61101842,
        3.66742868, 3.66230047, 3.56486458],
       [3.72137999, 3.57942415, 3.53841469, 3.49109607, 3.79393519,
        3.53841469, 3.68983424, 3.51317809, 4.4879415 , 3.51633267,
        3.59835159, 3.49109607, 3.81601721, 3.5857333 , 3.59835159,
        3.53210554, 3.66144308, 3.51002352],
       [3.64287108, 3.82596967, 3.50906826, 3.52315277, 3.72033587,
        3.69216685, 3.5794908 , 3.78371615, 3.55132178, 4.4879415 ,
        3.53019502, 3.52315277, 3.58653305, 3.82596967, 3.63582882,
        3.63582882, 3.64287108, 3.60765981],
       [4.06877982, 3.70949839, 3.62566605, 3.49392952, 3.95500737,
        3.55380976, 3.98494749, 3.64961815, 3.69752234, 3.52386964,
        4.4879415 , 3.54782174, 4.04482773, 3.70949839, 3.69752234,
        3.70351036, 4.11069599, 3.54183372],
       [3.9279415 , 3.8879415 , 3.5679415 , 3.4879415 , 3.5679415 ,
        3.5279415 , 3.8879415 , 4.2079415 , 3.5279415 , 3.6879415 ,
        3.8879415 , 4.4879415 , 3.6879415 , 4.0079415 , 3.6079415 ,
        3.6079415 , 3.9679415 , 3.6879415 ],
       [3.76723144, 3.65953913, 3.52817819, 3.49267523, 3.79445038,
        3.55894742, 3.56604801, 3.50569298, 3.61101842, 3.50450955,
        3.59800067, 3.49385866, 4.4879415 , 3.70805984, 3.79800067,
        3.80155097, 3.71042671, 3.50805984],
       [3.76223956, 3.77951817, 3.51817908, 3.50737994, 3.69744474,
        3.59377303, 3.57865424, 3.59161321, 3.55489614, 3.59161321,
        3.56785511, 3.51601925, 3.88966936, 4.4879415 , 3.74280111,
        3.77519852, 3.61537131, 3.59161321],
       [3.57011204, 3.600603  , 3.49776062, 3.49104228, 3.53031876,
        3.50706295, 3.5008614 , 3.5003446 , 3.50602936, 3.49879421,
        3.50602936, 3.48949189, 3.62334202, 3.54892341, 4.4879415 ,
        4.17166243, 3.51946605, 3.4998278 ],
       [3.56307811, 3.64606992, 3.49203986, 3.48896609, 3.51082401,
        3.50638412, 3.49852893, 3.49989505, 3.49272292, 3.49511363,
        3.50023658, 3.48896609, 3.57844696, 3.533365  , 3.93978576,
        4.4879415 , 3.50809177, 3.49408904],
       [3.85250362, 3.69975413, 3.54496798, 3.48997816, 3.96248325,
        3.56533458, 3.68346085, 3.55718794, 3.59995779, 3.53274802,
        3.69975413, 3.51238142, 3.87083356, 3.60810443, 3.61217775,
        3.60810443, 4.4879415 , 3.538858  ],
       [3.71685716, 3.72890536, 3.49998969, 3.53613427, 3.63251981,
        3.62047162, 3.62047162, 3.66866439, 3.57227885, 3.69276078,
        3.59637523, 3.54818246, 3.69276078, 4.06625475, 3.76504993,
        3.70480897, 3.78914632, 4.4879415 ]])

h = ma.Heatmap(ar_data, cmap='Reds')
h.hsplit(labels = ['a', 'b'] * 9, order=['a', 'b'])
h.vsplit(labels = ['a', 'b'] * 9, order=['a', 'b'])
h.add_dendrogram('top')

h.render()
plt.close()

h.add_dendrogram('left', linkage=h.get_col_linkage())
h.render()

image

@Mr-Milk Mr-Milk self-requested a review December 10, 2023 07:22
@Mr-Milk
Copy link
Member

Mr-Milk commented Dec 10, 2023

Please don't feel pressured on this, there is no need to be hurry. The purpose of open-source is welcoming any communication and contributions then improve from that. I'll start reviewing soon. Thank you for your contributions! This is the first PR for Marsilea!

@Mr-Milk
Copy link
Member

Mr-Milk commented Dec 10, 2023

I don't know how to edit the pull request, I checkout to your branch but cannot commit to it. The git just created a new branch instead. So I just opened a new PR #18.

I made a few modifications, I placed get_linkage() method in Deformation, the ClusterBoard is for handling the rendering process. You are right about adding a split_order attribute, i merge it with the set_split_{axis} method to keep things simple. I added an extra key attribute for Dendrogram, so tracking of linkage is easier.

I will merge all the code for now. But I will have to close this and merge the #18. If you know how to edit PR directly instead of creating a new one, please let me know.

Thanks for your contributions again! Great job!

@Mr-Milk Mr-Milk closed this Dec 10, 2023
Mr-Milk added a commit that referenced this pull request Dec 10, 2023
* add `get_linkage`

* Enables the linkage of add_dendrogram to be set to dictionary

* Get linkage move to Deformation; Simplify setting order for split situation; The dendrogram now has a key attribute to track name.

---------

Co-authored-by: liuzj <[email protected]>
@liuzj039
Copy link
Contributor Author

Oh, I forgot to tick the box to allow maintainers to edit. If there's a next time, I'll be sure to tick it.

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

Successfully merging this pull request may close these issues.

Unable to provide pre-calculated linkage for the split heatmap.
2 participants