|
1
|
|
|
#!/usr/bin/env python |
|
2
|
|
|
# -*- coding: utf-8 -*- |
|
3
|
|
|
""" |
|
4
|
|
|
|
|
5
|
|
|
""" |
|
6
|
|
|
from __future__ import print_function |
|
7
|
|
|
|
|
8
|
|
|
import argparse |
|
9
|
|
|
import matplotlib.pyplot as plt # to start |
|
10
|
|
|
import matplotlib |
|
11
|
|
|
|
|
12
|
|
|
import pandas as pd |
|
13
|
|
|
import matplotlib.pyplot as plt |
|
14
|
|
|
import seaborn as sns |
|
15
|
|
|
from scipy.cluster import hierarchy |
|
16
|
|
|
import numpy as np |
|
17
|
|
|
|
|
18
|
|
|
|
|
19
|
|
|
def get_parser(): |
|
20
|
|
|
parser = argparse.ArgumentParser( |
|
21
|
|
|
description=__doc__, formatter_class=argparse.RawDescriptionHelpFormatter) |
|
22
|
|
|
|
|
23
|
|
|
parser.add_argument('--font-scale', help="default=0.6", default=0.6) |
|
24
|
|
|
parser.add_argument('--sep', help="sep for input file, default=' '", default=",") |
|
25
|
|
|
parser.add_argument('--annot', help="annotate squares, default=False", |
|
26
|
|
|
action="store_true", default=False) |
|
27
|
|
|
parser.add_argument('--plot', help="output plot, default=_plot_.png", default="_plot_.png") |
|
28
|
|
|
parser.add_argument("-v", "--verbose", |
|
29
|
|
|
action="store_true", help="be verbose") |
|
30
|
|
|
parser.add_argument("file", help="", default="") # nargs='+') |
|
31
|
|
|
|
|
32
|
|
|
return parser |
|
33
|
|
|
|
|
34
|
|
|
|
|
35
|
|
|
if __name__ == '__main__': |
|
36
|
|
|
parser = get_parser() |
|
37
|
|
|
args = parser.parse_args() |
|
38
|
|
|
|
|
39
|
|
|
df = pd.read_csv(args.file, |
|
40
|
|
|
sep=args.sep, index_col=False)#, index=False) |
|
41
|
|
|
print(df) |
|
42
|
|
|
mat = df.to_numpy() |
|
43
|
|
|
print(mat) |
|
44
|
|
|
# https://docs.scipy.org/doc/scipy/reference/generated/scipy.cluster.hierarchy.dendrogram.html |
|
45
|
|
|
Z = hierarchy.linkage(mat, 'single') |
|
46
|
|
|
matplotlib.rcParams['lines.linewidth'] = 2 |
|
47
|
|
|
plt.style.use('dark_background') |
|
48
|
|
|
dn = hierarchy.dendrogram(Z) |
|
49
|
|
|
#ax.set_linecolor('orange') |
|
50
|
|
|
print(dn) |
|
51
|
|
|
plt.savefig(args.plot, dpi=300, transparent=True) |
|
52
|
|
|
|