1
0
Fork 0

added Conformations.small_kmedoids method to compute kmedoids

master
nicolas-zimmermann 2019-09-18 17:09:32 +02:00
parent dfe4789af2
commit 1f2f9fcfef
1 changed files with 37 additions and 5 deletions

View File

@ -36,8 +36,8 @@ class Conformations:
"""
self.df = pd.DataFrame()
self.filename = filename
self.identity_dist = None
self.dissimilarity_dist = None
self.identity_dist = np.array(None)
self.dissimilarity_dist = np.array(None)
for chain_name, chain in pbx.chains_from_files([filename]):
dihedrals = chain.get_phi_psi_angles()
pb_seq = pbx.assign(dihedrals)
@ -104,9 +104,41 @@ class Conformations:
return dist
#def small_kmedoid(self, ncluster):
# pass
def small_kmedoids(self, matrix, ncluster):
"""
Returns clusters and medoids computed with kmedoids on a distance matrix
Arguments :
- matrix : str, ('identity' or 'dissimilarity')
corresponding to the desired distance matrix to
computed
- ncluster number of clusters to be computed
"""
if matrix == 'identity':
matrix = self.identity_dist
if matrix.all() == None:
print("Error : distance matrix from identity hasn't been " \
"computed yet")
return
elif matrix == 'dissimilarity':
matrix = self.dissimilarity_dist
if matrix.all() == None:
print("Error : distance matrix from dissimilarity hasn't " \
"been computed yet")
return
if ncluster > matrix.shape[0]:
print("Error : number of desired clusters > number of objects")
return
initial_medoids = np.random.randint(matrix.shape[0], size=ncluster)
kmed1 = kmedoids(matrix, initial_medoids, data_type='distance_matrix')
kmed1.process()
clusters = kmed1.get_clusters()
medoids = kmed1.get_medoids()
return (clusters, medoids)
if __name__ == "__main__":
if len(sys.argv) < 2: