Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
1"""
2@file
3@brief dendogram, heatmap functionalities.
5It comes from `linkage.py <https://raw.githubusercontent.com/biokit/biokit/master/biokit/viz/linkage.py>`_
6which I copied here because the module does not properly work on Python 3 (import issues).
7See also `biokit license <https://github.com/biokit/biokit/blob/master/LICENSE>`_.
9:author: Thomas Cokelaer
11"""
14class Linkage:
15 """
16 Linkage used in other tools such as Heatmap,
17 the class requires `scipy <http://www.scipy.org/>`_.
18 """
20 def __init__(self):
21 """
22 unused
23 """
24 pass
26 def linkage(self, df, method, metric):
27 """
28 Mostly calls `linkage
29 <https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html>`_.
31 @param df dataframe
32 @param method see `linkage
33 <https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html>`_
34 @param metric see `linkage
35 <https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html>`_
36 @return output of `linkage
37 <https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.linkage.html>`_
38 """
39 from scipy.cluster.hierarchy import linkage
40 from scipy.spatial.distance import pdist, squareform
41 d = pdist(df)
42 D = squareform(d)
43 Y = linkage(D, method=method, metric=metric)
44 return Y