added Conformations.small_kmedoids method to compute kmedoids
parent
dfe4789af2
commit
1f2f9fcfef
|
|
@ -36,8 +36,8 @@ class Conformations:
|
||||||
"""
|
"""
|
||||||
self.df = pd.DataFrame()
|
self.df = pd.DataFrame()
|
||||||
self.filename = filename
|
self.filename = filename
|
||||||
self.identity_dist = None
|
self.identity_dist = np.array(None)
|
||||||
self.dissimilarity_dist = None
|
self.dissimilarity_dist = np.array(None)
|
||||||
for chain_name, chain in pbx.chains_from_files([filename]):
|
for chain_name, chain in pbx.chains_from_files([filename]):
|
||||||
dihedrals = chain.get_phi_psi_angles()
|
dihedrals = chain.get_phi_psi_angles()
|
||||||
pb_seq = pbx.assign(dihedrals)
|
pb_seq = pbx.assign(dihedrals)
|
||||||
|
|
@ -104,9 +104,41 @@ class Conformations:
|
||||||
|
|
||||||
return dist
|
return dist
|
||||||
|
|
||||||
#def small_kmedoid(self, ncluster):
|
def small_kmedoids(self, matrix, ncluster):
|
||||||
# pass
|
"""
|
||||||
|
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 __name__ == "__main__":
|
||||||
if len(sys.argv) < 2:
|
if len(sys.argv) < 2:
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue