Is there a good way of obtaining the labels (e.g. genes) within individual clusters that haven been clustered hierarchically in Python (preferentially, but not necessarily, by seaborn)?

I found these difficulties highlighted elsewhere (here, and here), and would hope for some simple option (e.g.: like in MATLAB where cutoff can be specified, and corresponding genes would be returned), without potential risk that the plotted hierarchical heatmap differed from the cluster assignment ( see here)

  • $\begingroup$ This question needs more information; it's not specific enough. Python is a programming language, not a toolkit. At the moment, it's similar to asking "Is there a good way to find the names of common taxi companies that are found in cities in Europe (preferentially, but not necessarily, French cities)?" $\endgroup$ – gringer Oct 10 '17 at 3:59
  • $\begingroup$ @gringer; either solution or library would be fine as long as it can be called from Python and does the above job and works well (which would exclude for me solutions that go through Python executing compiled local code through bash, or calling local instance of R or MATLAB); perhaps: "is there at least one country in Europe, where it is possible to order a taxi (preferentially, but not necessarily, by phoning the taxi company)?" $\endgroup$ – tsttst Oct 10 '17 at 5:42

Clustering like this is typically done with scipy. Here's the code we use in deepTools (original context here):

from scipy.cluster.hierarchy import fcluster, linkage
Z = linkage(some_matrix)  # You might want to set `method` and `metric`
groups = fcluster(Z, nGroups)  # You might want to set `criterion`

groups is then a vector containing the group assignment of the input matrix according to the clustering. As an aside, this is exactly the same as what's shown in the last link in your post, so I'm not sure how you didn't find it.

BTW, at least in python, hierarchical clustering is painfully slow with large datasets.

| improve this answer | |
  • $\begingroup$ thanks; I had indeed been wondering about Python's usual libraries for clustering, including scipy, being awfully slow for hierarchical clustering $\endgroup$ – tsttst Oct 10 '17 at 18:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.