@@ -56,24 +56,51 @@ def mav_cli_generator(arg, k_val):
5656 return cli , output_dir
5757
5858
59- def mav_params_parser (parameter_filename ):
59+ def mav_ti_in_use (parameter_filename ):
6060 """
61- Parses MavericK's parameter file and switches some options if necessary .
61+ Checks if TI is in use. Returns True or Flase .
6262 """
63- param_file = open (parameter_filename , "r" )
63+ parsed_data = mav_params_parser (parameter_filename ,
64+ ("thermodynamic_on" ,))
65+
6466 use_ti = True
67+ if parsed_data ["thermodynamic_on" ] in ("f" , "false" , "0" ):
68+ use_ti = False
69+ logging .error ("Thermodynamic integration is turned OFF. "
70+ "Using STRUCTURE criteria for bestK estimation." )
71+ elif not parsed_data :
72+ logging .error ("The parameter setting Thermodynamic integration was not "
73+ "found. Assuming the default 'on' value." )
74+
75+ return use_ti
76+
77+
78+ def mav_params_parser (parameter_filename , query ):
79+ """
80+ Parses MavericK's parameter file and returns the results in a dict.
81+ Returns "None" if no matches are found.
82+ """
83+ # Add a "\t" at the end of each string to avoid finding partial strings
84+ # such as "alpha" and "alphaPropSD".
85+ sane_query = tuple ((x + '\t ' for x in query ))
86+ print (sane_query )
87+
88+ param_file = open (parameter_filename , "r" )
89+ result = {}
90+
6591 for lines in param_file :
66- if lines .startswith ("thermodynamic_on" ):
67- ti_status = lines .split ()[1 ].lower ()
68- if ti_status in ("f" , "false" , "0" ):
69- use_ti = False
70- logging .error ("Thermodynamic integration is turned OFF. "
71- "Using STRUCTURE criteria for bestK estimation." )
72- break
92+ if lines .startswith (sane_query ):
93+ lines = lines .split ()
94+ result [lines [0 ]] = lines [1 ]
7395
7496 param_file .close ()
7597
76- return use_ti
98+ if result == {}:
99+ logging .error ("Failed to find the parameter(s) '%s'. Please verify the "
100+ "parameter file, or the run options." , query )
101+ result = None
102+ else :
103+ return result
77104
78105
79106def mav_alpha_failsafe (parameter_filename , k_list ):
@@ -85,19 +112,23 @@ def mav_alpha_failsafe(parameter_filename, k_list):
85112 If the paramterer values are a single value, False is returned:
86113 {paramter: False, parameter: {k: paran_value}}
87114 """
88- parsed_data = {}
89- sorted_data = {"alpha" : False , "alphaPropSD" : False }
115+ parameters = ("alpha" , "alphaPropSD" )
90116
91- param_file = open (parameter_filename , "r" )
92- for lines in param_file :
93- if lines .lower ().startswith ("alpha\t " ):
94- parsed_data ["alpha" ] = lines .split ()[1 ].split ("," )
95- elif lines .lower ().startswith ("alphapropsd\t " ):
96- parsed_data ["alphaPropSD" ] = lines .split ()[1 ].split ("," )
117+ sorted_data = {x : False for x in parameters }
97118
98- param_file .close ()
119+ # param_file = open(parameter_filename, "r")
120+ # for lines in param_file:
121+ # if lines.lower().startswith("alpha\t"):
122+ # parsed_data["alpha"] = lines.split()[1].split(",")
123+ # elif lines.lower().startswith("alphapropsd\t"):
124+ # parsed_data["alphaPropSD"] = lines.split()[1].split(",")
125+ #
126+ # param_file.close()
127+
128+ parsed_data = mav_params_parser (parameter_filename , parameters )
99129
100130 for param , val in parsed_data .items ():
131+ val = val .split ("," )
101132 if len (val ) > 1 :
102133 if len (val ) != len (k_list ):
103134 logging .fatal ("The number of values provided for the %s "
@@ -115,6 +146,8 @@ def mav_alpha_failsafe(parameter_filename, k_list):
115146def maverick_merger (outdir , k_list , params , no_tests ):
116147 """
117148 Grabs the split outputs from MavericK and merges them in a single directory.
149+ Also uses the data from these file to generate an
150+ "outputEvidenceNormalized.csv" file.
118151 """
119152 files_list = ["outputEvidence.csv" , "outputEvidenceDetails.csv" ]
120153 mrg_res_dir = os .path .join (outdir , "merged" )
@@ -152,7 +185,7 @@ def _ti_test(outdir, log_evidence_mv):
152185
153186 for filename in files_list :
154187 header = True
155- if mav_params_parser (params ) is True :
188+ if mav_ti_in_use (params ) is True :
156189 column_num = - 2
157190 else :
158191 column_num = - 4
0 commit comments