88import numpy as np
99import scipy .cluster .hierarchy as hier
1010import Bio .PDB
11- from lightdock .constants import CLUSTER_ANALYSIS_FILE , DEFAULT_CLUSTER_FOLDER , DEFAULT_RMSD_EXTENSION , \
11+ from lightdock .constants import CLUSTER_ANALYSIS_FILE , DEFAULT_SWARM_FOLDER , DEFAULT_RMSD_EXTENSION , \
1212 NUMPY_FILE_SAVE_EXTENSION , EVALUATION_FILE , SCORING_FILE , GSO_OUTPUT_FILE , LIGHTDOCK_PDB_FILE , \
1313 CLUSTER_DEFAULT_NAME , CLUSTER_REPRESENTATIVES_FILE
1414from lightdock .util .logger import LoggingManager
15- from lightdock .util .analysis import read_rmsd_and_contacts_data ,\
16- read_lightdock_output
15+ from lightdock .util .analysis import read_rmsd_and_contacts_data , read_lightdock_output
1716
1817
19- log = LoggingManager .get_logger ('cluster_hierarchical' )
18+ log = LoggingManager .get_logger ('lgd_cluster_hierarchical' )
19+
2020
2121POPULATION_THRESHOLD = 10
2222
@@ -27,7 +27,7 @@ def parse_command_line():
2727 """
2828 parser = argparse .ArgumentParser (prog = 'cluster_poses' )
2929
30- parser .add_argument ("cluster_id " , help = "cluster to consider" , type = int , metavar = "cluster_id " )
30+ parser .add_argument ("swarm_id " , help = "swarm to consider for clustering " , type = int , metavar = "swarm_id " )
3131 parser .add_argument ("steps" , help = "steps to consider" , type = int , metavar = "steps" )
3232 parser .add_argument ("-f" , "--file_name" , help = "lightdock output file to consider" , dest = "result_file" )
3333 parser .add_argument ("-p" , "--ponderated" , help = "Structures selection takes into account cluster population" ,
@@ -38,7 +38,7 @@ def parse_command_line():
3838 return parser .parse_args ()
3939
4040
41- def calculate_inter_rmsd (cluster_id ):
41+ def calculate_inter_rmsd (swarm_id ):
4242 N = len (solutions )
4343 distances = np .zeros ((N , N ))
4444 indexes = np .triu_indices (N )
@@ -48,7 +48,7 @@ def calculate_inter_rmsd(cluster_id):
4848 ca_atoms = [[] for _ in xrange (N )]
4949 for i in range (N ):
5050 log .info ('Reading structure %d' % i )
51- structure_file = os .path .join (DEFAULT_CLUSTER_FOLDER + str (cluster_id ),
51+ structure_file = os .path .join (DEFAULT_SWARM_FOLDER + str (swarm_id ),
5252 LIGHTDOCK_PDB_FILE % i )
5353 structure = pdb_parser .get_structure ("reference" , structure_file )
5454 model = structure [0 ]
@@ -61,7 +61,7 @@ def calculate_inter_rmsd(cluster_id):
6161 super_imposer .set_atoms (ca_atoms [i ], ca_atoms [j ])
6262 distances [i ][j ] = super_imposer .rms
6363 distances [j ][i ] = distances [i ][j ]
64- numpy_file_name = os .path .join (DEFAULT_CLUSTER_FOLDER + str (cluster_id ),
64+ numpy_file_name = os .path .join (DEFAULT_SWARM_FOLDER + str (swarm_id ),
6565 CLUSTER_DEFAULT_NAME + DEFAULT_RMSD_EXTENSION )
6666 np .save (numpy_file_name , distances )
6767 log .info ('Done.' )
@@ -83,17 +83,17 @@ def stats(data):
8383 # Get contacts and rmsds
8484 contacts , rmsds = read_rmsd_and_contacts_data (EVALUATION_FILE )
8585
86- cluster_id = args .cluster_id
87- log .info ("cluster %d" % cluster_id )
86+ swarm_id = args .swarm_id
87+ log .info ("cluster %d" % swarm_id )
8888 solutions = []
8989 if args .result_file :
90- result_file_name = os .path .join (DEFAULT_CLUSTER_FOLDER + str (cluster_id ), args .result_file )
90+ result_file_name = os .path .join (DEFAULT_SWARM_FOLDER + str (swarm_id ), args .result_file )
9191 else :
92- result_file_name = os .path .join (DEFAULT_CLUSTER_FOLDER + str (cluster_id ), GSO_OUTPUT_FILE % args .steps )
93- scoring_file_name = os .path .join (DEFAULT_CLUSTER_FOLDER + str (cluster_id ), SCORING_FILE )
92+ result_file_name = os .path .join (DEFAULT_SWARM_FOLDER + str (swarm_id ), GSO_OUTPUT_FILE % args .steps )
93+ scoring_file_name = os .path .join (DEFAULT_SWARM_FOLDER + str (swarm_id ), SCORING_FILE )
9494 results = read_lightdock_output (result_file_name )
9595 for result in results :
96- result .id_cluster = cluster_id
96+ result .id_cluster = swarm_id
9797 try :
9898 result .rmsd = rmsds [result .id_cluster ][result .id_glowworm ]
9999 result .contacts = contacts [result .id_cluster ][result .id_glowworm ]
@@ -104,21 +104,21 @@ def stats(data):
104104
105105 if args .rmsd_file :
106106 log .info ('Previous RMSD matrix found. Loading...' )
107- rmsd_matrix_file = os .path .join (DEFAULT_CLUSTER_FOLDER + str (cluster_id ),
107+ rmsd_matrix_file = os .path .join (DEFAULT_SWARM_FOLDER + str (swarm_id ),
108108 CLUSTER_DEFAULT_NAME +
109109 DEFAULT_RMSD_EXTENSION + NUMPY_FILE_SAVE_EXTENSION )
110110 distances = np .load (rmsd_matrix_file )
111111 else :
112112 log .info ('Calculating RMSD distances...' )
113- distances = calculate_inter_rmsd (cluster_id )
113+ distances = calculate_inter_rmsd (swarm_id )
114114 log .info ('Done.' )
115115
116116 # Calculate clusters
117117 clusters = hier .fclusterdata (distances , distances .max (), criterion = 'maxclust' ,
118118 metric = 'euclidean' , depth = 2 , method = 'complete' )
119119
120120 # Save data
121- data_file_name = os .path .join (DEFAULT_CLUSTER_FOLDER + str (cluster_id ), CLUSTER_ANALYSIS_FILE )
121+ data_file_name = os .path .join (DEFAULT_SWARM_FOLDER + str (swarm_id ), CLUSTER_ANALYSIS_FILE )
122122 with open (data_file_name , 'w' ) as output :
123123 output .write ("Clusters found: %d" % max (clusters ) + os .linesep )
124124 output .write (os .linesep )
@@ -150,7 +150,7 @@ def stats(data):
150150 output .write ("Clashes: %s%s" % (stats ([solution .contacts for solution in cluster_solutions ]), os .linesep ))
151151 output .write (os .linesep )
152152
153- cluster_file_name = os .path .join (DEFAULT_CLUSTER_FOLDER + str (cluster_id ), CLUSTER_REPRESENTATIVES_FILE )
153+ cluster_file_name = os .path .join (DEFAULT_SWARM_FOLDER + str (swarm_id ), CLUSTER_REPRESENTATIVES_FILE )
154154 with open (cluster_file_name , 'w' ) as output :
155155 solutions_clustered = {}
156156 for id_solution , solution in enumerate (solutions ):
@@ -192,7 +192,7 @@ def stats(data):
192192 solution .pdb_file ) + os .linesep )
193193
194194
195- log .info ("Cluster: %d" % args .cluster_id )
195+ log .info ("Cluster: %d" % args .swarm_id )
196196 log .info ("Number of steps: %d" % args .steps )
197197 log .info ("Done." )
198198
0 commit comments