Mercurial > repos > chemteam > biomd_neqgamma
annotate rmsd_clustering.py @ 0:4f3222cb5cf6 draft
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
author | chemteam |
---|---|
date | Fri, 11 Sep 2020 21:54:45 +0000 |
parents | |
children | afcb925def69 |
rev | line source |
---|---|
0
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
1 import argparse |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
2 import json |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
3 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
4 import matplotlib.pyplot as plt |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
5 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
6 import numpy as np |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
7 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
8 from scipy.cluster.hierarchy import cophenet, dendrogram, linkage |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
9 from scipy.spatial.distance import pdist |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
10 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
11 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
12 def json_to_np(fname, start=None, end=None): |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
13 """ |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
14 Load json file and convert to numpy array |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
15 """ |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
16 with open(fname) as f: |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
17 k = json.load(f) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
18 print(np.array(k)[:, :, start:end].shape) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
19 return np.array(k)[:, :, start:end] |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
20 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
21 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
22 def flatten_tensor(tensor, normalize=True): |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
23 """ |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
24 Flatten tensor to a 2D matrix along the time axis |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
25 """ |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
26 av = np.mean(tensor, axis=(0, 1)) if normalize else 1 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
27 return np.mean(tensor/av, axis=2) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
28 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
29 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
30 def get_cluster_linkage_array(mat, clustering_method='average'): |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
31 Z = linkage(mat, clustering_method) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
32 c, coph_dists = cophenet(Z, pdist(mat)) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
33 print('Cophenetic correlation coefficient: {}'.format(c)) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
34 return Z |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
35 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
36 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
37 def plot_dist_mat(mat, output, cmap='plasma'): |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
38 """ |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
39 Plot distance matrix as heatmap |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
40 """ |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
41 fig, ax = plt.subplots(1) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
42 p = ax.pcolormesh(mat, cmap=cmap) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
43 plt.xlabel('Trajectory number') |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
44 plt.ylabel('Trajectory number') |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
45 plt.colorbar(p) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
46 plt.draw() |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
47 plt.savefig(output, format='png') |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
48 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
49 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
50 def plot_dendrogram(Z, output): |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
51 plt.figure(figsize=(25, 10)) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
52 plt.title('Hierarchical Clustering Dendrogram') |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
53 plt.xlabel('Trajectory index') |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
54 plt.ylabel('distance') |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
55 dendrogram( |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
56 Z, |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
57 leaf_rotation=90., # rotates the x axis labels |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
58 leaf_font_size=8., # font size for the x axis labels |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
59 ) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
60 plt.savefig(output, format='png') |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
61 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
62 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
63 def main(): |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
64 parser = argparse.ArgumentParser() |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
65 parser.add_argument('--json', help='JSON input file (for 3D tensor).') |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
66 parser.add_argument('--mat', help='Input tabular file (for 2D matrix).') |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
67 parser.add_argument('--outp-mat', help='Tabular output file.') |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
68 parser.add_argument('--Z', required=True, |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
69 help='File for cluster linkage array.') |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
70 parser.add_argument('--dendrogram', |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
71 help="Path to the output dendrogram file") |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
72 parser.add_argument('--heatmap', |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
73 help="Path to the output distance matrix file") |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
74 parser.add_argument('--clustering-method', default='average', |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
75 choices=['single', 'complete', 'average', |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
76 'centroid', 'median', 'ward', 'weighted'], |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
77 help="Method to use for clustering.") |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
78 parser.add_argument('--cmap', type=str, default='plasma', |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
79 help="Matplotlib colormap to use" |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
80 "for plotting distance matrix.") |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
81 parser.add_argument('--start', type=int, |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
82 help="First trajectory frame to" |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
83 "calculate distance matrix") |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
84 parser.add_argument('--end', type=int, |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
85 help="Last trajectory frame to" |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
86 "calculate distance matrix") |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
87 parser.add_argument('--normalize', action="store_true", |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
88 help="Normalize the RMSD variation over" |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
89 "the trajectories before averaging.") |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
90 args = parser.parse_args() |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
91 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
92 print(args) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
93 if args.json: |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
94 tensor = json_to_np(args.json, args.start, args.end) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
95 mat = flatten_tensor(tensor, args.normalize) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
96 np.savetxt(args.outp_mat, mat) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
97 elif args.mat: |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
98 mat = np.loadtxt(args.mat) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
99 else: |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
100 print("Either --json or --mat must be specified.") |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
101 exit(1) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
102 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
103 Z = get_cluster_linkage_array(mat, args.clustering_method) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
104 np.savetxt(args.Z, Z) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
105 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
106 if args.heatmap: |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
107 plot_dist_mat(mat, args.heatmap, args.cmap) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
108 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
109 if args.dendrogram: |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
110 plot_dendrogram(Z, args.dendrogram) |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
111 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
112 |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
113 if __name__ == "__main__": |
4f3222cb5cf6
"planemo upload for repository https://github.com/galaxycomputationalchemistry/galaxy-tools-compchem/ commit 79589d149a8ff2791d4f71d28b155011672db827"
chemteam
parents:
diff
changeset
|
114 main() |