|
@@ -94,7 +94,8 @@ class Conformations:
|
94
|
94
|
This function returns a distance matrix from the dissimilarity matrix.
|
95
|
95
|
|
96
|
96
|
Arguments :
|
97
|
|
- - diss_matrix : ndarray obtained from Configurations.dissimilarity
|
|
97
|
+ - diss_matrix : ndarray
|
|
98
|
+ obtained from Configurations.dissimilarity
|
98
|
99
|
"""
|
99
|
100
|
diss_matrix = -diss_matrix
|
100
|
101
|
diss_matrix = (diss_matrix - np.min(diss_matrix))/np.ptp(diss_matrix)
|
|
@@ -109,7 +110,7 @@ class Conformations:
|
109
|
110
|
Returns clusters and medoids computed with kmedoids on a distance matrix
|
110
|
111
|
Arguments :
|
111
|
112
|
- matrix : str, ('identity' or 'dissimilarity')
|
112
|
|
- corresponding to the desired distance matrix to
|
|
113
|
+ corresponding to the desired distance matrix to be
|
113
|
114
|
computed
|
114
|
115
|
- ncluster number of clusters to be computed
|
115
|
116
|
"""
|
|
@@ -140,11 +141,69 @@ class Conformations:
|
140
|
141
|
|
141
|
142
|
return (clusters, medoids)
|
142
|
143
|
|
|
144
|
+ def visualise(clusters, output_name=None):
|
|
145
|
+ """
|
|
146
|
+ Generate an image to visualise clusters. Can currently display up to
|
|
147
|
+ seven different colors
|
|
148
|
+ Arguments :
|
|
149
|
+ - clusters : list of lists
|
|
150
|
+ output of the small_kmedoids method
|
|
151
|
+
|
|
152
|
+ - output_name : str
|
|
153
|
+ desired filename for the image output, if none don't save file
|
|
154
|
+ """
|
|
155
|
+ nb_confs = sum([len(x) for x in clusters])
|
|
156
|
+ x = np.arange(nb_confs)
|
|
157
|
+ y = np.zeros(nb_confs)
|
|
158
|
+
|
|
159
|
+ for i in range(len(clusters_diss)):
|
|
160
|
+ for j in clusters_diss[i]:
|
|
161
|
+ y[j] = i+1
|
|
162
|
+
|
|
163
|
+ color = []
|
|
164
|
+ for i in y:
|
|
165
|
+ if i == 1:
|
|
166
|
+ color.append('b')
|
|
167
|
+ if i == 2:
|
|
168
|
+ color.append('c')
|
|
169
|
+ if i == 3:
|
|
170
|
+ color.append('g')
|
|
171
|
+ if i == 4:
|
|
172
|
+ color.append('y')
|
|
173
|
+ if i == 5:
|
|
174
|
+ color.append('r')
|
|
175
|
+ if i == 6:
|
|
176
|
+ color.append('m')
|
|
177
|
+ else:
|
|
178
|
+ color.append('k')
|
|
179
|
+
|
|
180
|
+ plt.bar(x, y, width=1.0, color=color)
|
|
181
|
+
|
|
182
|
+ if output_name != None:
|
|
183
|
+ plt.savefig(output_name)
|
|
184
|
+
|
143
|
185
|
if __name__ == "__main__":
|
144
|
186
|
if len(sys.argv) < 2:
|
145
|
|
- sys.exit("Error : usage '$ python3 projet8 md.pdb'")
|
|
187
|
+ sys.exit("Error : usage '$ python3 projet8 md.pdb ncluster(int)'")
|
146
|
188
|
|
|
189
|
+ # Initialization of the class, meaning loading the pdb and writing pd.df
|
147
|
190
|
confs = Conformations(sys.argv[1])
|
|
191
|
+ nclusters = int(sys.argv[2])
|
|
192
|
+
|
|
193
|
+ # Computation of the distance matrixes
|
|
194
|
+ confs.identity()
|
|
195
|
+ confs.dissimilarity()
|
|
196
|
+
|
|
197
|
+ # Running the kmedoids algorithm on the identity distance matrix
|
|
198
|
+ clusters_idt = confs.small_kmedoids('identity', nclusters)
|
|
199
|
+ medoids_idt = clusters_idt[1]
|
|
200
|
+ clusters_idt = clusters_idt[0]
|
|
201
|
+
|
|
202
|
+ # Running the kmedoids algorithm on the dissimilarity distance matrix
|
|
203
|
+ clusters_diss = confs.small_kmedoids('dissimilarity', nclusters)
|
|
204
|
+ medoids_diss = clusters_diss[1]
|
|
205
|
+ clusters_diss = clusters_diss[0]
|
|
206
|
+
|
148
|
207
|
|
149
|
208
|
|
150
|
209
|
print(confs.df)
|