How to obtain clusters of hierarchical heatmap when using Python?

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)

• 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)?" – gringer Oct 10 '17 at 3:59
• @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)?" – tsttst Oct 10 '17 at 5:42

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.