Coverage for src/pyensae/graphhelper/linkage.py: 100%

10 statements  

« prev     ^ index     » next       coverage.py v7.2.7, created at 2023-07-03 02:16 +0200

1""" 

2@file 

3@brief dendogram, heatmap functionalities. 

4 

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>`_. 

8 

9:author: Thomas Cokelaer 

10 

11""" 

12 

13 

14class Linkage: 

15 """ 

16 Linkage used in other tools such as Heatmap, 

17 the class requires `scipy <http://www.scipy.org/>`_. 

18 """ 

19 

20 def __init__(self): 

21 """ 

22 unused 

23 """ 

24 pass 

25 

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>`_. 

30 

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