2 from __future__
import print_function
5 from IMP
import ArgumentParser
8 __doc__ =
"List/extract good-scoring models from a set of sampling runs."""
11 parser = ArgumentParser(description="List and extract good-scoring models from a set of sampling runs. Example of usage: %(prog)s -rd <run_directory_for_sampling> -rp <run_prefix> -sl ExcludedVolumeSphere_None GaussianEMRestraint_None -pl CrossLinkingMassSpectrometryDataScore|XLDSS CrossLinkingMassSpectrometryDataScore|XLEDC -agl -9999999.0 -99999.0 -aul 99999999.0 999999.0 -mlt 0 0 -mut 0 0. Flag -h for more details.")
13 parser.add_argument("-rd", "--run_directory", dest="run_dir",
14 help="directory in which sampling results are stored",
17 parser.add_argument("-rp", "--run_prefix", dest="run_prefix",
18 help="prefix of runs", required=True)
20 parser.add_argument("-sl","--selection_keywords_list",nargs='+',type=str,dest="selection_keywords_list",help="list of stat file keywords corresponding to selection criteria")
21 parser.add_argument("-pl","--printing_keywords_list",nargs='+',type=str,dest="printing_keywords_list",help="list of stat file keywords whose values are printed out for selected models")
23 # thresholds only apply to selection keywords
24 parser.add_argument("-alt","--aggregate_lower_thresholds",nargs='+',type=float,dest="aggregate_lower_thresholds",help="aggregate lower thresholds")
25 parser.add_argument("-aut","--aggregate_upper_thresholds",nargs='+',type=float,dest="aggregate_upper_thresholds",help="aggregate upper thresholds")
26 parser.add_argument("-mlt","--member_lower_thresholds",nargs='+',type=float,dest="member_lower_thresholds",help="member lower thresholds")
27 parser.add_argument("-mut","--member_upper_thresholds",nargs='+',type=float,dest="member_upper_thresholds",help="member upper thresholds")
29 parser.add_argument("-e","--extract",default=False,dest="extract",action='store_true',help="Type -e to extract all good scoring model RMFs from the trajectory files")
30 parser.add_argument("-sf","--score_file",default="scores", type=str, dest="score_file_prefix",help="Score file prefix for samples A and B. Default is %(default)r")
31 result = parser.parse_args()
35 def select_good_scoring_models():
36 from IMP.sampcon.good_scoring_model_selector import GoodScoringModelSelector
41 gsms=GoodScoringModelSelector(arg.run_dir,arg.run_prefix)
43 subsets = gsms.get_good_scoring_models(selection_keywords_list=arg.selection_keywords_list,printing_keywords_list=arg.printing_keywords_list,
44 aggregate_lower_thresholds=arg.aggregate_lower_thresholds,aggregate_upper_thresholds=arg.aggregate_upper_thresholds,
45 member_lower_thresholds=arg.member_lower_thresholds,member_upper_thresholds=arg.member_upper_thresholds,extract=arg.extract)
48 def create_score_files(subsets, field="Total_Score"):
50 score_dir = os.path.join(arg.run_dir,
51 "good_scoring_models" if arg.extract else "filter")
52 scoreA = open(os.path.join(score_dir, arg.score_file_prefix + "A.txt"), "w")
53 scoreB = open(os.path.join(score_dir, arg.score_file_prefix + "B.txt"), "w")
54 model_file = open(os.path.join(score_dir, "model_ids_scores.txt"), "r")
56 print("Creating input files for Total_Score convergence test")
58 for line_index,each_model_line
in enumerate(model_file.readlines()):
62 field_headers = each_model_line.strip().split()
63 ts_ix = field_headers.index(field)
64 run_ix = field_headers.index(
"Run_id")
65 model_ix = field_headers.index(
"Model_index")
69 fields = each_model_line.strip().split()
72 model = int(fields[model_ix])
73 print(score, file=scoreA
if model
in subsets[0]
else scoreB)
75 if int(fields[run_ix])==1:
76 print(score, file=scoreA)
77 elif int(fields[run_ix])==2:
78 print(score, file=scoreB)
80 print(
"create_scores_file: model_ids_scores.txt file has an incorrect format.")
88 subsets = select_good_scoring_models()
91 create_score_files(subsets)
93 print(
"Ready to calculate sampling precision with Master_Sampling_Exhaustiveness_Analysis.py")
96 if __name__ ==
"__main__":