added Conformations.visualise method to visualise clusters, added lines to main
parent
cf44de69ed
commit
194bb3dcef
BIN
easter.mp3
BIN
easter.mp3
Binary file not shown.
|
|
@ -94,7 +94,8 @@ class Conformations:
|
||||||
This function returns a distance matrix from the dissimilarity matrix.
|
This function returns a distance matrix from the dissimilarity matrix.
|
||||||
|
|
||||||
Arguments :
|
Arguments :
|
||||||
- diss_matrix : ndarray obtained from Configurations.dissimilarity
|
- diss_matrix : ndarray
|
||||||
|
obtained from Configurations.dissimilarity
|
||||||
"""
|
"""
|
||||||
diss_matrix = -diss_matrix
|
diss_matrix = -diss_matrix
|
||||||
diss_matrix = (diss_matrix - np.min(diss_matrix))/np.ptp(diss_matrix)
|
diss_matrix = (diss_matrix - np.min(diss_matrix))/np.ptp(diss_matrix)
|
||||||
|
|
@ -109,7 +110,7 @@ class Conformations:
|
||||||
Returns clusters and medoids computed with kmedoids on a distance matrix
|
Returns clusters and medoids computed with kmedoids on a distance matrix
|
||||||
Arguments :
|
Arguments :
|
||||||
- matrix : str, ('identity' or 'dissimilarity')
|
- matrix : str, ('identity' or 'dissimilarity')
|
||||||
corresponding to the desired distance matrix to
|
corresponding to the desired distance matrix to be
|
||||||
computed
|
computed
|
||||||
- ncluster number of clusters to be computed
|
- ncluster number of clusters to be computed
|
||||||
"""
|
"""
|
||||||
|
|
@ -140,11 +141,69 @@ class Conformations:
|
||||||
|
|
||||||
return (clusters, medoids)
|
return (clusters, medoids)
|
||||||
|
|
||||||
|
def visualise(clusters, output_name=None):
|
||||||
|
"""
|
||||||
|
Generate an image to visualise clusters. Can currently display up to
|
||||||
|
seven different colors
|
||||||
|
Arguments :
|
||||||
|
- clusters : list of lists
|
||||||
|
output of the small_kmedoids method
|
||||||
|
|
||||||
|
- output_name : str
|
||||||
|
desired filename for the image output, if none don't save file
|
||||||
|
"""
|
||||||
|
nb_confs = sum([len(x) for x in clusters])
|
||||||
|
x = np.arange(nb_confs)
|
||||||
|
y = np.zeros(nb_confs)
|
||||||
|
|
||||||
|
for i in range(len(clusters_diss)):
|
||||||
|
for j in clusters_diss[i]:
|
||||||
|
y[j] = i+1
|
||||||
|
|
||||||
|
color = []
|
||||||
|
for i in y:
|
||||||
|
if i == 1:
|
||||||
|
color.append('b')
|
||||||
|
if i == 2:
|
||||||
|
color.append('c')
|
||||||
|
if i == 3:
|
||||||
|
color.append('g')
|
||||||
|
if i == 4:
|
||||||
|
color.append('y')
|
||||||
|
if i == 5:
|
||||||
|
color.append('r')
|
||||||
|
if i == 6:
|
||||||
|
color.append('m')
|
||||||
|
else:
|
||||||
|
color.append('k')
|
||||||
|
|
||||||
|
plt.bar(x, y, width=1.0, color=color)
|
||||||
|
|
||||||
|
if output_name != None:
|
||||||
|
plt.savefig(output_name)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
sys.exit("Error : usage '$ python3 projet8 md.pdb'")
|
sys.exit("Error : usage '$ python3 projet8 md.pdb ncluster(int)'")
|
||||||
|
|
||||||
|
# Initialization of the class, meaning loading the pdb and writing pd.df
|
||||||
confs = Conformations(sys.argv[1])
|
confs = Conformations(sys.argv[1])
|
||||||
|
nclusters = int(sys.argv[2])
|
||||||
|
|
||||||
|
# Computation of the distance matrixes
|
||||||
|
confs.identity()
|
||||||
|
confs.dissimilarity()
|
||||||
|
|
||||||
|
# Running the kmedoids algorithm on the identity distance matrix
|
||||||
|
clusters_idt = confs.small_kmedoids('identity', nclusters)
|
||||||
|
medoids_idt = clusters_idt[1]
|
||||||
|
clusters_idt = clusters_idt[0]
|
||||||
|
|
||||||
|
# Running the kmedoids algorithm on the dissimilarity distance matrix
|
||||||
|
clusters_diss = confs.small_kmedoids('dissimilarity', nclusters)
|
||||||
|
medoids_diss = clusters_diss[1]
|
||||||
|
clusters_diss = clusters_diss[0]
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
print(confs.df)
|
print(confs.df)
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue